diff --git a/CHANGELOG.md b/CHANGELOG.md index 4c7e7926db6..5cd31018032 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -63,6 +63,11 @@ This release uses the API version `2026-01-28.preview`. * Add support for `url` on `financialconnections.Session` * Add support for `billingCycleAnchor` on `SubscriptionCreateParams.trial_settings.end_behavior` and `SubscriptionUpdateParams.trial_settings.end_behavior` +## 31.4.1 - 2026-03-06 +* [#2168](https://github.com/stripe/stripe-java/pull/2168) Support serializing Stripe objects with ApiResource.GSON + * `ApiResource.GSON` now supports serializing Stripe objects back into compatible JSON +* [#2165](https://github.com/stripe/stripe-java/pull/2165) Add AI Agent information to UserAgent + ## 31.4.0 - 2026-02-25 This release changes the pinned API version to `2026-02-25.clover`. diff --git a/CODEGEN_VERSION b/CODEGEN_VERSION index b7a4b42e31e..6d8155ee2e3 100644 --- a/CODEGEN_VERSION +++ b/CODEGEN_VERSION @@ -1 +1 @@ -49b1e23eef1a5004ed00987c41d5ec8447a19e27 \ No newline at end of file +6dded749243c6d0c16f48c648aa32d13cb66c439 \ No newline at end of file diff --git a/OPENAPI_VERSION b/OPENAPI_VERSION index 4c2310759e9..466b261db46 100644 --- a/OPENAPI_VERSION +++ b/OPENAPI_VERSION @@ -1 +1 @@ -v2189 \ No newline at end of file +v2190 \ No newline at end of file diff --git a/src/main/java/com/stripe/model/BalanceTransaction.java b/src/main/java/com/stripe/model/BalanceTransaction.java index 13729aef1d4..680e512266a 100644 --- a/src/main/java/com/stripe/model/BalanceTransaction.java +++ b/src/main/java/com/stripe/model/BalanceTransaction.java @@ -43,8 +43,8 @@ public class BalanceTransaction extends ApiResource implements HasId { /** * The balance that this transaction impacts. * - *

One of {@code issuing}, {@code payments}, {@code refund_and_dispute_prefunding}, {@code - * risk_reserved}, or {@code transit}. + *

