Create a payment intent
A payment intent tracks one purchase from create to capture. We recommend that you call CreatePaymentIntent from your agent’s tool code, and that the tool code sets the user ID, the Payment Manager, and the connector itself. For the recommended role split, see Agentic commerce payment permissions. Call CreatePaymentIntent with the following parameters:
-
paymentManagerArn(required): the ARN of your Payment Manager. -
paymentConnectorId(required): the ID of your payment service provider connector. You can’t change the connector later. -
captureStrategy(required):INSTANT,FUTURE, orSETUP. For more information, see Capture strategies. -
checkoutDetails(required): the merchant, the line items, and the total. For more information, see Checkout details. -
userId: the buyer’s user ID, in theX-Amzn-Bedrock-AgentCore-Payments-User-Idheader. -
clientToken(optional): an idempotency token. AWS SDKs and the AWS CLI generate one for you. If you set your own token, use 33 to 256 characters. Use only letters, digits, and hyphens. Start and end with a letter or digit.
CreatePaymentIntent doesn’t call the payment service provider. The status of the new payment intent is CREATED.
The following example creates a FUTURE payment intent for an Amazon Pay connector:
import boto3 payments = boto3.client("bedrock-agentcore", region_name="us-east-1") intent = payments.create_payment_intent( userId="user-123", paymentManagerArn="<paymentManagerArn>", paymentConnectorId="<paymentConnectorId>", captureStrategy="FUTURE", checkoutDetails={ # Example values. Use the amounts from your own cart. "totalAmount": {"value": "49.90", "currency": "USD"}, "lineItems": [ {"sku": "SKU-1", "quantity": 1, "amount": {"value": "49.90", "currency": "USD"}} ], "returnUrl": "https://shop.example.com/checkout/amazon-pay/return", "referenceId": "order-1001", "merchant": {"name": "Example Shop", "website": "https://shop.example.com"}, }, ) payment_intent_id = intent["paymentIntent"]["paymentIntentId"]
Checkout details
checkoutDetails contains the following fields:
-
merchant(required): the merchantnameand an optionalwebsite. The buyer approval widget shows them to the buyer. -
totalAmount(required): the total, withvalueandcurrency. The currency must beUSDorEUR, and the value must be greater than zero. Use at most 2 decimal places. Every other amount on the payment intent must use the same currency. -
lineItems(optional): each line item has asku, aquantity, and anamount, which is the price of one item. -
amountBreakdown(optional):shipping,tax, anddiscount. -
amountMode(optional):EXACT, the default, orUPTOfor aSETUPmaximum amount. -
returnUrl(optional): the page that the payment service provider returns the buyer to. Amazon Pay andSETUPpayment intents require it. -
referenceId(optional): your order number. AgentCore payments sends it to the payment service provider.
When you include line items, the sum of amount × quantity across them, plus shipping and tax, minus discount, must equal totalAmount. For a SETUP intent with amountMode set to UPTO, the sum must not exceed totalAmount.
Details for each payment service provider
Example
Next, get buyer approval for the payment intent.