03 checkout Widget

The Stablix Checkout Widget lets you accept crypto payments with a single line of code. No npm package required — just add a script tag and start accepting USDC/USDT payments.

Quick Start

<script src="https://api.stablix.xyz/js/checkout.js"></script>

<button onclick="payWithStablix()">Pay $99.99</button>

<script>
function payWithStablix() {
  StablixPay.setup({
    key: 'pk_live_your_public_key',
    amount: 99.99,
    currency: 'USDC',
    chain: 'solana',
    onSuccess: function(response) {
      console.log('Payment successful!', response);
      window.location.href = '/success?ref=' + response.invoice_id;
    }
  });
}
</script>

That's it. The widget handles everything: QR code generation, wallet address display, payment detection, and confirmation.


Configuration Options

Parameter
Type
Required
Default
Description

key

string

Yes

-

Your public key (pk_live_xxx or pk_test_xxx)

amount

number

Yes

-

Payment amount in USD

currency

string

No

USDC

Token to accept: USDC or USDT

chain

string

No

solana

Blockchain: solana or base

email

string

No

-

Customer email for receipts

metadata

object

No

{}

Custom data (order ID, product info, etc.)

onSuccess

function

No

-

Called when payment is confirmed

onClose

function

No

-

Called when user closes the widget

onError

function

No

-

Called on initialization error


Callback Responses

onSuccess Response

onError Response


Framework Examples

React / Next.js

Vue.js

Plain HTML (E-commerce)


How It Works

  1. User clicks pay → Your code calls StablixPay.setup()

  2. Widget opens → Modal appears with amount, QR code, and wallet address

  3. Invoice created → Backend creates invoice using your public key

  4. User sends crypto → Pays from their wallet (Phantom, MetaMask, etc.)

  5. Payment detected → Widget polls for confirmation (every 3 seconds)

  6. Callback firedonSuccess called with transaction details

  7. You verify → Your backend confirms payment via webhook or API


Test Mode

Use your test public key (pk_test_xxx) to test without real payments:

Test mode:

  • Creates real invoices (for testing your integration)

  • Uses testnet/devnet addresses

  • No real funds required


Customization

Custom API URL (Self-hosted)


Security

Public Key Safety

Your public key (pk_live_xxx) is safe to expose in frontend code. It can only:

  • Create invoices

  • Check payment status

It cannot:

  • Access merchant data

  • Release funds

  • View transaction history

  • Modify settings

Always Verify Payments

Never trust the onSuccess callback alone. Always verify payments on your backend:


Supported Browsers

The checkout widget supports all modern browsers:

  • Chrome (Desktop & Mobile)

  • Safari (Desktop & Mobile)

  • Firefox (Desktop)

  • Edge (Desktop)


Troubleshooting

Widget doesn't open

Payment not detected

  • Ensure customer sent the exact amount

  • Ensure customer used the correct token (USDC vs USDT)

  • Ensure customer used the correct chain (Solana vs Base)

  • Check transaction on block explorer

CORS errors

If testing locally, ensure your backend allows CORS from localhost:


API Endpoints

The widget uses these endpoints internally:

Endpoint
Method
Auth
Description

/checkout/initialize

POST

X-Public-Key

Create invoice

/checkout/:id/status

GET

None

Poll payment status

You don't need to call these directly — the widget handles everything.

Last updated