Skip to content

Latest commit

 

History

History
208 lines (168 loc) · 12.8 KB

payments.md

File metadata and controls

208 lines (168 loc) · 12.8 KB

Merchant payments

Merchant checkout supports Stripe, PayPal and Amazon Pay configuration alongside the existing CoinbaseCDP and StripePrivy projects. New provider screens are deferred; the existing interactive flows remain unchanged.

Configuration and secrets

Use a provider subcommand; each requires --name. New provider leaves are headless:

agentcore add credentials payment stripe --name stripe-checkout --restricted-key file://restricted-key.txt
agentcore add credentials payment paypal --name paypal-checkout --client-id CLIENT_ID --environment SANDBOX --client-secret -
agentcore add credentials payment amazon-pay --name amazon-checkout --merchant-id MERCHANT_ID --store-id STORE_ID --environment LIVE --amazon-pay-region EU --authorization-token-secret-reference '{"secretId":"merchant-authorization","jsonKey":"token"}'
agentcore add credentials payment coinbase-cdp --name wallet
agentcore add credentials payment stripe-privy --name privy
Subcommand Provider-owned flags
stripe --restricted-key, --restricted-key-secret-reference, --publishable-key
paypal --client-id, --client-secret, --client-secret-reference, --environment
amazon-pay --merchant-id, --store-id, --authorization-token, --authorization-token-secret-reference, --environment, --amazon-pay-region
coinbase-cdp --api-key-id, --api-key-secret, --wallet-secret
stripe-privy --app-id, --app-secret, --authorization-private-key, --authorization-id

Secret value flags accept file://<path> or - for stdin; raw secret literals are rejected. Only one secret may claim stdin. Secret-reference flags take strict JSON with secretId and jsonKey and cannot accompany the corresponding value flag. Stripe requires a restricted key (rk_test_ or rk_live_); an optional publishable key must use the same test/live mode.

All fields except the name may be omitted during setup. Missing deployment-required fields create .env.local placeholders with instructions to fill them before deployment. PayPal requires client ID, client secret and environment at deployment; Amazon Pay requires merchant ID, store ID, authorization token, environment and merchant region. Environment is SANDBOX or LIVE; Amazon Pay merchant region is NA or EU. JP is deferred and rejected during credential setup and deploy validation. Neither setting has an implicit default. A supplied value must still be valid even if other fields are deferred.

Existing flat payment --name NAME --provider CoinbaseCDP|StripePrivy ... commands and the bare interactive wizard remain supported. Do not mix a subcommand with --provider or put provider flags before its subcommand. A bare noninteractive command shows usage and exits with code 2. Provider-specific reference flags map to the shared persisted secretRef field below.

Vendor values, including environment and merchant region, are saved in agentcore/.env.local under AGENTCORE_CREDENTIAL_<NAME>_<FIELD>. External secret references stay in agentcore.json:

{
  "authorizerType": "PaymentCredentialProvider",
  "name": "merchant",
  "provider": "AmazonPay",
  "secretRef": { "secretId": "merchant-authorization", "jsonKey": "token" }
}

An external reference replaces only that provider's secret value requirement. Merchant identifiers, environment and merchant region remain required. Amazon Pay merchant region, payment currency (USD or EUR) and AWS deployment region are separate settings.

Deployment validates local provider inputs before writing providers, creates absent providers, updates supplied configuration, and reuses existing providers when required local values are absent. An external reference requires all other vendor fields even for an existing provider, so a reference change cannot be silently ignored. A vendor mismatch is rejected.

A merchant provider's secret source cannot change between MANAGED and EXTERNAL. When Identity returns the source, deployment rejects a mode change before writing any provider. To use another source, create a credential with a different name, point the connector to it, then deploy. Same-source secret rotation and external reference updates remain supported. Missing source metadata is not assumed to mean MANAGED; Identity validates those updates. Inline secret values use the service's managed default without requiring the external-secrets feature; external references still require it.

When a deployment fails, rollback deletes every provider that deployment tried to create, newest first. That includes a provider whose create call failed, because a failed or interrupted call can still have created it; a provider that is not found is skipped. A provider that cannot be deleted is reported, and the next deploy of the target adopts it. Existing providers are never deleted by rollback, and their successful updates are not restored. The CLI never creates or deletes customer-owned external secrets.

Connectors

agentcore add payment-connector --manager payments --name merchant --credential merchant
agentcore add payment-connector --manager payments --name marketplace --aws-billing

Exactly one of --credential, --quick-create or --aws-billing is required. AWS Billing connectors have no credential. The customer must create the Marketplace service-linked role before deployment; no role ARN is accepted as connector input. Runtime AWS Billing payment-header and offer selection integration is separate work.

Headless intent lifecycle

All seven intent commands require --manager-id and a nonblank --user-id. The CLI resolves the manager ID to its ARN and supports IAM managers. --agent-name is optional telemetry. JSON output retains the complete nested response, intent version, decimal money strings, structured partner data and separate capture status. CAPTURE_PENDING is not settlement.

Create a checkout with trusted application values, using a JSON file or stdin for the checkout:

agentcore payment intent create --manager-id MANAGER_ID --user-id BUYER_ID \
  --connector-id CONNECTOR_ID --capture-strategy FUTURE \
  --checkout-details file://checkout.json --json
agentcore payment intent get --manager-id MANAGER_ID --user-id BUYER_ID --intent-id INTENT_ID --json
agentcore payment intent create-buyer-approval-url --manager-id MANAGER_ID --user-id BUYER_ID \
  --intent-id INTENT_ID --parent-origin https://shop.example --json

checkout.json follows the service checkout structure. Monetary values must remain strings:

{
  "totalAmount": { "value": "12.0100", "currency": "EUR" },
  "merchant": { "name": "Example shop", "website": "https://shop.example" },
  "lineItems": [{ "sku": "item", "quantity": 2, "amount": { "value": "5.00", "currency": "EUR" } }],
  "amountBreakdown": { "shipping": { "value": "2.0100", "currency": "EUR" } },
  "referenceId": "order-123"
}

Capture strategies are INSTANT, FUTURE and SETUP; amountMode may be EXACT or UPTO. The service enforces provider, arithmetic and lifecycle constraints. Deliver the opaque approval URL to the buyer UI. These commands never open or redeem it. Only after approval, a separate backend principal may initiate, authorize and capture:

agentcore payment intent initiate --manager-id MANAGER_ID --user-id BUYER_ID --intent-id INTENT_ID --json
agentcore payment intent authorize --manager-id MANAGER_ID --user-id BUYER_ID --intent-id INTENT_ID \
  --partner-callback-result file://partner-callback.txt --json
agentcore payment intent capture --manager-id MANAGER_ID --user-id BUYER_ID --intent-id INTENT_ID \
  --capture-amount '{"value":"5.0100","currency":"EUR"}' \
  --client-token 9467ced1-60fd-4e48-8494-40bfa473d648 --json
agentcore payment intent cancel --manager-id MANAGER_ID --user-id BUYER_ID --intent-id INTENT_ID --json

The partner callback is optional and accepted only from a file or - for stdin. Checkout and capture-amount objects accept inline JSON, file://... or -. Errors and debug flag logs omit sensitive input contents. Successful JSON output can contain approval URLs and partner secrets; deliver it only to the intended application/UI.

Capture requires a caller-owned --client-token: 33 to 256 letters, digits or hyphens, such as a UUID. The CLI rejects any other token before calling AWS and sends a valid one unchanged. Store and reuse that token for retries of the same capture; a new token requests another capture. Omitting --capture-amount requests the remaining authorization. Other mutations accept an optional --client-token. There is no complete or intent list command.

These mutation commands run with the developer's explicit AWS credentials. Agent tools should be limited to Create/Get/Cancel and approval-link delivery. Buyer approval and backend settlement are separate responsibilities; do not grant the agent backend settlement permissions.

Invoking an application with payment context

Headless HTTP Runtime invocation accepts four application-context flags, also available through agentcore invoke --runtime ..., including --local:

Flag JSON payload field
--payment-user-id user_id
--payment-intent-id payment_intent_id
--payment-instrument-id payment_instrument_id
--payment-session-id payment_session_id
agentcore runtime invoke --id RUNTIME_ID --payload '{"prompt":"Review my checkout"}' \
  --payment-user-id BUYER_ID --payment-intent-id INTENT_ID --json
agentcore invoke --runtime checkout --local --payload file://request.json \
  --payment-user-id BUYER_ID --payment-instrument-id INSTRUMENT_ID \
  --payment-session-id PAYMENT_SESSION_ID

Any payment flag requires explicit --payment-user-id and a headless --payload containing an application/json object. Merchant intent context cannot coexist with legacy instrument/session context, including values already in the payload. Identical existing values are accepted; different values, blank/non-string context fields and incompatible combinations fail. Unrelated JSON is preserved, including numeric representations. With no payment flags, the exact input bytes are unchanged. Gateway, harness, MCP and other non-HTTP protocols do not support this context.

Runtime --user-id and --session-id still identify the Runtime invocation; they neither supply nor replace payment buyer/session identity. No new service headers are invented. Body context is not authentication or authorization: the application must compare the buyer with trusted authenticated identity before creating payment adapters, and an intent ID does not authorize settlement.

For v0.x migration, the explicit payment instrument/session flag names remain the same. Use --payload instead of the v0 --prompt flow and always pass --payment-user-id; the v0 fallback to Runtime --user-id or a default buyer is removed. There is no CLI --auto-session: create a legacy payment session through the existing SDK PaymentManager.create_payment_session method, then pass --payment-session-id. Existing interactive behavior is unchanged; these payment-context flags are headless-only.

Dependency and acceptance gates

Payment intent commands and the Stripe, PayPal and Amazon Pay provider fields require @aws-sdk/client-bedrock-agentcore and @aws-sdk/client-bedrock-agentcore-control 3.1181.0 or later. Connector deployment also requires the CloudFormation properties for the provider and a vended @aws/agentcore-cdk that supports them; SDK model availability alone does not provide those.

Run bun test src/handlers/payment to verify the request each command sends and the response it renders. For deployed read/ownership acceptance, create a sandbox intent through the SDK and set:

  • PAYMENT_TEST_MANAGER_ID, PAYMENT_TEST_INTENT_ID, PAYMENT_TEST_USER_ID
  • PAYMENT_TEST_OTHER_USER_ID (a distinct buyer)
  • PAYMENT_TEST_REGION, PAYMENT_TEST_CURRENCY (USD or EUR)
  • AWS credentials and AGENTCORE_CLI_PATH="node $PWD/dist/index.js"

Then run bunx vitest run --config vitest.payment-e2e.config.ts. This read-only configuration does not run the general deployment suite’s stale-stack cleanup. Repeat per provider/currency/merchant-region combination in each supported AWS Region. Browser approval, PSP sandbox checkout and CloudFormation create/update/delete remain separate deployed acceptance checks.