Pay with Card
Payment acceptance phase of the order lifecycle for credit cards
The order lifecycle can be summarized as follows:
Order Creation or Update
Your application determines recipient info for the buyer. It can be an email wallet or wallet address. Create or update an order with this info to proceed to next step.
API Response
The API response returned from create/update order call(s) will include a payment.preparation
object that your
application uses to render the Stripe payment element.
Render Stripe Payment Element
Use the stripePublishableKey
and stripeClientSecret
returned in the API response to render the credit card
checkout form.
User Completes Payment
Poll for Status
Your application will poll the GET order status and update the UI as the order progresses to the next phase.
quote
phase of the order the payment status will be requires-quote
.Once the quote phase is completed, the order enters the payment phase and will have the status awaiting-payment
, which indicates that the order is ready to be paid.
See below the full list of possible statuses:
Payment Status | Explanation |
---|---|
requires-quote | still in the quote phase |
awaiting-payment | ready to submit payment |
completed | order is in the delivery or order completion phase |
Render the Stripe Payment Element
When the order is ready to accept payment, the API response will include an order.payment.preparation
object, which contains two important properties to render the payment element. These properties are named: stripePublishableKey
and stripeClientSecret
. You can use these with the Stripe Payment Element package to collect the user’s credit card payment.
The key
property on the Elements
component is important to re-render the payment element if either the
stripeClientSecret
or stripePublishableKey
change, as these fields can't be 'live' updated
Handle Payment Confirmation
The Stripe Payment Element does not handle submitting the payment, so you will also need to create your own submit button.
First, at the top of the file, update the import for @stripe/react-stripe-js
to be:
Then, update the SubmitButton
component with the following code:
At this point, your app should look similar to the one displayed below (fill in the 2 input fields with the data you recieved in order.payment.preparation
in order to see the live Payment Element).
Poll for Status Updates
After making the payment via whichever payment method, you'll need to poll the Get Order API to check on the delivery status and present this info to your user.
Refer to the complete get order API reference here.
GET
https://staging.crossmint.com/api/2022-06-09/orders/<orderId>