Quickstart
The shortest path from nothing to a completed payment. It assumes a public key, a secret key and at least one settlement wallet configured. Keep the secret key on your server.
1. Install
Section titled “1. Install”npm install stablezact-pay2. Create the checkout on your server, then open it in the browser
Section titled “2. Create the checkout on your server, then open it in the browser”Every payment starts from a checkout that your server creates. The amount is
fixed there, so the browser cannot change what the customer is charged. Your
server sends your secret key; the browser only ever receives the checkout
reference.
// Your backend, for example POST /api/checkoutconst response = await fetch('https://hub.stablezact.com/api/v1/payments/checkout', { method: 'POST', headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${process.env.STABLEZACT_SECRET_KEY}`, }, body: JSON.stringify({ amount: 49.99, currency: 'USD', orderId: 'ORD-1234', callbackUrl: 'https://yourstore.com/webhooks/stablezact', }),});
const { checkout } = await response.json();// Send checkout.reference (it starts with "ckr_") to your frontend.Then pass that reference to the SDK:
import { useState } from 'react';import { StablezactPayment } from 'stablezact-pay';import 'stablezact-pay/dist/style.css';
export default function Checkout() { const [open, setOpen] = useState(false); const [reference, setReference] = useState(null);
async function startPayment() { const res = await fetch('/api/checkout', { method: 'POST' }); const data = await res.json(); setReference(data.reference); setOpen(true); }
return ( <> <button onClick={startPayment}>Pay with crypto</button>
{reference && ( <StablezactPayment isOpen={open} onClose={() => { setOpen(false); setReference(null); }} publicKey="pk_your_public_key" reference={reference} onSuccess={({ paymentId, transactionHash }) => { // The customer has submitted. Do not fulfil here. See step 3. console.log('submitted', paymentId, transactionHash); }} onError={(error) => console.error(error)} /> )} </> );}apiUrl is not needed: the SDK talks to production (hub.stablezact.com) by
default. See Configuration for staging.
Not using React? The same flow in plain JavaScript:
const stablezact = new StablezactVanilla({ publicKey: 'pk_your_public_key', theme: 'light',});
document.getElementById('payButton').addEventListener('click', async () => { const { reference } = await (await fetch('/api/checkout', { method: 'POST' })).json();
stablezact.open( { reference }, { onSuccess: (result) => console.log('submitted', result), onError: (error) => console.error(error), } );});3. Confirm on your server
Section titled “3. Confirm on your server”Confirm from your backend, where the answer cannot be forged by the browser:
curl https://hub.stablezact.com/api/v1/payments/PAYMENT_UUID/status \ -H "X-Public-Key: pk_your_public_key"Read outcome:
{ "payment": { "outcome": "paid", "isFinal": true } }paid means the customer’s money is in and you can fulfil. The other two
values are pending and failed. That is the whole rule, and it is the same
however the customer paid.
Better still, let us tell you: see Webhooks.
What next
Section titled “What next”- Configuration: the options worth knowing about
- Payment lifecycle: fulfilling, and tracking your payout
- Overpayments and refunds: what happens when the amount is wrong
