@stble/sdk
v1.0.4
Published
Official SDK for Crypto Checkout - Accept crypto payments in your app
Maintainers
Readme
@stble/sdk
Official Node.js/TypeScript SDK for Crypto Checkout - Accept crypto payments in your app.
Installation
npm install @stble/sdk
# or
yarn add @stble/sdk
# or
pnpm add @stble/sdkQuick Start
import Checkout from '@stble/sdk';
const checkout = new Checkout('ck_test_xxx');
// Create a checkout session
const session = await checkout.sessions.create({
mode: 'payment',
amount: 10_000000, // $10 USD (in micro-units)
currency: 'USD',
chain: 'base',
success_url: 'https://yoursite.com/success',
cancel_url: 'https://yoursite.com/cancel',
});
// Redirect to hosted checkout
res.redirect(session.checkout_url);API Reference
Sessions
// Create a session
const session = await checkout.sessions.create({
mode: 'payment',
amount: 10_000000,
currency: 'USD', // or 'USDC', 'EUR', 'GBP'
chain: 'base', // or 'solana', 'polygon'
success_url: 'https://...',
cancel_url: 'https://...',
metadata: { order_id: '123' }, // optional
});
// Retrieve a session
const session = await checkout.sessions.retrieve('cs_xxx');
// List sessions
const sessions = await checkout.sessions.list({ limit: 10 });Payments
// Get a payment
const payment = await checkout.payments.retrieve('pay_xxx');
// List all payments
const payments = await checkout.payments.list({ limit: 50 });Webhooks
import express from 'express';
app.post('/webhook', express.raw({ type: 'application/json' }), (req, res) => {
const signature = req.headers['x-checkout-signature'];
try {
const event = checkout.webhooks.constructEvent(
req.body.toString(),
signature,
process.env.WEBHOOK_SECRET
);
switch (event.event) {
case 'payment.succeeded':
const paymentData = event.data;
// Fulfill the order
break;
case 'payment.failed':
// Handle failed payment
break;
}
res.json({ received: true });
} catch (err) {
res.status(400).send(`Webhook Error: ${err.message}`);
}
});Configuration
const checkout = new Checkout({
apiKey: 'ck_test_xxx',
baseUrl: 'https://api.checkout.example.com', // optional
timeout: 30000, // optional, in milliseconds
});TypeScript
Full TypeScript support is included. Import types as needed:
import type { SessionCreateParams, Payment } from '@stble/sdk';Test vs Live Mode
- Test mode keys start with
ck_test_- use testnet networks (Base Sepolia, Solana Devnet) - Live mode keys start with
ck_live_- use mainnet networks
License
MIT
