ibc-payment-gateway
v1.0.2
Published
A modular payment gateway for Node.js applications with PostgreSQL and Sequelize
Downloads
69
Maintainers
Readme
Payment Gateway Module
A modular payment gateway for Node.js applications with PostgreSQL and Sequelize support.
Installation
npm install ibc-payment-gatewayUsage
1. Initialize the Payment Gateway
const PaymentGateway = require('ibc-payment-gateway');
const paymentGateway = new PaymentGateway({
database: {
host: 'localhost',
port: 5432,
database: 'your_database',
username: 'your_username',
password: 'your_password',
logging: false // Set to console.log to see SQL queries
}
});
// Initialize the gateway
await paymentGateway.initialize();
// Use in Express app
app.use('/api', paymentGateway.getRouter());2. Create a Payment Provider (Razorpay)
// POST /api/payments/providers
{
"name": "test_razorpay",
"display_name": "Test Razorpay",
"provider": "razorpay",
"is_active": true,
"config": {
"key_id": "your_razorpay_key_id",
"key_secret": "your_razorpay_key_secret",
"webhook_secret": "your_webhook_secret"
},
"supported_methods": ["card", "netbanking", "wallet", "upi"]
}3. Initiate Payment
// POST /api/payments/initiate
{
"amount": 1000.00,
"currency": "INR",
"customer_info": {
"name": "John Doe",
"email": "[email protected]",
"phone": "9876543210"
},
"metadata": {
"productId": "123",
"userId": "456"
}
}4. Webhook Endpoint
The webhook endpoint is automatically created at:
POST /api/payments/webhook/:providerNameConfigure this URL in your Razorpay dashboard.
5. Check Transaction Status
// GET /api/payments/transactions/:orderId
// GET /api/payments/transactions/status/successFeatures
- ✅ Modular architecture supporting multiple payment providers
- ✅ Complete Razorpay integration
- ✅ Automatic webhook handling and signature verification
- ✅ Transaction logging and status tracking
- ✅ Database abstraction with Sequelize
- ✅ Comprehensive error handling
- ✅ Ready for multiple app integration
Database Tables
The module automatically creates these tables:
payment_providers- Store payment provider configurationspayment_transactions- Store all payment transactionspayment_webhook_logs- Log all webhook events
Adding New Payment Providers
To add a new payment provider:
- Create a new provider class in
src/services/providers/ - Implement the required methods:
createOrder,verifyWebhook - Add the provider initialization logic in
PaymentService.js
