View a markdown version of this page

Create a payment intent - Amazon Bedrock AgentCore

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, or SETUP. 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 the X-Amzn-Bedrock-AgentCore-Payments-User-Id header.

  • 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 merchant name and an optional website. The buyer approval widget shows them to the buyer.

  • totalAmount (required): the total, with value and currency. The currency must be USD or EUR, 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 a sku, a quantity, and an amount, which is the price of one item.

  • amountBreakdown (optional): shipping, tax, and discount.

  • amountMode (optional): EXACT, the default, or UPTO for a SETUP maximum amount.

  • returnUrl (optional): the page that the payment service provider returns the buyer to. Amazon Pay and SETUP payment 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
Amazon Pay
  • checkoutDetails.returnUrl is required. Amazon Pay sends the buyer back to this URL with an amazonCheckoutSessionId query parameter.

  • captureStrategy is INSTANT or FUTURE. Amazon Pay doesn’t support SETUP.

  • checkoutDetails.referenceId is sent to Amazon Pay as custom information on the checkout session, so you can match the Amazon Pay charge to your own order.

Stripe
  • captureStrategy is INSTANT, FUTURE, or SETUP.

  • checkoutDetails.referenceId is added to the Stripe PaymentIntent as the reference_id metadata key. For SETUP, it’s added to the Checkout Session and SetupIntent metadata.

PayPal
  • captureStrategy is INSTANT or FUTURE. PayPal doesn’t support SETUP.

  • checkoutDetails.referenceId is sent to PayPal as the invoice ID. PayPal rejects an invoice ID that a completed or voided payment already used.

Next, get buyer approval for the payment intent.