Dafa

API integration guide

One API for every Libyan payment method, in two calls: initiate the payment, then confirm it. The full reference, no sign-in needed.

Introduction

One API for every Libyan payment method, in two calls:

  1. POST /payments/initiate starts the payment.
  2. POST /payments/{id}/confirm confirms it with the OTP, when the method requires one.

A third, read-only call, GET /payments/{id}, returns the transaction's status at any time.

Every example runs against the test environment with a dafa_test_… key; nothing there moves money.

Authentication

Send your key (top of this page) in a header on every request:

X-API-Key: <your-key>

The key prefix sets its environment: dafa_test_ creates simulated transactions, dafa_live_ real ones. A key never reads or confirms the other environment's transactions.

You need an API key to run requests. Yours is created in a minute with your phone number.

Get an API key

Step 1: Initiate the payment

POSThttps://dev.dafa.ly/api/v1/payments/initiate

Format: application/json, application/x-www-form-urlencoded or multipart/form-data, with the same fields in all three.

providerrequired
Method identifier, from the providers table
amountrequired
Amount in Libyan Dinar
user_identifierPer method
Customer phone or card number; every method except bank cards
birthyearSadad only
Customer's birth year
callback_urlOptional
Your URL, notified when the payment completes
return_urlOptional, bank cards only
Where the checkout page's "Continue" button takes the customer after a successful payment: an https:// address or an app link (myapp://…). Without it the page shows no button

Example: bank cards

The simplest to try: no user_identifier and no confirm step.

POST /api/v1/payments/initiate HTTP/1.1
X-API-Key: <your-key>

provider=moamalat
amount=50

Successful response:

{
  "id": "b7e1c9a0-1234-4a5b-9c8d-abcdef123456",
  "amount": 50.000,
  "amount_str": "50.000",
  "is_paid": false,
  "payment_page_url": "https://localbankcards.dafa.ly/b7e1c9a0-…",
  "callback_url": null,
  "created_at": "2026-07-18T10:00:00Z",
  "payment_method_details": { "id": "7b992f96-…", "name": { "ar": "البطاقات المصرفية", "en": "Local Cards" } },
  "gateway": { "id": "895d5537-…", "name": "البطاقات المصرفية" },
  "workspace": { "id": "3f0c6a2e-…", "name": "My store", "is_test": true }
}

Redirect the customer to payment_page_url to enter their card details on a secure page. Once they pay there, the transaction confirms automatically.

If you sent return_url, the success screen shows a "Continue" button that takes the customer to it, unchanged. Reaching that address does not prove payment: check the transaction's status before you deliver.

Response fields

idstring (UUID)
Transaction id; needed to confirm and to check status
amountnumber
Amount with three decimal places
amount_strstring
The same amount as text, for display without losing decimals
is_paidboolean
true once the money has actually been received
payment_page_urlstring or null
Checkout page; bank cards only
callback_urlstring or null
What you sent in the request
return_urlstring
What you sent in the request; absent if you sent none
created_atstring (date)
Creation time, UTC
payment_method_detailsobject
Payment method: id and name in Arabic and English
gatewayobject
Channel the transaction went through: id and name
workspaceobject
Your organization: id, name and is_test

Methods that send an OTP

Sadad, Edfali, MobiCash and the other methods text the customer an OTP and need user_identifier (Sadad also needs birthyear):

POST /api/v1/payments/initiate HTTP/1.1
X-API-Key: <your-key>

provider=edfali
amount=25.5
user_identifier=912345678

Same response shape with "payment_page_url": null. Keep the id for the next step.

Step 2: Confirm the payment

Only for methods that send an OTP. Ask the customer for the code and send it:

POSThttps://dev.dafa.ly/api/v1/payments/{id}/confirm
otprequired
The code the customer received
POST /api/v1/payments/b7e1c9a0-1234-4a5b-9c8d-abcdef123456/confirm HTTP/1.1
X-API-Key: <your-key>

otp=111111

Successful response, same fields; is_paid: true means the money reached your wallet:

{
  "id": "b7e1c9a0-1234-4a5b-9c8d-abcdef123456",
  "amount": 25.500,
  "amount_str": "25.500",
  "is_paid": true,
  "payment_page_url": null,
  "callback_url": null,
  "created_at": "2026-07-18T10:00:00Z",
  "payment_method_details": { "id": "a1d2f3e4-…", "name": { "ar": "إدفعلي", "en": "Edfali" } },
  "gateway": { "id": "c4b5a6d7-…", "name": "إدفعلي" },
  "workspace": { "id": "3f0c6a2e-…", "name": "My store", "is_test": true }
}

Checking payment status

This call is the source of truth for any transaction: whether it was paid, and for how much.

GEThttps://dev.dafa.ly/api/v1/payments/{id}

{id} is the transaction id from the initiate response. The call takes no fields:

GET /api/v1/payments/b7e1c9a0-1234-4a5b-9c8d-abcdef123456 HTTP/1.1
X-API-Key: <your-key>

The response has the same fields as the initiate response:

{
  "id": "b7e1c9a0-1234-4a5b-9c8d-abcdef123456",
  "amount": 50.000,
  "amount_str": "50.000",
  "is_paid": true,
  "payment_page_url": "https://localbankcards.dafa.ly/b7e1c9a0-…",
  "callback_url": "https://example.com/dafa/webhook",
  "created_at": "2026-07-18T10:00:00Z",
  "payment_method_details": { "id": "7b992f96-…", "name": { "ar": "البطاقات المصرفية", "en": "Local Cards" } },
  "gateway": { "id": "895d5537-…", "name": "البطاقات المصرفية" },
  "workspace": { "id": "3f0c6a2e-…", "name": "My store", "is_test": true }
}

Before you fulfil an order, check that is_paid is true and that amount is your order's. is_paid: false means the money has not been received yet.

Use a key from the environment the transaction was initiated in; a transaction from the other environment answers 404.

Test environment

Every method is available with no setup, and you control the outcome:

A successful payment
OTP 111111
A payment declined by the bank
OTP 222222
A wrong-OTP error
any other OTP
  • Any correctly formatted phone number is accepted.
  • Bank cards (moamalat) open a test checkout page: card 6394984349023404, expiry 11/28, OTP 111111. Closing the page leaves the transaction unconfirmed.
  • Every response carries "workspace": { "is_test": true }.
  • A declined payment answers 400 with data.code (for example PAYER_INSUFFICIENT_FUNDS), exactly like live.

Try it in two minutes

  1. POST /payments/initiate with provider=sadad, amount=10, user_identifier=912345678, birthyear=1995.
  2. POST /payments/{id}/confirm with otp=111111 → is_paid: true.
  3. Repeat step 1, then confirm with otp=222222 → 400 with data.code.
  4. Pass a callback_url, watch for the webhook, then call GET /payments/{id} → is_paid: true.

Automatic notifications (Webhook)

If you pass callback_url when initiating, we POST to your URL as soon as the transaction completes, as JSON:

{ "transaction_id": "b7e1c9a0-1234-4a5b-9c8d-abcdef123456", "is_confirmed": true }

Answer 200 within 15 seconds. Without a 200 we send it again after about 30 seconds, then after about two minutes, then stop.

The webhook is a notice that the transaction has an update, not its status. When it arrives, take transaction_id and fetch the transaction to learn its status:

GEThttps://dev.dafa.ly/api/v1/payments/{id}

Fulfil the order only after this call returns is_paid: true for your order's amount (see Checking payment status). The webhook is not signed, so its body alone proves nothing.

A webhook can arrive more than once for the same transaction, so make fulfilment idempotent.

Every webhook carries the header X-Dafa-Environment: test or live; a test webhook never reports a real payment.

Providers table

sadadSadad
Customer phone + birthyear
edfaliEdfali
Customer phone
mobicashMobiCash
Card number
moamalatBank cards
Not sent; the customer enters details on the checkout page
yussor-payYussor Pay
Card number
masrafi-payMasrafi Pay
Card number
sahara-paySahara Pay
Card number