Naafi Pay

Using Claude with NaafiPay

Claude is an AI assistant from Anthropic that is particularly good at reading long documents, following precise instructions, and writing production-quality code. When you give Claude your NaafiPay API documentation as context, it can generate complete, working integrations on the first try — including the small details like idempotency keys, webhook verification, and error handling that ad-hoc AI prompts usually skip. This page explains how to feed Claude the right context and gives you four ready-to-paste prompt templates for the most common integration tasks.

Why context matters

Without context, an AI assistant has to guess what your payment API looks like. That usually produces code that uses Stripe field names, the wrong authentication header, or a non-existent endpoint. By pasting the relevant docs page into your conversation before asking for code, you remove the guesswork — Claude works from the same spec you do and produces code that matches the real API on the first try.

Setting up the conversation

Open a new Claude conversation, paste the full text of the API page you care about (for example, the Verify Payment page), then ask your question. If you are integrating end-to-end, paste the API Overview page, the Create Checkout page, the Verify Payment page, and the Webhooks page — Claude can hold all four in context at once.

TipUse the Projects feature
If you have a Claude Pro account, create a Project and add the NaafiPay docs as Project files. Every new chat in that Project automatically has the docs in context, so you do not have to paste them every time.

Prompt template 1 — Create a checkout

Claude Prompt
1Here is the NaafiPay Create Checkout endpoint:
2[paste the full Create Checkout page]
3
4Using my Node.js + TypeScript Express backend, write a POST /checkout route that:
5- Accepts { orderId, amount, customerName, customerEmail } from the request body
6- Calls NaafiPay /api/public/v1/payments with the API key from process.env.NAAFIPAY_KEY
7- Returns the checkout_url to the client as JSON
8- Includes full error handling and TypeScript types
9- Does not use any npm package other than the built-in fetch
10
11Show the complete file, including imports.

Prompt template 2 — Verify payment

Claude Prompt
1Here is the NaafiPay Verify Payment endpoint:
2[paste the full Verify Payment page]
3
4I have a Next.js App Router success page at app/thank-you/page.tsx that receives
5?invoice_id as a search param. Write the server component that:
6- Calls /api/public/v1/verify-payment server-side with the invoice_id
7- Renders a success UI if status is "completed"
8- Renders a "payment not yet confirmed" UI for "pending"
9- Renders an error UI for "failed" or "cancelled"
10- Never imports the API key into a client component
11
12Provide the complete page.tsx.

Prompt template 3 — Handle webhooks

Claude Prompt
1Here is the NaafiPay Webhooks page:
2[paste the full Webhooks page]
3
4Write a Python Flask route that:
5- Accepts POST /webhooks/naafipay
6- Verifies the x-paygate-signature-v2 HMAC and the 5-minute replay window
7- For event "payment.completed", marks the order with metadata.order_id as paid
8 in a Postgres database (use the orders table with columns id, status, paid_at)
9- Returns 200 for handled events and 401 for invalid signatures
10- Uses psycopg2 and reads the signing secret from env NAAFIPAY_WEBHOOK_SECRET
11
12Provide the complete file.

Prompt template 4 — Full payment flow

Claude Prompt
1Here are the NaafiPay docs:
2[paste API Overview, Create Checkout, Verify Payment, Webhooks pages]
3
4I run a Bangladeshi digital course platform. Write a complete payment flow in
5PHP (Laravel 11) that:
61. Has a buy button that POSTs to /buy/{course} and redirects to the NaafiPay
7 checkout_url
82. Has a /payment/success route that verifies the payment and grants course
9 access only if completed
103. Has a /webhooks/naafipay route that revokes access on payment.cancelled and
11 grants access on payment.completed (idempotently)
124. Uses Laravel's HTTP client and the User and Course Eloquent models
13
14Show migrations, routes, controllers, and the env variables I need.
WarningReview every line
Claude is excellent but not infallible. Always read the generated code, run it against test mode, and verify the webhook signature logic before going live.
Updated at: May 30, 2026