# Owner-approved Stripe sandbox payments

This opt-in pilot tests financial authority and evidence. It creates and confirms a Stripe PaymentIntent with Stripe's `pm_card_visa` test fixture, in the account behind the configured test key. It is not an agent card, a bank transfer, or a live checkout for an external merchant. No real money moves. General payment execution remains disabled.

Check `GET /api/v1/commerce/capabilities`: `sandboxPayments.enabled` must be true. Keep the authorized base URL; local development uses localhost and production may not enable this feature. Send the restricted commerce key as an Authorization Bearer header, never in a URL. No SDK upgrade is needed for these HTTP endpoints.

## Prepare exact authority

1. Request a policy with `POST /api/v1/commerce/policy-requests`, preserving one idempotency key and exact terms. Use purchase, USD, `stripe:test:acct_...` for the configured receiving test account, and at most 1000 minor units per request and total for the pilot. Return its reviewPath to the owner. Only the owner can activate it with their enrolled passkey.
2. Prepare exact financial terms **before** creating runtime authority. Choose an explicit review expiry within 24 hours and no later than the mandate expiry; allow enough time for the owner to review. Omit `decisionId` in new proposals. No execution clock starts from creating this proposal.
3. Submit the proposal below using `POST /api/v1/commerce/proposals` with a persisted `Idempotency-Key`. Reusing the same key with changed terms is refused.

```json
{
  "mandateId": "OWNER_ACTIVATED_MANDATE_ID",
  "action": "purchase",
  "counterpartyId": "stripe:test:acct_RECEIVING_TEST_ACCOUNT",
  "amountMinor": 1000,
  "currency": "usd",
  "description": "Owner-approved $10 sandbox purchase",
  "paymentTarget": {
    "accountId": "acct_RECEIVING_TEST_ACCOUNT",
    "expiresAt": "REPLACE_WITH_EXPLICIT_UTC_EXPIRY",
    "paymentMethod": "pm_card_visa"
  }
}
```

4. Hand off `/commerce/control?view=requests` for exact proposal review. The owner must use their own passkey. The approval binds the agent, mandate, amount, currency, account, test method, description, expiry and any cart details. Approval permits a later single submission; it does not mean a payment has happened. Poll the existing proposal until APPROVED; do not ask for repeated approval or create replacement requests on timeout.
5. **After approval**, a separately authorized runtime integration creates a fresh `stripe.payment_intent.create` decision for the same workspace and agent. It must return APPROVE/PERMITTED and record metadata `provider: "stripe"`, integer `amount` in minor units, `currency: "usd"`, `account_target`, `commerceProposalId` and `commerceDigest` matching the approved proposal. A decision created before approval cannot bind this flow. The restricted commerce key cannot call runtime authorization endpoints.
6. POST `{"action":"bind","digest":"EXACT_PROPOSAL_DIGEST","decisionId":"FRESH_DECISION_ID"}` to `/api/v1/commerce/proposals/{id}/payment`. One decision binds one proposal, once. Concurrent attempts cannot replace the winning decision. This writes a separate runtime link; it never changes the owner's signed terms.
7. The authorized runtime integration produces STRICT or CRITICAL UNLOCKED authority using actual replay verification, then submits promptly. The default runtime window is five minutes from decision creation, now **after** owner review. The runtime gate, financial admission and provider account checks still apply. Never manufacture authority or extend old timestamps. If a bound decision expires before submission, cancel the unexecuted proposal and obtain a new exact approval. Started or uncertain submissions must be reconciled instead. Legacy proposals containing `decisionId` keep their original digest and decision-first behavior.

## Itemized purchase review

HTTP clients can optionally include `purchaseContext` on a purchase proposal. It is immutable and included in both the proposal digest and owner passkey confirmation. A changed item, image URL, quantity, delivery summary, or cost requires a new request and approval; it cannot be attached retroactively to approved terms. Existing requests retain their original digests.

```json
{
  "merchantName": "Example store",
  "merchantUrl": "https://shop.example.com/",
  "capturedAt": "REPLACE_WITH_ACTUAL_CAPTURE_TIME",
  "items": [{
    "title": "Example product",
    "quantity": 2,
    "unitAmountMinor": 450,
    "productUrl": "https://shop.example.com/product",
    "imageUrl": "https://images.example.com/product.jpg",
    "sku": "OPTIONAL_PRODUCT_ID",
    "variant": "OPTIONAL_SIZE_OR_COLOR"
  }],
  "shippingMinor": 50,
  "taxMinor": 50,
  "discountMinor": 0,
  "deliverySummary": "Optional delivery estimate; omit private addresses",
  "returnPolicyUrl": "https://shop.example.com/returns"
}
```

