KuvarPay API
Home
Home
  1. Home
  • Overview
  • SDK Integration Guide
  • Webhooks Integration Guide
  • Subscriptions Guide
  • Transactions
    • Calculate Payment Amount
      POST
    • Create Transaction
      POST
    • Get Transactions Details
      GET
    • Get Transactions
      GET
    • Update Status
      PATCH
    • Get Transaction Status by Reference
      GET
    • Simulate payment for sandbox transactions
      POST
    • Get detailed payment status for a transaction
      GET
    • Manually trigger refund for excess payment
      POST
    • Get list of expired transactions
      GET
  • Checkout Sessions
    • Arm Checkout Session
      PATCH
    • Payment Status Webhook
      POST
    • Cleanup Expired Sessions
      POST
    • Create Checkout Session
      POST
    • Get Checkout Session
      GET
    • Update Checkout Session
      PATCH
  • Transfer Fees
    • /api/v1/optimal-transfer-fee
      GET
  • Sandbox Simulator
    • Force Simulator Scenario
      POST
    • Force Transaction Status
      POST
  • Invoices
    • Create a new invoice
      POST
    • Send invoice email to customer
      POST
  • Payment Links
    • Create a new payment link
  • Server-Sent Events (SSE)
    • Get Transaction Details
    • Get Session Details
  • Subscriptions
    • Create Plans
    • Get Plans
    • Get Plans Details
    • Update Plans Details
    • Create Prices
    • Get Prices
    • Update Prices Details
    • Create Checkout Sessions
    • Get Checkout Sessions Details
    • Confirm Subscription Checkout
    • Create Subscriptions
    • Get Subscriptions
    • Get Subscriptions Details
    • Update Subscriptions Details
    • Delete Subscriptions Details
    • Renew Subscription
    • Confirm Subscription Cancellation
    • Create Subscription Invoices
    • Upgrade Subscription
    • Get Subscription Invoices
    • Downgrade Subscription
    • Create Metered Invoices
    • Renew Subscription Authorization
    • Get Subscription Invoices Details
    • Get Charge Attempts
    • Create Authorizations
    • Revoke Relay Authorization
    • Get Relay Authorization Status
  • Currencies
    • Get Subscription Currencies
    • Get Supported Currencies
    • Get networks supported for subscription payments
    • Get Currencies
    • Get all supported networks
  • Schemas
    • ErrorResponse
    • CreateInvoiceRequest
    • CreatePaymentLinkRequest
    • InvoiceResponse
    • PaymentLinkResponse
    • CreateInvoiceResponse
    • CreatePaymentLinkResponse
    • SendInvoiceEmailRequest
    • SendInvoiceEmailResponse
    • SubscriptionInvoice
  1. Home

SDK Integration Guide

KuvarPay Web SDK Integration Guide#

This guide shows how to embed KuvarPay's checkout modal on your website using the Web SDK. It lets your customers pay in crypto while you receive fiat payouts.

Overview#

One line to include the SDK script
Initialize once with your publishable API key and business ID
Call KuvarPay.openPayment(...) for one-time payments
Call KuvarPay.openSubscription(...) for subscription approvals (supports FIXED and METERED billing)
Handle onSuccess, onCancel, and onError callbacks
Built-in idempotency for safe retries

Prerequisites#

Before integrating the SDK, you need:
1.
A KuvarPay Merchant Account — Sign up at merchant.kuvarpay.com and complete business verification.
2.
API Keys — Go to your Merchant Dashboard → Settings → API Keys to generate:
A Publishable (Client) Key — used in the browser SDK (starts with rsp_test_ or rsp_live_).
A Secret Key — used only on your server (starts with kp_sk_test_ or kp_sk_live_). Never expose this in client-side code.
3.
Business ID — Found in your Merchant Dashboard → Settings → Business Info.

Supported Currencies#

KuvarPay supports the following settlement (fiat) currencies:
NGN (Nigerian Naira)
RWF (Rwandan Franc)
KES (Kenyan Shilling)
Customers can pay using popular cryptocurrencies including USDT, USDC, BNB, ETH, AVAX, and more across multiple networks (BSC, Ethereum, Avalanche, Polygon, etc.). Use the Currencies API to fetch the full list of supported crypto assets and networks dynamically.

1) Include the SDK Script#

Or include with auto-initialization using data attributes (recommended when possible):

2) Initialize the SDK#

