Skip to content

Commit

Permalink
✨📚 update types and docs
Browse files Browse the repository at this point in the history
  • Loading branch information
a-tokyo committed May 19, 2021
1 parent 1c4c564 commit 4013ab8
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 10 deletions.
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>,
},
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<string>,
},
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.
Expand Down
38 changes: 28 additions & 10 deletions src/StripeCheckout.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>,
},
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<string>,
},
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' */
Expand Down
19 changes: 19 additions & 0 deletions src/stripeCheckoutRedirectHTML.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,31 @@ const stripeCheckoutRedirectHTML = (
input:
| {
sessionId: string,
successUrl: string,
cancelUrl: string,
// common
customerEmail?: string,
billingAddressCollection?: 'required' | 'auto',
shippingAddressCollection?: {
allowedCountries: Array<string>,
},
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<string>,
},
locale?: string,
},
options?: {
/** The loading item is set on the element with id='sc-loading' */
Expand Down

0 comments on commit 4013ab8

Please sign in to comment.