The server requires `sum(quantity × unitAmountMinor) + shippingMinor + taxMinor − discountMinor` to equal the proposal amount in the proposal currency. Costs are integer minor units, never floating-point dollars. There can be at most 20 items. HTTPS source URLs must not contain credentials or point to local/internal hosts. Never include session tokens, payment credentials, or private delivery addresses in source URLs or summaries.

Capture the final quote, not just the product price. A cart may display `$0.00` beside “shipping/tax calculated at checkout”; those are unknown amounts, not confirmed zero charges. Keep such a capture as a review-only draft outside the financial proposal API until all charges are known. Do not invent totals, delivery terms or stock, and do not associate a real merchant cart with this sandbox payment as if Stripe placed that merchant's order.

These details are **agent-submitted, not independently verified**. The browser can show supplied source images after the owner opts in to contacting those sites. DeAlgo does not scrape Amazon, import an order, verify stock, or place a merchant checkout through this field. A Stripe sandbox payment creates no merchandise order. Only show order IDs, receipts, tracking or fulfillment as separate evidence when actually supplied by an authorized integration, with its source and observation time. A payment confirmation alone does not prove delivery.

The request page disables approval/submission when the explicit payment expiry is reached. Already-started payments remain available for reconciliation, even after expiry. Never create a replacement for an unknown outcome.

## Payment execution

Call `POST /api/v1/commerce/proposals/{id}/payment` with `{"action":"execute","digest":"EXACT_PROPOSAL_DIGEST"}`. The server rechecks active policy, connection, owner proof, credential, expiry, runtime authority, quarantine, and the receiving Stripe account. A durable release claim permits one create attempt. The server chooses the Stripe idempotency key; callers cannot choose a new effect identity.

Read stored state with `GET` on the same URL. Check Stripe directly using POST `{"action":"reconcile"}`. Reconciliation is a provider read and an evidence write, never another payment. A succeeded create response is not yet a separately reconciled observation. The workspace shows both provider status and whether it was checked directly.

An outcome_unknown, already_claimed, reconciliation_required, network error, or missing search result never authorizes a new submission, new decision, or new request key. Stripe search can lag. Keep the reservation and original identity, then reconcile or ask the owner to investigate. The original release-claim error remains in history even when a later provider lookup finds the payment. Reconciliation does not free allowance or reopen execution.

Pause, policy revocation, connection revocation and approval-key revocation stop future submissions. Once release begins, cancellation cannot recall it or release its reserved allowance. Unknown outcomes stay reserved. The owner may inspect the audit trail at any time.

## Automatic Stripe status updates

Configure a dedicated signing secret as `STRIPE_COMMERCE_WEBHOOK_SECRET` and deliver `payment_intent.*` events to `/api/webhooks/commerce-payments`. For local development, Stripe CLI can forward these to `http://localhost:3110/api/webhooks/commerce-payments`; use the same sandbox account as the portal, not an unrelated CLI default. Store the listener's secret privately and restart the local portal after configuration.

Signatures are checked against the raw body. The handler checks test mode, account, workspace, decision, proposal digest and exact financial terms, then retrieves the current PaymentIntent from Stripe. An older event never replaces current status with its old payload. The event ID and provider observation commit atomically; duplicate delivery does not duplicate evidence or payments. Failed retrieval returns non-2xx for retry. Reconciliation continues after policy expiry or revocation and never grants new spending authority. A manual reconcile remains available if the listener is offline. This local listener must remain running; production needs a separately configured Stripe webhook endpoint and secret.

## Launch boundaries

This pilot is capped at $10 USD per payment, test Visa only, and the configured account only. A successful sandbox pilot does not establish live-money readiness, regulatory exemption, or independent security certification. Business verification, production operations, a security review, and applicable payments-law review remain separate launch requirements.

Provider references: [PaymentIntent creation](https://docs.stripe.com/api/payment_intents/create), [test environments](https://docs.stripe.com/testing), [idempotent requests](https://docs.stripe.com/api/idempotent_requests).
