Ecommerce Integration·Currency KWD·Secrets stay on the server
Developer Documentation

Connect a website to Kwik Pay

The website server creates every payment. The shopper’s browser opens the pay page. The bank talks to Kwik Pay, and Kwik Pay sends the shopper back to the website. The client secret, webhook secret, and access token never go in the browser.

Currency:KWD (Kuwaiti Dinar)
Type:Server-to-Server REST API
Auth:OAuth2 Bearer Token
Webhook:HMAC-SHA256 Signed
Methods:KNET · Visa/MC · Apple Pay

Build faster with AI (Cursor, Claude, ChatGPT, Copilot)

Download the complete single-file specification (.md) to generate routes and webhook handlers in any language.

1

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

EnvironmentMerchant PortalAPI Origin
UAT (Sandbox)https://bptest2.qp.com.kwhttps://mpostest2.qp.com.kw or https://botest2.qp.com.kw
Productionhttps://bpl2.kwikpay.com.kwhttps://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 terminalNeeded for
KNETDirect KNET, and KNET on the Kwik Pay checkout page. Local debit cards.
Visa / MastercardDirect card payment, and the card choice on the checkout page. Local and international debit and credit cards.
Apple PayApple Pay on the Kwik Pay checkout page.
Kwik Pay walletThe 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 valueMeaning
KWIKPAY_API_BASEAPI origin only, from the environments table above.
KWIKPAY_CLIENT_IDFrom the ecommerce terminal.
KWIKPAY_CLIENT_SECRETFrom the ecommerce terminal. Server only. Never put in client apps.
KWIKPAY_TENANT_IDFrom the Kwik Pay contact person.
KWIKPAY_WEBHOOK_SECRETShown once as webhookSecret. Required before Kwik Pay will POST a signed callback.
PUBLIC_BASE_URLPublic 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.

2

What the server does for every payment

Step 1

Confirm Cart

Browser sends cart to your server.

Server only
Step 2

Create Payment

Server requests token & stores paymentId.

API call
Step 3

Open Pay Page

Browser opens Kwik Pay checkout URL.

Browser redirect
Step 4

Shopper Pays

Bank communicates with Kwik Pay.

KNET / Bank
Step 5

Return & Callback

Shopper returns; mark order paid once.

Complete

Access token

Obtain a Bearer token using your client credentials:

POST{API}/api/v1/external/auth/token
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:

POST{API}/api/v1/external/channel/ecommerce/payments
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"
  }'
FieldRule
amountGreater than 0, in dinars. 1.500 is 1.500 KWD.
currencyCodeKWD
merchantRefYour order id, 1–80 characters. One id per attempt. A repeat returns 409, so a retry uses a new id.
redirectUrlPut merchantRef on this URL when creating the payment. Kwik Pay adds result and paymentId with &.
callbackUrlWhere Kwik Pay POSTs signed callback. It must be reachable from Kwik Pay (public https address).
paymentMethodCodeOmit it for Kwik Pay checkout. KNET for direct KNET. VISA for combined Visa / Mastercard. Never send CYBERSOURCE.
udf1 – udf5Optional 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.

3

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.

4

How a payment becomes paid

Create the return URL with the order number already on it:

Redirect URL Structure
https://shop.example/checkout/return?merchantRef=ORD-100245

After the shopper pays, Kwik Pay opens that page and appends the result parameters:

Return URL with Parameters
https://shop.example/checkout/return?merchantRef=ORD-100245&result=CAPTURED&paymentId={uuid}&udf1=board:1

Mark the order paid when all three are true:

  • result is CAPTURED
  • merchantRef is an order this shop created
  • paymentId equals 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.

HeaderMeaning & Verification
X-KwikPay-TimestampUnix seconds when Kwik Pay signed the body. Reject it when it is more than 300 seconds from now.
X-KwikPay-Signaturev1= 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):

POSTCallback Signature Verification
# 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:

GET{API}/api/v1/external/channel/ecommerce/payments/{paymentId}
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"
EvidenceOrder Status
Inquiry COMPLETED, and the amount and KWD matchPaid
Inquiry COMPLETED, but amount or currency differsHold for review. Do not ship
KNET, Visa / Mastercard, or checkout returned CAPTURED for stored paymentIdPaid, even while inquiry is PROCESSING
result=FAILED, or inquiry FAILED / EXPIREDNot paid
INITIATED, or PROCESSING with no matching CAPTUREDStill waiting
Inquiry REVERSEDRefunded
5

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.

POST{API}/api/v1/external/channel/ecommerce/payments/{paymentId}/refund
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.

6

Test it

Use the UAT API and UAT portal. Production keys do not belong in this test.

1Put the UAT client id, client secret, tenant id, and webhook secret in the server environment. Set KWIKPAY_API_BASE to the UAT API. Restart the server.
2Open the website and add one item. At checkout, the name, email, and phone can be your own test details.
3Choose KNET or Visa / Mastercard and pay. Each click creates a new merchantRef. Do not reuse an old order to retry.
4On the bank page, use a UAT test card from the table below. Approve the payment.
5The browser should land on /checkout/return?merchantRef=...&result=CAPTURED&paymentId=.... The order number in that link must be the one stored for this attempt, and paymentId must match. The order is then paid.
6Open the same order again. It stays paid. A second inquiry does not undo it.
7Run one payment and cancel or use a failing expiry. result=FAILED leaves the order unpaid.
8On a paid order, choose refund. The server sends reason: REVERSE. After Kwik Pay accepts it, inquiry shows REVERSED and the order is refunded.

UAT Test Cards

These are sandbox cards for the UAT bank pages. They are not production cards:

MethodCard DetailsWhat to expect
KNETBank: KNET Test Card [KNET1]
Number: 8888880000000001
Expiry: 09/30 · PIN: 1234
CAPTURED. A different expiry (such as 05/21) is not captured.
VisaNumber: 4508750015741019
Expiry: 01/39 · CVV: 100
Use this on the direct Visa / Mastercard page.
MastercardNumber: 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:

1
Phase 1: Terminal SetupMerchant Portal
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.

2
Phase 1: Terminal SetupPayment Methods
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.

3
Phase 2: Security & ConfigServer Secrets
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_SECRET
4
Phase 2: Security & ConfigWebhooks
Configure 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))

5
Phase 3: Order FlowCheckout
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

6
Phase 3: Order FlowOrder Ledger
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.

7
Phase 4: ReconciliationVerification
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.

8
Phase 4: ReconciliationRefunds
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" }
7

If a test fails

Common errors and how to resolve them:

What you seeWhat to change
401 on the tokenClient id, client secret, or tenant id does not match this terminal. Restart after fixing the environment.
403 on the tokenThe 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 createmerchantRef was already used. Start a new order id.
BR-PAY-HOSTED-SEL-002Two card terminals share priority 100. Kwik Pay must set a distinct priority.
Return page has no order numberThe 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 pendingpaymentId on the link does not match the id stored for that order.
No callback arriveswebhookSecret is missing, or callbackUrl is localhost. The browser return can still mark the order paid.
Refund says reason must be REVERSE or CHARGEBACKSend {"reason":"REVERSE"}. Do not send a free-text reason.
Create payment times outAllow at least 90 seconds. A 20 second client timeout can expire while UAT is still working.
8

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:

AI-Ready Integration Promptkwikpay-integration.md

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.

Optimized for:Cursor(.cursorrules)Claude Code(Project Knowledge)ChatGPT(Custom Prompt)GitHub Copilot(Workspace Context)Windsurf(Cascade Rules)Gemini(System Context)
1. Cursor & Windsurf

Drop the file into your project or reference it via @kwikpay-integration.md in chat to generate routes.

2. Claude Projects

Add the .md file to your Project Knowledge base for accurate backend handler implementation.

3. ChatGPT & Copilot

Paste the markdown prompt into your AI conversation to generate customized controllers, models, and webhooks.

Kwik Pay ecommerce integration. Nothing on this page is a live secret.