fakepe-sdk
v1.0.1
Published
Official Node.js SDK for FakePE Payment Gateway - A Razorpay-inspired mock payment system
Downloads
11
Maintainers
Readme
fakepe-sdk
Official Node.js SDK for FakePE Payment Gateway - A Razorpay-inspired mock payment system for testing and development.
🚀 Installation
npm install fakepe-sdk📦 Quick Start
const FakePE = require('fakepe-sdk');
const fakepe = new FakePE({
key_id: 'your_key_id',
key_secret: 'your_key_secret',
baseUrl: 'http://localhost:4000' // Optional
});
// Create a payment
const payment = await fakepe.payments.create({
merchantId: 'mer_123',
amount: 50000, // Amount in paise (₹500)
orderId: 'order_001',
callbackUrl: 'https://yoursite.com/webhook'
});
console.log(payment.paymentId);
console.log(payment.paymentUrl);📚 API Reference
Initialize SDK
const fakepe = new FakePE({
key_id: 'your_key_id', // Required
key_secret: 'your_key_secret', // Required
baseUrl: 'http://localhost:4000' // Optional
});Payments
Create Payment
const payment = await fakepe.payments.create({
merchantId: 'mer_123',
amount: 50000, // in paise
orderId: 'order_001',
callbackUrl: 'https://yoursite.com/webhook',
metadata: { // optional
customer_name: 'John Doe',
customer_email: '[email protected]'
}
});Fetch Payment
const payment = await fakepe.payments.fetch('pay_xyz789');List Payments
const payments = await fakepe.payments.list({
merchantId: 'mer_123',
status: 'COMPLETED',
limit: 10,
offset: 0
});Refund Payment
await fakepe.payments.refund('pay_xyz789', {
amount: 25000, // partial refund
reason: 'Customer request'
});UPI
Create VPA
await fakepe.upi.createVpa({
userId: 'usr_123',
vpa: 'user@fakepe'
});Get User VPAs
const vpas = await fakepe.upi.getVpas('usr_123');Generate QR Code
const qr = await fakepe.upi.generateQr('pay_xyz789');
console.log(qr.upiIntent); // upi://pay?...
console.log(qr.qrCodeData); // base64 QR code imageInitiate Payment
const txn = await fakepe.upi.initiate({
paymentId: 'pay_xyz789',
payerVpa: 'user@fakepe'
});Confirm Payment
const result = await fakepe.upi.confirm({
txnId: txn.txnId,
pin: '1234' // Mock PIN
});Get Transaction
const txn = await fakepe.upi.getTransaction('UPI2024011512345678');Get Transaction History
const history = await fakepe.upi.getHistory('usr_123', {
limit: 20,
offset: 0
});Wallets
Get Balance
const wallet = await fakepe.wallets.getBalance('usr_123');
console.log(wallet.balance); // in paiseTop Up
await fakepe.wallets.topup({
userId: 'usr_123',
amount: 100000 // ₹1000
});Transfer
await fakepe.wallets.transfer({
from: 'usr_123',
to: 'usr_456',
amount: 50000
});Webhooks
Verify Signature
app.post('/webhook', (req, res) => {
const signature = req.headers['x-fakepe-signature'];
// Verify webhook signature
if (!fakepe.webhooks.verify(req.body, signature)) {
return res.status(400).send('Invalid signature');
}
// Process webhook
const { event, data } = req.body;
switch(event) {
case 'payment.completed':
console.log('Payment completed:', data.paymentId);
break;
case 'payment.failed':
console.log('Payment failed:', data.paymentId);
break;
}
res.status(200).send('OK');
});Generate Signature (for testing)
const signature = fakepe.webhooks.generateSignature(payload);📋 Examples
Check the examples/ directory for complete working examples:
basic-payment.js- Simple payment creationupi-payment.js- Complete UPI payment flowwebhook-server.js- Webhook handling with signature verification
🔧 Error Handling
try {
const payment = await fakepe.payments.create({
merchantId: 'mer_123',
amount: 50000,
orderId: 'order_001'
});
} catch (error) {
console.error('Payment creation failed:', error.message);
console.error('Error code:', error.response?.status);
console.error('Error details:', error.response?.data);
}💡 Best Practices
- Store credentials securely - Never commit API keys
- Use environment variables -
process.env.FAKEPE_KEY_ID - Handle errors gracefully - Wrap API calls in try-catch
- Verify webhooks - Always verify signature before processing
- Use idempotency - Pass
Idempotency-Keyheader for safe retries
🔗 Related Projects
- Main SDK: fakepe-sdk - NPM Package
- User App: fakePE-user-app
⚠️ Disclaimer
This is a MOCK payment system for testing and development only. All transactions use fake money and are not real financial transactions.
For production use, integrate with real payment providers like:
📄 License
MIT License - see LICENSE file
👨💻 Author
Mihir Rabari
⭐ Star the repo if you find it useful!
