Test a payment service provider integration in sandbox mode
Before you take live payments, run one test payment through each payment service provider that you plan to use. You set up the resources once, and then you run the same payment intent flow for each payment service provider. Every step uses sandbox or test mode credentials, so no real money moves.
-
Use only sandbox or test mode credentials. Don’t use a payment auth with the
LIVEenvironment, or a Striperk_live_key. -
Don’t share keys, client secrets, tokens, or approval URLs.
Prerequisites
-
An AWS account and credentials for the AWS Region that you test in.
-
Python 3.10 or later and the latest version of the AWS SDK for Python (Boto3). Earlier versions don’t include the payment intent operations. To upgrade, run
pip install --upgrade boto3. -
A web page that you serve over HTTPS, for the buyer approval widget and the payment service provider checkout. For local testing, you can use HTTP on
localhost. For more information, see Get buyer approval for a payment intent. -
A sandbox account for each payment service provider that you test:
Payment service provider What you need Stripe
A test mode restricted API key (
rk_test_), and its publishable key (pk_test_). For the access that the key needs, see Set up Stripe.PayPal
The client ID and client secret of a sandbox REST app, and a sandbox personal account to pay as the buyer. For more information, see Set up PayPal.
Amazon Pay
A registered merchant account, its merchant ID and store ID, an MWS authorization token for AgentCore payments, and a sandbox buyer account. Authorize AgentCore payments once in the Production view of Seller Central, and then test in the Sandbox view of the same account. For which values to copy and which to ignore, see Get your Amazon Pay merchant details. You don’t need to add your test page to the JavaScript origins of your store for sandbox testing. For more information, see Set up Amazon Pay.
Step 1: Create the payment resources
-
Create a payment auth for each payment service provider. For PayPal and Amazon Pay, set the environment to
SANDBOX. For Amazon Pay, also set the region toNA. Stripe has no environment setting, because therk_test_prefix sets test mode. -
Create one Payment Manager. To call the payment intent operations with your AWS credentials, for Inbound auth, choose Use IAM username.
-
For Permissions, choose Create and use a new service role. The console gives the role read access to each payment auth that you choose.
-
Add one connector for each payment service provider to the Payment Manager. For Payment type, choose Payment accounts for e-commerce.
-
Wait until each connector status is
READY. For Amazon Pay, connector creation also checks your MWS authorization token with Amazon Pay.
For the console steps, see Set up a payment service provider connector in the console. Copy the Payment Manager ARN and each connector ID.
Step 2: Run a test payment
The following script runs the same flow for every payment service provider. It stops at each step where the buyer acts in a browser.
import boto3 REGION = "<your-region>" # The AWS Region of your Payment Manager, for example us-east-1. TEST_ORIGIN = "<your-test-page-origin>" # The origin of your test page, for example https://localhost:8443. payments = boto3.client("bedrock-agentcore", region_name=REGION) MANAGER_ARN = "<paymentManagerArn>" CONNECTOR_ID = "<paymentConnectorId>" # Stripe, PayPal, or Amazon Pay USER_ID = "test-buyer-001" # Use the same user ID on every call for a payment intent. common = {"userId": USER_ID, "paymentManagerArn": MANAGER_ARN} # 1. Create the payment intent. intent = payments.create_payment_intent( **common, paymentConnectorId=CONNECTOR_ID, captureStrategy="INSTANT", # Or FUTURE. checkoutDetails={ # Example amount for the test payment. "totalAmount": {"value": "25.00", "currency": "USD"}, "returnUrl": f"{TEST_ORIGIN}/checkout/return", "merchant": {"name": "Example Test Store", "website": TEST_ORIGIN}, }, ) payment_intent_id = intent["paymentIntent"]["paymentIntentId"] common["paymentIntentId"] = payment_intent_id # 2. Get buyer approval. Show the widget on your test page, and choose Approve. # Pass the URL to the widget on your test page. Treat the URL as a secret, and don't log it. approval = payments.create_buyer_approval_url(**common, parentOrigin=TEST_ORIGIN) buyer_approval_url = approval["buyerApprovalUrl"] input("Approve in the widget, and then press Enter.") # 3. Start checkout with the payment service provider. initiated = payments.initiate_payment_intent(**common) partner_intent_data = initiated["partnerIntentData"] input("Pay at the payment service provider, and then press Enter.") # 4. Authorize. For Amazon Pay, paste the amazonCheckoutSessionId from the return URL. session_id = input("Amazon Pay only: paste amazonCheckoutSessionId, or press Enter to skip: ").strip() if session_id: authorized = payments.authorize_payment_intent(**common, partnerCallbackResult=session_id) else: authorized = payments.authorize_payment_intent(**common) print(authorized["paymentIntent"]["status"]) # INSTANT: CAPTURED. FUTURE: AUTHORIZED. # 5. For FUTURE only, capture the funds. # captured = payments.capture_payment_intent(**common)
After the buyer approves, call InitiatePaymentIntent and AuthorizePaymentIntent within 15 minutes. Otherwise, the calls fail, and you start again with a new payment intent.
Step 3: Pay at the payment service provider
Between InitiatePaymentIntent and AuthorizePaymentIntent, the buyer pays with the payment service provider’s own checkout. Use the following test steps for each payment service provider.
Example
Expected results
| Payment service provider |
INSTANT
|
FUTURE
|
SETUP
|
|---|---|---|---|
|
Stripe |
|
|
|
|
PayPal |
|
|
Not supported |
|
Amazon Pay |
|
|
Not supported |
To test SETUP with Stripe, see Save a payment method for later charges.
Clean up
After you test, call CancelPaymentIntent on each FUTURE payment intent that you didn’t capture, so that the payment service provider releases the test hold.
Test EUR payments
Payment intents support USD and EUR. To test EUR, set currency to EUR on totalAmount and on every other amount. Your payment service provider account must also accept EUR.
-
Stripe: a test mode account can charge in
EUR. To test methods that requireEUR, such as iDEAL or SEPA Direct Debit, turn them on in the Stripe Dashboard. -
PayPal: in your sandbox merchant account, set Block payments to accept payments in a currency that you don’t hold. Otherwise, the capture waits until you accept each payment manually.
-
Amazon Pay: Amazon Pay charges in the ledger currency of the merchant account. Use a merchant account in the
EUregion, in its Sandbox view. Authorize theEUdeveloper ID, and set the payment auth region toEU. On your page, load theEUAmazon Pay script.
A currency other than USD or EUR returns a ValidationException from CreatePaymentIntent.
Troubleshooting
| Symptom | Resolution |
|---|---|
|
|
More than 15 minutes passed since the buyer approval. Create a new payment intent. For Stripe, if the buyer already confirmed the payment, |
|
|
The buyer didn’t finish the approval in the widget. Show the widget again, and choose Approve. |
|
The widget doesn’t start. |
The widget doesn’t run in browsers that automation software controls. Open your test page in your own browser. |
|
Creating the Stripe payment auth fails with a message about a secret key. |
Use a restricted key ( |
|
The Amazon Pay connector doesn’t reach |
Amazon Pay rejected the MWS authorization token. Authorize AgentCore payments again in Seller Central. Update the payment auth (credential provider) with the new token, and then create the connector again. |
|
Seller Central doesn’t show MWS Authorizations. |
Switch Seller Central to the Production view. A developer account that can use only the Sandbox view doesn’t have this section, so register a merchant account instead. For more information, see Get an Amazon Pay merchant account. |
|
The Amazon Pay button doesn’t render. |
Check that |
|
|
Your payment service provider account doesn’t accept the currency. Check the currency settings of your Stripe or PayPal account. |
|
A payment auth is missing from the Payment auth list. |
Choose the refresh icon next to Payment auth. Payment resources are Regional, so also check that the console is in the Region where you created the payment auth. |
|
The connector shows IAM permissions not attached. |
The service role didn’t get read access to the payment auth. Add the permissions to the role, or create the Payment Manager again with Create and use a new service role. |
For more errors, see Agentic commerce payment errors.