API reference
Send each sale when it closes. One record per sale, from your register, POS or checkout, becomes the evidence for any dispute on it.
On this page
- Quick startA test key, a check, your first sale.
- KeysSecret and publishable, test and live.
- Recording a saleThe request, the answer and every field.
- Tap receiptsThe customer confirms on their own phone.
- Online checkoutOne script for card-not-present sales.
- ErrorsWhat each answer means, and what to do.
Quick start
The API is JSON over HTTPS. Amounts are whole cents, times are ISO 8601 with their zone, and every request carries a key.
https://mzbkaiqhtvfgmgsbxwjz.supabase.co/functions/v1/capture
-
Make a test secret key
The business makes it in the dashboard: API keys, then Make a key, with Secret key and Test. It’s shown once, so copy it into your server’s settings.
-
Check the connection
Run this once from your server. An answer with
"ok": truemeans you’re connected, and the business’s dashboard marks the install step done.POST /pingcurl -X POST https://mzbkaiqhtvfgmgsbxwjz.supabase.co/functions/v1/capture/ping \ -H "Authorization: Bearer cs_sk_test_…"
200{ "ok": true, "kind": "secret", "mode": "test", "installed": true } -
Send each sale when it closes
One request per sale, from your server, as soon as the check or order closes. The whole record is below, under Recording a sale.
-
Go live
Once the business presses Go live in the dashboard, swap in a live secret key. Nothing else changes.
Keys
Send the key as Authorization: Bearer … on every request. Each key belongs to one business and reaches nothing else. ChargeSecured keeps only its hash, so a lost key is revoked and replaced, never recovered.
| Key | Where it goes | What it does |
|---|---|---|
cs_sk_test_… | Your server, while you build | Records test sales, kept apart from real ones |
cs_sk_live_… | Your server, once the business is live | Records real sales |
cs_pk_test_… | A checkout page, any address | Runs the checkout script on staging sites |
cs_pk_live_… | The checkout page on the business’s own website | Runs the checkout script; refused on any other website |
Secret keys never go on a web page, a receipt or an app people download. A request from a browser with a secret key is refused. If one was ever on a public page, revoke it on the dashboard’s API keys tab.
Live keys work once the business is live. Until then, use the test keys.
Recording a sale
POST /sales with a secret key, at close. The more of the record you send, the stronger the answer to a dispute.
curl -X POST https://mzbkaiqhtvfgmgsbxwjz.supabase.co/functions/v1/capture/sales \
-H "Authorization: Bearer cs_sk_test_…" \
-H "Content-Type: application/json" \
-d '{
"schema": 1,
"order_id": "VR-20931",
"transaction_id": "TRxxxxxxxxxxxxxxxx",
"occurred_at": "2026-11-15T03:19:00Z",
"timezone": "America/New_York",
"amount": 148000,
"currency": "USD",
"subtotal": 110000,
"tax": 9763,
"service_charge": 22000,
"tip": 6237,
"tip_chosen_by": "customer",
"card": {
"brand": "visa",
"last4": "4242",
"approval_code": "083311",
"entry_mode": "contactless"
},
"items": [
{ "name": "Premium vodka, 750 ml", "quantity": 2, "unit_amount": 55000 }
],
"location": { "name": "Velvet Room", "area": "Main floor", "table": "VIP 4" },
"staff": { "server_id": "Server 118" },
"receipt": { "signed": true, "signed_at": "2026-11-15T03:20:00Z" }
}'{
"id": "6f0c…",
"duplicate": false,
"sha256": "9a41…",
"receivedAt": "2026-11-15T03:20:02Z"
}201 means it was saved. The same record sent again answers 200 with "duplicate": true, so retrying after a timeout is safe. A changed record with the same order_id is kept beside the first one: nothing is ever overwritten.
sha256 is the record’s place in the business’s chain of records, each one linked to the one before. A dispute response cites it, so the bank can see the record wasn’t changed after the fact.
The fields
| Field | What it is | Why it helps |
|---|---|---|
schema required | Always 1 | The version of this record |
order_id required | Your register’s id for the check or order, up to 80 characters | Ties every record of one order together |
occurred_at required | When the sale happened, ISO 8601 with its zone | The time of sale on the response |
amount, currency required | The total charged, in cents, and its three-letter currency | Checked against what the processor charged |
transaction_id | Your payment processor’s id for the charge | Matches the sale to its dispute exactly |
timezone | Where the sale happened, as an IANA zone like America/New_York | Times on the response read as local time |
opened_at, closed_at | When a tab or check opened and closed | Shows how long the customer was there |
subtotal, tax, service_charge, tip | The parts of the total, in cents | Answers “wrong amount” |
tip_chosen_by, tip_chosen_at | customer when they picked the tip on the payment screen, or staff | Answers “I never agreed to that tip” |
card | brand, last4, approval_code, and entry_mode: chip, contactless, swiped or keyed | A chip or tap read answers most fraud claims |
items | Up to 200 lines: name, quantity, unit_amount in cents, and served_at | Answers “not as described” and “I don’t recognize this” |
location | name, area and table of the venue | Shows the sale happened in person |
staff | server_id and manager_id: who served and who approved | Someone who can speak to the sale |
customer | name, email and phone, when they gave them | Mastercard counts the email and phone |
reservation | id, name and party_size | The customer booked under their own name |
receipt | signed and signed_at, emailed and emailed_at | The customer’s own agreement to the total |
terms | shown, accepted_at and the terms’ version | What the customer agreed to before paying |
online | The checkout script’s id and the customer’s details for an online sale: Online checkout | Visa Compelling Evidence 3.0 and Mastercard First-Party Trust |
Send it at close, not later. A record that arrives after a dispute has opened is flagged for a second look.
Never send full card numbers, security codes or passwords. Anything that looks like a full card number is refused, wherever it appears in the record. A field this table doesn’t list is refused too, so nothing unexpected is kept. A record can be up to 64 KB.
Tap receipts
Add ?receipt=1 to the same request. The answer carries a link for this sale: show it as a QR code on the customer display, print it on the receipt, or text it.
{
"id": "6f0c…",
"duplicate": false,
"sha256": "9a41…",
"receivedAt": "2026-11-15T03:20:02Z",
"receipt": {
"url": "https://chargesecured.com/portal/receipt#…",
"expiresAt": "2026-11-29T03:20:02Z"
}
}The customer checks the bill and the tip on their own phone. Looks right records their confirmation, which a dispute response then cites. Something’s wrong tells the business at once, while the charge can still be put right. Each link lasts 14 days, and each request makes a new one.
Online checkout
For “I didn’t make this purchase”, Visa looks at the customer’s earlier visits. One script on your checkout page records them.
1. On your checkout page, with a publishable key:
<script src="https://chargesecured.com/capture/v1.js" data-key="cs_pk_live_…"
data-api="https://mzbkaiqhtvfgmgsbxwjz.supabase.co/functions/v1/capture" async></script>
<form data-chargesecured-checkout …>
<div data-chargesecured-terms data-version="2026-11">Your terms of sale</div>
<label><input type="checkbox" data-chargesecured-accept> I agree</label>
</form>It records the checkout when the page opens, and again when the terms box is ticked, and keeps the latest id in a hidden chargesecured_checkout_id field on the form. It keeps a random device id in your website’s own storage, with no fingerprinting and nothing shared across websites, and ChargeSecured adds the IP address it sees. It never reads card or other form fields, never delays the checkout, and gives up after 2.5 seconds.
A page that sends its orders itself can call it directly:
const { checkoutId } = await ChargeSecured.checkout({
terms: { version: '2026-11', text: 'Your terms of sale', accepted: true },
});2. With each online sale, add online to the sale record, with the customer’s email and phone. Visa uses the device, the IP address, the account and the shipping address; Mastercard also counts the email, the phone and the billing address.
"customer": { "email": "[email protected]", "phone": "+1 512 555 0142" },
"online": {
"checkout_id": "the chargesecured_checkout_id from the form",
"account_id": "cust_884",
"shipping": {
"line1": "12 Pier St",
"city": "Austin",
"region": "TX",
"postal_code": "78701",
"country": "US"
},
"billing": { "line1": "12 Pier St", "postal_code": "78701", "country": "US" }
}Errors
Every refusal answers with a code and a sentence. A record that was refused was not saved, so fix it and send it again.
{
"error": {
"code": "invalid_record",
"message": "That record wasn’t saved.",
"problems": [{ "field": "card.last4", "problem": "must be exactly the last 4 digits" }]
}
}200 "duplicate": trueThe same record arrived twice. Nothing to do.400 invalid_requestThe body isn’t a JSON object, or it’s over 64 KB.401 invalid_keyThe key is mistyped, revoked, or missing itsBearerprefix.403 secret_key_in_browserA secret key was used from a web page. Revoke it, and use a publishable key there.403 secret_key_requiredA publishable key was sent to/sales. Sale records come from your server, with a secret key.403 origin_not_allowedA live publishable key was used on another website. It works only on the business’s own.403 not_liveA live key was used before the business went live. Use the test key until then.403 business_closedThe business’s account is closed.422 invalid_recordThe answer lists each field to fix, like above.422 card_number_not_allowedSomething looked like a full card number. Send only the last 4. Give long numeric ids a prefix, likecust_884.500 server_errorSomething went wrong on our side. Send the same record again in a minute: it’s saved once.