Skip to main content
@creptapay/checkout opens the CreptaPay checkout from your website. The customer pays with stablecoins without leaving your page (or on the hosted page), and you get a callback when it’s paid. It works in any browser setup: plain HTML, React, Vue, Next.js, and others.

Install

The SDK only takes your public key (pk_…). It refuses a secret key, so a secret key never ends up in your website’s code.
If the browser creates the payment, someone could edit your page and change the price first. Instead, create the payment on your server with your secret key, using the amount from your own order data. Then open it in the browser with resumePayment.
1

Create the payment on your server

2

Open it on your page

resumePayment checks that the payment belongs to your account and hasn’t expired before showing it.
3

Confirm on your server

Wait for the signed payment.paid webhook, then check its metadata.order_id and amount match the order.

Create the payment in the browser

You can also create the payment straight from the browser with your public key. This is quicker to set up, but the price can be changed on the page, so always check the paid amount on your server.
Then show it in one of three ways.
A modal over your page.
To create and show the payment in one call, use checkout():

Callbacks

If you don’t pass onSuccess and the payment has a redirect URL, the popup and inline modes redirect after success. Change this with redirectOnSuccess. The popup closes itself 2.5 seconds after success; change this with autoCloseAfterSuccess (or false to keep it open).

Methods

Errors are thrown as CreptaPayError, with .message and .status (for example 403 for a payment from another account, 410 for an expired one).

Always confirm on your server

The callbacks and the ?status=paid on your redirect URL come from the browser, so anyone can fake them. Before you ship an order, confirm on your server that the payment:
  • is paid or overpaid,
  • has this order’s metadata.order_id,
  • is for at least the order’s amount, in the right currency.
The most reliable way is the payment.paid webhook. You can also fetch the payment with your secret key: