Cutluy
Medusa Payment Module Provider for CutLuy — Bakong KHQR scan-to-pay (asynchronous payment method).
medusa-payment-cutluy
A Medusa Payment Module Provider for CutLuy — Bakong KHQR scan-to-pay payments.
CutLuy is an asynchronous payment method: the customer scans a KHQR code (or opens a hosted checkout page) and pays from their banking app. The plugin is a standalone Medusa payment provider (like ) and installable in any Medusa v2 application.
Features
- ✅ Create a CutLuy KHQR payment per payment session
- ✅ Exposes and to the storefront through the payment session
- ✅ Asynchronous authorization () → order created as "awaiting"
- ✅ Webhook handling via Medusa's built-in listener with HMAC-SHA256 signature verification (over the raw body) and session/amount verification
- ✅ Scheduled sweep job that detects CutLuy payments expired/failed while their order is still (dropped webhook events) and flags them for operators
- ✅ webhook marks the session captured and completes the cart/order
- ✅ Poll-based status () and retrieval ()
- ✅ USD-only enforcement (CutLuy only charges USD)
- ❌ Capture / cancel / delete / update / refund are not part of CutLuy's public v1 API — implemented as safe no-ops or explicit errors
How it works
Because returns , the order is created with an awaiting payment status. When CutLuy fires , Medusa's re-invokes — the provider re-checks the CutLuy payment status and returns once it's paid — which creates the Payment record, captures it, and flips the order to paid/captured. If the QR expires or the payment fails, / are mapped to a action — which Medusa 2.18's webhook processor ignores, so the order remains awaiting and no capture occurs. The storefront must surface CutLuy's own payment status (poll ), and operators see a warning log per event.
Async flow requirement: polls on every call and only returns while the payment is still pending. This is what lets the webhook-driven autocapture flow create and capture the Payment.
Requirements
- Medusa v2.17.0 or later (uses the async payment methods support)
- Node.js 20+
- A CutLuy account with an API key and a configured webhook endpoint
Testing
A complete end-to-end test harness lives in the directory (sibling of this repo — not part of the package):
- — Postgres + Redis for the Medusa app
- — a backend with the plugin registered
- — a mock of the CutLuy API (), so no real credentials are needed
- — drives the full flow via the API: cart → payment session () → verify / → complete cart (order "awaiting") → simulate customer paying at the mock → deliver a signed webhook → assert the order becomes
When you later point the provider at the real CutLuy API ( + real key), the same script works unchanged.
Dependency & security posture: the published package ships zero runtime dependencies — it only declares the peer (>=2.17.0) that any Medusa app already provides. Scanner findings (CVEs, telemetry, minified files) that appear for this package come from Medusa core's own dependency tree (e.g. , which is opt-out via ), and are identical for every Medusa plugin — they resolve upstream when Medusa updates its dependencies.
1. Install
Install locally for development (yalc)
From this plugin's directory (pnpm is the package manager for this repo):
Then, in your Medusa application:
npx medusa plugin:add medusa-payment-cutluyWhile developing, run in this plugin's directory to watch changes and auto-update the app.
Install from npm
2. Configure
In of your Medusa application, register the provider in the Payment Module's array:
Add the environment variables to your application's :
The provider's identifier is . Enable it in a region from the Medusa Admin (Settings → Regions → Payment Providers).
Options
| Option | Required | Description |
|---|---|---|
| ✅ | CutLuy secret API key ( / ) | |
| ⚠️ | Signing secret used to verify . Without it webhooks are rejected. | |
| Override the API base URL (default ) | ||
| HTTP request timeout (default ) |
3. Configure the webhook in CutLuy
-
Make sure your CutLuy store has a payment link configured (payment creation returns otherwise).
-
In the CutLuy dashboard, go to Webhooks.
-
Add an endpoint pointing at Medusa's built-in payment webhook listener:
https://<your-medusa-backend>/hooks/payment/cutluy_cutluy( is the provider's , repeated for the provider .)
-
Copy the endpoint's signing secret into .
The provider verifies the header (HMAC-SHA256 of ) before trusting any event. Medusa's built-in listener acks the request with 200 immediately and processes the event asynchronously (~5s delay, up to 3 internal attempts). Invalid or missing signatures are logged and dropped — the request is still acked, so CutLuy does not retry after a 2xx (non-2xx or timeout responses are retried with exponential backoff, up to 8 times); monitor your backend logs for signature failures. Use the dashboard's Send test or resend a delivery to exercise your endpoint.
Before completing, the provider also verifies the webhook's payment against its payment session: the session must exist, the payment must be USD, and the webhook amount must match the session amount cent-exact. On a mismatch or unknown session the event is logged and ignored (the order stays ). The payload is HMAC-authenticated, so this guards against CutLuy-side drift, not forgery.
Payment sweep job
Because Medusa 2.18's webhook processor ignores / events, an order whose QR expired or whose payment failed would stay forever with no signal. The plugin ships a scheduled job, , that closes the loop:
- Runs every 15 minutes (node-schedule cron ).
- Lists the provider's payment sessions older than 15 minutes that are still / , polls CutLuy for each, and for payments that are or at CutLuy:
- logs a warning with the session id, CutLuy payment id, amount, and currency, and
- marks the session (best-effort) so it stops being silently pending.
- Sessions are only touched once (they leave the pending set), so re-runs are idempotent.
To load the job, the plugin must be listed in the app's array (the provider itself is registered under ):
The staleness window is tunable via (default ).
4. Storefront integration
The payment session contains everything the storefront needs:
Choose one of:
- Redirect the customer to (hosted, branded page with countdown and live status), or
- Render as a QR code in your own UI (e.g. with a library) and poll the cart/order status.
After the customer pays, the webhook completes the order automatically — no storefront polling required.
CutLuy's hosted checkout redirects back to your configured success/failure URLs after a terminal payment, appending . Since Medusa drops / webhooks, the redirect (or polling ) is how the storefront learns the order failed — the order itself stays until the sweep job or an operator acts.
5. Development
6. Testing in a full Medusa app (Docker)
This repo ships only the plugin. To test it end-to-end, run a Medusa app in Docker and install the plugin into it. Follow the official guide — Install Medusa with Docker — then:
- Clone the DTC Starter repo and set up , , as described in the guide.
- Install the plugin locally via yalc ( here, then in the app), or mount this plugin's folder and install it with .
- Register the provider in (see Configure) and add the env vars to .
- , create an admin user, and enable the CutLuy payment provider in a region.
- Expose the backend to the internet (e.g. with a tunnel) and set the webhook URL in the CutLuy dashboard.
API mapping
| Medusa provider method | CutLuy API call |
|---|---|
| webhook events (signature verified) | |
| / / / | no-op (not in CutLuy v1 API) |
| throws — not supported by CutLuy yet |
Status mapping: / → pending · → captured · / → error/failed.
License
MIT

