Get ZBD Ramp integrated into your application in minutes using our official SDKs. This guide covers session initialization, widget rendering, and webhook handling.
Choose Your SDK
Select the SDK that best fits your application:
Integration Flow
Install SDK
Add the appropriate ZBD Ramp SDK to your project
Initialize Session
Create a session token from your backend using the SDK
Render Widget
Display the Ramp widget using SDK components
Handle Events
Process webhooks and widget callbacks
Quick Start
1. Install the SDK
TypeScript/JavaScript
React
React Native
npm install @zbdpay/ramp-ts
2. Initialize Session (Backend)
Create a session token from your backend to keep your API key secure:
import { initRampSession , QuoteCurrencyEnum , BaseCurrencyEnum } from '@zbdpay/ramp-ts' ;
const response = await initRampSession ({
apikey: process . env . ZBD_API_KEY ,
email: '[email protected] ' ,
destination: '[email protected] ' ,
quote_currency: QuoteCurrencyEnum . USD ,
base_currency: BaseCurrencyEnum . BTC ,
webhook_url: 'https://yourapp.com/webhooks/zbd' ,
reference_id: 'user_123_purchase_456' ,
metadata: {
user_id: '123' ,
session_id: 'abc'
}
});
const sessionToken = response . data . session_token ;
Display the Ramp widget in your application:
React
Vanilla JavaScript
React Native
import { ZBDRamp } from '@zbdpay/ramp-react' ;
function PaymentPage ({ sessionToken }) {
return (
< ZBDRamp
sessionToken = { sessionToken }
onSuccess = { ( data ) => {
console . log ( 'Payment successful:' , data );
// Handle successful payment
} }
onError = { ( error ) => {
console . error ( 'Payment error:' , error );
// Handle error
} }
onClose = { () => {
console . log ( 'Widget closed' );
// Handle close
} }
style = { { width: '100%' , height: '600px' } }
/>
);
}
4. Handle Webhooks
Process webhook events on your backend:
app . post ( '/webhooks/zbd' , ( req , res ) => {
const event = req . body ;
switch ( event . type ) {
case 'ramp.purchase.completed' :
// Payment successful - credit user account
const { amount , currency , reference_id } = event . data ;
creditUserAccount ( reference_id , amount );
break ;
case 'ramp.purchase.failed' :
// Payment failed - notify user
notifyUserOfFailure ( event . data . reference_id );
break ;
case 'ramp.kyc.completed' :
// KYC completed - update user status
updateUserKYCStatus ( event . data . user_id );
break ;
}
res . status ( 200 ). send ( 'OK' );
});
Complete Example
Here’s a full implementation using React and Node.js:
Backend (Node.js + Express)
import express from 'express' ;
import { initRampSession , QuoteCurrencyEnum , BaseCurrencyEnum } from '@zbdpay/ramp-ts' ;
const app = express ();
app . use ( express . json ());
// Create session endpoint
app . post ( '/api/ramp/session' , async ( req , res ) => {
try {
const response = await initRampSession ({
apikey: process . env . ZBD_API_KEY ,
email: req . body . email ,
destination: req . body . destination ,
quote_currency: QuoteCurrencyEnum . USD ,
base_currency: BaseCurrencyEnum . BTC ,
webhook_url: ` ${ process . env . BASE_URL } /webhooks/zbd` ,
reference_id: req . user . id ,
metadata: {
user_id: req . user . id ,
session_id: req . session . id
}
});
res . json ({ sessionToken: response . data . session_token });
} catch ( error ) {
res . status ( 500 ). json ({ error: 'Failed to create session' });
}
});
// Webhook handler
app . post ( '/webhooks/zbd' , async ( req , res ) => {
const event = req . body ;
if ( event . type === 'ramp.purchase.completed' ) {
// Credit user's account
await creditUserBalance (
event . data . reference_id ,
event . data . amount ,
event . data . currency
);
}
res . status ( 200 ). send ( 'OK' );
});
Frontend (React)
import React , { useState , useEffect } from 'react' ;
import { ZBDRamp } from '@zbdpay/ramp-react' ;
function BuyBitcoin () {
const [ sessionToken , setSessionToken ] = useState ( null );
const [ loading , setLoading ] = useState ( true );
useEffect (() => {
// Fetch session token from backend
fetch ( '/api/ramp/session' , {
method: 'POST' ,
headers: { 'Content-Type' : 'application/json' },
body: JSON . stringify ({
email: user . email ,
destination: user . lightningAddress
})
})
. then ( res => res . json ())
. then ( data => {
setSessionToken ( data . sessionToken );
setLoading ( false );
});
}, []);
if ( loading ) return < div > Loading... </ div > ;
return (
< div className = "payment-container" >
< h1 > Buy Bitcoin </ h1 >
< ZBDRamp
sessionToken = { sessionToken }
onSuccess = { ( data ) => {
alert ( 'Payment successful!' );
window . location . href = '/wallet' ;
} }
onError = { ( error ) => {
alert ( `Payment failed: ${ error . message } ` );
} }
style = { { width: '100%' , height: '600px' } }
/>
</ div >
);
}
Session Parameters
When initializing a session, you can configure various parameters:
Parameter Type Required Description apikeystring Yes Your ZBD API key emailstring Yes User’s email address webhook_urlstring Yes URL for webhook notifications destinationstring No Lightning or Bitcoin address quote_currencyenum No Source currency (USD, EUR, etc.) base_currencyenum No Target currency (BTC) reference_idstring No Your internal reference ID metadataobject No Additional data to attach
Sessions expire after 15 minutes. Create a new session if the user needs more time.
Security Best Practices
API Key Security
Never expose API keys in frontend code
Always create sessions from your backend
Use environment variables
Rotate keys regularly
Webhook Security
Use HTTPS endpoints only
Implement idempotency
Verify webhook signatures
Log all events for audit
Demo Applications
To help you get started quickly, we’ve created example applications showing ZBD Ramp integration across different platforms. These demos showcase best practices and real-world implementation patterns.
TypeScript
React Native
Flutter
Features:
Clean TypeScript implementation
Session management
Webhook handling
Error handling examples
Perfect for web applications and Node.js backends. See the TypeScript SDK documentation for more details.
These example applications demonstrate production-ready patterns for integrating ZBD Ramp. Use them as a starting point for your own implementation.
Next Steps