diff --git a/src/main/java/com/stripe/model/Charge.java b/src/main/java/com/stripe/model/Charge.java index 3f7e36991d3..5f9d61735a3 100644 --- a/src/main/java/com/stripe/model/Charge.java +++ b/src/main/java/com/stripe/model/Charge.java @@ -1,5 +1,7 @@ package com.stripe.model; +import com.google.gson.annotations.SerializedName; + import com.stripe.exception.StripeException; import com.stripe.net.ApiResource; import com.stripe.net.RequestOptions; @@ -30,6 +32,7 @@ public class Charge extends ApiResource implements MetadataStore, HasId AlternateStatementDescriptors alternateStatementDescriptors; @Getter(AccessLevel.NONE) @Setter(AccessLevel.NONE) ExpandableField balanceTransaction; + PaymentMethod.BillingDetails billingDetails; Boolean captured; Long created; String currency; @@ -48,6 +51,8 @@ public class Charge extends ApiResource implements MetadataStore, HasId @Getter(AccessLevel.NONE) @Setter(AccessLevel.NONE) ExpandableField order; Outcome outcome; Boolean paid; + String paymentMethod; + PaymentMethodDetails paymentMethodDetails; String receiptEmail; String receiptNumber; String receiptUrl; @@ -602,6 +607,487 @@ public static class Rule extends StripeObject implements HasId { } } + @Getter + @Setter + @EqualsAndHashCode(callSuper = false) + public static class PaymentMethodDetails extends StripeObject { + @SerializedName("ach_credit_transfer") + AchCreditTransfer achCreditTransfer; + + @SerializedName("ach_debit") + AchDebit achDebit; + + @SerializedName("alipay") + Alipay alipay; + + @SerializedName("bancontact") + Bancontact bancontact; + + @SerializedName("bitcoin") + Bitcoin bitcoin; + + @SerializedName("card") + Card card; + + @SerializedName("card_present") + CardPresent cardPresent; + + @SerializedName("eps") + Eps eps; + + @SerializedName("giropay") + Giropay giropay; + + @SerializedName("ideal") + Ideal ideal; + + @SerializedName("multibanco") + Multibanco multibanco; + + @SerializedName("p24") + P24 p24; + + @SerializedName("sepa_debit") + SepaDebit sepaDebit; + + @SerializedName("sofort") + Sofort sofort; + + @SerializedName("stripe_account") + StripeAccount stripeAccount; + + @SerializedName("type") + String type; + + @SerializedName("wechat") + Wechat wechat; + + @Getter + @Setter + @EqualsAndHashCode(callSuper = false) + public static class AchCreditTransfer extends StripeObject { + @SerializedName("account_number") + String accountNumber; + + @SerializedName("bank_name") + String bankName; + + @SerializedName("routing_number") + String routingNumber; + + @SerializedName("swift_code") + String swiftCode; + } + + @Getter + @Setter + @EqualsAndHashCode(callSuper = false) + public static class AchDebit extends StripeObject { + @SerializedName("account_holder_type") + String accountHolderType; + + @SerializedName("bank_name") + String bankName; + + @SerializedName("country") + String country; + + @SerializedName("fingerprint") + String fingerprint; + + @SerializedName("last4") + String last4; + + @SerializedName("routing_number") + String routingNumber; + } + + @Getter + @Setter + @EqualsAndHashCode(callSuper = false) + public static class Alipay extends StripeObject {} + + @Getter + @Setter + @EqualsAndHashCode(callSuper = false) + public static class Bancontact extends StripeObject { + @SerializedName("bank_code") + String bankCode; + + @SerializedName("bank_name") + String bankName; + + @SerializedName("bic") + String bic; + + @SerializedName("iban_last4") + String ibanLast4; + + @SerializedName("preferred_language") + String preferredLanguage; + + @SerializedName("verified_name") + String verifiedName; + } + + @Getter + @Setter + @EqualsAndHashCode(callSuper = false) + public static class Bitcoin extends StripeObject { + @SerializedName("address") + String address; + + @SerializedName("amount") + Long amount; + + @SerializedName("amount_charged") + Long amountCharged; + + @SerializedName("amount_received") + Long amountReceived; + + @SerializedName("amount_returned") + Long amountReturned; + + @SerializedName("refund_address") + String refundAddress; + } + + @Getter + @Setter + @EqualsAndHashCode(callSuper = false) + public static class Card extends StripeObject { + @SerializedName("brand") + String brand; + + @SerializedName("checks") + Checks checks; + + @SerializedName("country") + String country; + + @SerializedName("exp_month") + Long expMonth; + + @SerializedName("exp_year") + Long expYear; + + @SerializedName("fingerprint") + String fingerprint; + + @SerializedName("funding") + String funding; + + @SerializedName("last4") + String last4; + + @SerializedName("three_d_secure") + ThreeDSecure threeDSecure; + + /** If this Card is part of a Card Wallet, this contains the details of the Card Wallet. */ + @SerializedName("wallet") + Wallet wallet; + + // Please note that these field are for internal use only and are not typically returned + // as part of standard API requests. + @SerializedName("description") + String description; + + @SerializedName("iin") + String iin; + + @SerializedName("issuer") + String issuer; + + @Getter + @Setter + @EqualsAndHashCode(callSuper = false) + public static class Checks extends StripeObject { + @SerializedName("address_line1_check") + String addressLine1Check; + + @SerializedName("address_postal_code_check") + String addressPostalCodeCheck; + + @SerializedName("cvc_check") + String cvcCheck; + } + + @Getter + @Setter + @EqualsAndHashCode(callSuper = false) + public static class ThreeDSecure extends StripeObject {} + + @Getter + @Setter + @EqualsAndHashCode(callSuper = false) + public static class Wallet extends StripeObject { + @SerializedName("amex_express_checkout") + AmexExpressCheckout amexExpressCheckout; + + @SerializedName("apple_pay") + ApplePay applePay; + + /** (For tokenized numbers only.) The last four digits of the device account number. */ + @SerializedName("dynamic_last4") + String dynamicLast4; + + @SerializedName("google_pay") + GooglePay googlePay; + + @SerializedName("masterpass") + Masterpass masterpass; + + @SerializedName("samsung_pay") + SamsungPay samsungPay; + + @SerializedName("type") + String type; + + @SerializedName("visa_checkout") + VisaCheckout visaCheckout; + + @Getter + @Setter + @EqualsAndHashCode(callSuper = false) + public static class AmexExpressCheckout extends StripeObject {} + + @Getter + @Setter + @EqualsAndHashCode(callSuper = false) + public static class ApplePay extends StripeObject {} + + @Getter + @Setter + @EqualsAndHashCode(callSuper = false) + public static class GooglePay extends StripeObject {} + + @Getter + @Setter + @EqualsAndHashCode(callSuper = false) + public static class Masterpass extends StripeObject { + @SerializedName("billing_address") + Address billingAddress; + + @SerializedName("email") + String email; + + @SerializedName("name") + String name; + + @SerializedName("shipping_address") + Address shippingAddress; + } + + @Getter + @Setter + @EqualsAndHashCode(callSuper = false) + public static class SamsungPay extends StripeObject {} + + @Getter + @Setter + @EqualsAndHashCode(callSuper = false) + public static class VisaCheckout extends StripeObject { + @SerializedName("billing_address") + Address billingAddress; + + @SerializedName("email") + String email; + + @SerializedName("name") + String name; + + @SerializedName("shipping_address") + Address shippingAddress; + } + } + } + + @Getter + @Setter + @EqualsAndHashCode(callSuper = false) + public static class CardPresent extends StripeObject { + @SerializedName("brand") + String brand; + + @SerializedName("country") + String country; + + @SerializedName("emv_auth_data") + String emvAuthData; + + @SerializedName("exp_month") + Long expMonth; + + @SerializedName("exp_year") + Long expYear; + + @SerializedName("fingerprint") + String fingerprint; + + @SerializedName("funding") + String funding; + + @SerializedName("generated_card") + String generatedCard; + + @SerializedName("last4") + String last4; + + @SerializedName("read_method") + String readMethod; + + @SerializedName("receipt") + Receipt receipt; + + @Getter + @Setter + @EqualsAndHashCode(callSuper = false) + public static class Receipt extends StripeObject { + @SerializedName("application_cryptogram") + String applicationCryptogram; + + @SerializedName("application_preferred_name") + String applicationPreferredName; + + @SerializedName("authorization_code") + String authorizationCode; + + @SerializedName("authorization_response_code") + String authorizationResponseCode; + + @SerializedName("cardholder_verification_method") + String cardholderVerificationMethod; + + @SerializedName("dedicated_file_name") + String dedicatedFileName; + + @SerializedName("terminal_verification_results") + String terminalVerificationResults; + + @SerializedName("transaction_status_information") + String transactionStatusInformation; + } + } + + @Getter + @Setter + @EqualsAndHashCode(callSuper = false) + public static class Eps extends StripeObject { + @SerializedName("verified_name") + String verifiedName; + } + + @Getter + @Setter + @EqualsAndHashCode(callSuper = false) + public static class Giropay extends StripeObject { + @SerializedName("bank_code") + String bankCode; + + @SerializedName("bank_name") + String bankName; + + @SerializedName("bic") + String bic; + + @SerializedName("verified_name") + String verifiedName; + } + + @Getter + @Setter + @EqualsAndHashCode(callSuper = false) + public static class Ideal extends StripeObject { + @SerializedName("bank") + String bank; + + @SerializedName("bic") + String bic; + + @SerializedName("iban_last4") + String ibanLast4; + + @SerializedName("verified_name") + String verifiedName; + } + + @Getter + @Setter + @EqualsAndHashCode(callSuper = false) + public static class Multibanco extends StripeObject { + @SerializedName("entity") + String entity; + + @SerializedName("reference") + String reference; + } + + @Getter + @Setter + @EqualsAndHashCode(callSuper = false) + public static class P24 extends StripeObject { + @SerializedName("reference") + String reference; + + @SerializedName("verified_name") + String verifiedName; + } + + @Getter + @Setter + @EqualsAndHashCode(callSuper = false) + public static class SepaDebit extends StripeObject { + @SerializedName("bank_code") + String bankCode; + + @SerializedName("branch_code") + String branchCode; + + @SerializedName("country") + String country; + + @SerializedName("fingerprint") + String fingerprint; + + @SerializedName("last4") + String last4; + } + + @Getter + @Setter + @EqualsAndHashCode(callSuper = false) + public static class Sofort extends StripeObject { + @SerializedName("bank_code") + String bankCode; + + @SerializedName("bank_name") + String bankName; + + @SerializedName("bic") + String bic; + + @SerializedName("country") + String country; + + @SerializedName("iban_last4") + String ibanLast4; + + @SerializedName("verified_name") + String verifiedName; + } + + @Getter + @Setter + @EqualsAndHashCode(callSuper = false) + public static class StripeAccount extends StripeObject {} + + @Getter + @Setter + @EqualsAndHashCode(callSuper = false) + public static class Wechat extends StripeObject {} + } + @Getter @Setter @EqualsAndHashCode(callSuper = false) diff --git a/src/main/java/com/stripe/model/EventDataClassLookup.java b/src/main/java/com/stripe/model/EventDataClassLookup.java index 30e206b5d01..c9954ec0261 100644 --- a/src/main/java/com/stripe/model/EventDataClassLookup.java +++ b/src/main/java/com/stripe/model/EventDataClassLookup.java @@ -46,6 +46,7 @@ final class EventDataClassLookup { classLookup.put("order_item", OrderItem.class); classLookup.put("order_return", OrderReturn.class); classLookup.put("payment_intent", PaymentIntent.class); + classLookup.put("payment_method", PaymentMethod.class); classLookup.put("payout", Payout.class); classLookup.put("plan", Plan.class); classLookup.put("product", Product.class); diff --git a/src/main/java/com/stripe/model/PaymentIntent.java b/src/main/java/com/stripe/model/PaymentIntent.java index d43a429eb7f..ca96750db66 100644 --- a/src/main/java/com/stripe/model/PaymentIntent.java +++ b/src/main/java/com/stripe/model/PaymentIntent.java @@ -37,6 +37,7 @@ public class PaymentIntent extends ApiResource implements MetadataStore metadata; NextAction nextAction; @Getter(AccessLevel.NONE) @Setter(AccessLevel.NONE) ExpandableField onBehalfOf; + @Getter(AccessLevel.NONE) @Setter(AccessLevel.NONE) ExpandableField paymentMethod; List paymentMethodTypes; String receiptEmail; @Getter(AccessLevel.NONE) @Setter(AccessLevel.NONE) ExpandableField review; @@ -129,6 +130,24 @@ public void setOnBehalfOfObject(Account c) { } // + // + public String getPaymentMethod() { + return (this.paymentMethod != null) ? this.paymentMethod.getId() : null; + } + + public void setPaymentMethod(String paymentMethodId) { + this.paymentMethod = setExpandableFieldId(paymentMethodId, this.paymentMethod); + } + + public PaymentMethod getPaymentMethodObject() { + return (this.paymentMethod != null) ? this.paymentMethod.getExpanded() : null; + } + + public void setPaymentMethodObject(PaymentMethod c) { + this.paymentMethod = new ExpandableField<>(c.getId(), c); + } + // + // public String getReview() { return (this.review != null) ? this.review.getId() : null; diff --git a/src/main/java/com/stripe/model/PaymentIntentLastPaymentError.java b/src/main/java/com/stripe/model/PaymentIntentLastPaymentError.java index 1e7242618fe..619728c6114 100644 --- a/src/main/java/com/stripe/model/PaymentIntentLastPaymentError.java +++ b/src/main/java/com/stripe/model/PaymentIntentLastPaymentError.java @@ -14,6 +14,8 @@ public final class PaymentIntentLastPaymentError extends StripeObject { String docUrl; String message; String param; + PaymentIntent paymentIntent; + PaymentMethod paymentMethod; ExternalAccount source; String type; } diff --git a/src/main/java/com/stripe/model/PaymentMethod.java b/src/main/java/com/stripe/model/PaymentMethod.java new file mode 100644 index 00000000000..1f5c19ca63e --- /dev/null +++ b/src/main/java/com/stripe/model/PaymentMethod.java @@ -0,0 +1,383 @@ +package com.stripe.model; + +import com.google.gson.annotations.SerializedName; +import com.stripe.Stripe; +import com.stripe.exception.StripeException; +import com.stripe.net.ApiResource; +import com.stripe.net.RequestOptions; +import java.util.Map; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +@EqualsAndHashCode(callSuper = false) +public class PaymentMethod extends ApiResource implements HasId, MetadataStore { + @SerializedName("billing_details") + BillingDetails billingDetails; + + @SerializedName("card") + Card card; + + @SerializedName("card_present") + CardPresent cardPresent; + + /** Time at which the object was created. Measured in seconds since the Unix epoch. */ + @SerializedName("created") + Long created; + + /** + * The ID of the Customer to which this PaymentMethod is saved. This will not be set when the + * PaymentMethod has not been saved to a Customer. + */ + @SerializedName("customer") + @Getter(lombok.AccessLevel.NONE) + @Setter(lombok.AccessLevel.NONE) + ExpandableField customer; + + /** Unique identifier for the object. */ + @Getter(onMethod = @__({@Override})) + @SerializedName("id") + String id; + + /** + * Has the value `true` if the object exists in live mode or the value `false` if the object + * exists in test mode. + */ + @SerializedName("livemode") + Boolean livemode; + + /** + * 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. + */ + @Getter(onMethod = @__({@Override})) + @SerializedName("metadata") + Map metadata; + + /** String representing the object's type. Objects of the same type share the same value. */ + @SerializedName("object") + String object; + + /** + * The type of the PaymentMethod, one of `card` or `card_present`. An additional hash is included + * on the PaymentMethod with a name matching this value. It contains additional information + * specific to the PaymentMethod type. + */ + @SerializedName("type") + String type; + + /** Get id of expandable `customer` object. */ + public String getCustomer() { + return (this.customer != null) ? this.customer.getId() : null; + } + + public void setCustomer(String id) { + this.customer = ApiResource.setExpandableFieldId(id, this.customer); + } + + /** Get expanded `customer`. */ + public Customer getCustomerObject() { + return (this.customer != null) ? this.customer.getExpanded() : null; + } + + public void setCustomerObject(Customer expandableObject) { + this.customer = new ExpandableField(expandableObject.getId(), expandableObject); + } + + /** + * Creates a PaymentMethod object. Read the Stripe.js reference to learn + * how to create PaymentMethods via Stripe.js. + */ + public static PaymentMethod create(Map params) throws StripeException { + return create(params, (RequestOptions) null); + } + + /** + * Creates a PaymentMethod object. Read the Stripe.js reference to learn + * how to create PaymentMethods via Stripe.js. + */ + public static PaymentMethod create(Map params, RequestOptions options) + throws StripeException { + String url = String.format("%s%s", Stripe.getApiBase(), "/v1/payment_methods"); + return request(ApiResource.RequestMethod.POST, url, params, PaymentMethod.class, options); + } + + /** Retrieves a PaymentMethod object. */ + public static PaymentMethod retrieve(String paymentMethod) throws StripeException { + return retrieve(paymentMethod, (Map) null, (RequestOptions) null); + } + + /** Retrieves a PaymentMethod object. */ + public static PaymentMethod retrieve( + String paymentMethod, Map params, RequestOptions options) + throws StripeException { + String url = + String.format( + "%s%s", Stripe.getApiBase(), String.format("/v1/payment_methods/%s", paymentMethod)); + return request(ApiResource.RequestMethod.GET, url, params, PaymentMethod.class, options); + } + + /** Updates a PaymentMethod object. A PaymentMethod must be attached a customer to be updated. */ + public PaymentMethod update(Map params) throws StripeException { + return update(params, (RequestOptions) null); + } + + /** Updates a PaymentMethod object. A PaymentMethod must be attached a customer to be updated. */ + public PaymentMethod update(Map params, RequestOptions options) + throws StripeException { + String url = + String.format( + "%s%s", Stripe.getApiBase(), String.format("/v1/payment_methods/%s", this.getId())); + return request(ApiResource.RequestMethod.POST, url, params, PaymentMethod.class, options); + } + + /** Returns a list of PaymentMethods for a given Customer. */ + public static PaymentMethodCollection list(Map params) throws StripeException { + return list(params, (RequestOptions) null); + } + + /** Returns a list of PaymentMethods for a given Customer. */ + public static PaymentMethodCollection list(Map params, RequestOptions options) + throws StripeException { + String url = String.format("%s%s", Stripe.getApiBase(), "/v1/payment_methods"); + return requestCollection(url, params, PaymentMethodCollection.class, options); + } + + /** Attaches a PaymentMethod object to a Customer. */ + public PaymentMethod attach(Map params) throws StripeException { + return attach(params, (RequestOptions) null); + } + + /** Attaches a PaymentMethod object to a Customer. */ + public PaymentMethod attach(Map params, RequestOptions options) + throws StripeException { + String url = + String.format( + "%s%s", + Stripe.getApiBase(), String.format("/v1/payment_methods/%s/attach", this.getId())); + return request(ApiResource.RequestMethod.POST, url, params, PaymentMethod.class, options); + } + + /** Detaches a PaymentMethod object from a Customer. */ + public PaymentMethod detach() throws StripeException { + return detach((Map) null, (RequestOptions) null); + } + + /** Detaches a PaymentMethod object from a Customer. */ + public PaymentMethod detach(RequestOptions options) throws StripeException { + return detach((Map) null, options); + } + + /** Detaches a PaymentMethod object from a Customer. */ + public PaymentMethod detach(Map params, RequestOptions options) + throws StripeException { + String url = + String.format( + "%s%s", + Stripe.getApiBase(), String.format("/v1/payment_methods/%s/detach", this.getId())); + return request(ApiResource.RequestMethod.POST, url, params, PaymentMethod.class, options); + } + + @Getter + @Setter + @EqualsAndHashCode(callSuper = false) + public static class BillingDetails extends StripeObject { + /** Billing address. */ + @SerializedName("address") + Address address; + + /** Email address. */ + @SerializedName("email") + String email; + + /** Full name. */ + @SerializedName("name") + String name; + + /** Billing phone number (including extension). */ + @SerializedName("phone") + String phone; + } + + @Getter + @Setter + @EqualsAndHashCode(callSuper = false) + public static class Card extends StripeObject { + /** + * Card brand. Can be `amex`, `diners`, `discover`, `jcb`, `mastercard`, `unionpay`, `visa`, or + * `unknown`. + */ + @SerializedName("brand") + String brand; + + /** Checks on Card address and CVC if provided. */ + @SerializedName("checks") + Checks checks; + + /** + * Two-letter ISO code representing the country of the card. You could use this attribute to get + * a sense of the international breakdown of cards you've collected. + */ + @SerializedName("country") + String country; + + /** Two-digit number representing the card's expiration month. */ + @SerializedName("exp_month") + Long expMonth; + + /** Four-digit number representing the card's expiration year. */ + @SerializedName("exp_year") + Long expYear; + + /** + * Uniquely identifies this particular card number. You can use this attribute to check whether + * two customers who've signed up with you are using the same card number, for example. + */ + @SerializedName("fingerprint") + String fingerprint; + + /** Card funding type. Can be `credit`, `debit`, `prepaid`, or `unknown`. */ + @SerializedName("funding") + String funding; + + /** The last four digits of the card. */ + @SerializedName("last4") + String last4; + + /** Contains details on how this Card maybe be used for 3D Secure authentication. */ + @SerializedName("three_d_secure_usage") + ThreeDSecureUsage threeDSecureUsage; + + /** If this Card is part of a Card Wallet, this contains the details of the Card Wallet. */ + @SerializedName("wallet") + Wallet wallet; + + // Please note that these field are for internal use only and are not typically returned + // as part of standard API requests. + @SerializedName("description") + String description; + + @SerializedName("iin") + String iin; + + @SerializedName("issuer") + String issuer; + + @Getter + @Setter + @EqualsAndHashCode(callSuper = false) + public static class Checks extends StripeObject { + @SerializedName("address_line1_check") + String addressLine1Check; + + @SerializedName("address_postal_code_check") + String addressPostalCodeCheck; + + @SerializedName("cvc_check") + String cvcCheck; + } + + @Getter + @Setter + @EqualsAndHashCode(callSuper = false) + public static class ThreeDSecureUsage extends StripeObject { + /** 3D Secure is supported on this card. */ + @SerializedName("supported") + Boolean supported; + } + + @Getter + @Setter + @EqualsAndHashCode(callSuper = false) + public static class Wallet extends StripeObject { + @SerializedName("amex_express_checkout") + AmexExpressCheckout amexExpressCheckout; + + @SerializedName("apple_pay") + ApplePay applePay; + + /** (For tokenized numbers only.) The last four digits of the device account number. */ + @SerializedName("dynamic_last4") + String dynamicLast4; + + @SerializedName("google_pay") + GooglePay googlePay; + + @SerializedName("masterpass") + Masterpass masterpass; + + @SerializedName("samsung_pay") + SamsungPay samsungPay; + + @SerializedName("type") + String type; + + @SerializedName("visa_checkout") + VisaCheckout visaCheckout; + + @Getter + @Setter + @EqualsAndHashCode(callSuper = false) + public static class AmexExpressCheckout extends StripeObject {} + + @Getter + @Setter + @EqualsAndHashCode(callSuper = false) + public static class ApplePay extends StripeObject {} + + @Getter + @Setter + @EqualsAndHashCode(callSuper = false) + public static class GooglePay extends StripeObject {} + + @Getter + @Setter + @EqualsAndHashCode(callSuper = false) + public static class Masterpass extends StripeObject { + @SerializedName("billing_address") + Address billingAddress; + + @SerializedName("email") + String email; + + @SerializedName("name") + String name; + + @SerializedName("shipping_address") + Address shippingAddress; + } + + @Getter + @Setter + @EqualsAndHashCode(callSuper = false) + public static class SamsungPay extends StripeObject {} + + @Getter + @Setter + @EqualsAndHashCode(callSuper = false) + public static class VisaCheckout extends StripeObject { + @SerializedName("billing_address") + Address billingAddress; + + @SerializedName("email") + String email; + + @SerializedName("name") + String name; + + @SerializedName("shipping_address") + Address shippingAddress; + } + } + } + + @Getter + @Setter + @EqualsAndHashCode(callSuper = false) + public static class CardPresent extends StripeObject {} +} + diff --git a/src/main/java/com/stripe/model/PaymentMethodCollection.java b/src/main/java/com/stripe/model/PaymentMethodCollection.java new file mode 100644 index 00000000000..1daf7ee0866 --- /dev/null +++ b/src/main/java/com/stripe/model/PaymentMethodCollection.java @@ -0,0 +1,4 @@ +package com.stripe.model; + +public class PaymentMethodCollection extends StripeCollection { +} diff --git a/src/main/java/com/stripe/model/StripeError.java b/src/main/java/com/stripe/model/StripeError.java index c159477ca49..7d6bff66ee2 100644 --- a/src/main/java/com/stripe/model/StripeError.java +++ b/src/main/java/com/stripe/model/StripeError.java @@ -45,7 +45,17 @@ public class StripeError extends StripeObject { @SerializedName("param") String param; - // TODO: add `payment_method` + /** + * The PaymentIntent object for errors returned on a request involving a PaymentIntent. + */ + @SerializedName("payment_intent") + PaymentIntent paymentIntent; + + /** + * The PaymentMethod object for errors returned on a request involving a PaymentMethod. + */ + @SerializedName("payment_method") + PaymentMethod paymentMethod; /** * The source object for errors returned on a request involving a source. diff --git a/src/test/java/com/stripe/functional/PaymentMethodTest.java b/src/test/java/com/stripe/functional/PaymentMethodTest.java new file mode 100644 index 00000000000..15d801e3c00 --- /dev/null +++ b/src/test/java/com/stripe/functional/PaymentMethodTest.java @@ -0,0 +1,114 @@ +package com.stripe.functional; + +import static org.junit.Assert.assertNotNull; + +import com.stripe.BaseStripeTest; +import com.stripe.exception.StripeException; +import com.stripe.model.PaymentMethod; +import com.stripe.model.PaymentMethodCollection; +import com.stripe.net.ApiResource; + +import java.util.HashMap; +import java.util.Map; + +import org.junit.Test; + +public class PaymentMethodTest extends BaseStripeTest { + public static final String PAYMENT_METHOD_ID = "pm_123"; + + private PaymentMethod getPaymentMethodFixture() throws StripeException { + final PaymentMethod payment_method = PaymentMethod.retrieve(PAYMENT_METHOD_ID); + resetNetworkSpy(); + return payment_method; + } + + @Test + public void testCreate() throws StripeException { + final Map params = new HashMap<>(); + params.put("type", "card"); + + final PaymentMethod payment_method = PaymentMethod.create(params); + + assertNotNull(payment_method); + verifyRequest( + ApiResource.RequestMethod.POST, + String.format("/v1/payment_methods"), + params + ); + } + + @Test + public void testRetrieve() throws StripeException { + final PaymentMethod payment_method = PaymentMethod.retrieve(PAYMENT_METHOD_ID); + + assertNotNull(payment_method); + verifyRequest( + ApiResource.RequestMethod.GET, + String.format("/v1/payment_methods/%s", PAYMENT_METHOD_ID) + ); + } + + @Test + public void testUpdate() throws StripeException { + final PaymentMethod payment_method = getPaymentMethodFixture(); + + final Map metadata = new HashMap<>(); + metadata.put("key", "value"); + final Map params = new HashMap<>(); + params.put("metadata", metadata); + + final PaymentMethod updatedPaymentMethod = payment_method.update(params); + + assertNotNull(updatedPaymentMethod); + verifyRequest( + ApiResource.RequestMethod.POST, + String.format("/v1/payment_methods/%s", payment_method.getId()), + params + ); + } + + @Test + public void testList() throws StripeException { + final Map params = new HashMap<>(); + params.put("customer", "cus_123"); + params.put("limit", 1); + params.put("type", "card"); + + final PaymentMethodCollection payment_methods = PaymentMethod.list(params); + + assertNotNull(payment_methods); + verifyRequest( + ApiResource.RequestMethod.GET, + String.format("/v1/payment_methods") + ); + } + + @Test + public void testAttach() throws StripeException { + final PaymentMethod payment_method = getPaymentMethodFixture(); + + final Map params = new HashMap<>(); + params.put("customer", "cus_123"); + + final PaymentMethod attachedPaymentMethod = payment_method.attach(params); + + assertNotNull(attachedPaymentMethod); + verifyRequest( + ApiResource.RequestMethod.POST, + String.format("/v1/payment_methods/%s/attach", payment_method.getId()) + ); + } + + @Test + public void testDetach() throws StripeException { + final PaymentMethod payment_method = getPaymentMethodFixture(); + + final PaymentMethod detachedPaymentMethod = payment_method.detach(); + + assertNotNull(detachedPaymentMethod); + verifyRequest( + ApiResource.RequestMethod.POST, + String.format("/v1/payment_methods/%s/detach", payment_method.getId()) + ); + } +} diff --git a/src/test/java/com/stripe/model/PaymentIntentTest.java b/src/test/java/com/stripe/model/PaymentIntentTest.java index b2a7eb23c09..eed15cf0b41 100644 --- a/src/test/java/com/stripe/model/PaymentIntentTest.java +++ b/src/test/java/com/stripe/model/PaymentIntentTest.java @@ -90,6 +90,7 @@ public void testDeserializeWithExpansions() throws Exception { "application", "customer", "on_behalf_of", + "payment_method", "review", "source", "transfer_data.destination", @@ -113,6 +114,10 @@ public void testDeserializeWithExpansions() throws Exception { assertNotNull(account); assertNotNull(account.getId()); assertEquals(resource.getOnBehalfOf(), account.getId()); + final PaymentMethod paymentMethod = resource.getPaymentMethodObject(); + assertNotNull(paymentMethod); + assertNotNull(paymentMethod.getId()); + assertEquals(resource.getPaymentMethod(), paymentMethod.getId()); final Review review = resource.getReviewObject(); assertNotNull(review); assertNotNull(review.getId()); diff --git a/src/test/java/com/stripe/model/PaymentMethodTest.java b/src/test/java/com/stripe/model/PaymentMethodTest.java new file mode 100644 index 00000000000..26d13fbda95 --- /dev/null +++ b/src/test/java/com/stripe/model/PaymentMethodTest.java @@ -0,0 +1,18 @@ +package com.stripe.model; + +import static org.junit.Assert.assertNotNull; + +import com.stripe.BaseStripeTest; +import com.stripe.net.ApiResource; + +import org.junit.Test; + +public class PaymentMethodTest extends BaseStripeTest { + @Test + public void testDeserialize() throws Exception { + final String data = getFixture("/v1/payment_methods/pm_123"); + final PaymentMethod resource = ApiResource.GSON.fromJson(data, PaymentMethod.class); + assertNotNull(resource); + assertNotNull(resource.getId()); + } +}