One of {@code fee_credits}, {@code issuing}, {@code payments}, {@code + * refund_and_dispute_prefunding}, {@code risk_reserved}, or {@code transit}. */ @SerializedName("balance_type") String balanceType; diff --git a/src/main/java/com/stripe/model/BalanceTransactionSourceTypeAdapterFactory.java b/src/main/java/com/stripe/model/BalanceTransactionSourceTypeAdapterFactory.java index 29e3c7c60be..fc84822c515 100644 --- a/src/main/java/com/stripe/model/BalanceTransactionSourceTypeAdapterFactory.java +++ b/src/main/java/com/stripe/model/BalanceTransactionSourceTypeAdapterFactory.java @@ -25,9 +25,6 @@ public TypeAdapter create(Gson gson, TypeToken type) { } final String discriminator = "object"; final TypeAdapter jsonElementAdapter = gson.getAdapter(JsonElement.class); - final TypeAdapter balanceTransactionSourceAdapter = - gson.getDelegateAdapter( - this, TypeToken.get(com.stripe.model.BalanceTransactionSource.class)); final TypeAdapter applicationFeeAdapter = gson.getDelegateAdapter(this, TypeToken.get(com.stripe.model.ApplicationFee.class)); final TypeAdapter chargeAdapter = @@ -68,7 +65,13 @@ public TypeAdapter create(Gson gson, TypeToken type) { new TypeAdapter() { @Override public void write(JsonWriter out, BalanceTransactionSource value) throws IOException { - balanceTransactionSourceAdapter.write(out, value); + @SuppressWarnings("unchecked") + TypeAdapter adapter = + (TypeAdapter) + gson.getDelegateAdapter( + BalanceTransactionSourceTypeAdapterFactory.this, + TypeToken.get(value.getClass())); + adapter.write(out, value); } @Override diff --git a/src/main/java/com/stripe/model/Dispute.java b/src/main/java/com/stripe/model/Dispute.java index f5960a8e47b..0e5ce2f3852 100644 --- a/src/main/java/com/stripe/model/Dispute.java +++ b/src/main/java/com/stripe/model/Dispute.java @@ -38,6 +38,14 @@ public class Dispute extends ApiResource @SerializedName("amount") Long amount; + /** + * The amount you want to contest, in the dispute's currency. Setting this to less than the full + * dispute amount means accepting the loss on the remaining amount. If not specified, the entire + * disputed amount is contested. + */ + @SerializedName("amount_to_counter") + Long amountToCounter; + /** * List of zero, one, or two balance transactions that show funds withdrawn and reinstated to your * Stripe account as a result of this dispute. diff --git a/src/main/java/com/stripe/model/EventDataClassLookup.java b/src/main/java/com/stripe/model/EventDataClassLookup.java index c9e3ac98d0c..1c9f829a554 100644 --- a/src/main/java/com/stripe/model/EventDataClassLookup.java +++ b/src/main/java/com/stripe/model/EventDataClassLookup.java @@ -226,6 +226,9 @@ public final class EventDataClassLookup { classLookup.put("radar.account_evaluation", com.stripe.model.radar.AccountEvaluation.class); classLookup.put("radar.early_fraud_warning", com.stripe.model.radar.EarlyFraudWarning.class); + classLookup.put( + "radar.issuing_authorization_evaluation", + com.stripe.model.radar.IssuingAuthorizationEvaluation.class); classLookup.put("radar.payment_evaluation", com.stripe.model.radar.PaymentEvaluation.class); classLookup.put("radar.value_list", com.stripe.model.radar.ValueList.class); classLookup.put("radar.value_list_item", com.stripe.model.radar.ValueListItem.class); diff --git a/src/main/java/com/stripe/model/ExternalAccountTypeAdapterFactory.java b/src/main/java/com/stripe/model/ExternalAccountTypeAdapterFactory.java index 1d24a1d21a3..a4c99067782 100644 --- a/src/main/java/com/stripe/model/ExternalAccountTypeAdapterFactory.java +++ b/src/main/java/com/stripe/model/ExternalAccountTypeAdapterFactory.java @@ -28,8 +28,6 @@ public TypeAdapter create(Gson gson, TypeToken type) { } final String discriminator = "object"; final TypeAdapter jsonElementAdapter = gson.getAdapter(JsonElement.class); - final TypeAdapter externalAccountAdapter = - gson.getDelegateAdapter(this, TypeToken.get(com.stripe.model.ExternalAccount.class)); final TypeAdapter bankAccountAdapter = gson.getDelegateAdapter(this, TypeToken.get(com.stripe.model.BankAccount.class)); final TypeAdapter cardAdapter = @@ -39,7 +37,12 @@ public TypeAdapter create(Gson gson, TypeToken type) { new TypeAdapter() { @Override public void write(JsonWriter out, ExternalAccount value) throws IOException { - externalAccountAdapter.write(out, value); + @SuppressWarnings("unchecked") + TypeAdapter adapter = + (TypeAdapter) + gson.getDelegateAdapter( + ExternalAccountTypeAdapterFactory.this, TypeToken.get(value.getClass())); + adapter.write(out, value); } @Override diff --git a/src/main/java/com/stripe/model/InvoiceItem.java b/src/main/java/com/stripe/model/InvoiceItem.java index 07d637d87e4..48a0846804f 100644 --- a/src/main/java/com/stripe/model/InvoiceItem.java +++ b/src/main/java/com/stripe/model/InvoiceItem.java @@ -92,6 +92,13 @@ public class InvoiceItem extends ApiResource implements HasId, MetadataStore> discounts; + /** + * Array of field names that can't be modified. Attempting to update a frozen field returns an + * error. + */ + @SerializedName("frozen_fields") + List frozenFields; + /** Unique identifier for the object. */ @Getter(onMethod_ = {@Override}) @SerializedName("id") diff --git a/src/main/java/com/stripe/model/PaymentSourceTypeAdapterFactory.java b/src/main/java/com/stripe/model/PaymentSourceTypeAdapterFactory.java index 309770b166e..59a32b6884f 100644 --- a/src/main/java/com/stripe/model/PaymentSourceTypeAdapterFactory.java +++ b/src/main/java/com/stripe/model/PaymentSourceTypeAdapterFactory.java @@ -25,8 +25,6 @@ public TypeAdapter create(Gson gson, TypeToken type) { } final String discriminator = "object"; final TypeAdapter jsonElementAdapter = gson.getAdapter(JsonElement.class); - final TypeAdapter paymentSourceAdapter = - gson.getDelegateAdapter(this, TypeToken.get(com.stripe.model.PaymentSource.class)); final TypeAdapter accountAdapter = gson.getDelegateAdapter(this, TypeToken.get(com.stripe.model.Account.class)); final TypeAdapter bankAccountAdapter = @@ -40,7 +38,12 @@ public TypeAdapter create(Gson gson, TypeToken type) { new TypeAdapter() { @Override public void write(JsonWriter out, PaymentSource value) throws IOException { - paymentSourceAdapter.write(out, value); + @SuppressWarnings("unchecked") + TypeAdapter adapter = + (TypeAdapter) + gson.getDelegateAdapter( + PaymentSourceTypeAdapterFactory.this, TypeToken.get(value.getClass())); + adapter.write(out, value); } @Override diff --git a/src/main/java/com/stripe/model/StripeRawJsonObjectSerializer.java b/src/main/java/com/stripe/model/StripeRawJsonObjectSerializer.java new file mode 100644 index 00000000000..b72548746d6 --- /dev/null +++ b/src/main/java/com/stripe/model/StripeRawJsonObjectSerializer.java @@ -0,0 +1,18 @@ +package com.stripe.model; + +import com.google.gson.JsonElement; +import com.google.gson.JsonNull; +import com.google.gson.JsonSerializationContext; +import com.google.gson.JsonSerializer; +import java.lang.reflect.Type; + +public class StripeRawJsonObjectSerializer implements JsonSerializer { + @Override + public JsonElement serialize( + StripeRawJsonObject src, Type typeOfSrc, JsonSerializationContext context) { + if (src.json != null) { + return src.json; + } + return JsonNull.INSTANCE; + } +} diff --git a/src/main/java/com/stripe/model/radar/IssuingAuthorizationEvaluation.java b/src/main/java/com/stripe/model/radar/IssuingAuthorizationEvaluation.java new file mode 100644 index 00000000000..0464af5bbb1 --- /dev/null +++ b/src/main/java/com/stripe/model/radar/IssuingAuthorizationEvaluation.java @@ -0,0 +1,384 @@ +// File generated from our OpenAPI spec +package com.stripe.model.radar; + +import com.google.gson.annotations.SerializedName; +import com.stripe.exception.StripeException; +import com.stripe.model.HasId; +import com.stripe.model.StripeObject; +import com.stripe.net.ApiRequest; +import com.stripe.net.ApiRequestParams; +import com.stripe.net.ApiResource; +import com.stripe.net.BaseAddress; +import com.stripe.net.RequestOptions; +import com.stripe.net.StripeResponseGetter; +import com.stripe.param.radar.IssuingAuthorizationEvaluationCreateParams; +import java.math.BigDecimal; +import java.util.Map; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.Setter; + +/** + * Authorization Evaluations represent fraud risk assessments for Issuing card authorizations. They + * include fraud risk signals and contextual details about the authorization. + */ +@Getter +@Setter +@EqualsAndHashCode(callSuper = false) +public class IssuingAuthorizationEvaluation extends ApiResource implements HasId { + /** Details about the authorization transaction. */ + @SerializedName("authorization_details") + AuthorizationDetails authorizationDetails; + + /** Details about the card used in the authorization. */ + @SerializedName("card_details") + CardDetails cardDetails; + + /** Details about the cardholder. */ + @SerializedName("cardholder_details") + CardholderDetails cardholderDetails; + + /** Unique identifier for the object. */ + @Getter(onMethod_ = {@Override}) + @SerializedName("id") + String id; + + /** + * If the object exists in live mode, the value is {@code true}. If the object exists in test + * mode, the value is {@code false}. + */ + @SerializedName("livemode") + Boolean livemode; + + /** Details about the merchant where the authorization occurred. */ + @SerializedName("merchant_details") + MerchantDetails merchantDetails; + + /** + * Set of key-value pairs that you can attach to an object. This can be useful for storing + * additional information about the object in a structured format. + */ + @SerializedName("metadata") + Map metadata; + + /** Details about the card network processing. */ + @SerializedName("network_details") + NetworkDetails networkDetails; + + /** + * String representing the object's type. Objects of the same type share the same value. + * + *

Equal to {@code radar.issuing_authorization_evaluation}. + */ + @SerializedName("object") + String object; + + /** Collection of fraud risk signals for this authorization evaluation. */ + @SerializedName("signals") + Signals signals; + + /** Details about the token, if a tokenized payment method was used. */ + @SerializedName("token_details") + TokenDetails tokenDetails; + + /** Details about verification checks performed. */ + @SerializedName("verification_details") + VerificationDetails verificationDetails; + + /** Request a fraud risk assessment from Stripe for an Issuing card authorization. */ + public static IssuingAuthorizationEvaluation create(Map params) + throws StripeException { + return create(params, (RequestOptions) null); + } + + /** Request a fraud risk assessment from Stripe for an Issuing card authorization. */ + public static IssuingAuthorizationEvaluation create( + Map params, RequestOptions options) throws StripeException { + String path = "/v1/radar/issuing_authorization_evaluations"; + ApiRequest request = + new ApiRequest(BaseAddress.API, ApiResource.RequestMethod.POST, path, params, options); + return getGlobalResponseGetter().request(request, IssuingAuthorizationEvaluation.class); + } + + /** Request a fraud risk assessment from Stripe for an Issuing card authorization. */ + public static IssuingAuthorizationEvaluation create( + IssuingAuthorizationEvaluationCreateParams params) throws StripeException { + return create(params, (RequestOptions) null); + } + + /** Request a fraud risk assessment from Stripe for an Issuing card authorization. */ + public static IssuingAuthorizationEvaluation create( + IssuingAuthorizationEvaluationCreateParams params, RequestOptions options) + throws StripeException { + String path = "/v1/radar/issuing_authorization_evaluations"; + ApiResource.checkNullTypedParams(path, params); + ApiRequest request = + new ApiRequest( + BaseAddress.API, + ApiResource.RequestMethod.POST, + path, + ApiRequestParams.paramsToMap(params), + options); + return getGlobalResponseGetter().request(request, IssuingAuthorizationEvaluation.class); + } + + /** Details about the authorization transaction. */ + @Getter + @Setter + @EqualsAndHashCode(callSuper = false) + public static class AuthorizationDetails extends StripeObject { + /** The authorization amount in the smallest currency unit. */ + @SerializedName("amount") + Long amount; + + /** + * The method used for authorization. + * + *

One of {@code chip}, {@code contactless}, {@code keyed_in}, {@code online}, or {@code + * swipe}. + */ + @SerializedName("authorization_method") + String authorizationMethod; + + /** Three-letter ISO currency code in lowercase. */ + @SerializedName("currency") + String currency; + + /** + * The card entry mode. + * + *

One of {@code contactless}, {@code contactless_magstripe}, {@code credential_on_file}, + * {@code integrated_circuit_card}, {@code magstripe}, {@code magstripe_no_cvv}, {@code manual}, + * {@code other}, or {@code unknown}. + */ + @SerializedName("entry_mode") + String entryMode; + + /** The raw code for the card entry mode. */ + @SerializedName("entry_mode_raw_code") + String entryModeRawCode; + + /** The time when the authorization was initiated. */ + @SerializedName("initiated_at") + Long initiatedAt; + + /** + * The point of sale condition. + * + *

One of {@code account_verification}, {@code card_not_present}, {@code card_present}, + * {@code e_commerce}, {@code key_entered_pos}, {@code missing}, {@code moto}, {@code other}, + * {@code pin_entered}, or {@code recurring}. + */ + @SerializedName("point_of_sale_condition") + String pointOfSaleCondition; + + /** The raw code for the point of sale condition. */ + @SerializedName("point_of_sale_condition_raw_code") + String pointOfSaleConditionRawCode; + + /** External reference for the authorization. */ + @SerializedName("reference") + String reference; + } + + /** Details about the card used in the authorization. */ + @Getter + @Setter + @EqualsAndHashCode(callSuper = false) + public static class CardDetails extends StripeObject { + /** The Bank Identification Number (BIN) of the card. */ + @SerializedName("bin") + String bin; + + /** The country code associated with the card BIN. */ + @SerializedName("bin_country") + String binCountry; + + /** + * The type of card (physical or virtual). + * + *

One of {@code physical}, or {@code virtual}. + */ + @SerializedName("card_type") + String cardType; + + /** The time when the card was created. */ + @SerializedName("created_at") + Long createdAt; + + /** The last 4 digits of the card number. */ + @SerializedName("last4") + String last4; + + /** External reference for the card. */ + @SerializedName("reference") + String reference; + } + + /** Details about the cardholder. */ + @Getter + @Setter + @EqualsAndHashCode(callSuper = false) + public static class CardholderDetails extends StripeObject { + /** The time when the cardholder was created. */ + @SerializedName("created_at") + Long createdAt; + + /** External reference for the cardholder. */ + @SerializedName("reference") + String reference; + } + + /** Details about the merchant where the authorization occurred. */ + @Getter + @Setter + @EqualsAndHashCode(callSuper = false) + public static class MerchantDetails extends StripeObject { + /** The merchant category code (MCC). */ + @SerializedName("category_code") + String categoryCode; + + /** The merchant country code. */ + @SerializedName("country") + String country; + + /** The merchant name. */ + @SerializedName("name") + String name; + + /** The merchant identifier from the card network. */ + @SerializedName("network_id") + String networkId; + + /** The terminal identifier. */ + @SerializedName("terminal_id") + String terminalId; + } + + /** Details about the card network processing. */ + @Getter + @Setter + @EqualsAndHashCode(callSuper = false) + public static class NetworkDetails extends StripeObject { + /** The acquiring institution identifier. */ + @SerializedName("acquiring_institution_id") + String acquiringInstitutionId; + + /** + * The card network that processed the authorization. + * + *

One of {@code cirrus}, {@code interlink}, {@code maestro}, {@code mastercard}, {@code + * other}, {@code plus}, or {@code visa}. + */ + @SerializedName("routed_network") + String routedNetwork; + } + + /** Collection of fraud risk signals for this authorization evaluation. */ + @Getter + @Setter + @EqualsAndHashCode(callSuper = false) + public static class Signals extends StripeObject { + /** A fraud risk signal with status, error, and data fields. */ + @SerializedName("fraud_risk") + FraudRisk fraudRisk; + + /** A fraud risk signal with status, error, and data fields. */ + @Getter + @Setter + @EqualsAndHashCode(callSuper = false) + public static class FraudRisk extends StripeObject { + /** Signal evaluation data, including score and level. */ + @SerializedName("data") + Data data; + + /** Details of an error that prevented reporting this signal. */ + @SerializedName("error") + Map error; + + /** + * The status of this signal. + * + *

One of {@code error}, or {@code success}. + */ + @SerializedName("status") + String status; + + /** The signal's data payload, available upon a successful signal evaluation. */ + @Getter + @Setter + @EqualsAndHashCode(callSuper = false) + public static class Data extends StripeObject { + /** The time when this signal was evaluated. */ + @SerializedName("evaluated_at") + Long evaluatedAt; + + /** + * Risk level, based on the score. + * + *

One of {@code elevated}, {@code highest}, {@code low}, {@code normal}, {@code + * not_assessed}, or {@code unknown}. + */ + @SerializedName("level") + String level; + + /** + * Fraud risk score for this evaluation. Score in the range [0,100], formatted as a 2 + * decimal float, with higher scores indicating a higher likelihood of fraud. + */ + @SerializedName("score") + BigDecimal score; + } + } + } + + /** Details about the token, if a tokenized payment method was used. */ + @Getter + @Setter + @EqualsAndHashCode(callSuper = false) + public static class TokenDetails extends StripeObject { + /** The time when the token was created. */ + @SerializedName("created_at") + Long createdAt; + + /** External reference for the token. */ + @SerializedName("reference") + String reference; + + /** + * The wallet provider, if applicable. + * + *

One of {@code apple_pay}, {@code google_pay}, or {@code samsung_pay}. + */ + @SerializedName("wallet") + String wallet; + } + + /** Details about verification checks performed. */ + @Getter + @Setter + @EqualsAndHashCode(callSuper = false) + public static class VerificationDetails extends StripeObject { + /** + * The result of the 3D Secure verification. + * + *

One of {@code attempt_acknowledged}, {@code authenticated}, {@code exempted}, {@code + * failed}, or {@code required}. + */ + @SerializedName("three_d_secure_result") + String threeDSecureResult; + } + + @Override + public void setResponseGetter(StripeResponseGetter responseGetter) { + super.setResponseGetter(responseGetter); + trySetResponseGetter(authorizationDetails, responseGetter); + trySetResponseGetter(cardDetails, responseGetter); + trySetResponseGetter(cardholderDetails, responseGetter); + trySetResponseGetter(merchantDetails, responseGetter); + trySetResponseGetter(networkDetails, responseGetter); + trySetResponseGetter(signals, responseGetter); + trySetResponseGetter(tokenDetails, responseGetter); + trySetResponseGetter(verificationDetails, responseGetter); + } +} diff --git a/src/main/java/com/stripe/model/v2/core/Event.java b/src/main/java/com/stripe/model/v2/core/Event.java index c19c433c879..ecc2fc1e21d 100644 --- a/src/main/java/com/stripe/model/v2/core/Event.java +++ b/src/main/java/com/stripe/model/v2/core/Event.java @@ -98,12 +98,15 @@ protected StripeObject fetchRelatedObject(RelatedObject relatedObject) throws St objectClass = StripeRawJsonObject.class; } - RequestOptions opts = null; + RequestOptions.RequestOptionsBuilder optsBuilder = new RequestOptions.RequestOptionsBuilder(); + // optsBuilder.setStripeRequestTrigger("event=" + id); // TODO https://go/j/DEVSDK-3018 if (context != null) { - opts = new RequestOptions.RequestOptionsBuilder().setStripeAccount(context).build(); + optsBuilder.setStripeAccount(context); } + RequestOptions opts = optsBuilder.build(); + return this.responseGetter.request( new ApiRequest( BaseAddress.API, ApiResource.RequestMethod.GET, relatedObject.getUrl(), null, opts), diff --git a/src/main/java/com/stripe/net/ApiResource.java b/src/main/java/com/stripe/net/ApiResource.java index d23ce045463..8f6abb033a0 100644 --- a/src/main/java/com/stripe/net/ApiResource.java +++ b/src/main/java/com/stripe/net/ApiResource.java @@ -57,9 +57,11 @@ private static Gson createGson(boolean shouldSetResponseGetter) { .registerTypeAdapter(Event.Request.class, new EventRequestDeserializer()) .registerTypeAdapter(StripeContext.class, new StripeContextDeserializer()) .registerTypeAdapter(ExpandableField.class, new ExpandableFieldDeserializer()) + .registerTypeAdapter(ExpandableField.class, new ExpandableFieldSerializer()) .registerTypeAdapter(Instant.class, new InstantDeserializer()) .registerTypeAdapterFactory(new EventTypeAdapterFactory()) .registerTypeAdapter(StripeRawJsonObject.class, new StripeRawJsonObjectDeserializer()) + .registerTypeAdapter(StripeRawJsonObject.class, new StripeRawJsonObjectSerializer()) .registerTypeAdapterFactory(new StripeCollectionItemTypeSettingFactory()) .addReflectionAccessFilter( new ReflectionAccessFilter() { diff --git a/src/main/java/com/stripe/net/HttpClient.java b/src/main/java/com/stripe/net/HttpClient.java index ebbae9e9842..60c5f3e607b 100644 --- a/src/main/java/com/stripe/net/HttpClient.java +++ b/src/main/java/com/stripe/net/HttpClient.java @@ -144,13 +144,18 @@ static String detectAIAgent() { static String detectAIAgent(Function getEnv) { String[][] agents = { + // The beginning of the section generated from our OpenAPI spec {"ANTIGRAVITY_CLI_ALIAS", "antigravity"}, {"CLAUDECODE", "claude_code"}, {"CLINE_ACTIVE", "cline"}, {"CODEX_SANDBOX", "codex_cli"}, + {"CODEX_THREAD_ID", "codex_cli"}, + {"CODEX_SANDBOX_NETWORK_DISABLED", "codex_cli"}, + {"CODEX_CI", "codex_cli"}, {"CURSOR_AGENT", "cursor"}, {"GEMINI_CLI", "gemini_cli"}, {"OPENCODE", "open_code"}, + // The end of the section generated from our OpenAPI spec }; for (String[] agent : agents) { String val = getEnv.apply(agent[0]); diff --git a/src/main/java/com/stripe/param/delegatedcheckout/RequestedSessionConfirmParams.java b/src/main/java/com/stripe/param/delegatedcheckout/RequestedSessionConfirmParams.java index 83a2e9d5e63..d4dbbe217ed 100644 --- a/src/main/java/com/stripe/param/delegatedcheckout/RequestedSessionConfirmParams.java +++ b/src/main/java/com/stripe/param/delegatedcheckout/RequestedSessionConfirmParams.java @@ -14,8 +14,8 @@ @EqualsAndHashCode(callSuper = false) public class RequestedSessionConfirmParams extends ApiRequestParams { /** Affiliate attribution data associated with this requested session. */ - @SerializedName("affiliate_attributions") - List affiliateAttributions; + @SerializedName("affiliate_attribution") + AffiliateAttribution affiliateAttribution; /** Specifies which fields in the response should be expanded. */ @SerializedName("expand") @@ -43,13 +43,13 @@ public class RequestedSessionConfirmParams extends ApiRequestParams { RiskDetails riskDetails; private RequestedSessionConfirmParams( - List affiliateAttributions, + AffiliateAttribution affiliateAttribution, List expand, Map extraParams, String paymentMethod, PaymentMethodData paymentMethodData, RiskDetails riskDetails) { - this.affiliateAttributions = affiliateAttributions; + this.affiliateAttribution = affiliateAttribution; this.expand = expand; this.extraParams = extraParams; this.paymentMethod = paymentMethod; @@ -62,7 +62,7 @@ public static Builder builder() { } public static class Builder { - private List affiliateAttributions; + private AffiliateAttribution affiliateAttribution; private List expand; @@ -77,7 +77,7 @@ public static class Builder { /** Finalize and obtain parameter instance from this builder. */ public RequestedSessionConfirmParams build() { return new RequestedSessionConfirmParams( - this.affiliateAttributions, + this.affiliateAttribution, this.expand, this.extraParams, this.paymentMethod, @@ -85,31 +85,10 @@ public RequestedSessionConfirmParams build() { this.riskDetails); } - /** - * Add an element to `affiliateAttributions` list. A list is initialized for the first - * `add/addAll` call, and subsequent calls adds additional elements to the original list. See - * {@link RequestedSessionConfirmParams#affiliateAttributions} for the field documentation. - */ - public Builder addAffiliateAttribution( - RequestedSessionConfirmParams.AffiliateAttribution element) { - if (this.affiliateAttributions == null) { - this.affiliateAttributions = new ArrayList<>(); - } - this.affiliateAttributions.add(element); - return this; - } - - /** - * Add all elements to `affiliateAttributions` list. A list is initialized for the first - * `add/addAll` call, and subsequent calls adds additional elements to the original list. See - * {@link RequestedSessionConfirmParams#affiliateAttributions} for the field documentation. - */ - public Builder addAllAffiliateAttribution( - List elements) { - if (this.affiliateAttributions == null) { - this.affiliateAttributions = new ArrayList<>(); - } - this.affiliateAttributions.addAll(elements); + /** Affiliate attribution data associated with this requested session. */ + public Builder setAffiliateAttribution( + RequestedSessionConfirmParams.AffiliateAttribution affiliateAttribution) { + this.affiliateAttribution = affiliateAttribution; return this; } diff --git a/src/main/java/com/stripe/param/delegatedcheckout/RequestedSessionCreateParams.java b/src/main/java/com/stripe/param/delegatedcheckout/RequestedSessionCreateParams.java index 4b92f7bbfd6..359e6d847ec 100644 --- a/src/main/java/com/stripe/param/delegatedcheckout/RequestedSessionCreateParams.java +++ b/src/main/java/com/stripe/param/delegatedcheckout/RequestedSessionCreateParams.java @@ -14,8 +14,8 @@ @EqualsAndHashCode(callSuper = false) public class RequestedSessionCreateParams extends ApiRequestParams { /** Affiliate attribution data associated with this requested session. */ - @SerializedName("affiliate_attributions") - List affiliateAttributions; + @SerializedName("affiliate_attribution") + AffiliateAttribution affiliateAttribution; /** Required. The currency for this requested session. */ @SerializedName("currency") @@ -71,7 +71,7 @@ public class RequestedSessionCreateParams extends ApiRequestParams { Map sharedMetadata; private RequestedSessionCreateParams( - List affiliateAttributions, + AffiliateAttribution affiliateAttribution, String currency, String customer, List expand, @@ -84,7 +84,7 @@ private RequestedSessionCreateParams( SellerDetails sellerDetails, SetupFutureUsage setupFutureUsage, Map sharedMetadata) { - this.affiliateAttributions = affiliateAttributions; + this.affiliateAttribution = affiliateAttribution; this.currency = currency; this.customer = customer; this.expand = expand; @@ -104,7 +104,7 @@ public static Builder builder() { } public static class Builder { - private List affiliateAttributions; + private AffiliateAttribution affiliateAttribution; private String currency; @@ -133,7 +133,7 @@ public static class Builder { /** Finalize and obtain parameter instance from this builder. */ public RequestedSessionCreateParams build() { return new RequestedSessionCreateParams( - this.affiliateAttributions, + this.affiliateAttribution, this.currency, this.customer, this.expand, @@ -148,31 +148,10 @@ public RequestedSessionCreateParams build() { this.sharedMetadata); } - /** - * Add an element to `affiliateAttributions` list. A list is initialized for the first - * `add/addAll` call, and subsequent calls adds additional elements to the original list. See - * {@link RequestedSessionCreateParams#affiliateAttributions} for the field documentation. - */ - public Builder addAffiliateAttribution( - RequestedSessionCreateParams.AffiliateAttribution element) { - if (this.affiliateAttributions == null) { - this.affiliateAttributions = new ArrayList<>(); - } - this.affiliateAttributions.add(element); - return this; - } - - /** - * Add all elements to `affiliateAttributions` list. A list is initialized for the first - * `add/addAll` call, and subsequent calls adds additional elements to the original list. See - * {@link RequestedSessionCreateParams#affiliateAttributions} for the field documentation. - */ - public Builder addAllAffiliateAttribution( - List elements) { - if (this.affiliateAttributions == null) { - this.affiliateAttributions = new ArrayList<>(); - } - this.affiliateAttributions.addAll(elements); + /** Affiliate attribution data associated with this requested session. */ + public Builder setAffiliateAttribution( + RequestedSessionCreateParams.AffiliateAttribution affiliateAttribution) { + this.affiliateAttribution = affiliateAttribution; return this; } diff --git a/src/main/java/com/stripe/param/radar/IssuingAuthorizationEvaluationCreateParams.java b/src/main/java/com/stripe/param/radar/IssuingAuthorizationEvaluationCreateParams.java new file mode 100644 index 00000000000..9865f2d923e --- /dev/null +++ b/src/main/java/com/stripe/param/radar/IssuingAuthorizationEvaluationCreateParams.java @@ -0,0 +1,1282 @@ +// File generated from our OpenAPI spec +package com.stripe.param.radar; + +import com.google.gson.annotations.SerializedName; +import com.stripe.net.ApiRequestParams; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import lombok.EqualsAndHashCode; +import lombok.Getter; + +@Getter +@EqualsAndHashCode(callSuper = false) +public class IssuingAuthorizationEvaluationCreateParams extends ApiRequestParams { + /** Required. Details about the authorization. */ + @SerializedName("authorization_details") + AuthorizationDetails authorizationDetails; + + /** Required. Details about the card used in the authorization. */ + @SerializedName("card_details") + CardDetails cardDetails; + + /** Details about the cardholder. */ + @SerializedName("cardholder_details") + CardholderDetails cardholderDetails; + + /** Specifies which fields in the response should be expanded. */ + @SerializedName("expand") + List expand; + + /** + * Map of extra parameters for custom features not available in this client library. The content + * in this map is not serialized under this field's {@code @SerializedName} value. Instead, each + * key/value pair is serialized as if the key is a root-level field (serialized) name in this + * param object. Effectively, this map is flattened to its parent instance. + */ + @SerializedName(ApiRequestParams.EXTRA_PARAMS_KEY) + Map extraParams; + + /** Required. Details about the merchant where the authorization occurred. */ + @SerializedName("merchant_details") + MerchantDetails merchantDetails; + + /** + * Set of key-value pairs that you can attach + * to an object. This can be useful for storing additional information about the object in a + * structured format. Individual keys can be unset by posting an empty value to them. All keys can + * be unset by posting an empty value to {@code metadata}. + */ + @SerializedName("metadata") + Map metadata; + + /** Details about the card network processing. */ + @SerializedName("network_details") + NetworkDetails networkDetails; + + /** Details about the token, if a tokenized payment method was used. */ + @SerializedName("token_details") + TokenDetails tokenDetails; + + /** Details about verification checks performed. */ + @SerializedName("verification_details") + VerificationDetails verificationDetails; + + private IssuingAuthorizationEvaluationCreateParams( + AuthorizationDetails authorizationDetails, + CardDetails cardDetails, + CardholderDetails cardholderDetails, + List expand, + Map extraParams, + MerchantDetails merchantDetails, + Map metadata, + NetworkDetails networkDetails, + TokenDetails tokenDetails, + VerificationDetails verificationDetails) { + this.authorizationDetails = authorizationDetails; + this.cardDetails = cardDetails; + this.cardholderDetails = cardholderDetails; + this.expand = expand; + this.extraParams = extraParams; + this.merchantDetails = merchantDetails; + this.metadata = metadata; + this.networkDetails = networkDetails; + this.tokenDetails = tokenDetails; + this.verificationDetails = verificationDetails; + } + + public static Builder builder() { + return new Builder(); + } + + public static class Builder { + private AuthorizationDetails authorizationDetails; + + private CardDetails cardDetails; + + private CardholderDetails cardholderDetails; + + private List expand; + + private Map extraParams; + + private MerchantDetails merchantDetails; + + private Map metadata; + + private NetworkDetails networkDetails; + + private TokenDetails tokenDetails; + + private VerificationDetails verificationDetails; + + /** Finalize and obtain parameter instance from this builder. */ + public IssuingAuthorizationEvaluationCreateParams build() { + return new IssuingAuthorizationEvaluationCreateParams( + this.authorizationDetails, + this.cardDetails, + this.cardholderDetails, + this.expand, + this.extraParams, + this.merchantDetails, + this.metadata, + this.networkDetails, + this.tokenDetails, + this.verificationDetails); + } + + /** Required. Details about the authorization. */ + public Builder setAuthorizationDetails( + IssuingAuthorizationEvaluationCreateParams.AuthorizationDetails authorizationDetails) { + this.authorizationDetails = authorizationDetails; + return this; + } + + /** Required. Details about the card used in the authorization. */ + public Builder setCardDetails( + IssuingAuthorizationEvaluationCreateParams.CardDetails cardDetails) { + this.cardDetails = cardDetails; + return this; + } + + /** Details about the cardholder. */ + public Builder setCardholderDetails( + IssuingAuthorizationEvaluationCreateParams.CardholderDetails cardholderDetails) { + this.cardholderDetails = cardholderDetails; + return this; + } + + /** + * Add an element to `expand` list. A list is initialized for the first `add/addAll` call, and + * subsequent calls adds additional elements to the original list. See {@link + * IssuingAuthorizationEvaluationCreateParams#expand} for the field documentation. + */ + public Builder addExpand(String element) { + if (this.expand == null) { + this.expand = new ArrayList<>(); + } + this.expand.add(element); + return this; + } + + /** + * Add all elements to `expand` list. A list is initialized for the first `add/addAll` call, and + * subsequent calls adds additional elements to the original list. See {@link + * IssuingAuthorizationEvaluationCreateParams#expand} for the field documentation. + */ + public Builder addAllExpand(List elements) { + if (this.expand == null) { + this.expand = new ArrayList<>(); + } + this.expand.addAll(elements); + return this; + } + + /** + * Add a key/value pair to `extraParams` map. A map is initialized for the first `put/putAll` + * call, and subsequent calls add additional key/value pairs to the original map. See {@link + * IssuingAuthorizationEvaluationCreateParams#extraParams} for the field documentation. + */ + public Builder putExtraParam(String key, Object value) { + if (this.extraParams == null) { + this.extraParams = new HashMap<>(); + } + this.extraParams.put(key, value); + return this; + } + + /** + * Add all map key/value pairs to `extraParams` map. A map is initialized for the first + * `put/putAll` call, and subsequent calls add additional key/value pairs to the original map. + * See {@link IssuingAuthorizationEvaluationCreateParams#extraParams} for the field + * documentation. + */ + public Builder putAllExtraParam(Map map) { + if (this.extraParams == null) { + this.extraParams = new HashMap<>(); + } + this.extraParams.putAll(map); + return this; + } + + /** Required. Details about the merchant where the authorization occurred. */ + public Builder setMerchantDetails( + IssuingAuthorizationEvaluationCreateParams.MerchantDetails merchantDetails) { + this.merchantDetails = merchantDetails; + return this; + } + + /** + * Add a key/value pair to `metadata` map. A map is initialized for the first `put/putAll` call, + * and subsequent calls add additional key/value pairs to the original map. See {@link + * IssuingAuthorizationEvaluationCreateParams#metadata} for the field documentation. + */ + public Builder putMetadata(String key, String value) { + if (this.metadata == null) { + this.metadata = new HashMap<>(); + } + this.metadata.put(key, value); + return this; + } + + /** + * Add all map key/value pairs to `metadata` map. A map is initialized for the first + * `put/putAll` call, and subsequent calls add additional key/value pairs to the original map. + * See {@link IssuingAuthorizationEvaluationCreateParams#metadata} for the field documentation. + */ + public Builder putAllMetadata(Map map) { + if (this.metadata == null) { + this.metadata = new HashMap<>(); + } + this.metadata.putAll(map); + return this; + } + + /** Details about the card network processing. */ + public Builder setNetworkDetails( + IssuingAuthorizationEvaluationCreateParams.NetworkDetails networkDetails) { + this.networkDetails = networkDetails; + return this; + } + + /** Details about the token, if a tokenized payment method was used. */ + public Builder setTokenDetails( + IssuingAuthorizationEvaluationCreateParams.TokenDetails tokenDetails) { + this.tokenDetails = tokenDetails; + return this; + } + + /** Details about verification checks performed. */ + public Builder setVerificationDetails( + IssuingAuthorizationEvaluationCreateParams.VerificationDetails verificationDetails) { + this.verificationDetails = verificationDetails; + return this; + } + } + + @Getter + @EqualsAndHashCode(callSuper = false) + public static class AuthorizationDetails { + /** Required. The authorization amount in the smallest currency unit. */ + @SerializedName("amount") + Long amount; + + /** The method used for authorization. */ + @SerializedName("authorization_method") + AuthorizationMethod authorizationMethod; + + /** Required. Three-letter ISO currency code in lowercase. */ + @SerializedName("currency") + String currency; + + /** The card entry mode. */ + @SerializedName("entry_mode") + EntryMode entryMode; + + /** The raw code for the card entry mode. */ + @SerializedName("entry_mode_raw_code") + String entryModeRawCode; + + /** + * Map of extra parameters for custom features not available in this client library. The content + * in this map is not serialized under this field's {@code @SerializedName} value. Instead, each + * key/value pair is serialized as if the key is a root-level field (serialized) name in this + * param object. Effectively, this map is flattened to its parent instance. + */ + @SerializedName(ApiRequestParams.EXTRA_PARAMS_KEY) + Map extraParams; + + /** + * Required. The time when the authorization was initiated (Unix timestamp). + */ + @SerializedName("initiated_at") + Long initiatedAt; + + /** The point of sale condition. */ + @SerializedName("point_of_sale_condition") + PointOfSaleCondition pointOfSaleCondition; + + /** The raw code for the point of sale condition. */ + @SerializedName("point_of_sale_condition_raw_code") + String pointOfSaleConditionRawCode; + + /** Required. External reference for the authorization. */ + @SerializedName("reference") + String reference; + + private AuthorizationDetails( + Long amount, + AuthorizationMethod authorizationMethod, + String currency, + EntryMode entryMode, + String entryModeRawCode, + Map extraParams, + Long initiatedAt, + PointOfSaleCondition pointOfSaleCondition, + String pointOfSaleConditionRawCode, + String reference) { + this.amount = amount; + this.authorizationMethod = authorizationMethod; + this.currency = currency; + this.entryMode = entryMode; + this.entryModeRawCode = entryModeRawCode; + this.extraParams = extraParams; + this.initiatedAt = initiatedAt; + this.pointOfSaleCondition = pointOfSaleCondition; + this.pointOfSaleConditionRawCode = pointOfSaleConditionRawCode; + this.reference = reference; + } + + public static Builder builder() { + return new Builder(); + } + + public static class Builder { + private Long amount; + + private AuthorizationMethod authorizationMethod; + + private String currency; + + private EntryMode entryMode; + + private String entryModeRawCode; + + private Map extraParams; + + private Long initiatedAt; + + private PointOfSaleCondition pointOfSaleCondition; + + private String pointOfSaleConditionRawCode; + + private String reference; + + /** Finalize and obtain parameter instance from this builder. */ + public IssuingAuthorizationEvaluationCreateParams.AuthorizationDetails build() { + return new IssuingAuthorizationEvaluationCreateParams.AuthorizationDetails( + this.amount, + this.authorizationMethod, + this.currency, + this.entryMode, + this.entryModeRawCode, + this.extraParams, + this.initiatedAt, + this.pointOfSaleCondition, + this.pointOfSaleConditionRawCode, + this.reference); + } + + /** Required. The authorization amount in the smallest currency unit. */ + public Builder setAmount(Long amount) { + this.amount = amount; + return this; + } + + /** The method used for authorization. */ + public Builder setAuthorizationMethod( + IssuingAuthorizationEvaluationCreateParams.AuthorizationDetails.AuthorizationMethod + authorizationMethod) { + this.authorizationMethod = authorizationMethod; + return this; + } + + /** Required. Three-letter ISO currency code in lowercase. */ + public Builder setCurrency(String currency) { + this.currency = currency; + return this; + } + + /** The card entry mode. */ + public Builder setEntryMode( + IssuingAuthorizationEvaluationCreateParams.AuthorizationDetails.EntryMode entryMode) { + this.entryMode = entryMode; + return this; + } + + /** The raw code for the card entry mode. */ + public Builder setEntryModeRawCode(String entryModeRawCode) { + this.entryModeRawCode = entryModeRawCode; + return this; + } + + /** + * Add a key/value pair to `extraParams` map. A map is initialized for the first `put/putAll` + * call, and subsequent calls add additional key/value pairs to the original map. See {@link + * IssuingAuthorizationEvaluationCreateParams.AuthorizationDetails#extraParams} for the field + * documentation. + */ + public Builder putExtraParam(String key, Object value) { + if (this.extraParams == null) { + this.extraParams = new HashMap<>(); + } + this.extraParams.put(key, value); + return this; + } + + /** + * Add all map key/value pairs to `extraParams` map. A map is initialized for the first + * `put/putAll` call, and subsequent calls add additional key/value pairs to the original map. + * See {@link IssuingAuthorizationEvaluationCreateParams.AuthorizationDetails#extraParams} for + * the field documentation. + */ + public Builder putAllExtraParam(Map map) { + if (this.extraParams == null) { + this.extraParams = new HashMap<>(); + } + this.extraParams.putAll(map); + return this; + } + + /** + * Required. The time when the authorization was initiated (Unix timestamp). + */ + public Builder setInitiatedAt(Long initiatedAt) { + this.initiatedAt = initiatedAt; + return this; + } + + /** The point of sale condition. */ + public Builder setPointOfSaleCondition( + IssuingAuthorizationEvaluationCreateParams.AuthorizationDetails.PointOfSaleCondition + pointOfSaleCondition) { + this.pointOfSaleCondition = pointOfSaleCondition; + return this; + } + + /** The raw code for the point of sale condition. */ + public Builder setPointOfSaleConditionRawCode(String pointOfSaleConditionRawCode) { + this.pointOfSaleConditionRawCode = pointOfSaleConditionRawCode; + return this; + } + + /** Required. External reference for the authorization. */ + public Builder setReference(String reference) { + this.reference = reference; + return this; + } + } + + public enum AuthorizationMethod implements ApiRequestParams.EnumParam { + @SerializedName("chip") + CHIP("chip"), + + @SerializedName("contactless") + CONTACTLESS("contactless"), + + @SerializedName("keyed_in") + KEYED_IN("keyed_in"), + + @SerializedName("online") + ONLINE("online"), + + @SerializedName("swipe") + SWIPE("swipe"); + + @Getter(onMethod_ = {@Override}) + private final String value; + + AuthorizationMethod(String value) { + this.value = value; + } + } + + public enum EntryMode implements ApiRequestParams.EnumParam { + @SerializedName("contactless") + CONTACTLESS("contactless"), + + @SerializedName("contactless_magstripe") + CONTACTLESS_MAGSTRIPE("contactless_magstripe"), + + @SerializedName("credential_on_file") + CREDENTIAL_ON_FILE("credential_on_file"), + + @SerializedName("integrated_circuit_card") + INTEGRATED_CIRCUIT_CARD("integrated_circuit_card"), + + @SerializedName("magstripe") + MAGSTRIPE("magstripe"), + + @SerializedName("magstripe_no_cvv") + MAGSTRIPE_NO_CVV("magstripe_no_cvv"), + + @SerializedName("manual") + MANUAL("manual"), + + @SerializedName("other") + OTHER("other"), + + @SerializedName("unknown") + UNKNOWN("unknown"); + + @Getter(onMethod_ = {@Override}) + private final String value; + + EntryMode(String value) { + this.value = value; + } + } + + public enum PointOfSaleCondition implements ApiRequestParams.EnumParam { + @SerializedName("account_verification") + ACCOUNT_VERIFICATION("account_verification"), + + @SerializedName("card_not_present") + CARD_NOT_PRESENT("card_not_present"), + + @SerializedName("card_present") + CARD_PRESENT("card_present"), + + @SerializedName("e_commerce") + E_COMMERCE("e_commerce"), + + @SerializedName("key_entered_pos") + KEY_ENTERED_POS("key_entered_pos"), + + @SerializedName("missing") + MISSING("missing"), + + @SerializedName("moto") + MOTO("moto"), + + @SerializedName("other") + OTHER("other"), + + @SerializedName("pin_entered") + PIN_ENTERED("pin_entered"), + + @SerializedName("recurring") + RECURRING("recurring"); + + @Getter(onMethod_ = {@Override}) + private final String value; + + PointOfSaleCondition(String value) { + this.value = value; + } + } + } + + @Getter + @EqualsAndHashCode(callSuper = false) + public static class CardDetails { + /** Required. Bank Identification Number (BIN) of the card. */ + @SerializedName("bin") + String bin; + + /** Two-letter ISO country code of the card's issuing bank. */ + @SerializedName("bin_country") + String binCountry; + + /** Required. The type of card (physical or virtual). */ + @SerializedName("card_type") + CardType cardType; + + /** Required. The time when the card was created (Unix timestamp). */ + @SerializedName("created_at") + Long createdAt; + + /** + * Map of extra parameters for custom features not available in this client library. The content + * in this map is not serialized under this field's {@code @SerializedName} value. Instead, each + * key/value pair is serialized as if the key is a root-level field (serialized) name in this + * param object. Effectively, this map is flattened to its parent instance. + */ + @SerializedName(ApiRequestParams.EXTRA_PARAMS_KEY) + Map extraParams; + + /** Last 4 digits of the card number. */ + @SerializedName("last4") + String last4; + + /** Required. External reference for the card. */ + @SerializedName("reference") + String reference; + + private CardDetails( + String bin, + String binCountry, + CardType cardType, + Long createdAt, + Map extraParams, + String last4, + String reference) { + this.bin = bin; + this.binCountry = binCountry; + this.cardType = cardType; + this.createdAt = createdAt; + this.extraParams = extraParams; + this.last4 = last4; + this.reference = reference; + } + + public static Builder builder() { + return new Builder(); + } + + public static class Builder { + private String bin; + + private String binCountry; + + private CardType cardType; + + private Long createdAt; + + private Map extraParams; + + private String last4; + + private String reference; + + /** Finalize and obtain parameter instance from this builder. */ + public IssuingAuthorizationEvaluationCreateParams.CardDetails build() { + return new IssuingAuthorizationEvaluationCreateParams.CardDetails( + this.bin, + this.binCountry, + this.cardType, + this.createdAt, + this.extraParams, + this.last4, + this.reference); + } + + /** Required. Bank Identification Number (BIN) of the card. */ + public Builder setBin(String bin) { + this.bin = bin; + return this; + } + + /** Two-letter ISO country code of the card's issuing bank. */ + public Builder setBinCountry(String binCountry) { + this.binCountry = binCountry; + return this; + } + + /** Required. The type of card (physical or virtual). */ + public Builder setCardType( + IssuingAuthorizationEvaluationCreateParams.CardDetails.CardType cardType) { + this.cardType = cardType; + return this; + } + + /** Required. The time when the card was created (Unix timestamp). */ + public Builder setCreatedAt(Long createdAt) { + this.createdAt = createdAt; + return this; + } + + /** + * Add a key/value pair to `extraParams` map. A map is initialized for the first `put/putAll` + * call, and subsequent calls add additional key/value pairs to the original map. See {@link + * IssuingAuthorizationEvaluationCreateParams.CardDetails#extraParams} for the field + * documentation. + */ + public Builder putExtraParam(String key, Object value) { + if (this.extraParams == null) { + this.extraParams = new HashMap<>(); + } + this.extraParams.put(key, value); + return this; + } + + /** + * Add all map key/value pairs to `extraParams` map. A map is initialized for the first + * `put/putAll` call, and subsequent calls add additional key/value pairs to the original map. + * See {@link IssuingAuthorizationEvaluationCreateParams.CardDetails#extraParams} for the + * field documentation. + */ + public Builder putAllExtraParam(Map map) { + if (this.extraParams == null) { + this.extraParams = new HashMap<>(); + } + this.extraParams.putAll(map); + return this; + } + + /** Last 4 digits of the card number. */ + public Builder setLast4(String last4) { + this.last4 = last4; + return this; + } + + /** Required. External reference for the card. */ + public Builder setReference(String reference) { + this.reference = reference; + return this; + } + } + + public enum CardType implements ApiRequestParams.EnumParam { + @SerializedName("physical") + PHYSICAL("physical"), + + @SerializedName("virtual") + VIRTUAL("virtual"); + + @Getter(onMethod_ = {@Override}) + private final String value; + + CardType(String value) { + this.value = value; + } + } + } + + @Getter + @EqualsAndHashCode(callSuper = false) + public static class CardholderDetails { + /** The time when the cardholder was created (Unix timestamp). */ + @SerializedName("created_at") + Long createdAt; + + /** + * Map of extra parameters for custom features not available in this client library. The content + * in this map is not serialized under this field's {@code @SerializedName} value. Instead, each + * key/value pair is serialized as if the key is a root-level field (serialized) name in this + * param object. Effectively, this map is flattened to its parent instance. + */ + @SerializedName(ApiRequestParams.EXTRA_PARAMS_KEY) + Map extraParams; + + /** External reference for the cardholder. */ + @SerializedName("reference") + String reference; + + private CardholderDetails(Long createdAt, Map extraParams, String reference) { + this.createdAt = createdAt; + this.extraParams = extraParams; + this.reference = reference; + } + + public static Builder builder() { + return new Builder(); + } + + public static class Builder { + private Long createdAt; + + private Map extraParams; + + private String reference; + + /** Finalize and obtain parameter instance from this builder. */ + public IssuingAuthorizationEvaluationCreateParams.CardholderDetails build() { + return new IssuingAuthorizationEvaluationCreateParams.CardholderDetails( + this.createdAt, this.extraParams, this.reference); + } + + /** The time when the cardholder was created (Unix timestamp). */ + public Builder setCreatedAt(Long createdAt) { + this.createdAt = createdAt; + return this; + } + + /** + * Add a key/value pair to `extraParams` map. A map is initialized for the first `put/putAll` + * call, and subsequent calls add additional key/value pairs to the original map. See {@link + * IssuingAuthorizationEvaluationCreateParams.CardholderDetails#extraParams} for the field + * documentation. + */ + public Builder putExtraParam(String key, Object value) { + if (this.extraParams == null) { + this.extraParams = new HashMap<>(); + } + this.extraParams.put(key, value); + return this; + } + + /** + * Add all map key/value pairs to `extraParams` map. A map is initialized for the first + * `put/putAll` call, and subsequent calls add additional key/value pairs to the original map. + * See {@link IssuingAuthorizationEvaluationCreateParams.CardholderDetails#extraParams} for + * the field documentation. + */ + public Builder putAllExtraParam(Map map) { + if (this.extraParams == null) { + this.extraParams = new HashMap<>(); + } + this.extraParams.putAll(map); + return this; + } + + /** External reference for the cardholder. */ + public Builder setReference(String reference) { + this.reference = reference; + return this; + } + } + } + + @Getter + @EqualsAndHashCode(callSuper = false) + public static class MerchantDetails { + /** Required. Merchant Category Code (MCC). */ + @SerializedName("category_code") + String categoryCode; + + /** Two-letter ISO country code of the merchant. */ + @SerializedName("country") + String country; + + /** + * Map of extra parameters for custom features not available in this client library. The content + * in this map is not serialized under this field's {@code @SerializedName} value. Instead, each + * key/value pair is serialized as if the key is a root-level field (serialized) name in this + * param object. Effectively, this map is flattened to its parent instance. + */ + @SerializedName(ApiRequestParams.EXTRA_PARAMS_KEY) + Map extraParams; + + /** Required. Name of the merchant. */ + @SerializedName("name") + String name; + + /** Required. Network merchant identifier. */ + @SerializedName("network_id") + String networkId; + + /** Terminal identifier. */ + @SerializedName("terminal_id") + String terminalId; + + private MerchantDetails( + String categoryCode, + String country, + Map extraParams, + String name, + String networkId, + String terminalId) { + this.categoryCode = categoryCode; + this.country = country; + this.extraParams = extraParams; + this.name = name; + this.networkId = networkId; + this.terminalId = terminalId; + } + + public static Builder builder() { + return new Builder(); + } + + public static class Builder { + private String categoryCode; + + private String country; + + private Map extraParams; + + private String name; + + private String networkId; + + private String terminalId; + + /** Finalize and obtain parameter instance from this builder. */ + public IssuingAuthorizationEvaluationCreateParams.MerchantDetails build() { + return new IssuingAuthorizationEvaluationCreateParams.MerchantDetails( + this.categoryCode, + this.country, + this.extraParams, + this.name, + this.networkId, + this.terminalId); + } + + /** Required. Merchant Category Code (MCC). */ + public Builder setCategoryCode(String categoryCode) { + this.categoryCode = categoryCode; + return this; + } + + /** Two-letter ISO country code of the merchant. */ + public Builder setCountry(String country) { + this.country = country; + return this; + } + + /** + * Add a key/value pair to `extraParams` map. A map is initialized for the first `put/putAll` + * call, and subsequent calls add additional key/value pairs to the original map. See {@link + * IssuingAuthorizationEvaluationCreateParams.MerchantDetails#extraParams} for the field + * documentation. + */ + public Builder putExtraParam(String key, Object value) { + if (this.extraParams == null) { + this.extraParams = new HashMap<>(); + } + this.extraParams.put(key, value); + return this; + } + + /** + * Add all map key/value pairs to `extraParams` map. A map is initialized for the first + * `put/putAll` call, and subsequent calls add additional key/value pairs to the original map. + * See {@link IssuingAuthorizationEvaluationCreateParams.MerchantDetails#extraParams} for the + * field documentation. + */ + public Builder putAllExtraParam(Map map) { + if (this.extraParams == null) { + this.extraParams = new HashMap<>(); + } + this.extraParams.putAll(map); + return this; + } + + /** Required. Name of the merchant. */ + public Builder setName(String name) { + this.name = name; + return this; + } + + /** Required. Network merchant identifier. */ + public Builder setNetworkId(String networkId) { + this.networkId = networkId; + return this; + } + + /** Terminal identifier. */ + public Builder setTerminalId(String terminalId) { + this.terminalId = terminalId; + return this; + } + } + } + + @Getter + @EqualsAndHashCode(callSuper = false) + public static class NetworkDetails { + /** The acquiring institution identifier. */ + @SerializedName("acquiring_institution_id") + String acquiringInstitutionId; + + /** + * Map of extra parameters for custom features not available in this client library. The content + * in this map is not serialized under this field's {@code @SerializedName} value. Instead, each + * key/value pair is serialized as if the key is a root-level field (serialized) name in this + * param object. Effectively, this map is flattened to its parent instance. + */ + @SerializedName(ApiRequestParams.EXTRA_PARAMS_KEY) + Map extraParams; + + /** The card network that routed the authorization. */ + @SerializedName("routed_network") + RoutedNetwork routedNetwork; + + private NetworkDetails( + String acquiringInstitutionId, + Map extraParams, + RoutedNetwork routedNetwork) { + this.acquiringInstitutionId = acquiringInstitutionId; + this.extraParams = extraParams; + this.routedNetwork = routedNetwork; + } + + public static Builder builder() { + return new Builder(); + } + + public static class Builder { + private String acquiringInstitutionId; + + private Map extraParams; + + private RoutedNetwork routedNetwork; + + /** Finalize and obtain parameter instance from this builder. */ + public IssuingAuthorizationEvaluationCreateParams.NetworkDetails build() { + return new IssuingAuthorizationEvaluationCreateParams.NetworkDetails( + this.acquiringInstitutionId, this.extraParams, this.routedNetwork); + } + + /** The acquiring institution identifier. */ + public Builder setAcquiringInstitutionId(String acquiringInstitutionId) { + this.acquiringInstitutionId = acquiringInstitutionId; + return this; + } + + /** + * Add a key/value pair to `extraParams` map. A map is initialized for the first `put/putAll` + * call, and subsequent calls add additional key/value pairs to the original map. See {@link + * IssuingAuthorizationEvaluationCreateParams.NetworkDetails#extraParams} for the field + * documentation. + */ + public Builder putExtraParam(String key, Object value) { + if (this.extraParams == null) { + this.extraParams = new HashMap<>(); + } + this.extraParams.put(key, value); + return this; + } + + /** + * Add all map key/value pairs to `extraParams` map. A map is initialized for the first + * `put/putAll` call, and subsequent calls add additional key/value pairs to the original map. + * See {@link IssuingAuthorizationEvaluationCreateParams.NetworkDetails#extraParams} for the + * field documentation. + */ + public Builder putAllExtraParam(Map map) { + if (this.extraParams == null) { + this.extraParams = new HashMap<>(); + } + this.extraParams.putAll(map); + return this; + } + + /** The card network that routed the authorization. */ + public Builder setRoutedNetwork( + IssuingAuthorizationEvaluationCreateParams.NetworkDetails.RoutedNetwork routedNetwork) { + this.routedNetwork = routedNetwork; + return this; + } + } + + public enum RoutedNetwork implements ApiRequestParams.EnumParam { + @SerializedName("cirrus") + CIRRUS("cirrus"), + + @SerializedName("interlink") + INTERLINK("interlink"), + + @SerializedName("maestro") + MAESTRO("maestro"), + + @SerializedName("mastercard") + MASTERCARD("mastercard"), + + @SerializedName("other") + OTHER("other"), + + @SerializedName("plus") + PLUS("plus"), + + @SerializedName("visa") + VISA("visa"); + + @Getter(onMethod_ = {@Override}) + private final String value; + + RoutedNetwork(String value) { + this.value = value; + } + } + } + + @Getter + @EqualsAndHashCode(callSuper = false) + public static class TokenDetails { + /** The time when the token was created (Unix timestamp). */ + @SerializedName("created_at") + Long createdAt; + + /** + * Map of extra parameters for custom features not available in this client library. The content + * in this map is not serialized under this field's {@code @SerializedName} value. Instead, each + * key/value pair is serialized as if the key is a root-level field (serialized) name in this + * param object. Effectively, this map is flattened to its parent instance. + */ + @SerializedName(ApiRequestParams.EXTRA_PARAMS_KEY) + Map extraParams; + + /** External reference for the token. */ + @SerializedName("reference") + String reference; + + /** The wallet provider for the tokenized payment method. */ + @SerializedName("wallet") + Wallet wallet; + + private TokenDetails( + Long createdAt, Map extraParams, String reference, Wallet wallet) { + this.createdAt = createdAt; + this.extraParams = extraParams; + this.reference = reference; + this.wallet = wallet; + } + + public static Builder builder() { + return new Builder(); + } + + public static class Builder { + private Long createdAt; + + private Map extraParams; + + private String reference; + + private Wallet wallet; + + /** Finalize and obtain parameter instance from this builder. */ + public IssuingAuthorizationEvaluationCreateParams.TokenDetails build() { + return new IssuingAuthorizationEvaluationCreateParams.TokenDetails( + this.createdAt, this.extraParams, this.reference, this.wallet); + } + + /** The time when the token was created (Unix timestamp). */ + public Builder setCreatedAt(Long createdAt) { + this.createdAt = createdAt; + return this; + } + + /** + * Add a key/value pair to `extraParams` map. A map is initialized for the first `put/putAll` + * call, and subsequent calls add additional key/value pairs to the original map. See {@link + * IssuingAuthorizationEvaluationCreateParams.TokenDetails#extraParams} for the field + * documentation. + */ + public Builder putExtraParam(String key, Object value) { + if (this.extraParams == null) { + this.extraParams = new HashMap<>(); + } + this.extraParams.put(key, value); + return this; + } + + /** + * Add all map key/value pairs to `extraParams` map. A map is initialized for the first + * `put/putAll` call, and subsequent calls add additional key/value pairs to the original map. + * See {@link IssuingAuthorizationEvaluationCreateParams.TokenDetails#extraParams} for the + * field documentation. + */ + public Builder putAllExtraParam(Map map) { + if (this.extraParams == null) { + this.extraParams = new HashMap<>(); + } + this.extraParams.putAll(map); + return this; + } + + /** External reference for the token. */ + public Builder setReference(String reference) { + this.reference = reference; + return this; + } + + /** The wallet provider for the tokenized payment method. */ + public Builder setWallet( + IssuingAuthorizationEvaluationCreateParams.TokenDetails.Wallet wallet) { + this.wallet = wallet; + return this; + } + } + + public enum Wallet implements ApiRequestParams.EnumParam { + @SerializedName("apple_pay") + APPLE_PAY("apple_pay"), + + @SerializedName("google_pay") + GOOGLE_PAY("google_pay"), + + @SerializedName("samsung_pay") + SAMSUNG_PAY("samsung_pay"); + + @Getter(onMethod_ = {@Override}) + private final String value; + + Wallet(String value) { + this.value = value; + } + } + } + + @Getter + @EqualsAndHashCode(callSuper = false) + public static class VerificationDetails { + /** + * Map of extra parameters for custom features not available in this client library. The content + * in this map is not serialized under this field's {@code @SerializedName} value. Instead, each + * key/value pair is serialized as if the key is a root-level field (serialized) name in this + * param object. Effectively, this map is flattened to its parent instance. + */ + @SerializedName(ApiRequestParams.EXTRA_PARAMS_KEY) + Map extraParams; + + /** The result of 3D Secure verification. */ + @SerializedName("three_d_secure_result") + ThreeDSecureResult threeDSecureResult; + + private VerificationDetails( + Map extraParams, ThreeDSecureResult threeDSecureResult) { + this.extraParams = extraParams; + this.threeDSecureResult = threeDSecureResult; + } + + public static Builder builder() { + return new Builder(); + } + + public static class Builder { + private Map extraParams; + + private ThreeDSecureResult threeDSecureResult; + + /** Finalize and obtain parameter instance from this builder. */ + public IssuingAuthorizationEvaluationCreateParams.VerificationDetails build() { + return new IssuingAuthorizationEvaluationCreateParams.VerificationDetails( + this.extraParams, this.threeDSecureResult); + } + + /** + * Add a key/value pair to `extraParams` map. A map is initialized for the first `put/putAll` + * call, and subsequent calls add additional key/value pairs to the original map. See {@link + * IssuingAuthorizationEvaluationCreateParams.VerificationDetails#extraParams} for the field + * documentation. + */ + public Builder putExtraParam(String key, Object value) { + if (this.extraParams == null) { + this.extraParams = new HashMap<>(); + } + this.extraParams.put(key, value); + return this; + } + + /** + * Add all map key/value pairs to `extraParams` map. A map is initialized for the first + * `put/putAll` call, and subsequent calls add additional key/value pairs to the original map. + * See {@link IssuingAuthorizationEvaluationCreateParams.VerificationDetails#extraParams} for + * the field documentation. + */ + public Builder putAllExtraParam(Map map) { + if (this.extraParams == null) { + this.extraParams = new HashMap<>(); + } + this.extraParams.putAll(map); + return this; + } + + /** The result of 3D Secure verification. */ + public Builder setThreeDSecureResult( + IssuingAuthorizationEvaluationCreateParams.VerificationDetails.ThreeDSecureResult + threeDSecureResult) { + this.threeDSecureResult = threeDSecureResult; + return this; + } + } + + public enum ThreeDSecureResult implements ApiRequestParams.EnumParam { + @SerializedName("attempt_acknowledged") + ATTEMPT_ACKNOWLEDGED("attempt_acknowledged"), + + @SerializedName("authenticated") + AUTHENTICATED("authenticated"), + + @SerializedName("exempted") + EXEMPTED("exempted"), + + @SerializedName("failed") + FAILED("failed"), + + @SerializedName("required") + REQUIRED("required"); + + @Getter(onMethod_ = {@Override}) + private final String value; + + ThreeDSecureResult(String value) { + this.value = value; + } + } + } +} diff --git a/src/main/java/com/stripe/service/RadarService.java b/src/main/java/com/stripe/service/RadarService.java index 21a1596c52e..f206c140487 100644 --- a/src/main/java/com/stripe/service/RadarService.java +++ b/src/main/java/com/stripe/service/RadarService.java @@ -17,6 +17,12 @@ public com.stripe.service.radar.EarlyFraudWarningService earlyFraudWarnings() { return new com.stripe.service.radar.EarlyFraudWarningService(this.getResponseGetter()); } + public com.stripe.service.radar.IssuingAuthorizationEvaluationService + issuingAuthorizationEvaluations() { + return new com.stripe.service.radar.IssuingAuthorizationEvaluationService( + this.getResponseGetter()); + } + public com.stripe.service.radar.PaymentEvaluationService paymentEvaluations() { return new com.stripe.service.radar.PaymentEvaluationService(this.getResponseGetter()); } diff --git a/src/main/java/com/stripe/service/radar/IssuingAuthorizationEvaluationService.java b/src/main/java/com/stripe/service/radar/IssuingAuthorizationEvaluationService.java new file mode 100644 index 00000000000..354108e440a --- /dev/null +++ b/src/main/java/com/stripe/service/radar/IssuingAuthorizationEvaluationService.java @@ -0,0 +1,39 @@ +// File generated from our OpenAPI spec +package com.stripe.service.radar; + +import com.stripe.exception.StripeException; +import com.stripe.model.radar.IssuingAuthorizationEvaluation; +import com.stripe.net.ApiRequest; +import com.stripe.net.ApiRequestParams; +import com.stripe.net.ApiResource; +import com.stripe.net.ApiService; +import com.stripe.net.BaseAddress; +import com.stripe.net.RequestOptions; +import com.stripe.net.StripeResponseGetter; +import com.stripe.param.radar.IssuingAuthorizationEvaluationCreateParams; + +public final class IssuingAuthorizationEvaluationService extends ApiService { + public IssuingAuthorizationEvaluationService(StripeResponseGetter responseGetter) { + super(responseGetter); + } + + /** Request a fraud risk assessment from Stripe for an Issuing card authorization. */ + public IssuingAuthorizationEvaluation create(IssuingAuthorizationEvaluationCreateParams params) + throws StripeException { + return create(params, (RequestOptions) null); + } + /** Request a fraud risk assessment from Stripe for an Issuing card authorization. */ + public IssuingAuthorizationEvaluation create( + IssuingAuthorizationEvaluationCreateParams params, RequestOptions options) + throws StripeException { + String path = "/v1/radar/issuing_authorization_evaluations"; + ApiRequest request = + new ApiRequest( + BaseAddress.API, + ApiResource.RequestMethod.POST, + path, + ApiRequestParams.paramsToMap(params), + options); + return this.request(request, IssuingAuthorizationEvaluation.class); + } +} diff --git a/src/test/java/com/stripe/model/GsonRoundTripTest.java b/src/test/java/com/stripe/model/GsonRoundTripTest.java new file mode 100644 index 00000000000..1e1763c5b6d --- /dev/null +++ b/src/test/java/com/stripe/model/GsonRoundTripTest.java @@ -0,0 +1,144 @@ +package com.stripe.model; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; +import com.stripe.BaseStripeTest; +import com.stripe.net.ApiResource; +import org.junit.jupiter.api.Test; + +public class GsonRoundTripTest extends BaseStripeTest { + + @Test + public void testUnexpandedExpandableField() { + String json = "{\"id\":\"in_123\",\"object\":\"invoice\",\"customer\":\"cus_456\"}"; + Invoice invoice = ApiResource.GSON.fromJson(json, Invoice.class); + + assertEquals("cus_456", invoice.getCustomer()); + assertNull(invoice.getCustomerObject()); + + String serialized = ApiResource.GSON.toJson(invoice); + Invoice roundTripped = ApiResource.GSON.fromJson(serialized, Invoice.class); + + assertEquals("cus_456", roundTripped.getCustomer()); + assertNull(roundTripped.getCustomerObject()); + } + + @Test + public void testExpandedExpandableField() { + String json = + "{\"id\":\"in_123\",\"object\":\"invoice\"," + + "\"customer\":{\"id\":\"cus_456\",\"object\":\"customer\"," + + "\"name\":\"John Doe\",\"metadata\":{\"key\":\"value\"}}}"; + Invoice invoice = ApiResource.GSON.fromJson(json, Invoice.class); + + assertEquals("cus_456", invoice.getCustomer()); + Customer customer = invoice.getCustomerObject(); + assertNotNull(customer); + assertEquals("cus_456", customer.getId()); + assertEquals("John Doe", customer.getName()); + + String serialized = ApiResource.GSON.toJson(invoice); + Invoice roundTripped = ApiResource.GSON.fromJson(serialized, Invoice.class); + + assertEquals("cus_456", roundTripped.getCustomer()); + Customer rtCustomer = roundTripped.getCustomerObject(); + assertNotNull(rtCustomer); + assertEquals("cus_456", rtCustomer.getId()); + assertEquals("John Doe", rtCustomer.getName()); + assertEquals("value", rtCustomer.getMetadata().get("key")); + } + + @Test + public void testNullExpandableField() { + String json = "{\"id\":\"in_123\",\"object\":\"invoice\",\"customer\":null}"; + Invoice invoice = ApiResource.GSON.fromJson(json, Invoice.class); + + assertNull(invoice.getCustomer()); + assertNull(invoice.getCustomerObject()); + + String serialized = ApiResource.GSON.toJson(invoice); + Invoice roundTripped = ApiResource.GSON.fromJson(serialized, Invoice.class); + + assertNull(roundTripped.getCustomer()); + assertNull(roundTripped.getCustomerObject()); + } + + @Test + public void testPaymentSourceDirectField() { + // Charge.source is a direct PaymentSource field (not ExpandableField) + String json = + "{\"id\":\"ch_123\",\"object\":\"charge\"," + + "\"source\":{\"id\":\"card_789\",\"object\":\"card\"," + + "\"brand\":\"Visa\",\"last4\":\"4242\"}}"; + Charge charge = ApiResource.GSON.fromJson(json, Charge.class); + + assertNotNull(charge.getSource()); + assertTrue(charge.getSource() instanceof Card); + assertEquals("card_789", charge.getSource().getId()); + + String serialized = ApiResource.GSON.toJson(charge); + Charge roundTripped = ApiResource.GSON.fromJson(serialized, Charge.class); + + assertNotNull(roundTripped.getSource()); + assertTrue(roundTripped.getSource() instanceof Card); + assertEquals("card_789", roundTripped.getSource().getId()); + assertEquals("Visa", ((Card) roundTripped.getSource()).getBrand()); + assertEquals("4242", ((Card) roundTripped.getSource()).getLast4()); + } + + @Test + public void testStripeRawJsonObjectRoundTrip() { + String innerJson = "{\"id\":\"unknown_123\",\"object\":\"unknown_type\",\"foo\":\"bar\"}"; + StripeRawJsonObject raw = new StripeRawJsonObject(); + raw.json = JsonParser.parseString(innerJson).getAsJsonObject(); + + String serialized = ApiResource.GSON.toJson(raw); + // Should serialize as the raw JSON, not wrapped in {"json":{...}} + JsonObject parsed = JsonParser.parseString(serialized).getAsJsonObject(); + assertEquals("unknown_123", parsed.get("id").getAsString()); + assertEquals("bar", parsed.get("foo").getAsString()); + + StripeRawJsonObject roundTripped = + ApiResource.GSON.fromJson(serialized, StripeRawJsonObject.class); + assertNotNull(roundTripped.json); + assertEquals("unknown_123", roundTripped.json.get("id").getAsString()); + assertEquals("bar", roundTripped.json.get("foo").getAsString()); + } + + @Test + public void testInvoiceWithExpandedCustomerRoundTrip() throws Exception { + // Realistic scenario from RUN_DEVSDK-2253 + final String[] expansions = {"customer"}; + final String data = getFixture("/v1/invoices/in_123", expansions); + final Invoice original = ApiResource.GSON.fromJson(data, Invoice.class); + + assertNotNull(original.getCustomerObject()); + assertEquals(original.getCustomer(), original.getCustomerObject().getId()); + + String serialized = ApiResource.GSON.toJson(original); + Invoice roundTripped = ApiResource.GSON.fromJson(serialized, Invoice.class); + + assertEquals(original.getId(), roundTripped.getId()); + assertEquals(original.getCustomer(), roundTripped.getCustomer()); + assertNotNull(roundTripped.getCustomerObject()); + assertEquals(original.getCustomerObject().getId(), roundTripped.getCustomerObject().getId()); + } + + @Test + public void testSubscriptionWithDefaultSourceRoundTrip() throws Exception { + // Realistic scenario from DEVSDK-2319 + final String[] expansions = {"default_source"}; + final String data = getFixture("/v1/subscriptions/sub_123", expansions); + final Subscription original = ApiResource.GSON.fromJson(data, Subscription.class); + + String serialized = ApiResource.GSON.toJson(original); + Subscription roundTripped = ApiResource.GSON.fromJson(serialized, Subscription.class); + + assertEquals(original.getId(), roundTripped.getId()); + } +} diff --git a/src/test/java/com/stripe/model/InvoiceTest.java b/src/test/java/com/stripe/model/InvoiceTest.java index f6c6a07c46b..edf74e992b1 100644 --- a/src/test/java/com/stripe/model/InvoiceTest.java +++ b/src/test/java/com/stripe/model/InvoiceTest.java @@ -48,6 +48,23 @@ public void testDeserializeWithUnexpandedArrayExpansions() throws Exception { assertEquals(2, invoice.getDiscountObjects().size()); } + @Test + public void testRoundTripWithExpandedCustomer() throws Exception { + final String[] expansions = {"charge", "customer"}; + final String data = getFixture("/v1/invoices/in_123", expansions); + final Invoice original = ApiResource.GSON.fromJson(data, Invoice.class); + + assertNotNull(original.getCustomerObject()); + + String serialized = ApiResource.GSON.toJson(original); + Invoice roundTripped = ApiResource.GSON.fromJson(serialized, Invoice.class); + + assertEquals(original.getId(), roundTripped.getId()); + assertEquals(original.getCustomer(), roundTripped.getCustomer()); + assertNotNull(roundTripped.getCustomerObject()); + assertEquals(original.getCustomerObject().getId(), roundTripped.getCustomerObject().getId()); + } + @Test public void testDeserializeWithArrayExpansions() throws Exception { final Invoice invoice =