@@ -29,7 +29,6 @@ styles, fonts).
2929 - [ The Stripe context (` StripeProvider ` )] ( #the-stripe-context-stripeprovider )
3030 - [ Element groups (` Elements ` )] ( #element-groups-elements )
3131 - [ Setting up your payment form (` injectStripe ` )] ( #setting-up-your-payment-form-injectstripe )
32- - [ Using Stripe.js methods that do not have automatic element detection] ( #using-methods-that-do-not-have-automatic-element-detection )
3332 - [ Using individual ` *Element ` components] ( #using-individual-element-components )
3433 - [ Using the ` PaymentRequestButtonElement ` ] ( #using-the-paymentrequestbuttonelement )
3534- [ Advanced integrations] ( #advanced-integrations )
@@ -197,6 +196,8 @@ class CheckoutForm extends React.Component {
197196 // Use Elements to get a reference to the Card Element mounted somewhere
198197 // in your <Elements> tree. Elements will know how to find your Card Element
199198 // becase only one is allowed.
199+ // See our getElement documentation for more:
200+ // https://stripe.com/docs/stripe-js/reference#elements-get-element
200201 const cardElement = this .props .elements .getElement (' card' );
201202
202203 // From here we cal call createPaymentMethod to create a PaymentMethod
@@ -223,8 +224,8 @@ class CheckoutForm extends React.Component {
223224
224225 // You can also use confirmCardSetup with the SetupIntents API.
225226 // See our confirmCardSetup documentation for more:
226- // https://stripe.com/docs/stripe-js/reference#stripe-handle -card-setup
227- this .props .stripe .handleCardSetup (' {PAYMENT_INTENT_CLIENT_SECRET}' , {
227+ // https://stripe.com/docs/stripe-js/reference#stripe-confirm -card-setup
228+ this .props .stripe .confirmCardSetpu (' {PAYMENT_INTENT_CLIENT_SECRET}' , {
228229 payment_method: {
229230 card: cardElement,
230231 },
@@ -234,7 +235,7 @@ class CheckoutForm extends React.Component {
234235 // See our tokens documentation for more:
235236 // https://stripe.com/docs/stripe-js/reference#stripe-create-token
236237 // With createToken, you will not need to pass in the reference to
237- // the Card Element. It will be inferred automatically.
238+ // the Element. It will be inferred automatically.
238239 this .props .stripe .createToken ({type: ' card' , name: ' Jenny Rosen' });
239240 // token type can optionally be inferred if there is only one Element
240241 // with which to create tokens
@@ -244,7 +245,7 @@ class CheckoutForm extends React.Component {
244245 // See our Sources documentation for more:
245246 // https://stripe.com/docs/stripe-js/reference#stripe-create-source
246247 // With createSource, you will not need to pass in the reference to
247- // the Card Element. It will be inferred automatically.
248+ // the Element. It will be inferred automatically.
248249 this .props .stripe .createSource ({
249250 type: ' card' ,
250251 owner: {
@@ -668,14 +669,13 @@ function injectStripe(
668669Use `injectStripe` to wrap a component that needs to interact with `Stripe.js`
669670to create sources or tokens.
670671
671- 1. First, create a component that accepts the `stripe` prop and calls
672- `this.props.stripe.createToken` or `this.props.stripe.createSource` when
673- necessary.
672+ 1. First, create a component that accepts the `stripe` prop and calls one of
673+ the Stripe or Elements methods when necessary.
6746742. Wrap that component by passing it to `injectStripe` so that it actually
675675 receives the `stripe` and `elements` props.
6766763. Render the component that `injectStripe` returns.
677677
678- ### Example
678+ #### Example
679679
680680```jsx
681681// 1. Create a component that uses this.props.stripe:
@@ -684,7 +684,12 @@ class CheckoutForm extends React.Component {
684684 /* ... */
685685 }
686686 onCompleteCheckout () {
687- this .props .stripe .createPaymentMethod (' card' ).then (/* ... */ );
687+ this .props .stripe
688+ .createPaymentMethod ({
689+ type: ' card' ,
690+ card: this .props .stripe .getElement (' card' ),
691+ })
692+ .then (/* ... */ );
688693 }
689694}
690695
@@ -715,10 +720,15 @@ available with the `getWrappedInstance()` method of the wrapper component. This
715720feature can not be used if the wrapped component is a stateless function
716721component.
717722
718- Within the wrapped component, the ` stripe ` prop has the type:
723+ Within the wrapped component, the ` stripe ` and ` elements ` props have the type:
719724
720725``` jsx
721726type FactoryProps = {
727+ elements: null | {
728+ getElement : (type : string ) => Element | null ,
729+ // and other functions available on the `elements` object,
730+ // as officially documented here: https://stripe.com/docs/elements/reference#the-elements-object
731+ },
722732 stripe: null | {
723733 createToken : (tokenData : {type?: string}) => Promise < {
724734 token?: Object ,
@@ -729,8 +739,7 @@ type FactoryProps = {
729739 error?: Object ,
730740 }> ,
731741 createPaymentMethod: (
732- type: string,
733- paymentMethodData?: Object
742+ paymentMethodData: Object
734743 ) => Promise < {
735744 paymentMethod?: Object ,
736745 error?: Object ,
@@ -755,10 +764,7 @@ type FactoryProps = {
755764};
756765```
757766
758- In addition to the ` stripe ` prop, ` injectStripe ` also injects a reference to the
759- Elements instance as the ` elements ` prop.
760-
761- The ` stripe ` and ` elements ` prop can only be ` null ` if you are using one of the
767+ The ` stripe ` and ` elements ` props can only be ` null ` if you are using one of the
762768[ Advanced integrations] ( #advanced-integrations ) mentioned above, like loading
763769Stripe.js asynchronously or providing an existing instance. If you are using a
764770basic integration where you pass in an api key to ` <StripeProvider/> ` , they will
@@ -805,14 +811,9 @@ reach all components.
8058112. You can use the [` pure: false` ][pure- false ] option for redux- connect:
806812
807813 ` ` ` jsx
808- const Component = connect(
809- mapStateToProps,
810- mapDispatchToProps,
811- mergeProps,
812- {
813- pure: false,
814- }
815- )(injectStripe(_CardForm));
814+ const Component = connect(mapStateToProps, mapDispatchToProps, mergeProps, {
815+ pure: false,
816+ })(injectStripe(_CardForm));
816817 ` ` `
817818
818819[pure- false ]:
0 commit comments