Get buyer approval for a payment intent
Before AgentCore payments starts a checkout with your payment service provider, the payment intent needs a confirmed buyer approval. The buyer approves in a widget that AgentCore payments hosts and that you embed in your web page. The widget reads the merchant, the line items, and the total from the stored payment intent. Neither your page nor your agent can change the terms that the buyer sees.
Buyer approval fixes the terms of a payment. It doesn’t authenticate the buyer. For what it covers and what remains your responsibility, see What buyer approval covers.
When the buyer approves, AgentCore payments records a signed payment mandate for that version of the payment intent. The mandate stays inside AgentCore payments. InitiatePaymentIntent succeeds only when the approval status for the current version is BUYER_APPROVAL_CONFIRMED, and only within 15 minutes of the approval.
How buyer approval works
-
Your agent hands the buyer off to your checkout page with the payment intent ID.
-
Your merchant backend calls
CreateBuyerApprovalUrl. AgentCore payments returns an approval URL for the current payment intent version. -
Your backend sends the URL to your checkout page. The agent never gets the URL.
-
Your web page passes the URL to the Buyer Approval SDK. The SDK loads the widget in an iframe on your page.
-
The buyer reviews the terms in the widget and chooses to approve or cancel.
-
The SDK returns the outcome to your page.
-
Your backend calls
GetPaymentIntentto confirm the approval status. There’s no server callback. -
Your backend calls
InitiatePaymentIntent.
The widget calls other AgentCore payments operations through the Buyer Approval SDK to record the buyer’s choice. You don’t call these operations yourself.
Prerequisites
-
A payment intent that you created with
CreatePaymentIntent. For more information, see Create a payment intent. -
A web page that embeds the widget. The page must use HTTPS. For local testing, you can use HTTP on
localhost,127.0.0.1, or[::1]. -
The Buyer Approval SDK, installed in your web page:
npm install @aws/buyer-approval-sdk-agentcore-paymentsThe SDK is a TypeScript library with no runtime dependencies. It’s licensed under Apache 2.0.
Step 1: Create an approval URL
We recommend that you call CreateBuyerApprovalUrl from your merchant backend, not from your agent or its tools. Call it with the following parameters:
-
paymentManagerArn(required): the ARN of the Payment Manager that owns the payment intent. -
paymentIntentId(required): the ID of the payment intent to approve. -
parentOrigin(required): the origin of the page that embeds the widget, for examplehttps://shop.example.com. Use only the scheme, the host, and an optional port, with no path, query, or trailing slash. Only this exact origin can embed the widget. -
userId(required for IAM authentication): the buyer’s user ID, in theX-Amzn-Bedrock-AgentCore-Payments-User-Idheader. Use the same user ID as onCreatePaymentIntent. -
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.
import boto3 payments = boto3.client("bedrock-agentcore", region_name="us-east-1") approval = payments.create_buyer_approval_url( userId="user-123", paymentManagerArn="<paymentManagerArn>", paymentIntentId="<paymentIntentId>", parentOrigin="https://shop.example.com", ) buyer_approval_url = approval["buyerApprovalUrl"]
The response contains the following fields:
-
buyerApprovalUrl: the approval URL. It contains a short-lived credential, so treat it as a secret. Send it only to the buyer’s browser, and don’t log it. -
expiresAt: the deadline for opening the URL. -
paymentIntentIdandpaymentIntentVersion: the payment intent version that the buyer approves.
If you retry with the same clientToken, AgentCore payments returns the same URL. If you call CreateBuyerApprovalUrl again with a new clientToken, AgentCore payments creates a new URL and cancels any earlier attempt that isn’t confirmed. The earlier URL then stops working.
CreateBuyerApprovalUrl returns a ConflictException in the following cases:
-
The buyer already approved the payment intent.
-
You reused a
clientTokenwith different parameters. -
Another request changed the payment intent at the same time. Retry the request.
Step 2: Show the widget to the buyer
In your web page, call captureBuyerApproval with the approval URL and an element to mount the widget in. The function returns a Promise that resolves with the buyer’s outcome.
import { captureBuyerApproval } from "@aws/buyer-approval-sdk-agentcore-payments"; const controller = new AbortController(); try { const result = await captureBuyerApproval({ container: document.getElementById("approval"), buyerApprovalUrl, // from your merchant backend signal: controller.signal, }); // result.status is "CONFIRMED", "REJECTED", or "EXPIRED" await notifyBackend(result.paymentIntentId, result.status); } catch (err) { if (err?.name === "AbortError") { // You aborted the capture, or removed the container from the page. } else { // A BuyerApprovalError. Read err.code. } } // When you tear down the page: controller.abort();
captureBuyerApproval takes the following options:
-
container(required): an element in the page. The SDK mounts the widget iframe in it. -
buyerApprovalUrl(required): the URL fromCreateBuyerApprovalUrl. -
signal(optional): anAbortSignalthat stops the capture. -
locale(optional): the display language, as a BCP 47 tag such asdeorpt-BR. If the widget has no translation for the language, it uses the closest translated language, then the buyer’s browser language, and then English. To use the buyer’s browser language, omitlocale. A tag in another format rejects withINVALID_ARGUMENT.
The Promise resolves with status, paymentIntentId, and paymentIntentVersion. A resolved status is a buyer outcome:
-
CONFIRMED: the buyer approved. This doesn’t mean that the payment succeeded. Your backend still initiates, authorizes, and captures the payment. -
REJECTED: the buyer canceled. -
EXPIRED: the buyer didn’t open the URL or decide in time.
The SDK accepts only approval URLs from https://bedrock-agentcore.<region>.amazonaws.com with a path that starts with /payments/. It checks every message from the widget by its exact origin and frame.
If your page sets a Content Security Policy, add https://bedrock-agentcore.<region>.amazonaws.com to its frame-src directive. Otherwise, the browser blocks the widget.
The approval works only inside the widget iframe on the parentOrigin page. To test locally, serve your page from that exact origin. Don’t open the approval URL directly in a browser tab.
Size the widget
You size the widget through the container. The SDK sets the iframe width to 100% of the container and adjusts its height to fit the content.
-
Width: the widget is laid out for 320 to 640 CSS pixels. Set the container width, for example with
max-width: 480px. -
Height: don’t set the iframe height yourself, because a fixed height can hide the Approve button. To avoid a jump before the widget reports its height, set a
min-heighton the container. -
Limited space: to show the widget in a modal or drawer, put the container inside an element that scrolls.
The Approve button stays disabled until the buyer has seen each payment detail, and until the button has been fully visible for one second. The buyer can always cancel.
Handle SDK errors
The Promise rejects with a BuyerApprovalError for technical failures. Read its code:
-
INVALID_ARGUMENT: an option is missing or invalid, or the code isn’t running in a browser. -
INVALID_APPROVAL_URL: the URL isn’t an AgentCore approval URL. -
CONTAINER_IN_USE: the container already has an active capture. -
WIDGET_LOAD_FAILED: the iframe failed to load, or the widget wasn’t ready within 30 seconds. -
WIDGET_PROTOCOL_ERROR: the widget sent a malformed or oversized message. -
WIDGET_ERROR: the widget reported an error.
If you abort the capture, or remove the container from the page, the Promise rejects with an AbortError. An abort is never reported as REJECTED.
The widget doesn’t start in a browser that automation software controls, such as WebDriver, Playwright, or Puppeteer. It asks the buyer to use their own browser, and the Promise doesn’t settle. The approval stays unused, so you can show the same URL in the buyer’s own browser. To stop waiting, abort the capture with your own timer.
Step 3: Confirm the approval on your server
Don’t rely on the browser result alone. On your backend, call GetPaymentIntent and read paymentIntent.buyerApprovalStatus:
intent = payments.get_payment_intent( userId="user-123", paymentManagerArn="<paymentManagerArn>", paymentIntentId="<paymentIntentId>", ) if intent["paymentIntent"]["buyerApprovalStatus"] == "BUYER_APPROVAL_CONFIRMED": payments.initiate_payment_intent( userId="user-123", paymentManagerArn="<paymentManagerArn>", paymentIntentId="<paymentIntentId>", )
InitiatePaymentIntent returns a ConflictException in the following cases:
-
The status isn’t
BUYER_APPROVAL_CONFIRMED. -
The buyer approved more than 15 minutes ago. The status still reads
BUYER_APPROVAL_CONFIRMED, so you can’t create a new approval URL for this payment intent. Create a new payment intent, and get buyer approval for it.
Approval statuses and time limits
buyerApprovalStatus on the payment intent has one of the following values:
-
BUYER_APPROVAL_REQUIRED: no approval is in progress. Create an approval URL. -
BUYER_APPROVAL_IN_PROGRESS: the widget opened the URL, and the buyer is deciding. -
BUYER_APPROVAL_CONFIRMED: the buyer approved. You can callInitiatePaymentIntent. -
BUYER_APPROVAL_REJECTED: the buyer canceled. -
BUYER_APPROVAL_EXPIRED: the widget reported that the buyer didn’t open the URL or decide in time.
The following time limits apply:
-
The buyer has 5 minutes to open the URL. The
expiresAtvalue in theCreateBuyerApprovalUrlresponse is this deadline. -
After the widget opens, the buyer has 15 minutes to decide.
-
After the buyer approves, you have 15 minutes to call
InitiatePaymentIntent.
The status doesn’t change on its own when a deadline passes. A URL that the buyer never opened still reads BUYER_APPROVAL_REQUIRED, and an abandoned widget still reads BUYER_APPROVAL_IN_PROGRESS. The status becomes BUYER_APPROVAL_EXPIRED only when the widget reports the expiry. Treat the deadlines as the cutoff. After the open or decide deadline, create a new approval URL.
A confirmed approval also expires after 15 minutes, even though the status still reads BUYER_APPROVAL_CONFIRMED. Because CreateBuyerApprovalUrl rejects a confirmed payment intent, create a new payment intent after a confirmed approval expires.
The first widget that opens a URL is bound to it. A copied URL can’t open a second active widget.
For a payment intent with amountMode set to UPTO, the widget shows the total as a maximum amount, and the buyer approves charges up to that amount.
What buyer approval covers
Buyer approval records that the holder of an approval URL approved a specific set of terms. It doesn’t authenticate the buyer, and it doesn’t prove that a person approved. Plan your integration around this difference.
Buyer approval covers the following:
-
The terms are fixed. The widget reads the merchant, the line items, and the total from the stored payment intent. The mandate is bound to that version of the payment intent, and
InitiatePaymentIntentchecks the mandate against the current terms. If the terms change, the approval no longer applies. -
Each approval is used once. An approval URL works for one payment intent version. The first widget that opens it is bound to it, and a second confirmation of the same approval creates no second mandate.
-
Approvals are short-lived. The time limits in Approval statuses and time limits apply to every approval.
Buyer approval doesn’t cover the following:
-
That the buyer approved. The approval URL contains a bearer credential. AgentCore payments returns it to the caller of
CreateBuyerApprovalUrl, and any client that has the URL can confirm the approval. A principal that can callCreateBuyerApprovalUrlcan therefore confirm an approval without the buyer. For this reason, callCreateBuyerApprovalUrlonly from your merchant backend, and block approval URLs in the agent’s browser and HTTP tools. -
That a person approved. The widget refuses to start in browsers that automation software controls, and the Approve button waits until the buyer has seen the terms. These checks raise the cost of automated approval. They don’t prevent it.
The approval is your record that you showed these terms to your buyer and that the buyer approved them. You’re responsible for making sure that only your buyer opens the approval URL. The integration rules that follow describe how.
If your use case needs proof that a specific person approved the payment, authenticate the buyer yourself before you show the widget. For example, require the buyer to sign in to your site, or use your payment service provider’s own buyer authentication during checkout. To have AgentCore payments use a verified end-user identity, use the CUSTOM_JWT authorization type for the payment manager. For more information, see Secure multi-tenant deployments. With CUSTOM_JWT, IAM policies don’t restrict operations, so the agent and backend role split in Agentic commerce payment permissions doesn’t apply.
AWS CloudTrail records each CreateBuyerApprovalUrl call as a data event, so you can see which principal created each approval URL. To receive these events, add a data event selector for the AWS::BedrockAgentCore::Payments resource type to a trail.
Integration rules
To keep the approval URL with the buyer, follow these rules:
-
Create the approval URL in your merchant backend, and send it only to your checkout page. Don’t give your agent or its tools
CreateBuyerApprovalUrl. A principal that can callCreateBuyerApprovalUrlcan confirm an approval without the buyer. -
Give your agent payments only through tools. The tools call
CreatePaymentIntent,GetPaymentIntent, andCancelPaymentIntent, and return only the payment intent ID and status. For an example policy, see Agent tool permissions. -
Run
CreateBuyerApprovalUrl,InitiatePaymentIntent,AuthorizePaymentIntent, andCapturePaymentIntentin your merchant backend, such as an AWS Lambda function. The agent never calls the backend. -
Scope each agent session to one buyer. Set the user ID in your tool code from the signed-in buyer’s session, not from model output.
-
Build the cart from your own catalog and prices, not from model output.
-
Show the widget in a dedicated checkout step from your own frontend code.
-
Embed the widget only from your own sites, fully visible, with no element on top of it.
-
Block approval URLs and the approval API in your agent’s browser and HTTP tools.
-
After a buyer rejects, start a new checkout instead of creating a new URL.
-
Grant
CapturePaymentIntentonly to the backend that fulfills orders.
Next, complete checkout with your payment service provider.