Get the keys
Do this before any code calls the API. The website does not call the merchant portal. Staff use the portal to create the terminal and to read the keys.
Log in
| Environment | Merchant Portal | API Origin |
|---|---|---|
| UAT (Sandbox) | https://bptest2.qp.com.kw | https://mpostest2.qp.com.kw or https://botest2.qp.com.kw |
| Production | https://bpl2.kwikpay.com.kw | https://mposl2.kwikpay.com.kw |
Create an ecommerce terminal
Create a terminal of type ECOMMERCE for the outlet. It must be ACTIVE and bound to that outlet and its point of sale. Enable each method the shop will offer.
| Enable on terminal | Needed for |
|---|---|
| KNET | Direct KNET, and KNET on the Kwik Pay checkout page. Local debit cards. |
| Visa / Mastercard | Direct card payment, and the card choice on the checkout page. Local and international debit and credit cards. |
| Apple Pay | Apple Pay on the Kwik Pay checkout page. |
| Kwik Pay wallet | The wallet on the Kwik Pay checkout page. |
A method that is not enabled is not offered. A direct payment for a disabled method is rejected.
Copy the keys once
On create or rotate, the terminal shows the client id, client secret, and webhook secret once. Copy them onto the server at that moment. They cannot be read again later. Ask the Kwik Pay contact person for the tenant id. Two ecommerce terminals do not share a client id or secret. The tenant id is the same for the same merchant.
| Server value | Meaning |
|---|---|
| KWIKPAY_API_BASE | API origin only, from the environments table above. |
| KWIKPAY_CLIENT_ID | From the ecommerce terminal. |
| KWIKPAY_CLIENT_SECRET | From the ecommerce terminal. Server only. Never put in client apps. |
| KWIKPAY_TENANT_ID | From the Kwik Pay contact person. |
| KWIKPAY_WEBHOOK_SECRET | Shown once as webhookSecret. Required before Kwik Pay will POST a signed callback. |
| PUBLIC_BASE_URL | Public https origin of the shop, when Kwik Pay must call a server that is not the address opened in the browser. |
Important configuration rule
Restart the server after these values change. The process reads them at startup. If the terminal has an allowed-domain list, the token request must send Origin for a host on that list. Send that header on the token call only.
What the server does for every payment
Confirm Cart
Browser sends cart to your server.
Create Payment
Server requests token & stores paymentId.
Open Pay Page
Browser opens Kwik Pay checkout URL.
Shopper Pays
Bank communicates with Kwik Pay.
Return & Callback
Shopper returns; mark order paid once.
Access token
Obtain a Bearer token using your client credentials:
curl -X POST "https://mpostest2.qp.com.kw/api/v1/external/auth/token" \
-H "Content-Type: application/json" \
-H "Origin: https://shop.example" \
-d '{
"grantType": "client_credentials",
"clientId": "gw_your_client_id",
"clientSecret": "your_client_secret",
"tenantId": "your_tenant_id"
}'Use data.accessToken as Authorization: Bearer {accessToken} on payment, inquiry, and refund. Reuse it until shortly before expiresInSeconds. Never log this request body.
Create the payment
Send the payment creation request from your server:
curl -X POST "https://mpostest2.qp.com.kw/api/v1/external/channel/ecommerce/payments" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"amount": 1.5,
"currencyCode": "KWD",
"merchantRef": "ORD-100245",
"redirectUrl": "https://shop.example/checkout/return?merchantRef=ORD-100245",
"callbackUrl": "https://shop.example/api/kwikpay/callback",
"udf1": "board:1",
"paymentMethodCode": "VISA"
}'| Field | Rule |
|---|---|
| amount | Greater than 0, in dinars. 1.500 is 1.500 KWD. |
| currencyCode | KWD |
| merchantRef | Your order id, 1–80 characters. One id per attempt. A repeat returns 409, so a retry uses a new id. |
| redirectUrl | Put merchantRef on this URL when creating the payment. Kwik Pay adds result and paymentId with &. |
| callbackUrl | Where Kwik Pay POSTs signed callback. It must be reachable from Kwik Pay (public https address). |
| paymentMethodCode | Omit it for Kwik Pay checkout. KNET for direct KNET. VISA for combined Visa / Mastercard. Never send CYBERSOURCE. |
| udf1 – udf5 | Optional shop text, max 120 characters each. Returned back on the redirect URL. |
Store data.paymentId with the order before the redirect. data.paymentUrl is where the browser goes. Keep that URL even when its host is not the API host. A CyberSource link can come back on a bank host. A missing paymentUrl on KNET or card is an error.
The three checkout choices
Choice A: Kwik Pay Checkout
Leave paymentMethodCode out. Kwik Pay returns one link, data.paymentUrl, on {API}/pay/ecom/{token}. Send the browser straight to that link.
On that page the shopper picks a method that is enabled for the merchant: KNET, Visa / Mastercard, Apple Pay, or the Kwik Pay wallet. The website does not send a method code for this flow. The checkout token lasts about 10 minutes, then it becomes EXPIRED.
Choice B: Direct KNET
Send "paymentMethodCode": "KNET". The browser goes straight to the KNET payment gateway. There is no intermediate method chooser. Direct KNET accepts local debit cards only, and KNET must be enabled on the terminal.
Choice C: Direct Visa / Mastercard
This is one combined choice in the shop for both brands. Send "paymentMethodCode": "VISA". The browser goes straight to the card page. It accepts local and international debit and credit cards after Visa / Mastercard is enabled on the terminal.
Note: CYBERSOURCE is the underlying gateway Kwik Pay selects. It is not a method code you send.
Terminal priority conflict
If create payment returns BR-PAY-HOSTED-SEL-002, Visa and Mastercard are enabled but two card terminals share the same priority. Kwik Pay support will set a distinct priority before the direct card page can open.
How a payment becomes paid
Create the return URL with the order number already on it:
https://shop.example/checkout/return?merchantRef=ORD-100245After the shopper pays, Kwik Pay opens that page and appends the result parameters:
https://shop.example/checkout/return?merchantRef=ORD-100245&result=CAPTURED&paymentId={uuid}&udf1=board:1Mark the order paid when all three are true:
resultis CAPTUREDmerchantRefis an order this shop createdpaymentIdequals the id stored on that order
Inquiry can still say PROCESSING. For this matched payment, CAPTURED is paid. Do this once. A later inquiry must not un-pay the order.
Signed callback
Kwik Pay POSTs callbackUrl once, after it records the result. A missed callback does not change the payment; the return URL and inquiry still work. Without webhookSecret on the terminal, Kwik Pay does not POST at all. Use a public https address in PUBLIC_BASE_URL.
| Header | Meaning & Verification |
|---|---|
| X-KwikPay-Timestamp | Unix seconds when Kwik Pay signed the body. Reject it when it is more than 300 seconds from now. |
| X-KwikPay-Signature | v1= plus the hex HMAC-SHA256 of {timestamp}.{raw body}, using webhookSecret. |
Verify webhook signature (HMAC-SHA256)
Verify the signature using your webhookSecret and reject expired requests (>300s):
# Testing Webhook locally with HMAC-SHA256:
TIMESTAMP=$(date +%s)
SECRET="your_webhook_secret"
BODY='{"paymentId":"...","result":"CAPTURED","merchantRef":"ORD-100245"}'
SIG="v1=$(echo -n "$TIMESTAMP.$BODY" | openssl dgst -sha256 -hmac "$SECRET" | sed 's/^.* //')"
curl -X POST "http://localhost:3000/api/kwikpay/callback" \
-H "Content-Type: application/json" \
-H "X-KwikPay-Timestamp: $TIMESTAMP" \
-H "X-KwikPay-Signature: $SIG" \
-d "$BODY"Inquiry API
Use the same Bearer token to query the payment status:
curl -X GET "https://mpostest2.qp.com.kw/api/v1/external/channel/ecommerce/payments/3fa85f64-5717-4562-b3fc-2c963f66afa6" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN"| Evidence | Order Status |
|---|---|
Inquiry COMPLETED, and the amount and KWD match | Paid |
Inquiry COMPLETED, but amount or currency differs | Hold for review. Do not ship |
KNET, Visa / Mastercard, or checkout returned CAPTURED for stored paymentId | Paid, even while inquiry is PROCESSING |
result=FAILED, or inquiry FAILED / EXPIRED | Not paid |
INITIATED, or PROCESSING with no matching CAPTURED | Still waiting |
Inquiry REVERSED | Refunded |
Refund
Full refund only. Use the same Bearer token. Send reason as "REVERSE" for a shop refund. "CHARGEBACK" is the other accepted value. Any other reason is rejected.
curl -X POST "https://mpostest2.qp.com.kw/api/v1/external/channel/ecommerce/payments/3fa85f64-5717-4562-b3fc-2c963f66afa6/refund" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"reason": "REVERSE"
}'Refund only after inquiry is COMPLETED. Omit amount for the full remaining balance. The payment then becomes REVERSED. Confirm with inquiry.
Test it
Use the UAT API and UAT portal. Production keys do not belong in this test.
UAT Test Cards
These are sandbox cards for the UAT bank pages. They are not production cards:
| Method | Card Details | What to expect |
|---|---|---|
| KNET | Bank: KNET Test Card [KNET1] Number: 8888880000000001 Expiry: 09/30 · PIN: 1234 | CAPTURED. A different expiry (such as 05/21) is not captured. |
| Visa | Number: 4508750015741019 Expiry: 01/39 · CVV: 100 | Use this on the direct Visa / Mastercard page. |
| Mastercard | Number: 5123450000000008 Expiry: 01/39 · CVV: 100 | Use this on the direct Visa / Mastercard page. |
Apple Pay and the Kwik Pay wallet do not use these card numbers. The callback will not arrive on localhost. The browser return is enough to mark a matched CAPTURED payment as paid during a local test.
Checklist before go-live
Complete these 8 steps in order before switching from UAT to the live production gateway:
Activate Production ECOMMERCE Terminal
Log in to the Production Merchant Portal (https://bpl2.kwikpay.com.kw) and verify your terminal type is ECOMMERCE and status is ACTIVE. Confirm it is bound to the correct outlet and point of sale.
💡 Note: Do not use UAT terminals or credentials on live production domains.
Enable Required Payment Methods
Confirm that KNET, Visa / Mastercard, Apple Pay, and the Kwik Pay wallet are enabled on the terminal for the payment options you plan to offer shoppers.
💡 Note: A method that is not enabled in the portal will be rejected if called directly.
Store Secrets on Server Only
Keep KWIKPAY_CLIENT_SECRET, KWIKPAY_WEBHOOK_SECRET, and the OAuth Bearer token strictly in your server environment variables. They must never be exposed to browsers or client apps.
KWIKPAY_CLIENT_SECRET · KWIKPAY_WEBHOOK_SECRETConfigure Public HTTPS Webhook Endpoint
Ensure callbackUrl is a publicly reachable https:// URL. The webhook handler must verify the HMAC-SHA256 signature in X-KwikPay-Signature and reject any callback older than 300 seconds.
💡 Note: Signature verification: v1= + hex(HMAC-SHA256('{timestamp}.{raw_body}', webhookSecret))
Generate Unique merchantRef per Attempt
Every payment attempt must have its own unique merchantRef (1–80 characters). Ensure merchantRef is already appended to redirectUrl so the order context returns with the customer from the bank.
💡 Note: Example: https://shop.example/checkout/return?merchantRef=ORD-100245
Store paymentId Before Redirecting Customer
Save data.paymentId to your database order record before redirecting the shopper's browser to data.paymentUrl. This guarantees you can match the payment even if the shopper closes the tab.
Mark Order Paid on Matched CAPTURED Result
Mark an order as PAID only when: (1) result is CAPTURED, (2) merchantRef matches a local order, and (3) paymentId equals the recorded ID (or Inquiry API returns COMPLETED with the identical KWD amount).
💡 Note: Do not fulfill or ship if amounts or currencies do not match.
Confirm Refund & Reversal Handling
Ensure shop refund operations send {"reason":"REVERSE"} only after Inquiry is COMPLETED, and confirm that Inquiry updates to REVERSED in your database.
POST /refund -> { "reason": "REVERSE" }If a test fails
Common errors and how to resolve them:
| What you see | What to change |
|---|---|
| 401 on the token | Client id, client secret, or tenant id does not match this terminal. Restart after fixing the environment. |
| 403 on the token | The terminal is not an active ecommerce device, the shop origin is not allowlisted, or the HTTP client sent a custom User-Agent. Call without a custom User-Agent and send Origin. |
| 409 on create | merchantRef was already used. Start a new order id. |
| BR-PAY-HOSTED-SEL-002 | Two card terminals share priority 100. Kwik Pay must set a distinct priority. |
| Return page has no order number | The create call did not put merchantRef on redirectUrl. Create a new payment. An older payment still has the old link. |
Return says CAPTURED but order stays pending | paymentId on the link does not match the id stored for that order. |
| No callback arrives | webhookSecret is missing, or callbackUrl is localhost. The browser return can still mark the order paid. |
| Refund says reason must be REVERSE or CHARGEBACK | Send {"reason":"REVERSE"}. Do not send a free-text reason. |
| Create payment times out | Allow at least 90 seconds. A 20 second client timeout can expire while UAT is still working. |
AI Integration (.md)
Use this ready-to-prompt Markdown specification with AI coding assistants (Cursor, Claude Code, ChatGPT, GitHub Copilot) to generate your integration code instantly:
Integrate with Any AI in Minutes
Download or copy the complete single-file Markdown specification (.md). Provide it to your AI coding assistant to automatically generate end-to-end integration code in your preferred framework.
Drop the file into your project or reference it via @kwikpay-integration.md in chat to generate routes.
Add the .md file to your Project Knowledge base for accurate backend handler implementation.
Paste the markdown prompt into your AI conversation to generate customized controllers, models, and webhooks.

