Start here
Quickstart
Take one order from creation to payment.
Put your dashboard credentials in your server’s environment:
FANAK_API_KEY=pk_your_api_keyFANAK_ACCESS_TOKEN=your_access_tokenFANAK_WEBHOOK_SECRET=whsec_your_webhook_secret-
Create a payment intent
Section titled “Create a payment intent”Amounts are in minor units:
5000is 5.000 LYD.Terminal window curl https://pay.fanak.ly/api/v1/payment-intents \-H "X-API-Key: $FANAK_API_KEY" \-H "Authorization: Bearer $FANAK_ACCESS_TOKEN" \-H "Accept: application/json" \-H "Content-Type: application/json" \-d '{"merchant_reference": "order-1042","amount": 5000,"currency": "LYD","description": "Order #1042","return_url": "https://shop.example.com/orders/1042/return"}'use Illuminate\Support\Facades\Http;$intent = Http::withHeaders(['X-API-Key' => config('services.fanak.api_key')])->withToken(config('services.fanak.access_token'))->acceptJson()->post('https://pay.fanak.ly/api/v1/payment-intents', ['merchant_reference' => 'order-1042','amount' => 5000,'currency' => 'LYD','description' => 'Order #1042','return_url' => 'https://shop.example.com/orders/1042/return',])->throw()->json('data');const response = await fetch('https://pay.fanak.ly/api/v1/payment-intents', {method: 'POST',headers: {'X-API-Key': process.env.FANAK_API_KEY,Authorization: `Bearer ${process.env.FANAK_ACCESS_TOKEN}`,Accept: 'application/json','Content-Type': 'application/json',},body: JSON.stringify({merchant_reference: 'order-1042',amount: 5000,currency: 'LYD',description: 'Order #1042',return_url: 'https://shop.example.com/orders/1042/return',}),});if (!response.ok) {throw new Error(`Fanak answered ${response.status}: ${await response.text()}`);}const { data: intent } = await response.json();Response,
201 Created:{"data": {"uuid": "4d893346-bd5e-482f-8347-3f509a877f1a","reference": "c5pk2mfgmv167awg","merchant_reference": "order-1042","amount": 5000,"currency": "LYD","status": "requires_payment_method","description": "Order #1042","customer": { "external_id": null },"return_url": "https://shop.example.com/orders/1042/return","metadata": null,"expires_at": "2026-10-10T16:19:07+00:00","checkout_url": "https://pay.fanak.ly/payment-intents/4d893346-bd5e-482f-8347-3f509a877f1a/checkout","created_at": "2026-10-09T16:19:07+00:00","updated_at": "2026-10-09T16:19:07+00:00"}}Save
data.uuid. On a timeout, resend with the samemerchant_reference(Idempotency). -
Send the customer to the checkout
Section titled “Send the customer to the checkout”Redirect to
data.checkout_urlas is. Add?lang=enfor English.return redirect()->away($intent['checkout_url']);// In your HTTP handler (`res` is a node:http ServerResponse):res.writeHead(303, { Location: intent.checkout_url }).end(); -
Check the result when the customer returns
Section titled “Check the result when the customer returns”Nothing is added to
return_url, so put your order ID in it. Re-fetch the intent there.Terminal window curl https://pay.fanak.ly/api/v1/payment-intents/4d893346-bd5e-482f-8347-3f509a877f1a \-H "X-API-Key: $FANAK_API_KEY" \-H "Authorization: Bearer $FANAK_ACCESS_TOKEN" \-H "Accept: application/json"use Illuminate\Support\Facades\Http;$intent = Http::withHeaders(['X-API-Key' => config('services.fanak.api_key')])->withToken(config('services.fanak.access_token'))->acceptJson()->get("https://pay.fanak.ly/api/v1/payment-intents/{$order->payment_intent_uuid}")->throw()->json('data');$paid = $intent['status'] === 'succeeded';const response = await fetch(`https://pay.fanak.ly/api/v1/payment-intents/${order.paymentIntentUuid}`, {headers: {'X-API-Key': process.env.FANAK_API_KEY,Authorization: `Bearer ${process.env.FANAK_ACCESS_TOKEN}`,Accept: 'application/json',},});if (!response.ok) {throw new Error(`Fanak answered ${response.status}: ${await response.text()}`);}const { data: intent } = await response.json();const paid = intent.status === 'succeeded';processingis not a failure: say the payment is being confirmed. -
Receive the webhook
Section titled “Receive the webhook”The customer may never return; the webhook still arrives. Set it up in Webhooks.