Call KuvarPay.init as early as possible (e.g., on page load):
Notes:
Use a publishable API key intended for client-side usage.
baseUrl is REQUIRED. Set it to https://pay.kuvarpay.com.
In redirect mode (inlineCheckout: false), the SDK navigates away from your page; therefore onSuccess/onCancel/onError callbacks will not fire on the originating page.
Use your redirectUrl (provided during session creation) to bring the user back to a success page on your site once payment completes.

3) Open the Payment Modal#

Trigger the modal when the customer clicks a button or when your flow requires payment.

Option A: Create New Session (Default Behavior)#

Option B: Use Existing Session (Recommended for Server-Side Integration)#

If you've already created a checkout session on your server, you can use it directly:
Attach to your checkout button:

4) How It Works#

New Session Creation (Option A)#

The SDK creates a Checkout Session on your behalf.
Built-in idempotency ensures repeated clicks or retries won't create duplicate sessions.
The secure checkout is displayed in a modal overlay on your page.

Existing Session Usage (Option B)#

The SDK skips session creation and directly loads the existing session in the modal.
This prevents duplicate session creation when you've already created a session on your server.
Recommended for server-side integrations where you control session creation timing and parameters.

5) Payment Data Parameters#

ParameterTypeRequiredDescription
amountnumberYes (new sessions)Payment amount in the target fiat currency
currencystringYes (new sessions)Settlement currency code (e.g., 'NGN', 'RWF', 'KES')
descriptionstringNoPayment description shown to the customer
customerEmailstringNoCustomer's email address
customerNamestringNoCustomer's full name
redirectUrlstringNoURL to redirect after successful payment
callbackUrlstringNoServer-side webhook URL — KuvarPay will POST payment status updates to this URL
expiresInnumberNoSession time-to-live in seconds. Default: 1800 (30 minutes)
metadataobjectNoCustom key-value data for your internal tracking. Stored with the session and transaction, accessible in dashboards and webhook payloads, but not displayed to the customer
sessionIdstringNoExisting session ID — skips session creation and opens the modal directly
Init options:
inlineCheckout (boolean): When false, the SDK redirects to the standalone checkout page after creating/using a session. Default true (embedded modal).

6) Options and Callbacks#

options.theme: 'light' | 'dark' (default 'light').
callbacks.onSuccess(sessionId): invoked when the payment session completes successfully.
callbacks.onCancel(): invoked when the user closes/cancels the modal.
callbacks.onError(error): invoked on network/validation failures.
Redirect mode considerations:
When inlineCheckout: false, callbacks will not run because the page navigates away to the standalone checkout.
Handle success/failure on your own route using the redirectUrl or server-side webhooks via callbackUrl.

7) Security Notes#

Use only your publishable (client) API key on the frontend.
Keep secret keys on your server. Never embed secret keys in client code.

8) Troubleshooting#

If the modal doesn't open, ensure KuvarPay.init ran without errors (check console if debug: true).
Verify your amount and currency are valid and within min/max limits configured on your KuvarPay account.
When using existing sessions, ensure the sessionId is valid and the session hasn't expired.

Server SDK (Backend Integration)#

For server-side operations (verifying sessions, creating checkout sessions, fetching transaction status), use the KuvarPay Server SDK.

Constructor#

Methods#

createCheckoutSession(data) — Create a checkout session#

ParameterTypeRequiredDescription
amountnumberYesPayment amount
currencystringYesSettlement currency (e.g., 'NGN')
descriptionstringNoPayment description
customerEmailstringNoCustomer's email
customerNamestringNoCustomer's name
redirectUrlstringNoRedirect URL after payment
callbackUrlstringNoWebhook URL for status updates
expiresInnumberNoSession TTL in seconds (default 1800)
metadataobjectNoCustom key-value data
businessIdstringNoOverride the default business ID
Returns: { sessionId, authToken?, approvalUrl?, raw }

verifyPayment(sessionId) — Verify a payment#

Returns: { verified, status, sessionId, transactionId, metadata, raw }

getSessionStatus(sessionId) — Get session details#

Returns: { sessionId, status, transactionId, metadata, raw }

getTransactionStatus(transactionId) — Get transaction details#

Returns: { transactionId, status, metadata, raw }

createSubscriptionCheckoutSession(data) — Create a subscription session#

Returns: { sessionId, approvalUrl?, raw }

getSubscription(subscriptionId) — Get subscription details#

cancelSubscription(subscriptionId) — Cancel subscription#

createMeteredInvoice(subscriptionId, data) — Create a metered invoice#

Example Usage#

