Skip to content
FanakDocs
WebsiteDashboard

API reference

Create a payment intent

POST
/payment-intents
curl --request POST \
--url https://pay.fanak.ly/api/v1/payment-intents \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--header 'X-API-Key: <X-API-Key>' \
--data '{ "merchant_reference": "order-1042", "amount": 5000, "currency": "LYD", "customer": { "external_id": "cust_981" }, "description": "Order #1042", "return_url": "https://shop.example.com/orders/1042/return", "metadata": { "order_id": "1042" }, "expires_at": "2026-10-10T18:00:00+02:00" }'

Creates an intent in requires_payment_method and returns its checkout_url. Redirect the customer there to pay.

merchant_reference is the idempotency key. Creating an intent again with a reference this application already used returns the existing intent with 200, unchanged and whatever its state, instead of a new one with 201. The other fields of the repeated request are ignored, so compare the returned amount with your order. A repeated request must still pass validation.

Media typeapplication/json
StorePaymentIntent
object
merchant_reference
required

Your own unique reference for this payment, such as an order number. It is the idempotency key: creating an intent again with a reference this application already used returns the existing intent unchanged (200) instead of creating a new one (201).

string
<= 255 characters
amount
required

The amount in the currency’s minor unit, as an integer. LYD has 3 decimal places, so 5000 is 5.000 LYD. The minimum is 1000 (1.000 LYD), the maximum 1000000000 (1,000,000.000 LYD).

integer
>= 1000 <= 1000000000
currency
required

ISO 4217 currency code. Currently LYD.

string
>= 3 characters <= 3 characters
customer
object
external_id

Your identifier for the customer, echoed back as customer.external_id.

string | null
<= 255 characters
description
required

What the customer is paying for. Shown on the hosted checkout.

string
<= 255 characters
return_url

Where the hosted checkout sends the customer back after paying (and offers a link back from an expired checkout). Nothing is appended to it: include your own order identifier in the URL.

string | null format: uri
<= 2048 characters
metadata

Up to you: key-value pairs stored with the intent and returned as-is. At most 20 keys of up to 40 characters; values must be strings of up to 255 characters.

object | null
expires_at

When the checkout stops taking payments (ISO 8601). It must be more than 5 minutes and less than 31 days ahead; without it the intent expires 24 hours after creation. The window is checked only when an intent is created, so a retried create still returns the existing intent.

string | null format: date-time

An intent with this merchant_reference already existed; it is returned unchanged.

Media typeapplication/json
object
data
required
PaymentIntentResource
object
uuid
required

The intent’s ID. Store it with your order: you need it to retrieve the intent.

string format: uuid
reference
required

A short Fanak reference, shown to the customer on the checkout receipt (in capitals).

string | null
merchant_reference
required

The merchant_reference you created the intent with.

string | null
amount
required

The amount in the currency’s minor unit (5000 = 5.000 LYD).

integer
currency
required

ISO 4217 currency code

string
status
required

The intent’s state. requires_payment_method: waiting for the customer to pay (or to try again after a failed attempt). processing: a payment attempt is under way. succeeded: paid; final. canceled: expired unpaid; a verified late payment can still move it to succeeded. Fulfil the order on succeeded only.

string
Allowed values: requires_payment_method processing succeeded canceled
description
required

What the customer is paying for.

string | null
customer
required
object
external_id
required

Your identifier for the customer, if you sent one.

string | null
return_url
required

Where the hosted checkout sends the customer back, if you set one.

string | null
metadata
required

The key-value pairs you sent, returned as-is.

object | null
expires_at
required

When the checkout stops taking payments (ISO 8601).

string | null format: date-time
checkout_url
required

The hosted checkout page. Redirect the customer here to pay; append ?lang=en for English (Arabic is the default).

string format: uri
created_at
required
string | null format: date-time
updated_at
required
string | null format: date-time

Example

{
"data": {
"reference": "c5pk2mfgmv167awg",
"currency": "LYD",
"status": "requires_payment_method"
}
}

The intent was created.

Media typeapplication/json
object
data
required
PaymentIntentResource
object
uuid
required

The intent’s ID. Store it with your order: you need it to retrieve the intent.

string format: uuid
reference
required

A short Fanak reference, shown to the customer on the checkout receipt (in capitals).

string | null
merchant_reference
required

The merchant_reference you created the intent with.

string | null
amount
required

The amount in the currency’s minor unit (5000 = 5.000 LYD).

integer
currency
required

ISO 4217 currency code

string
status
required

The intent’s state. requires_payment_method: waiting for the customer to pay (or to try again after a failed attempt). processing: a payment attempt is under way. succeeded: paid; final. canceled: expired unpaid; a verified late payment can still move it to succeeded. Fulfil the order on succeeded only.

string
Allowed values: requires_payment_method processing succeeded canceled
description
required

What the customer is paying for.

string | null
customer
required
object
external_id
required

Your identifier for the customer, if you sent one.

string | null
return_url
required

Where the hosted checkout sends the customer back, if you set one.

string | null
metadata
required

The key-value pairs you sent, returned as-is.

object | null
expires_at
required

When the checkout stops taking payments (ISO 8601).

string | null format: date-time
checkout_url
required

The hosted checkout page. Redirect the customer here to pay; append ?lang=en for English (Arabic is the default).

string format: uri
created_at
required
string | null format: date-time
updated_at
required
string | null format: date-time

Example

{
"data": {
"reference": "c5pk2mfgmv167awg",
"currency": "LYD",
"status": "requires_payment_method"
}
}

Missing or invalid credentials. A missing or invalid access token returns message; a missing or unknown API key returns error.

Media typeapplication/json
Any of:
object
message
required
string

Example generated

{
"message": "example"
}

An error

Media typeapplication/json
object
message
required

Error overview.

string

Example

{
"message": "Conflict creating payment intent."
}

Validation error

Media typeapplication/json
object
message
required

Errors overview.

string
errors
required

A detailed description of each field that failed validation.

object
key
additional properties
Array<string>

Example generated

{
"message": "example",
"errors": {
"additionalProperty": [
"example"
]
}
}