Save a payment method for later charges
With captureStrategy set to SETUP and checkoutDetails.amountMode set to UPTO, the buyer saves a payment method once, and you charge it later without the buyer present. totalAmount is the maximum total of all later charges. SETUP is supported for Stripe only.
Use SETUP for pre-approved purchases, where the buyer is present to approve but not when you charge. Use it when the final amount or the charge time isn’t known at checkout. For example, charge when an order ships, charge for each item of a split shipment, or charge for a booking after the service. If you know the amount at checkout and only want to delay the charge, use the FUTURE capture strategy instead. For more information, see Capture strategies.
-
Call
CreatePaymentIntentwithcaptureStrategyset toSETUP,amountModeset toUPTO, andtotalAmountset to the maximum amount.SETUPrequirescheckoutDetails.returnUrl. -
Get buyer approval with
CreateBuyerApprovalUrl. The buyer approves charges up to that amount. For more information, see Get buyer approval for a payment intent. -
Call
InitiatePaymentIntentwith the buyer’suserId. AgentCore payments creates a Stripe-hosted Checkout Session in setup mode.partnerIntentDatacontainssetupCheckoutUrl, and the status becomesSAVE_PENDING. No money moves. -
Redirect the buyer to
setupCheckoutUrl. Stripe sends the buyer back toreturnUrlafter the save. -
Later, without the buyer present, call
CapturePaymentIntenton the same payment intent. Each call can charge part of the maximum amount. OmitcaptureAmountto charge whatever remains.
GetPaymentIntent and CapturePaymentIntent check the Checkout Session and move the payment intent to SAVED, or to SAVE_FAILED if the buyer abandons the page. After a charge that leaves part of the maximum amount, the status is PARTIALLY_CAPTURED.
The remaining amount is totalAmount minus the captured amount and any pending charges. A charge over the remaining amount returns a ValidationException. AgentCore payments sets no time limit: a saved payment method stays usable until Stripe or the card issuer declines it. AgentCore payments stores only Stripe IDs, never card data.
If the card needs 3-D Secure for the first charge, the status becomes REAUTH_REQUIRED. If the card declines the first charge, the status becomes PAYMENT_DECLINED. Both statuses are final. To try again, bring the buyer back and create a new SETUP payment intent.
Your responsibilities for later charges
The buyer saves the payment method in a customer-initiated transaction (CIT). Each later charge, made without the buyer present, is a merchant-initiated transaction (MIT). Card networks and Stripe set rules for saving a payment method and charging it later. You’re responsible for following them. For Stripe’s requirements, see Customer-initiated and merchant-initiated transactions
Stripe’s requirements include the following:
-
Show your terms for saving the payment method, and get the buyer’s agreement before you save it. The buyer approval widget shows only the maximum amount and your merchant name, so show your own terms on your checkout page.
-
State in your terms when and how often you charge, and how you determine the amount.
-
Use the saved payment method only for the purposes in your terms.
-
Keep a record of each buyer’s agreement to your terms.
AgentCore payments records part of this for you. The signed payment mandate records the merchant, a hash of the cart, the maximum amount, and the approval time. GetPaymentIntent returns the cart and each charge with its Stripe reference. Store the terms that the buyer accepted alongside these records.
Cancel a saved payment method
To stop future charges before any charge is made, call CancelPaymentIntent while the status is SAVE_PENDING or SAVED. AgentCore payments expires the Stripe Checkout Session. If the buyer already saved a payment method, AgentCore payments detaches it from the Stripe Customer, and keeps the Customer.
After the first charge (PARTIALLY_CAPTURED or CAPTURED), or while a charge is CAPTURE_PENDING, CancelPaymentIntent returns a ConflictException.