Sites WayDevelopers
API reference

Payments

Create payments and send customers to pay them.

Create a payment

POST /v1/payments

Creates a payment to be paid on the hosted page (POST /v1/payments/{id}/checkout-link) or on your own page (client secret). The same Idempotency-Key with the same body answers the first result again (header Idempotency-Replayed: true); with another body it is refused.

Permission: payments:write

curl -X POST https://api.sw-staging.dev/v1/payments \
  -H "Authorization: Bearer sw_test_…" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{"amount":1000,"currency":"SAR"}'

Parameters

FieldTypeRequiredDescription
Idempotency-Keystring (header)yesA unique key per operation (1-255 visible ASCII characters). Retrying with the same key and body answers the first result.. at most 255 characters

Request body

FieldTypeRequiredDescription
amountnumberyesIn the minor unit of the currency (1050 = 10.50 SAR)
capture_methodautomatic, manualnoOnly 'automatic' today (authorize and capture at once). default "automatic"
currencystringyesISO 4217 currency code, upper case. pattern ^[A-Z]{3}$
customer_referencestringnoat most 255 characters
descriptionstringnoat most 1000 characters
expires_in_secondsintegernoHow long the payment can be paid. default 86400. min 300. max 604800
merchant_referencestringnoYour order number; searchable with GET /v1/payments. at most 255 characters
metadataobjectnoYour own key-value data, returned as sent (at most 8 KB as JSON). default {}

201 — The payment

FieldTypeDescription
amountintegerAmount in the minor unit of the currency (e.g. halalas: 1050 = 10.50 SAR)
amount_authorizedintegerAmount in the minor unit of the currency (e.g. halalas: 1050 = 10.50 SAR)
amount_capturedintegerAmount in the minor unit of the currency (e.g. halalas: 1050 = 10.50 SAR)
amount_refundedintegerAmount in the minor unit of the currency (e.g. halalas: 1050 = 10.50 SAR)
capture_methodautomatic, manual
created_atstring (date-time)
currencystringISO 4217 currency code, upper case. pattern ^[A-Z]{3}$
customer_referencestring or null
descriptionstring or null
environmenttest, live
expires_atstring (date-time) or null
idstringpattern ^pay_[0-9A-HJKMNP-TV-Z]{26}$
merchant_referencestring or null
metadataobjectYour own key-value data, returned as sent (at most 8 KB as JSON)
statusCREATED, REQUIRES_PAYMENT_METHOD, REQUIRES_ACTION, PROCESSING, AUTHORIZED, CAPTURED, SUCCEEDED, FAILED, CANCELED, EXPIRED, PARTIALLY_REFUNDED, REFUNDED

Errors answer with the error object.

List payments

GET /v1/payments

Newest first. Page with starting_after (the last id of the previous page).

Permission: payments:read

curl -X GET https://api.sw-staging.dev/v1/payments \
  -H "Authorization: Bearer sw_test_…"

Parameters

FieldTypeRequiredDescription
limitinteger (query)nodefault 20. min 1. max 100
starting_afterstring (query)noThe last id of the previous page. pattern ^pay_[0-9A-HJKMNP-TV-Z]{26}$
statusCREATED, REQUIRES_PAYMENT_METHOD, REQUIRES_ACTION, PROCESSING, AUTHORIZED, CAPTURED, SUCCEEDED, FAILED, CANCELED, EXPIRED, PARTIALLY_REFUNDED, REFUNDED (query)no
merchant_referencestring (query)noat most 255 characters

200 — A page of payments

FieldTypeDescription
dataarray of object
data[].amountintegerAmount in the minor unit of the currency (e.g. halalas: 1050 = 10.50 SAR)
data[].amount_authorizedintegerAmount in the minor unit of the currency (e.g. halalas: 1050 = 10.50 SAR)
data[].amount_capturedintegerAmount in the minor unit of the currency (e.g. halalas: 1050 = 10.50 SAR)
data[].amount_refundedintegerAmount in the minor unit of the currency (e.g. halalas: 1050 = 10.50 SAR)
data[].capture_methodautomatic, manual
data[].created_atstring (date-time)
data[].currencystringISO 4217 currency code, upper case. pattern ^[A-Z]{3}$
data[].customer_referencestring or null
data[].descriptionstring or null
data[].environmenttest, live
data[].expires_atstring (date-time) or null
data[].idstringpattern ^pay_[0-9A-HJKMNP-TV-Z]{26}$
data[].merchant_referencestring or null
data[].metadataobjectYour own key-value data, returned as sent (at most 8 KB as JSON)
data[].statusCREATED, REQUIRES_PAYMENT_METHOD, REQUIRES_ACTION, PROCESSING, AUTHORIZED, CAPTURED, SUCCEEDED, FAILED, CANCELED, EXPIRED, PARTIALLY_REFUNDED, REFUNDED

Errors answer with the error object.

Retrieve a payment

GET /v1/payments/{id}

Permission: payments:read

curl -X GET https://api.sw-staging.dev/v1/payments/pay_01M6XF0H2MAC63MEKQAT4K3AXF \
  -H "Authorization: Bearer sw_test_…"

Parameters

FieldTypeRequiredDescription
idstring (path)yesThe payment id (pay_…)

