Charge subscriber
Charge a subscriber's saved card, without the payer. We send the charge to your acquirer as a merchant-initiated transaction, and answer when it is authorized, and captured unless you say not to, or when it has failed.
Request
POST https://{subid}is the subscriber's"id", from seq.
The key needs the charge permission.
Headers
| HTTP header | Description |
|---|---|
Authorization |
Required. Your API key, after |
Idempotency-Key |
A key you make up for this request, and send again with each retry of it, so that the request is done once however often it arrives. Up to the 4 KiB of all headers, and kept for 24 hours. See Idempotency. Always send one with a charge: see Retrying. |
Fields
An address you send is this charge's, in place of the subscriber's whole, and one you leave out is the subscriber's.
| Field | Type | Description |
|---|---|---|
items |
array, required | What the payer pays for: one or more items, whose totals add up to the amount to pay. All in one currency, and together more than 0. |
items[].total |
amount, required | The price of the item, its whole quantity together. At least 0, and with no more decimals than the currency has. See Amounts. |
items[].quantity |
integer | How many, a positive integer. The default is |
items[].name |
string | The name of the product or service, for your records and the dashboard. The payment window does not show it. |
items[].sku |
string | Your SKU for the product. |
orderid |
string | Your ID for what the charge pays, such as the subscription and its period. Seq returns it with the charge, which is how you match the charge to your records, and the acquirer passes it to the payer's bank, as for a payment link. Optional, but give it. |
autocapture |
boolean | Capture the charge as soon as it is authorized, which is the default, true, unlike for a payment link. With false, it is only authorized, and you capture it later. If a capture fails, the authorization is voided, and the charge fails. |
billing |
object | The billing address for this charge. See Addresses. |
shipping |
object | The shipping address for this charge. |
Example
Charge a month of a subscription, with a key made for that month and its first attempt:
curl https://api.gjold.com/v2/{shopid}:sub:19/charge \
-u {apikey} \
-H 'Idempotency-Key: sub19-2026-12-try1-7f3a9c2e5b1d4f60' \
-d @charge.json
{
"orderid": "M-7192-2026-12",
"items": [
{
"name": "Membership, December",
"total": "99 DKK"
}
],
"autocapture": true
}
Response
We answer 200 OK with the charge, a transaction, once the acquirer
has authorized it, and captured it with "autocapture":
| Field | Type | Description |
|---|---|---|
type |
string | Always "charge". |
id |
integer | The transaction's ID, by which you can capture, refund, or void it. |
totals.authorized |
amount | What the bank authorized: the items' total. |
{
"type": "charge",
"id": 1043,
"totals": {
"authorized": "99 DKK"
}
}
Seq returns the whole transaction too, as a
charge, with its act of capture if it had
"autocapture". A charge is never partly authorized: if the bank
approves only part of the amount, we void that, and the charge fails
with 402 transient {acquirer} error: partial authorization.
Headers
| HTTP header | Description |
|---|---|
Idempotency-Status: OK |
The answer is a replay: the stored answer to the first request with this Idempotency-Key, which this request did not run again. |
Timing
A charge waits for the acquirer, once to authorize, and again to capture: a second or two, as a rule, but up to 1 minute per call with Clearhaus, or 10 minutes with Nets, when the acquirer is slow. See Timeouts.
Errors
Declines
A charge that the acquirer declines, or that it does not answer in
time, fails with 402, and a message whose first word says whether to
try again:
HTTP/1.1 402 permanent clearhaus error: card expired
HTTP/1.1 402 transient nets error: not sufficient funds
| Status and message | Description |
|---|---|
402 transient {acquirer} error: {why} |
The charge failed for a reason that may pass: the account lacks the money, a limit is reached, the bank approved only part of it, or the acquirer did not answer. Try again later, with a new key, but not today: see When a charge fails. |
402 permanent {acquirer} error: {why} |
The charge will not succeed on this card: it has expired, been blocked, or the payer has stopped your charges. Don't try again, as the card schemes fine you for it, but have the payer renew the subscriber. |
{why} is the acquirer's reason, for your logs and support, which
acquirers word differently. Branch on the first word, never on the
rest. A declined charge leaves no transaction, so seq does not return
it; record it yourself.
When the acquirer did not answer in time, the payer's bank may have
authorized the charge without our knowing. There is then no
transaction to capture, so the bank releases the amount after some
days; until then, the payer may see it held. Waiting a day before the
next try, as for any transient failure, keeps two holds from piling
up.
Other errors
Besides the errors that any request can give, which Errors lists:
| Status and message | Description |
|---|---|
400 invalid json in {where}: {why} |
The body is not a JSON object, or a field is not as the table says. See Invalid JSON. |
400 missing items |
There are no "items", or the array is empty. |
400 total must be more than 0 |
The items' totals add up to 0. |
400 invalid item total currency |
An item's total is in a currency that is not in the ISO 4217 table. |
404 subscriber not found |
The shop has no subscriber with that {subid}. |
410 subscriber deleted |
The subscriber was deleted. Have the payer renew it. |
500 {why} |
We failed. If the charge reached the acquirer, it may have gone through: synchronize before you try again. |
Retrying
If the connection breaks before you have the answer, send the request
again with the same Idempotency-Key: a charge still running is
waited for, and a finished one answers as before. Without a key, you
can't know whether the charge went through, and a second request
charges the payer twice. For the same reason, never charge the same
subscriber twice at once.
See also
Charging subscribers, and in the knowledge base, Stored credentials and Declined charges.