Create Stripe Payment Intent for a Cart
POST/v2/carts/:cartID/payments
The Cart Payment Intent feature enables the creation of a Stripe Payment Intent specifically tied to a shopping cart and its subsequent order. This allows Payment Intent users to track payment details from the cart stage and seamlessly maintain consistency in payment information throughout the order stage. Using these features, you can create Payment Intents for their carts, update Payment Intents with final cart details, and synchronize Payment Intents from Stripe to Commerce.
- Typically, in Commerce, inventory is allocated at the time of payment initiation after an order is created. However, in the case of Cart Payment Intent, information about the payment is received only upon synchronizing the order from Stripe to Commerce. This may happen after the payment is completed. Therefore, there might be a delay between the payment made and allocation, increasing the chance of paying for items that are not in stock.
- There are certain fields you can choose to set up when creating a payment intent. However, if you decide to update a payment intent, the available options may not be the same as those allowed while creating a payment intent. See updating a payment intent.
The following steps outline the workflow associated with the Payment Intent:
- Add items to cart.
- Create a Payment Intent for the cart. The Payment Intent is created in Stripe, reflecting the cart and transaction details, including currency, amounts, payment type, and any optional Stripe details. The Payment Intent ID is generated and linked to the cart.
- Update a Payment Intent. This step is optional but becomes necessary when there are changes in the cart details at the time of payment. It ensures the Payment Intent accurately reflects the current cart details when processing the payments on the front end.
- Checkout the cart. An unpaid order is created, and the Payment Intent ID is linked to the order.
- Confirm the order. This is important because after checkout, it is essential to confirm the Payment Intent and synchronize it with Commerce. This results in a corresponding transaction and change in order statuses in Commerce. Additionally, the Payment Intent ID is removed from the order once it is linked via the transaction.
Best Practices
We recommend you follow these practices to maintain consistency and accuracy when using Cart Payment Intent.
- After checkout, we recommend clearing the shopping cart. You can achieve this using a Delete a cart endpoint or Update a cart to remove the Payment Intent ID. This helps to avoid potential issues where subsequent checkouts for the same cart might unintentionally use the previous Stripe Payment Intent ID.
- If it is not reasonable to clear the cart immediately after checkout due to several subsequent, duplicate checkouts to the same cart, ensure that you only synchronize the Payment Intent when finalizing the order. Each order confirmation is unaware of the others, and syncing Payment Intent IDs for each confirmation can lead to duplicate transactions in Commerce. In other words, if you synchronize Payment Intents for earlier versions of a repeated checkout, you'll end up with multiple orders from the same cart, each having transactions linked to the same Payment Intent.
- To pay the entire amount at once, use the Update Cart Payment Intent endpoint to update the Stripe Payment Intent with the final cart details when preparing to take the payment. Doing so, ensures that the Payment Intent accurately reflects the current cart details when processing payments on the front end. We do not recommend calling the Update Cart Payment Intent for each individual change in the cart, as this can lead to more requests and may slow down the front-end performance.
Request
Path Parameters
The universally unique identifier of the cart for which you want to create a payment intent.
- application/json
Body
Possible values: [elastic_path_payments_stripe
]
Specifies the gateway. You must use elastic_path_payments_stripe
.
Possible values: [authorize
, purchase
, purchase_setup
, authorize_setup
]
Specifies the transaction method, such as purchase
or authorize
.
The amount to be paid for the transaction.
options object
Provides the email address to which you want to send the Stripe receipts for the transactions within the store. This feature is available only in the live mode.
automatic_payment_methods object
Parent object determining whether to use Stripe's automatic_payment_methods
setting.
When set to true, it displays all enabled payment methods from the Stripe dashboard. When set to false, the Stripe default, which is card, is used.
Specifies the Stripe payment method types configured for the store. See Stripe Documentation.
Specifies the Stripe token or source.
Responses
- 201
- 401
Payment Intent created successfully.
- application/json
- Schema
- Example (from schema)
Schema
The unique identifier for the cart. Use SDK or create it yourself.
The type of object being returned.
The name of this cart.
A description of the cart.
discount_settings object
This parameter enables custom discounts for a cart. When set to true, Elastic Path promotions will not be applied to the new carts. Default is set from cart discount settings for the store. See Cart Settings.
When set to true, this parameter allows the cart to use rule promotions.
Stripe-assigned unique identifier for the linked Payment Intent
links object
A link to that specific resource.
meta object
display_price object
with_tax object
The raw total of this cart.
The currency set for this cart.
The tax inclusive formatted total based on the currency.
without_tax object
The raw total of this cart.
The currency set for this cart.
The tax inclusive formatted total based on the currency.
tax object
The raw total of this cart.
The currency set for this cart.
The tax inclusive formatted total based on the currency.
discount object
The raw total of this cart.
The currency set for this cart.
The tax inclusive formatted total based on the currency.
without_discount object
The raw total of this cart.
The currency set for this cart.
The tax inclusive formatted total based on the currency.
shipping object
The raw total of this cart.
The currency set for this cart.
The tax inclusive formatted total based on the currency.
timestamps object
The date this was created.
The date this was last updated.
relationships object
customers object
data object
The type of related object.
The ID of the customer.
items object
data object
The type of related object.
The unique identifier for the cart item
{
"id": "string",
"type": "string",
"name": "string",
"description": "string",
"discount_settings": {
"custom_discounts_enabled": true,
"use_rule_promotions": true
},
"payment_intent_id": "string",
"links": {
"self": "string"
},
"meta": {
"display_price": {
"with_tax": {
"amount": 0,
"currency": "string",
"formatted": "string"
},
"without_tax": {
"amount": 0,
"currency": "string",
"formatted": "string"
},
"tax": {
"amount": 0,
"currency": "string",
"formatted": "string"
},
"discount": {
"amount": 0,
"currency": "string",
"formatted": "string"
},
"without_discount": {
"amount": 0,
"currency": "string",
"formatted": "string"
},
"shipping": {
"amount": 0,
"currency": "string",
"formatted": "string"
}
},
"timestamps": {
"created_at": "string"
}
},
"relationships": {
"customers": {
"data": {
"type": "string",
"id": "3fa85f64-5717-4562-b3fc-2c963f66afa6"
}
},
"items": {
"data": {
"type": "string",
"id": "3fa85f64-5717-4562-b3fc-2c963f66afa6"
}
}
}
}
Unauthorized
- application/json
- Schema
- Example (from schema)
- Example
Schema
[
null
]
{
"errors": {
"status": 401,
"title": "Unauthorized"
}
}