peyemapi-nodejs-sdk
v1.0.0
Published
Node.js SDK for PeyemAPI - Haitian payment gateway
Maintainers
Readme
PeyemAPI Node.js SDK
A lightweight Node.js SDK for integrating PeyemAPI payments into your application.
Installation
npm install peyemapi-nodejsUsage
Initialize the client
const { Peyem } = require('peyemapi-nodejs');
const peyem = new Peyem('your_secret_key');
// Or override the API URL (can also be set via PEYEM_API_URL env var)
const peyemCustom = new Peyem('your_secret_key', 'https://custom-api.com');Create a Payment
async function handlePayment() {
try {
const payment = await peyem.createPayment({
amount: 500, // HTG
referenceId: 'ORDER-123',
returnUrl: 'https://your-site.com/callback',
description: 'Optional description'
});
if (payment.payment_url) {
// Redirect your user to MonCash
console.log('Redirect to:', payment.payment_url);
}
} catch (error) {
console.error('Payment failed:', error.message);
}
}Check Payment Status
async function checkStatus() {
const status = await peyem.checkStatus('ORDER-123');
console.log('Status:', status.status); // e.g., 'completed'
}Get Balance
async function getBalance() {
const { balance, currency } = await peyem.getBalance();
console.log(`Balance: ${balance} ${currency}`);
}Webhook Verification
Verify the authenticity of webhooks from PeyemAPI using your Webhook Secret.
// Example using Express
app.post('/webhook', (req, res) => {
const signature = req.headers['x-webhook-signature'];
const payload = JSON.stringify(req.body);
const webhookSecret = 'whsec_...';
const isValid = Peyem.verifyWebhookSignature(payload, signature, webhookSecret);
if (!isValid) {
return res.status(401).send('Invalid signature');
}
// Handle the event
console.log('Received valid webhook:', req.body);
res.status(200).send('OK');
});License
MIT