200 — The payment

FieldTypeDescription
amountintegerAmount in the minor unit of the currency (e.g. halalas: 1050 = 10.50 SAR)
amount_authorizedintegerAmount in the minor unit of the currency (e.g. halalas: 1050 = 10.50 SAR)
amount_capturedintegerAmount in the minor unit of the currency (e.g. halalas: 1050 = 10.50 SAR)
amount_refundedintegerAmount in the minor unit of the currency (e.g. halalas: 1050 = 10.50 SAR)
capture_methodautomatic, manual
created_atstring (date-time)
currencystringISO 4217 currency code, upper case. pattern ^[A-Z]{3}$
customer_referencestring or null
descriptionstring or null
environmenttest, live
expires_atstring (date-time) or null
idstringpattern ^pay_[0-9A-HJKMNP-TV-Z]{26}$
merchant_referencestring or null
metadataobjectYour own key-value data, returned as sent (at most 8 KB as JSON)
statusCREATED, REQUIRES_PAYMENT_METHOD, REQUIRES_ACTION, PROCESSING, AUTHORIZED, CAPTURED, SUCCEEDED, FAILED, CANCELED, EXPIRED, PARTIALLY_REFUNDED, REFUNDED

Errors answer with the error object.

A payment's history

GET /v1/payments/{id}/events

Every state change of the payment, oldest first.

Permission: payments:read

curl -X GET https://api.sw-staging.dev/v1/payments/pay_01M6XF0H2MAC63MEKQAT4K3AXF/events \
  -H "Authorization: Bearer sw_test_…"

Parameters

FieldTypeRequiredDescription
idstring (path)yesThe payment id (pay_…)

200 — The events

FieldTypeDescription
dataarray of object
data[].dataobject
data[].occurred_atstring (date-time)
data[].typestring

Errors answer with the error object.

Cancel an unpaid payment

POST /v1/payments/{id}/cancel

Only a payment nobody has started paying can be canceled.

Permission: payments:write

curl -X POST https://api.sw-staging.dev/v1/payments/pay_01M6XF0H2MAC63MEKQAT4K3AXF/cancel \
  -H "Authorization: Bearer sw_test_…"

Parameters

FieldTypeRequiredDescription
idstring (path)yesThe payment id (pay_…)

200 — The canceled payment

FieldTypeDescription
amountintegerAmount in the minor unit of the currency (e.g. halalas: 1050 = 10.50 SAR)
amount_authorizedintegerAmount in the minor unit of the currency (e.g. halalas: 1050 = 10.50 SAR)
amount_capturedintegerAmount in the minor unit of the currency (e.g. halalas: 1050 = 10.50 SAR)
amount_refundedintegerAmount in the minor unit of the currency (e.g. halalas: 1050 = 10.50 SAR)
capture_methodautomatic, manual
created_atstring (date-time)
currencystringISO 4217 currency code, upper case. pattern ^[A-Z]{3}$
customer_referencestring or null
descriptionstring or null
environmenttest, live
expires_atstring (date-time) or null
idstringpattern ^pay_[0-9A-HJKMNP-TV-Z]{26}$
merchant_referencestring or null
metadataobjectYour own key-value data, returned as sent (at most 8 KB as JSON)
statusCREATED, REQUIRES_PAYMENT_METHOD, REQUIRES_ACTION, PROCESSING, AUTHORIZED, CAPTURED, SUCCEEDED, FAILED, CANCELED, EXPIRED, PARTIALLY_REFUNDED, REFUNDED

Errors answer with the error object.

A hosted payment page for the payment

POST /v1/payments/{id}/checkout-link

Redirect the customer to the returned url. After paying they return to return_url; confirm the result from your server (GET the payment, or a webhook), never from the return alone.

Permission: payments:write

curl -X POST https://api.sw-staging.dev/v1/payments/pay_01M6XF0H2MAC63MEKQAT4K3AXF/checkout-link \
  -H "Authorization: Bearer sw_test_…" \
  -H "Content-Type: application/json" \
  -d '{"return_url":"string"}'

Parameters

FieldTypeRequiredDescription
idstring (path)yesThe payment id (pay_…)

Request body

FieldTypeRequiredDescription
return_urlstringyesWhere the customer returns after paying. at most 2048 characters
FieldTypeDescription
expires_atstring (date-time) or null
idstring
urlstringSend the customer here (the hosted payment page)

Errors answer with the error object.

A client secret for your own checkout page

POST /v1/payments/{id}/client-secret

For a checkout page you host: the browser uses the secret, never your API key. Ask for it from your server.

Permission: payments:write

curl -X POST https://api.sw-staging.dev/v1/payments/pay_01M6XF0H2MAC63MEKQAT4K3AXF/client-secret \
  -H "Authorization: Bearer sw_test_…"

Parameters

FieldTypeRequiredDescription
idstring (path)yesThe payment id (pay_…)

Request body (optional)

FieldTypeRequiredDescription
return_urlstringnoWhere the customer returns; its origin must be one of your registered origins. at most 2048 characters

201 — The secret

FieldTypeDescription
client_secretstringFor your own checkout page in the browser; never log it
expires_atstring (date-time)

Errors answer with the error object.

On this page