diff --git a/README.md b/README.md index 30c9e8c..00e8959 100644 --- a/README.md +++ b/README.md @@ -76,6 +76,36 @@ export default MyStripeCheckout; - `stripePublicKey` (String) - Stripe public key of your project. - `checkoutSessionInput` (Object) - Object to be passed to Stripe's `redirectToCheckout` function. [Docs](https://stripe.com/docs/js/checkout/redirect_to_checkout). + - ```js + { + sessionId: string, + successUrl: string, + cancelUrl: string, + // common + customerEmail?: string, + billingAddressCollection?: 'required' | 'auto', + shippingAddressCollection?: { + allowedCountries: Array, + }, + locale?: string, + } + | { + clientReferenceId: string, + successUrl: string, + cancelUrl: string, + items?: Array<{ plan: string, quantity: string }>, + lineItems?: Array<{ price: number, quantity: number }>, + mode?: 'payment' | 'subscription', + submitType?: string, + // common + customerEmail?: string, + billingAddressCollection?: 'required' | 'auto', + shippingAddressCollection?: { + allowedCountries: Array, + }, + locale?: string, + } + ``` - `onSuccess` (?Function) - Called upon success of the checkout session with `{ ...props, checkoutSessionId: 'CHECKOUT_SESSION_ID' }` - `onCancel` (?Function) - Called upon success of the checkout session with `{ ...props }` - `onLoadingComplete` (?Function) - Called when the Stripe checkout session webpage loads successfully. diff --git a/src/StripeCheckout.js b/src/StripeCheckout.js index 464d75c..af72b2f 100644 --- a/src/StripeCheckout.js +++ b/src/StripeCheckout.js @@ -9,16 +9,34 @@ type Props = { /** Stripe public key */ stripePublicKey: string, /** Stripe Checkout Session input */ - checkoutSessionInput: - | { - sessionId: string, - } - | { - clientReferenceId: string, - successUrl: string, - cancelUrl: string, - items?: Array<{ plan: string, quantity: string }>, - }, + checkoutSessionInput: { + sessionId: string, + successUrl: string, + cancelUrl: string, + // common + customerEmail?: string, + billingAddressCollection?: 'required' | 'auto', + shippingAddressCollection?: { + allowedCountries: Array, + }, + locale?: string, + } +| { + clientReferenceId: string, + successUrl: string, + cancelUrl: string, + items?: Array<{ plan: string, quantity: string }>, + lineItems?: Array<{ price: number, quantity: number }>, + mode?: 'payment' | 'subscription', + submitType?: string, + // common + customerEmail?: string, + billingAddressCollection?: 'required' | 'auto', + shippingAddressCollection?: { + allowedCountries: Array, + }, + locale?: string, + }, /** Called when the Stripe checkout session completes with status 'success' */ onSuccess: ({ [key: string]: any, checkoutSessionId?: string }) => any, /** Called when the Stripe checkout session completes with status 'cancel' */ diff --git a/src/stripeCheckoutRedirectHTML.js b/src/stripeCheckoutRedirectHTML.js index b748761..c469a69 100644 --- a/src/stripeCheckoutRedirectHTML.js +++ b/src/stripeCheckoutRedirectHTML.js @@ -8,12 +8,31 @@ const stripeCheckoutRedirectHTML = ( input: | { sessionId: string, + successUrl: string, + cancelUrl: string, + // common + customerEmail?: string, + billingAddressCollection?: 'required' | 'auto', + shippingAddressCollection?: { + allowedCountries: Array, + }, + locale?: string, } | { clientReferenceId: string, successUrl: string, cancelUrl: string, items?: Array<{ plan: string, quantity: string }>, + lineItems?: Array<{ price: number, quantity: number }>, + mode?: 'payment' | 'subscription', + submitType?: string, + // common + customerEmail?: string, + billingAddressCollection?: 'required' | 'auto', + shippingAddressCollection?: { + allowedCountries: Array, + }, + locale?: string, }, options?: { /** The loading item is set on the element with id='sc-loading' */