1. Installation NPM
Install the official package via NPM or Yarn:
npm install razcrypto-node
2. Quick Setup
Initialize the SDK using your Gateway ID and Secret Key.
const RazCrypto = require('razcrypto-node');
const razcrypto = new RazCrypto("YOUR_GATEWAY_ID", "YOUR_SECRET_KEY");
3. Create a Payment
Generate a payment to get the checkout_page URL. You can use async/await for a clean flow.
async function createPayment() {
try {
const payment = await razcrypto.payment.create({
amount: 10.50,
currency: "USDT",
chain: "BSC",
email: "[email protected]",
callback_url: "https://yourwebsite.com/webhook",
custom_data: {
order_id: "ORD-9999"
}
});
console.log("Checkout URL:", payment.checkout_page);
// Redirect the user to payment.checkout_page
} catch (error) {
console.error("Payment Error:", error.message);
}
}
4. Webhook Verification Express.js
Verify incoming webhooks using the built-in Webhook helper to keep your integration secure.
const express = require('express');
const RazCrypto = require('razcrypto-node');
const app = express();
app.use(express.json());
app.post('/webhook', (req, res) => {
const signature = req.headers['x-razcrypto-signature'];
const secretKey = "YOUR_SECRET_KEY";
// Use the raw body for signature verification
const isValid = RazCrypto.Webhook.verifySignature(
JSON.stringify(req.body),
signature,
secretKey
);
if (isValid) {
const data = req.body;
if (data.event === 'payment.completed') {
console.log("Payment Success for Order:", data.custom_data.order_id);
// ✅ Update your database here
}
res.status(200).send({ status: 'ok' });
} else {
res.status(401).send({ error: 'Invalid Signature' });
}
});
5. Fetch Payment Status
Manually check the current status of any payment ID.
const status = await razcrypto.payment.fetch("payid_xxxxxxxxxx");
console.log(status.status); // pending, completed, or expired
6. Troubleshooting & Tips
Common Error: Invalid Signature
Ensure you are passing the raw JSON string to the verifySignature method. If you are using express.json(), use JSON.stringify(req.body) carefully or use a raw body parser.
How to handle multi-chain?
The SDK supports BSC (Binance Smart Chain) and ETH (Ethereum) out of the box. Just pass the correct chain parameter during payment creation.