diff --git a/types/stripe-v3/index.d.ts b/types/stripe-v3/index.d.ts index 0422ad1090..d0f54ce727 100644 --- a/types/stripe-v3/index.d.ts +++ b/types/stripe-v3/index.d.ts @@ -8,6 +8,7 @@ // Kamil Gałuszka // Stefan Langeder // Marlos Borges +// Thomas Marek // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped declare var Stripe: stripe.StripeStatic; @@ -26,39 +27,43 @@ declare namespace stripe { createSource(element: elements.Element, options?: {owner?: OwnerInfo}): Promise; createSource(options: SourceOptions): Promise; retrieveSource(options: RetrieveSourceOptions): Promise; - paymentRequest(options: paymentRequest.StripePaymentRequestOptions): paymentRequest.StripePaymentRequest; - createPaymentMethod(type: paymentMethodType, element: elements.Element, data?: StripePaymentMethodIncomplete): Promise; redirectToCheckout(options: StripeCheckoutOptions): Promise; - retrievePaymentIntent(clientSecret: string): Promise; - handleCardPayment(clientSecret: string, element: elements.Element, data?: paymentIntent.CardPaymentData): Promise; - handleCardPayment(clientSecret: string, data?: paymentIntent.CardPaymentData): Promise; - handleCardAction(clientSecret: string): Promise; - confirmPaymentIntent(clientSecret: string, element: elements.Element, data: paymentIntent.PaymentIntentConfirmationData): Promise; - confirmPaymentIntent(clientSecret: string, data: paymentIntent.PaymentIntentConfirmationData): Promise; + paymentRequest(options: paymentRequest.StripePaymentRequestOptions): paymentRequest.StripePaymentRequest; + createPaymentMethod( + type: paymentMethod.paymentMethodType, + element: elements.Element, + options?: CreatePaymentMethodOptions, + ): Promise; + retrievePaymentIntent( + clientSecret: string, + ): Promise; + handleCardPayment( + clientSecret: string, + element: elements.Element, + options?: HandleCardPaymentOptions, + ): Promise; + handleCardPayment( + clientSecret: string, + options?: HandleCardPaymentWithoutElementsOptions, + ): Promise; + handleCardAction( + clientSecret: string, + ): Promise; + confirmPaymentIntent( + clientSecret: string, + element: elements.Element, + options?: ConfirmPaymentIntentOptions, + ): Promise; + confirmPaymentIntent( + clientSecret: string, + options?: ConfirmPaymentIntentWithoutElementsOptions, + ): Promise; } type StripeRedirectResponse = never | { error: Error; }; - interface StripePaymentMethodResponse { - paymentMethod?: StripePaymentMethod; - error?: Error; - } - - type paymentMethodType = 'card' | 'card_present'; - interface StripePaymentMethod extends StripePaymentMethodIncomplete { - id: string; - type: paymentMethodType; - } - - interface StripePaymentMethodIncomplete { - type?: paymentMethodType; - billing_details?: OwnerInfo; - card?: StripePaymentMethodCard; - metadata?: any; - } - type billingAddressCollectionType = 'required' | 'auto' | ''; interface StripeCheckoutOptions { items: StripeCheckoutItem[]; @@ -77,17 +82,10 @@ declare namespace stripe { quantity: number; } - interface StripePaymentMethodCard { - exp_month: number; - exp_year: number; - number: string; - cvc?: string; - } - interface StripeOptions { - stripeAccount?: string; - betas?: string[]; - locale?: string; + stripeAccount?: string; + betas?: string[]; + locale?: string; } interface TokenOptions { @@ -206,13 +204,74 @@ declare namespace stripe { error?: Error; } + type ErrorType = 'api_connection_error' + | 'api_error' + | 'authentication_error' + | 'card_error' + | 'idempotency_error' + | 'invalid_request_error' + | 'rate_limit_error'; + interface Error { - type: string; + /** + * The type of error returned. + */ + type: ErrorType; + + /** + * For card errors, the ID of the failed charge. + */ charge: string; - message?: string; + + /** + * For some errors that could be handled programmatically, + * a short string indicating the error code reported. + */ code?: string; + + /** + * For card errors resulting from a card issuer decline, + * a short string indicating the card issuer’s reason for + * the decline if they provide one. + */ decline_code?: string; + + /** + * A URL to more information about the error code reported. + */ + doc_url?: string; + + /** + * A human-readable message providing more details about the + * error. For card errors, these messages can be shown to + * your users. + */ + message?: string; + + /** + * If the error is parameter-specific, the parameter related + * to the error. For example, you can use this to display a + * message near the correct form field. + */ param?: string; + + /** + * The PaymentIntent object for errors returned on a request + * involving a PaymentIntent. + */ + payment_intent?: paymentIntents.PaymentIntent; + + /** + * The PaymentMethod object for errors returned on a + * request involving a PaymentMethod. + */ + payment_method?: paymentMethod.PaymentMethod; + + /** + * The source object for errors returned on a request involving + * a source. + */ + source?: Source; } type statusType = 'new' | 'validated' | 'verified' | 'verification_failed' | 'errored'; @@ -266,65 +325,201 @@ declare namespace stripe { client_secret: string; } - namespace paymentIntent { - interface PaymentIntentResponse { - paymentIntent?: StripePaymentIntent; - error?: Error; - } + /** + * A set of key/value pairs that you can attach to an object. It can be useful for storing + * additional information about the object in a structured format. + */ + interface Metadata { + [x: string]: string; + } - type paymentIntentStatus = 'requires_payment_method' | 'requires_confirmation' | 'requires_action' | 'processing' | 'requires_capture' | 'canceled' | 'succeeded'; - interface StripePaymentIntent { - id: string; - object: 'payment_intent'; - amount: number; - canceled_at: number; - client_secret: string; - created: number; - currency: string; - description: string; - livemode: boolean; - next_action: NextAction; - payment_method: string; - receipt_email: string; - shipping: ShippingInformation; - status: paymentIntentStatus; - } + interface List { + /** + * Value is 'list' + */ + object: 'list'; - type nextActionType = 'redirect_to_url' | 'use_stripe_sdk'; - interface NextAction { - redirect_to_url: RedirectOptions; - type: nextActionType; - } + /** + * An array containing the actual response elements, paginated by any request parameters. + */ + data: T[]; - interface RedirectOptions { - return_url: string; - url: string; - } + /** + * Whether or not there are more elements available after this set. If false, this set comprises the end of the list. + */ + has_more: boolean; - interface ShippingInformation { - address: OwnerAddress; - carrier: string; - name: string; - phone: string; - tracking_number: string; - } + /** + * The URL for accessing this list. + */ + url: string; + } - interface CardPaymentData { - payment_method?: string; - payment_method_data?: PaymentMethodData; - shipping?: ShippingInformation; - receipt_email?: string; - save_payment_method?: boolean; - } + interface BillingDetailsAddress { + city?: string; + country?: string; + line1?: string; + line2?: string; + postal_code?: string; + state?: string; + } - interface PaymentMethodData { - billing_details?: OwnerInfo; - card?: {[token: string]: string}; - } + interface BillingDetails { + address?: BillingDetailsAddress | null; + email?: string | null; + name?: string | null; + phone?: string | null; + } - interface PaymentIntentConfirmationData extends CardPaymentData { - return_url?: string; - } + interface ShippingDetailsAddress { + line1: string; + city?: string; + country?: string; + line2?: string; + postal_code?: string; + state?: string; + } + + interface ShippingDetails { + address: ShippingDetailsAddress; + name: string | null; + carrier: string | null; + phone: string | null; + tracking_number: string | null; + } + + interface CreatePaymentMethodOptions { + /** + * Billing information associated with the PaymentMethod + * that may be used or required by particular types of + * payment methods. + */ + billing_details?: BillingDetails; + metadata?: Metadata; + } + + interface HandleCardPaymentOptions { + /** + * Use this parameter to supply additional data relevant to + * the payment method, such as billing details + */ + payment_method_data?: { + /** + * The billing details associated with the card. [Recommended] + */ + billing_details?: BillingDetails, + }; + /** + * The shipping details for the payment, if collected. [Recommended] + */ + shipping?: ShippingDetails; + /** + * Email address that the receipt for the resulting payment will be sent to. + */ + receipt_email?: string; + /** + * If the PaymentIntent is associated with a customer and this parameter + * is set to true, the provided payment method will be attached to the + * customer. Default is false. + */ + save_payment_method?: boolean; + } + + interface HandleCardPaymentWithoutElementsOptions extends HandleCardPaymentOptions { + /** + * Only one of payment_method_data and payment_method is required. + * Use payment_method to specify an existing PaymentMethod to use + * for this payment. + */ + payment_method?: string; + /** + * Use this parameter to supply additional data relevant to + * the payment method, such as billing details + */ + payment_method_data?: { + /** + * The billing details associated with the card. [Recommended] + */ + billing_details?: BillingDetails, + card?: { + /** + * Converts the provided token into a PaymentMethod to + * use for the payment. + */ + token: string; + } + }; + } + + interface ConfirmPaymentIntentOptions { + /** + * A return_url may be supplied if you are not planning to use + * stripe.handleCardPayment to complete the payment. If you are + * handling next actions yourself, pass in a return_url. If the + * subsequent action is redirect_to_url, this URL will be used + * on the return path for the redirect. + */ + return_url?: string; + /** + * Use this parameter to supply additional data relevant to + * the payment method, such as billing details + */ + payment_method_data?: { + /** + * The billing details associated with the card. [Recommended] + */ + billing_details?: BillingDetails, + }; + /** + * The shipping details for the payment, if collected. [Recommended] + */ + shipping?: ShippingDetails; + /** + * Email address that the receipt for the resulting payment will be sent to. + */ + receipt_email?: string; + /** + * If the PaymentIntent is associated with a customer and this parameter + * is set to true, the provided payment method will be attached to the + * customer. Default is false. + */ + save_payment_method?: boolean; + } + + interface ConfirmPaymentIntentWithoutElementsOptions extends ConfirmPaymentIntentOptions { + /** + * Only one of payment_method_data and payment_method is required. + * Use payment_method to specify an existing PaymentMethod to use + * for this payment. + */ + payment_method?: string; + /** + * Use this parameter to supply additional data relevant to + * the payment method, such as billing details + */ + payment_method_data?: { + /** + * The billing details associated with the card. [Recommended] + */ + billing_details?: BillingDetails, + card?: { + /** + * Converts the provided token into a PaymentMethod to + * use for the payment. + */ + token: string; + } + }; + } + + interface PaymentMethodResponse { + paymentMethod?: paymentMethod.PaymentMethod; + error?: Error; + } + + interface PaymentIntentResponse { + paymentIntent?: paymentIntents.PaymentIntent; + error?: Error; } // Container for all payment request related types @@ -520,4 +715,826 @@ declare namespace stripe { height: string; } } + + namespace paymentIntents { + type PaymentIntentStatus = 'requires_payment_method' + | 'requires_confirmation' + | 'requires_action' + | 'processing' + | 'requires_capture' + | 'canceled' + | 'succeeded'; + + type PaymentIntentCancelationReason = 'duplicate' + | 'fraudulent' + | 'requested_by_customer' + | 'abandoned' + // Generated by Stripe internally: + | 'failed_invoice' + | 'void_invoice' + | 'automatic'; + + interface PaymentIntentNextActionRedirectToUrl { + /** + * Type of the next action to perform + */ + type: 'redirect_to_url'; + /** + * Contains instructions for authenticating a payment by + * redirecting your customer to another page or application. + */ + redirect_to_url: { + /** + * If the customer does not exit their browser while + * authenticating, they will be redirected to this + * specified URL after completion. + */ + return_url: string; + + /** + * The URL you must redirect your customer to in + * order to authenticate the payment. + */ + url: string; + }; + } + + interface PaymentIntentNextActionUseStripeSdk { + /** + * Type of the next action to perform + */ + type: 'use_stripe_sdk'; + /** + * When confirming a PaymentIntent with Stripe.js, + * Stripe.js depends on the contents of this dictionary + * to invoke authentication flows. The shape of the contents + * is subject to change and is only intended to be used by Stripe.js. + */ + use_stripe_sdk: any; + } + + interface PaymentIntent { + /** + * Unique identifier for the object. + */ + id: string; + + /** + * Value is "payment_intent". + */ + object: 'payment_intent'; + + /** + * The amount in cents that is to be collected from this PaymentIntent. + */ + amount: number; + + /** + * The amount that can be captured with from this PaymentIntent (in cents). + */ + amount_capturable: number; + + /** + * The amount that was collected from this PaymentIntent (in cents). + */ + amount_received: number; + + /** + * ID of the Connect application that created the PaymentIntent. + */ + application: string | null; + + /** + * A fee in cents that will be applied to the invoice and transferred to the application owner's Stripe account. + */ + application_fee_amount: number | null; + + /** + * Populated when `status` is `canceled`, this is the time at which the PaymentIntent was canceled. + * Measured in seconds since the Unix epoch. + */ + canceled_at: number | null; + + /** + * User-given reason for cancellation of this PaymentIntent. + */ + cancelation_reason: PaymentIntentCancelationReason | null; + + /** + * Capture method of this PaymentIntent. + */ + capture_method: 'automatic' | 'manual'; + + /** + * Charges that were created by this PaymentIntent, if any. + */ + charges: List; + + /** + * The client secret of this PaymentIntent. Used for client-side retrieval using a publishable key. Please refer to dynamic authentication guide on how client_secret should be handled. + */ + client_secret: string; + + /** + * Confirmation method of this PaymentIntent. + */ + confirmation_method: 'automatic' | 'manual'; + + /** + * Time at which the object was created. Measured in seconds since the Unix epoch. + */ + created: number; + + /** + * Three-letter ISO currency code, in lowercase. Must be a supported currency. + */ + currency: string; + + /** + * ID of the Customer this PaymentIntent is for if one exists. + */ + customer: string | null; + + /** + * An arbitrary string attached to the object. Often useful for displaying to users. + */ + description?: string; + + /** + * The payment error encountered in the previous PaymentIntent confirmation. + */ + last_payment_error: Error | null; + + /** + * Has the value true if the object exists in live mode or the value false + * if the object exists in test mode. + */ + livemode: boolean; + + metadata: Metadata; + + /** + * If present, this property tells you what actions you need to take in order + * for your customer to fulfill a payment using the provided source. + */ + next_action: PaymentIntentNextActionUseStripeSdk | PaymentIntentNextActionRedirectToUrl; + + /** + * The account (if any) for which the funds of the PaymentIntent are intended. + * See the PaymentIntents Connect usage guide for details. + */ + on_behalf_of: string | null; + + /** + * The list of payment method types (e.g. card) that this PaymentIntent is allowed to use. + */ + payment_method_types: string[]; + + /** + * Email address that the receipt for the resulting payment will be sent to. + */ + receipt_email: string | null; + + /** + * ID of the review associated with this PaymentIntent, if any. + */ + review: string | null; + + /** + * Shipping information for this PaymentIntent. + */ + shipping: ShippingDetails | null; + + /** + * Extra information about a PaymentIntent. This will appear on your + * customer’s statement when this PaymentIntent succeeds in creating a charge. + */ + statement_descriptor: string | null; + + /** + * The several states the PaymentIntent goes through until it it either canceled or succeeds. + */ + status: PaymentIntentStatus; + + /** + * The data with which to automatically create a Transfer when the payment is finalized. + */ + transfer_data: { + /** + * The account (if any) the payment will be attributed to for tax reporting, + * and where funds from the payment will be transferred to upon payment success. + */ + destination: string; + } | null; + + /** + * A string that identifies the resulting payment as part of a group. + */ + transfer_group: string | null; + } + + interface Charge { + /** + * Unique identifier for the object. + */ + id: string; + + /** + * Value is 'charge' + */ + object: "charge"; + + /** + * Amount charged in cents/pence, positive integer or zero. + */ + amount: number; + + /** + * Amount in cents/pence refunded (can be less than the amount attribute on the + * charge if a partial refund was issued), positive integer or zero. + */ + amount_refunded: number; + + /** + * ID of the Connect application that created the charge. + */ + application: string | null; + + /** + * The application fee (if any) for the charge. See the Connect documentation + * for details. + */ + application_fee: string | null; + + /** + * The amount of the application fee (if any) for the charge. See the Connect + * documentation for details. + */ + application_fee_amount: number | null; + + /** + * ID of the balance transaction that describes the impact of this charge on + * your account balance (not including refunds or disputes). + */ + balance_transaction: string; + + /** + * Billing information associated with the payment method at the time of the transaction. + */ + billing_details: BillingDetails; + + /** + * If the charge was created without capturing, this boolean represents whether or not it is + * still uncaptured or has since been captured. + */ + captured: boolean; + + /** + * Time at which the object was created. Measured in seconds since the Unix epoch. + */ + created: number; + + /** + * Three-letter ISO currency code representing the currency in which the + * charge was made. + */ + currency: string; + + /** + * ID of the customer this charge is for if one exists. + */ + customer: string | null; + + /** + * An arbitrary string attached to the object. Often useful for displaying to users. + */ + description: string | null; + + /** + * Details about the dispute if the charge has been disputed. + */ + dispute: string | null; + + /** + * Error code explaining reason for charge failure if available (see the errors section for a list of + * codes: https://stripe.com/docs/api#errors). + */ + failure_code: string | null; + + /** + * Message to user further explaining reason for charge failure if available. + */ + failure_message: string | null; + + /** + * Hash with information on fraud assessments for the charge. + */ + fraud_details: { + /** + * Assessments reported by you have the key user_report and, if set, possible values of "safe" and "fraudulent". + */ + user_report?: "fraudulent" | "safe"; + + /** + * Assessments from Stripe have the key stripe_report and, if set, the value "fraudulent". + */ + stripe_report?: "fraudulent"; + }; + + /** + * ID of the invoice this charge is for if one exists. [Expandable] + */ + invoice: string | null; + + /** + * Has the value true if the object exists in live mode or the value false if + * the object exists in test mode. + */ + livemode: boolean; + + metadata: Metadata; + + /** + * The Stripe account ID for which these funds are intended. Automatically + * set if you use the destination parameter. For details, see [Creating + * Separate Charges and Transfers] + * . + */ + on_behalf_of: string | null; + + /** + * ID of the order this charge is for if one exists. + */ + order: string | null; + + /** + * Details about whether the payment was accepted, and why. See + * understanding declines for details. + */ + outcome: { + network_status: 'approved_by_network' | 'declined_by_network' | 'not_sent_to_network' | 'reversed_after_approval'; + reason: 'highest_risk_level' | 'elevated_risk_level' | 'rule' | null; + risk_level: 'normal' | 'elevated' | 'highest' | 'not_assessed' | 'unknown'; + risk_score: number; + rule?: string; + seller_message: string; + type: 'authorized' | 'manual_review' | 'issuer_declined' | 'blocked' | 'invalid'; + } | null; + + /** + * true if the charge succeeded, or was successfully authorized for later capture. + */ + paid: boolean; + + /** + * ID of the PaymentIntent associated with this charge, if one exists. + */ + payment_intent: string; + + /** + * ID of the payment method used in this charge. + */ + payment_method: string | null; + + payment_method_details: paymentMethod.PaymentMethodDetails; + + /** + * This is the email address that the receipt for this charge was sent to. + */ + receipt_email: string | null; + + /** + * This is the transaction number that appears on email receipts sent for this charge. + */ + receipt_number: string | null; + + /** + * This is the URL to view the receipt for this charge. The receipt is kept up-to-date to the + * latest state of the charge, including any refunds. If the charge is for an Invoice, the + * receipt will be stylized as an Invoice receipt. + */ + receipt_url: string; + + /** + * Whether or not the charge has been fully refunded. If the charge is only partially refunded, + * this attribute will still be false. + */ + refunded: boolean; + + /** + * A list of refunds that have been applied to the charge. + */ + refunds: List; + + /** + * ID of the review associated with this charge if one exists. + */ + review?: string | null; + + /** + * Shipping information for the charge. + */ + shipping?: ShippingDetails | null; + + /** + * For most Stripe users, the source of every charge is a credit or debit card. + * This hash is then the card object describing that card. + */ + source?: Source; + + /** + * The transfer ID which created this charge. Only present if the charge came + * from another Stripe account. See the Connect documentation for details. + */ + source_transfer: string | null; + + /** + * Extra information about a charge. This will appear on your customer’s + * credit card statement. + */ + statement_descriptor: string | null; + + /** + * The status of the payment is either "succeeded", "pending", or "failed". + */ + status: "succeeded" | "pending" | "failed"; + + /** + * ID of the transfer to the destination account (only applicable if the + * charge was created using the destination parameter). + */ + transfer?: string | null; + + /** + * A string that identifies this transaction as part of a group. + * See the Connect documentation for details. + */ + transfer_group?: string | null; + } + + interface Refund { + /** + * Unique identifier for the object. + */ + id: string; + + /** + * Value is "refund" + */ + object: 'refund'; + + /** + * Refund amount, in cents. + */ + amount: number; + + /** + * Balance transaction that describes the impact on your account balance. + */ + balance_transaction: string | null; + + /** + * ID of the charge that was refunded. + */ + charge: string; + + /** + * Time at which the object was created. Measured in seconds since the Unix epoch. + */ + created: number; + + /** + * Three-letter ISO currency code, in lowercase. Must be a supported currency. + */ + currency: string; + + /** + * An arbitrary string attached to the object. Often useful for + * displaying to users. (Available on non-card refunds only) + */ + description?: string; + + /** + * If the refund failed, this balance transaction describes the + * adjustment made on your account balance that reverses the + * initial balance transaction. + */ + failure_balance_transaction?: string; + + /** + * If the refund failed, the reason for refund failure if known + */ + failure_reason?: 'lost_or_stolen_card' + | 'expired_or_canceled_card' + | 'unknown'; + + metadata: Metadata; + + /** + * Reason for the refund + */ + reason: 'duplicate' | 'fraudulent' | 'requested_by_customer' | null; + + /** + * This is the transaction number that appears on email + * receipts sent for this refund. + */ + receipt_number: string | null; + + /** + * The transfer reversal that is associated with the refund. + * Only present if the charge came from another Stripe account. + * See the Connect documentation for details. + */ + source_transfer_reversal: string | null; + + /** + * Status of the refund. For credit card refunds, this can be + * pending, succeeded, or failed. For other types of refunds, + * it can be pending, succeeded, failed, or canceled. Refer to + * our refunds documentation for more details. + */ + status: 'pending' | 'succeeded' | 'failed' | 'canceled'; + + /** + * If the accompanying transfer was reversed, the transfer reversal object. + * Only applicable if the charge was created using the destination parameter. + */ + transfer_reversal: string | null; + } + } + + namespace paymentMethod { + type paymentMethodType = 'card' | 'card_present'; + + interface PaymentMethod { + /** + * The unique identifier for the object + */ + id: string; + + /** + * Value is "payment_method" + */ + object: 'payment_method'; + + /** + * Billing information associated with the PaymentMethod that may be + * used or required by particular types of payment methods. + */ + billing_details: BillingDetails; + + /** + * If this is a card PaymentMethod, this hash contains details about the card. + */ + card?: PaymentMethodCard; + + /** + * If this is an card_present PaymentMethod, this hash contains details + * about the Card Present payment method. + */ + card_present?: any; + + /** + * Time at which the object was created. Measured in seconds since the + * Unix epoch. + */ + created: number; + + /** + * 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. + */ + customer: string | null; + + /** + * Has the value true if the object exists in live mode or the value + * false if the object exists in test mode. + */ + livemode: boolean; + + metadata: Metadata; + + /** + * The type of the PaymentMethod. An additional hash is included on the + * PaymentMethod with a name matching this value. It contains additional + * information specific to the PaymentMethod type. + */ + type: string; + } + + type paymentMethodCardBrand = 'amex' + | 'diners' + | 'discover' + | 'jcb' + | 'mastercard' + | 'unionpay' + | 'visa' + | 'unknown'; + + interface PaymentMethodCard { + /** + * Card brand + */ + brand: paymentMethodCardBrand; + + /** + * Checks on Card address and CVC if provided. + */ + checks: { + address_line1_check: boolean | null; + address_postal_code_check: boolean | null; + cvc_check: boolean | null; + }; + + /** + * 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. + */ + country: string; + + /** + * Two-digit number representing the card’s expiration month. + */ + exp_month: number; + + /** + * Four-digit number representing the card’s expiration year. + */ + exp_year: number; + + /** + * 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. + */ + fingerprint: string; + + /** + * Card funding type + */ + funding: fundingType; + + /** + * Details of the original PaymentMethod that created this object. + */ + generated_from: { + charge?: string | null; + payment_method_details?: PaymentMethodDetails | null; + }; + + /** + * The last four digits of the card. + */ + last4: string; + + /** + * Contains details on how this Card maybe be used for 3D Secure authentication. + */ + three_d_secure_usage?: { + supported?: boolean; + }; + + /** + * If this Card is part of a card wallet, this contains the details of + * the card wallet. + */ + wallet: { + type: 'amex_express_checkout' + | 'apple_pay' + | 'google_pay' + | 'masterpass' + | 'samsung_pay' + | 'visa_checkout'; + amex_express_checkout?: any; + apple_pay?: any; + dynamic_last4?: any; + google_pay?: any; + masterpass?: any; + samsung_pay?: any; + visa_checkout?: any; + } | null; + } + + /** + * Details about the payment method at the time of the transaction. + */ + interface PaymentMethodDetails { + /** + * The type of transaction-specific details of the payment method used in the payment + */ + type: 'ach_credit_transfer' + | 'ach_debit' + | 'alipay' + | 'bancontact' + | 'card' + | 'eps' + | 'giropay' + | 'ideal' + | 'multibanco' + | 'p24' + | 'sepa_debit' + | 'sofort' + | 'stripe_account' + | 'wechat'; + + ach_credit_transfer?: AchCreditTransferDetails | null; + ach_debit?: AchDebitDetails | null; + alipay?: any | null; + bancontact?: BanContactDetails | null; + card?: PaymentMethodCard | null; + eps?: EpsDetails | null; + giropay?: GiropayDetails | null; + ideal?: IdealDetails | null; + multibanco?: MultibancoDetails | null; + p24?: P24Details | null; + sepa_debit?: SepaDebitDetails | null; + sofort?: SofortDetails | null; + stripe_account?: any | null; + wechat?: any | null; + } + + interface AchCreditTransferDetails { + account_number: string; + bank_name: string; + routing_number: string; + swift_coode: string; + } + + interface AchDebitDetails { + account_holder_type: 'individual' | 'company'; + bank_name: string; + country: string; + fingerprint: string; + last4: string; + routing_number: string; + } + + interface BanContactDetails { + bank_code: string; + bank_name: string; + bic: string; + iban_last4: string; + preferred_language: 'en' | 'de' | 'fr' | 'nl'; + verified_name: string; + } + + interface EpsDetails { + verified_name: string; + } + + interface GiropayDetails { + bank_code: string; + bank_name: string; + bic: string; + verified_name: string; + } + + interface IdealDetails { + bank: 'abn_amro' + | 'asn_bank' + | 'bunq' + | 'handelsbanken' + | 'ing' + | 'knab' + | 'moneyou' + | 'rabobank' + | 'regiobank' + | 'sns_bank' + | 'triodos_bank' + | 'van_lanschot'; + + bic: string; + iban_last4: string; + verified_name: string; + } + + interface MultibancoDetails { + entity: string; + reference: string; + } + + interface P24Details { + reference: string; + verified_name: string; + } + + interface SepaDebitDetails { + bank_code: string; + branch_code: string; + country: string; + fingerprint: string; + last4: string; + } + + interface SofortDetails { + bank_code: string; + bank_name: string; + bic: string; + country: string; + iban_last4: string; + verified_name: string; + } + } } diff --git a/types/stripe-v3/stripe-v3-tests.ts b/types/stripe-v3/stripe-v3-tests.ts index 0a36db11a5..39805c5b32 100644 --- a/types/stripe-v3/stripe-v3-tests.ts +++ b/types/stripe-v3/stripe-v3-tests.ts @@ -191,7 +191,7 @@ describe("Stripe elements", () => { if (result.error) { console.error(result.error.param); } else if (result.paymentMethod) { - console.log(result.paymentMethod.card && result.paymentMethod.card.number); + console.log(result.paymentMethod.card && result.paymentMethod.card.brand); } }); }); @@ -246,7 +246,7 @@ describe("Stripe elements", () => { if (result.error) { console.error(result.error.message); } else if (result.paymentIntent) { - console.log(result.paymentIntent.shipping.address); + console.log(result.paymentIntent.shipping && result.paymentIntent.shipping.address); } }); });