Naafi Pay

Code Examples

Ready-to-paste examples for the four endpoints you will use most often: Create Payment, Verify Payment, List Payments, and Create Payment Link. Each block reads the API key from an environment variable and handles the response, with tabs for PHP, Node.js, Python, and cURL. Pick the tab for your runtime, copy the snippet, and adapt the field values to your application. Webhook verification examples live on the Webhooks page.

TipOne API key per environment
Set NAAFIPAY_KEY in your environment variables. Use the test key (pg_test_…) locally and in CI, and the live key (pg_live_…) in production. Never commit either to version control.

Create Payment

Creates a payment record for a fixed amount. Store the returned id andreference_id so you can poll the payment status or receive it via webhook.

cURL
1curl -X POST https://naafipay.com/api/public/v1/payments \
2 -H "Authorization: Bearer pg_live_xxx" \
3 -H "Content-Type: application/json" \
4 -d '{
5 "amount": 1500,
6 "currency": "BDT",
7 "customer_name": "Tasin Fahim",
8 "customer_email": "tasin@example.com",
9 "customer_phone": "01700000000",
10 "reference_id": "ORD-1001",
11 "metadata": { "order_id": "ORD-1001" }
12 }'

Verify Payment

Confirms a payment in your success_url handler before delivering the product. Pass the invoice_id NaafiPay appended as a query parameter, and only fulfil the order when the response status is COMPLETED.

cURL
1curl -X POST https://naafipay.com/api/public/v1/verify-payment \
2 -H "Authorization: Bearer pg_live_xxx" \
3 -H "Content-Type: application/json" \
4 -d '{ "invoice_id": "udp_01HZX..." }'

List Payments

Pulls a paginated, filterable list of payments for the storefront. Useful for building custom dashboards and reconciliation jobs.

cURL
1curl "https://naafipay.com/api/public/v1/payments?status=completed&limit=50" \
2 -H "Authorization: Bearer pg_live_xxx"

Create Payment Link

Creates a reusable, shareable checkout link for a product or plan. The response includes acheckout_url you can redirect the customer to.

cURL
1curl -X POST https://naafipay.com/api/public/v1/payment-links \
2 -H "Authorization: Bearer pg_live_xxx" \
3 -H "Content-Type: application/json" \
4 -d '{
5 "name": "Pro Plan — Monthly",
6 "amount": 999,
7 "currency": "BDT",
8 "description": "Access to all Pro features for 30 days"
9 }'
Updated at: May 30, 2026