Invoice API issues an invoice with a payment link: the client pays by the link in the Freedom SuperApp, with Bybit Pay or with Binance Pay.
Create an invoice: type sets how the client pays, the response contains the payment link url.
Sign every request with X-JWS-Signature: see «Signature».
Methods#
Recurring payments are in development: the client confirms once, then you charge without the client. See Recurring payments.
Its methods use the headers, the signature and the errors described below.Invoice statuses#
| Status | Meaning | Final |
|---|
new | The invoice is created and waits for the payment. | No |
process | The payment is in progress. | No |
success | The invoice is paid. Refunds do not change the status. | Yes |
error | The payment failed. | Yes |
canceled | The invoice is cancelled with Cancel invoice. | Yes |
incomplete | The invoice expired: it was not paid before expires_at. | Yes |
| Header | Required | Value |
|---|
Content-Type | Yes | application/json. |
X-JWS-Signature | Yes | Request signature: see «Signature». |
X-Request-Id | Yes | Request ID, UUID. Use a new value for every request. |
X-Datetime | No | Request date and time in UTC, format YYYY-MM-DDThh:mm:ssZ. |
| Header | Value |
|---|
X-Request-Id | Equals X-Request-Id from the request. |
X-Request-Status | success for HTTP 200 and 201, error for 400 and 500. Not returned for 401 and 422. It describes the request, not the invoice: check status in the body. |
X-Datetime | Response date and time, RFC 3339. |
Errors#
| HTTP | Body | When | What to do |
|---|
200, 201 | Result of the method | The request is processed. | Check the status in the body. |
400 | status = error, error_description; error_code for most errors | The request is valid, but the operation is not possible, for example the invoice is not found or already paid. | See «Errors» of the method. |
401 | error_code = 9998 | The signature is invalid. | Check the signature: see «Signature». |
422 | error_code = 9403 | X-JWS-Signature is missing. | Pass the signature. |
500 | status = error, error_description | A field is missing or invalid: error_description names it. Also an internal error. | Fix the request. If it is valid, repeat it later with a new X-Request-Id. |
Signature#
The signature is a detached JWS (RFC 7515, appendix F): BASE64URL(header) + .. + BASE64URL(signature). The body is not included in the header value.Header (all fields are required):| Field | Value |
|---|
uri | Path of the called URL, for example /v5/merchant/invoice/status. |
auth_id | Your API user ID, as a string. |
method | POST |
params | Empty string "". |
alg | HS256 |
Signature: HMAC-SHA256 with your secret key over BASE64URL(header) + "." + BASE64URL(body).
BASE64URL — base64url without = padding.Sign exactly the bytes of the body you send. Any change after signing (formatting, spaces, key order) makes the signature invalid: 401, code 9998.
Example (secret key test_secret_key):{"uri":"/v5/merchant/invoice/status","auth_id":"12345","method":"POST","params":"","alg":"HS256"}
Body (sent exactly as shown, in one line):{"id":"019d0652-4e2f-7f54-a179-007c80c48cef"}
eyJ1cmkiOiIvdjUvbWVyY2hhbnQvaW52b2ljZS9zdGF0dXMiLCJhdXRoX2lkIjoiMTIzNDUiLCJtZXRob2QiOiJQT1NUIiwicGFyYW1zIjoiIiwiYWxnIjoiSFMyNTYifQ..Ntzsw75bc7exHPJSa3vEafIhyp6YsjpGULF98McbAFk
Python#
The code below produces the X-JWS-Signature of the example above.
verify_jws checks the signature of a notification: see «Notifications».PHP#
The code below produces the same X-JWS-Signature.Notifications#
If state_callback is passed in Create invoice, Freedom Pay sends a POST request to it when the invoice is paid, refunded, fails, is cancelled or expires.| Field | Type | Description |
|---|
id | string | Invoice ID. |
external_id | string | Invoice ID in the merchant system. |
status | string | Invoice status: see Get invoice status. After a refund, the status stays success. |
refund_id | string or null | ID of the latest refund, or null if there are no refunds. |
error_code | null | Reserved. |
error_description | null | Reserved. |
{
"id": "019d0652-4e2f-7f54-a179-007c80c48cef",
"external_id": "order_1001",
"status": "success",
"refund_id": null,
"error_code": null,
"error_description": null
}
The request headers: Content-Type: application/json, X-Request-Id, X-Datetime and X-JWS-Signature.
X-JWS-Signature is built as in «Signature», with your API user ID and secret key; uri is the path of your state_callback URL.
Check the signature before you process the notification: verify_jws / verifyJws from «Signature», with the raw request body.Answer with HTTP 2xx within 30 seconds.
Otherwise the notification is sent again: up to 3 attempts, 30 seconds apart.
The same notification can arrive more than once: process it by id and status. If in doubt, check the status with Get invoice status.