order.paid event is not queued when the Webhook is unconfigured; configuring it after a payment does not automatically replay that payment.
Choose your setup path
- Use the dashboard guide if you want to create products and review orders manually first.
- Use the API guide if your application should create checkout sessions from your server.
Overview
1. Set Up Your Server
Install the required dependencies:app-adapters.js using your application’s authentication and database:
requireUserrejects unauthenticated requests and suppliesreq.userfrom a verified login, never from client-supplied user IDs. Apply your application’s CSRF protection to cookie-authenticated purchase requests.checkoutStore.withLockedOrder(userId, productId, callback)creates or locks the user’s current pending business order, with authorization and a database lock or durable reservation across processes. Persist its expected product, price, currency and credit entitlement from your server’s catalog.markCreationPendingdurably records creation in progress before calling KyrenPay.attachSessionstores the Session ID, URL, amount, currency and expiry, verifies them against the order, and clears that marker. Keep the marker on timeouts or failed local saves; releasing a lock must not roll it back. Do not automatically create another Session for an uncertain request: the current API has no Checkout creation idempotency key.webhookInbox.insertIfAbsentdurably inserts a pending event with a unique event ID. Existing events are acknowledged without resetting their processing state. A worker must claim pending events and retry failures until handled or escalated.fulfillPaidOrderIdempotentlychecks the business order association, product, base amount and currency using decimal arithmetic. In one database transaction, uniquely record the KyrenPay order ID, mark the business order fulfilled and credit its recorded user and entitlement. Reject missing or mismatched associations. Apply it to both Webhooks and reconciliation.
express.json() before the raw Webhook route.
The code below deliberately uses KYREN_PRODUCT_ID as a minimal single-product shortcut. This is not a platform-required environment variable or the default Agent integration workflow. For an existing application, prefer a repeatable setup step that queries/reuses or, within authorization, creates products and persists local SKU mappings, as described in Quickstart. Resolve the mapped product ID from the trusted server catalog when creating Checkout instead of copying this single-product constant into every purchase.
2. Create a Product (One-Time Setup)
For this optional single-product example, create or select a fixed-price product once via the API or dashboard and set itsdata.id as KYREN_PRODUCT_ID. In an application-managed mapping flow, persist that ID against its local SKU instead. Checkout takes its amount and currency from that product; it does not accept per-session price, quantity or currency overrides. Product metadata is not automatically merged into Checkout metadata. Keep the expected entitlement in your business order.
Create the product before starting server.js, because startup requires its ID. For example, with KYREN_API_KEY already set in your shell:
data.id in the startup command. The function below is an alternative server-side request example; defining it does not execute it. Set KYREN_BASE_URL to the environment paired with your credentials when using an issued staging or local environment; changing credentials alone does not change the target API.
3. Create Checkout Endpoint
Add an endpoint that creates a checkout session when the customer clicks “Buy”:4. Handle the Frontend Redirect
On your frontend, redirect the customer to the checkout page:5. Handle Webhooks
Add a webhook endpoint to receive payment notifications:6. Process Notifications and Reconcile Payments
Run the following functions from your durable inbox worker and a scheduled reconciliation job, respectively. Mark an inbox event processed only afterprocessWebhook succeeds; a failure must remain retryable.
OPEN, COMPLETE, EXPIRED. Its successful KyrenPay orderId is available through the authenticated Session query; it is not returned when creating the Session. An expired or canceled browser flow is not proof that an existing payment attempt failed. Reconcile before offering a replacement purchase. Show pending status on successUrl until your backend confirms payment; never credit from a browser redirect. Use the exact returned data.url, without constructing the hosted path yourself.
7. Start the Server
8. Test the Flow
- If KyrenPay has issued staging credentials or enabled a test-capable gateway for your merchant account, run the flow with those credentials and the payment scenarios KyrenPay provides.
- If you only have live credentials, verify the flow with a low-risk real payment in production.
- Confirm your customer is redirected to the KyrenPay checkout page.
- Confirm your server receives the payment Webhook and that your fulfillment logic handles the event correctly.
Test duplicate and concurrent notifications, unavailable inbox storage, worker restart, a Webhook racing reconciliation, and expired Sessions. Each business order must credit at most once, and failed persistence must return a non-
2xxresponse. - If you used a real payment for verification, refund or handle it operationally according to KyrenPay support guidance if needed.
Your integration is ready when checkout creation, redirect handling, Webhook receipt, and fulfillment have all been verified with the credentials and gateway KyrenPay has enabled for your account.
Next Steps
Webhook Events
See all available webhook event types
Code Examples
See integration examples in other languages
