Merchant payments
1. Check that sandbox payments are enabled
Run these commands on the machine hosting the local sandbox. Replace YOUR_ANYCAP_KEY in each request with an all-resource connection key belonging to the personal owner or an organization owner or manager. Use it only on your server. Continue when enabled and sandbox are both true.
curl "http://localhost:8080/v1/payments/config" \ -H "Authorization: Bearer YOUR_ANYCAP_KEY"2. Publish a product and save its price
This example sells a digital guide at $10.01 per copy. Create a new UUID for each new product and reuse it for retries of the same request. From the response copy id, version and variants[0].code. For an existing product, read these fields from the product catalog instead.
curl "http://localhost:8080/v1/payments/products" \ -H "Authorization: Bearer YOUR_ANYCAP_KEY" \ -H "Content-Type: application/json" \ -H "Idempotency-Key: 8f6d5a0f-fc4a-45f4-9dd4-55a1b8fbb400" \ -d '{"name":"Digital guide","description":"PDF edition","unit_amount_cents":1001,"currency":"usd"}'{ "id": "8ec74625-6f15-48ab-84fc-2197fe219fe1", "name": "Digital guide", "description": "PDF edition", "unit_amount_cents": 1001, "currency": "usd", "status": "active", "version": 1, "variants": [ { "code": "default", "name": "Default", "unit_amount_cents": 1001 } ], "revision": "1", "created_at": "2026-11-13T08:00:00Z", "updated_at": "2026-11-13T08:00:00Z"}For an existing product, select the active item and its priced variant. If next_cursor is present, pass it as cursor on the next request.
curl "http://localhost:8080/v1/payments/products" \ -H "Authorization: Bearer YOUR_ANYCAP_KEY"3. Create and share the payment link
New reusable links open a checkout in the product currency. For example, cny and 1001 charge CNY 10.01. Replace PRODUCT_ID in the URL with id from step 2. In the body replace product_version with version and variant_code with the selected variant’s code. With quantity 1, monthly charges $10.01 per month. Use one_time to charge $10.01 once per purchase. Copy checkout_url from the response and send it to buyers. Repeating this request with the same product version, variant, quantity and billing period returns the same link.
curl "http://localhost:8080/v1/payments/products/PRODUCT_ID/payment-links" \ -H "Authorization: Bearer YOUR_ANYCAP_KEY" \ -H "Content-Type: application/json" \ -d '{"product_version":1,"variant_code":"default","quantity":1,"billing":"monthly"}'{ "id": "3b3af518-9070-4c89-9029-9bf441930125", "checkout_url": "https://checkout.example/product/example"}4. Find the order for a payment
After the buyer pays, poll events. For payment.paid copy items[].order_id for step 5. Process each event id once and save next_after as the next after cursor. The id from step 3 identifies the link. Each paid purchase or monthly invoice has its own order_id.
curl "http://localhost:8080/v1/payments/events?after=0" \ -H "Authorization: Bearer YOUR_ANYCAP_KEY"5. Verify payment before fulfillment
Replace ORDER_ID with the event’s order_id. Match items[].product_id and variant_code to the purchase. Fulfill each order id once, when status is paid and review_required is false. amount_cents is the gross payment, platform_fee_cents is the fee and merchant_amount_cents is the merchant share, all in minor units of the order currency.
curl "http://localhost:8080/v1/payments/orders/ORDER_ID" \ -H "Authorization: Bearer YOUR_ANYCAP_KEY"Alternative: create a link for a single order
To associate one checkout with your own order number, use the product id from step 2 and a new merchant_order_id. Replace both return URLs with your own. Store a new UUID as the Idempotency-Key before sending. Share the returned checkout_url while status is pending and use the returned order id in step 5.
curl "http://localhost:8080/v1/payments/orders" \ -H "Authorization: Bearer YOUR_ANYCAP_KEY" \ -H "Content-Type: application/json" \ -H "Idempotency-Key: 441c7141-a468-42c7-9286-98b513084d53" \ -d '{"merchant_order_id":"shop-order-1001","items":[{"product_id":"REPLACE_WITH_PRODUCT_ID","quantity":2}],"success_url":"https://shop.example/paid","cancel_url":"https://shop.example/cart"}'merchant_order_idYes
itemsYes
items[].product_idYes
items[].quantityYes
success_url / cancel_urlYes
Example response (checkout_url is illustrative; use the actual returned link unchanged). HTTP 201 means the order is saved: inspect status before using the link. Order total must be 50–99999999 minor units of the order currency. Prices and the 2% fee are frozen per order.
{ "id": "0a5775c1-e554-424e-84c5-7639f9c63919", "merchant_order_id": "shop-order-1001", "items": [ { "product_id": "8ec74625-6f15-48ab-84fc-2197fe219fe1", "quantity": 2, "name": "Digital guide", "unit_amount_cents": 1001, "product_revision": "1" } ], "amount_cents": 2002, "currency": "usd", "fee_basis_points": 200, "platform_fee_cents": 41, "merchant_amount_cents": 1961, "status": "pending", "review_required": false, "checkout_url": "https://checkout.example/pay/returned-link", "sandbox": true, "created_at": "2026-11-13T08:00:00Z", "updated_at": "2026-11-13T08:00:00Z", "paid_at": null}Only fulfill when the order returns status=paid and review_required=false. Query the order ID about every 5 seconds while waiting; order lists read saved status only. If a creation response is lost, find the saved order using merchant_order_id or repeat the exact original POST with its original key. An unknown result is not a failed payment: continue querying the original order without creating another payment attempt.
curl "http://localhost:8080/v1/payments/orders?merchant_order_id=shop-order-1001" \ -H "Authorization: Bearer YOUR_ANYCAP_KEY"Manage products, covers and versions
Products accept code and variants:[{code,name,unit_amount_cents}]. Product codes are unique per merchant and variant codes within a product. At most 50 variants are allowed; each price is 50–99999999 integer minor units of the order currency. The required compatibility field unit_amount_cents is derived from the first variant. An explicit empty variants array saves an unpriced product with amount zero and sales paused; it cannot be activated or ordered. Omitting variants uses the legacy single price; unchanged-price updates preserve existing variants. Multi-variant price changes require the complete array.
nameYes
descriptionNo
unit_amount_centsYes
currencyYes
version identifies immutable product content; revision is the optimistic lock. Content changes atomically save a new version; sale status updates only change revision. GET /v1/payments/products/{id}/versions returns known versions newest first, without inventing missing history. Order items accept variant_code and optional product_version. A code is required for multi-variant products; a stale version returns 409 before checkout creation. Different variants may appear as separate lines; duplicate product/variant pairs are rejected. Orders freeze product_version, product_revision, variant_code, variant_name, product_code and prices when known; historical orders may omit added fields.
curl "http://localhost:8080/v1/payments/products/PRODUCT_ID/versions" \ -H "Authorization: Bearer YOUR_ANYCAP_KEY"The response includes id, the input fields, status=active, revision, created_at and updated_at. PATCH the product ID with all product fields plus the current revision and status=active or archived. Archiving blocks new orders. Saved orders retain their original item names, prices and revisions. List responses contain items and next_cursor (null when complete), with at most 50 rows. Pass next_cursor as cursor for the next page.
curl "http://localhost:8080/v1/payments/products/PRODUCT_ID" \ -H "Authorization: Bearer YOUR_ANYCAP_KEY"To archive a product, copy its current revision from the preceding response. Keep all current product fields when updating. Editing product content or archiving closes its reusable links for new purchases. Existing subscriptions retain their agreed price.
curl "http://localhost:8080/v1/payments/products/PRODUCT_ID" \ -X PATCH -H "Authorization: Bearer YOUR_ANYCAP_KEY" \ -H "Content-Type: application/json" \ -d '{"name":"Digital guide","description":"PDF edition","unit_amount_cents":1001,"currency":"usd","status":"archived","revision":"1"}'Product cover images
Upload a cover with POST /v1/payments/product-images using one multipart field file, a JPEG or PNG up to 5 MiB, 4096 pixels per side and 16 million pixels. The server removes metadata, resizes proportionally to at most 1200 pixels and stores a permanent PNG. Set product image_id to the returned id. Omit image_id on update to retain the current cover, or send an empty string to remove it. Cover changes publish a new product version; previous versions keep their images. The authenticated key must belong to an owner/manager with all-resource access in the same merchant workspace. Read the cover from GET /v1/payments/product-images/{image_id}; no public object URL is returned.
curl "http://localhost:8080/v1/payments/product-images" \ -H "Authorization: Bearer YOUR_ANYCAP_KEY" \ -F "[email protected]"curl --output cover.png "http://localhost:8080/v1/payments/product-images/IMAGE_ID" \ -H "Authorization: Bearer YOUR_ANYCAP_KEY"Order and event fields
| Response field | Meaning |
|---|---|
| status | creating: preparing; pending: waiting for payment; unknown: creation result uncertain; paid: payment verified; failed: definitively rejected/failed; expired: link expired |
| checkout_url | Hosted payment URL, empty until confirmed. Redirect the buyer to this URL. |
| amount_cents | Buyer gross payment in integer minor units of the order currency |
| fee_basis_points / platform_fee_cents | 200 basis points = 2%. Fee = ceil(amount_cents × 200 / 10000), rounded once per order to cents. |
| merchant_amount_cents | Gross minus the platform fee; no additional processing-fee deduction. An order accounting amount, not a withdrawable balance. |
| sandbox | Always true in this contract |
| review_required | True on a payment contract mismatch, refund or dispute; pause fulfillment and review the order. |
| error_code / error_message | Optional machine code / sanitized readable specific reason, present when a failure or unknown/review condition is known |
| paid_at | Verified payment timestamp or null |
GET events returns {items:[{id,order_id,type,created_at}],next_after}. Types: payment.paid, payment.failed, payment.expired, payment.review_required. Read at most 100 events per request, in commit order; save next_after after processing, then continue with after=next_after. Idempotently process event IDs and fetch the current order before fulfillment. An empty page preserves the cursor. Events are polled, not pushed to a merchant callback. Keep financial records separate from Anycap credit balances.
Errors
Invalid catalog inputs return product_invalid, product_variants_invalid or product_variants_required. Activating an unpriced product returns product_price_required. Invalid order variants return payment_variant_required, payment_variant_invalid or payment_items_invalid; stale versions use payment_conflict. error.code is the machine code and error.message contains the specific readable reason. Mixed-currency orders return payment_currency_mismatch.
A saved order can report a definitive creation failure while retaining its original ID. Example:
{ "id": "0a5775c1-e554-424e-84c5-7639f9c63919", "merchant_order_id": "shop-order-1001", "items": [ { "product_id": "8ec74625-6f15-48ab-84fc-2197fe219fe1", "quantity": 2, "name": "Digital guide", "unit_amount_cents": 1001, "product_revision": "1" } ], "amount_cents": 2002, "currency": "usd", "fee_basis_points": 200, "platform_fee_cents": 41, "merchant_amount_cents": 1961, "status": "failed", "review_required": false, "checkout_url": "", "sandbox": true, "created_at": "2026-11-13T08:00:00Z", "updated_at": "2026-11-13T08:00:00Z", "paid_at": null, "error_code": "payment_option_unsupported", "error_message": "A configured checkout option is unsupported by the sandbox payment API."}{ "error": { "code": "payment_conflict", "message": "The idempotency key or merchant_order_id was already used for a different order.", "request_id": "trace-id" }}HTTP errors use error.code for the machine code, error.message for the specific readable reason, and error.request_id for tracing. 400: invalid fields or UUID; 401: missing/invalid/revoked key; 403: wrong role or selected-resource key; 404: resource outside this merchant account or absent; 409: changed idempotent parameters, archived product or stale revision; 429: rate limit (respect Retry-After); 503: sandbox payment configuration or service unavailable. A saved failed/unknown order can still return HTTP 201/200: read its status, error_code and error_message.