@blazium/checkout
v1.0.1
Published
BlaziumPay client-side checkout SDK for web and Telegram Mini Apps
Maintainers
Readme
@blazium/checkout
BlaziumPay client-side checkout SDK for web and Telegram Mini Apps.
Zero dependencies. Works in any browser.
Installation
npm install @blazium/checkoutOr use via CDN:
<script src="https://cdn.blaziumpay.com/checkout.js"></script>Quick Start
1. Create a payment (server-side)
Use your existing server SDK (@blazium/sdk, @blazium/js-sdk, or blaziumpay Python):
// Server-side
const payment = await blazium.createPayment({
amount: 10.00,
currency: 'USD',
description: 'Premium Subscription'
});
// Send payment.id to the client2. Open checkout (client-side)
import { BlaziumPay } from '@blazium/checkout';
const bp = new BlaziumPay();
// Option A: Popup (desktop web)
bp.openCheckout({
paymentId: payment.id,
onSuccess: (data) => {
console.log('Payment confirmed!', data.txHash);
},
onFailure: (data) => {
console.log('Payment failed:', data.status);
},
onClose: () => {
console.log('User closed checkout');
}
});
// Option B: Redirect (Telegram Mini Apps)
bp.redirectToCheckout({
paymentId: payment.id,
returnUrl: window.location.href
});Telegram Mini App Integration
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="https://telegram.org/js/telegram-web-app.js"></script>
<script src="https://cdn.blaziumpay.com/checkout.js"></script>
</head>
<body>
<button id="pay-btn">Pay $10.00</button>
<script>
const bp = new BlaziumPay();
const tg = window.Telegram.WebApp;
tg.ready();
document.getElementById('pay-btn').onclick = async () => {
// Your backend creates the payment
const res = await fetch('/api/create-payment', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ amount: 10.00, currency: 'USD' })
});
const { paymentId } = await res.json();
// Redirect to checkout (works in Telegram Mini Apps)
bp.redirectToCheckout({
paymentId,
returnUrl: window.location.href
});
};
</script>
</body>
</html>API
new BlaziumPay(config?)
| Option | Type | Default | Description |
|--------|------|---------|-------------|
| apiUrl | string | https://blaziumpay.com | BlaziumPay base URL |
bp.openCheckout(options)
Opens checkout in a centered popup. Falls back to redirect if popup is blocked.
| Option | Type | Description |
|--------|------|-------------|
| paymentId | string | Required. Payment ID from server SDK |
| onSuccess | function | Called when payment is confirmed |
| onFailure | function | Called on failure/expiry/cancellation |
| onClose | function | Called when user closes the popup |
bp.redirectToCheckout(options)
Redirects current page to checkout. Best for Telegram Mini Apps.
| Option | Type | Description |
|--------|------|-------------|
| paymentId | string | Required. Payment ID from server SDK |
| returnUrl | string | URL to redirect back to after payment |
bp.close()
Closes the popup if open.