Node (ESM) example:
Security notes:
Keep SECRET keys server-side only. Never expose them in client-side code.
Always use HTTPS in production.
Prefer server-side verification to confirm final payment states like COMPLETED.

End-to-End Integration Example#

This shows the recommended flow: create the session on your server, pass the sessionId to the frontend, open the modal, and verify on your server.

Step 1: Server — Create the checkout session#

Step 2: Frontend — Open the modal with the sessionId#

Step 3: Server — Verify the payment#


Subscription Integration#

The SDK also supports embedded subscription approvals via KuvarPay.openSubscription(...). This loads the subscription approval UI and communicates status back to your page using callbacks, similar to one-time payments.

Redirect (Non-Embedded) Subscription Approval#

When inlineCheckout: false is set at init, openSubscription(...) will redirect to the standalone approval page instead of opening a modal.
As with payments, callbacks will not fire on the original page because the browser navigates away; use your return routes or server-side notifications to update user state.

1) Open the Subscription Modal#

Option A: Use Existing Subscription Session#

If you have already created a subscription checkout session on your backend (recommended), you can pass either the session ID or the approval URL returned by your backend. When both are provided, the SDK will prefer the approval URL.

Option B: Create New Session From the Browser (Metered-only)#

If you prefer to let the SDK create the session from the browser, pass the required metered parameters.

2) Callback Events#

The SDK handles all communication between the subscription modal and your page automatically. Use the callbacks provided to openSubscription(...) to respond to events:
Success — fired when the subscription is successfully approved/activated
Error — fired when approval fails (insufficient funds, network errors, authorization issues, etc.)
Cancel — fired when the user cancels/closes the approval flow

3) Parameters for openSubscription(...)#

Required for new session creation (metered-only):
customer — { email: string; firstName: string; lastName: string }
expectedUsage — { amount: number; currency: string } (REQUIRED)
strategy — 'conservative' | 'moderate' | 'liberal' | 'custom' (REQUIRED)
customMultiplier — number (REQUIRED if strategy is 'custom', must be > 0)
Optional:
metadata — object (e.g., { planName, planDescription })
sessionId — use when you already have a session created (skip creation)
approvalUrl — alternatively, pass the approval URL returned by your backend
options.theme — 'light' | 'dark'
businessId — optional per-call override; SDK will use the businessId provided at KuvarPay.init(...) if not specified
Callbacks:
onSuccess(result) — subscription confirmed; result typically includes { sessionId, subscriptionId, status, txHash? }
onCancel() — closed/cancelled
onError(error) — any failure in session creation or approval flow

Verifying Session Status Programmatically#

If you need to confirm whether a checkout session completed successfully (or fetch its latest status/details), the SDK provides a helper:
Notes:
The response includes the current session status (PENDING, COMPLETED, etc.).
This is useful in redirect flows where you land on a confirmation page and want to double-check the final status.

Subscription Invoices (Client-Side Helper)#

For existing subscriptions, you may need to generate usage-based invoices programmatically. The SDK provides helpers:
KuvarPay.createSubscriptionInvoice(subscriptionId, data) — create an invoice immediately or scheduled based on chargeSchedule
KuvarPay.scheduleSubscriptionInvoice(subscriptionId, data) — convenience wrapper that enforces a future dueDate and sets chargeSchedule: 'SCHEDULED'
For backward compatibility, KuvarPay.createMeteredInvoice(...) remains available as an alias.
Notes:
The SDK does not automatically create invoices after subscription approval. Merchants decide when to invoice.
For trials, you can either:
Schedule the invoice for after the trial ends using chargeSchedule: 'SCHEDULED' and a dueDate (Unix seconds);
Or create the invoice on the day the trial expires with chargeSchedule: 'IMMEDIATE'.

SDK Versioning and Notes#

New in this version:
Metadata support for payments: Pass a metadata object in openPayment(...) or createCheckoutSession(...) to attach custom key-value data to sessions and transactions. Metadata is stored server-side, included in webhooks and dashboards, but not shown to customers on the payment page.
Metered-only subscription creation parameters (expectedUsage, strategy, customMultiplier).
Client-side helper to create subscription invoices for existing subscriptions (alias: createMeteredInvoice).
New helper: KuvarPay.getSessionStatus(sessionId) to verify the latest status of a checkout session.
Backward-compatible: Passing sessionId to openSubscription continues to work as before.
Auto-initialization: If your script tag includes data-api-key, data-business-id, and data-base-url, the SDK will initialize itself automatically.
Modified at 2026-02-16 19:58:54
Previous
Overview
Next
Webhooks Integration Guide
Built with