Open pray3m opened 9 months ago
To add Khalti or eSewa Nepali payment gateways during checkout alongside Stripe, you'll need to integrate their APIs into your application. Here's a high-level plan:
Research API Documentation
Backend Integration
Frontend Integration
Webhook Handling
Test the Payment Flow
Update Checkout UI
Deploy and Monitor
Frontend Button (React/JavaScript)
const onKhaltiPayment = () => {
const config = {
publicKey: "YOUR_KHALTI_PUBLIC_KEY",
productIdentity: "1234567890",
productName: "Your Product Name",
productUrl: "http://yourwebsite.com",
eventHandler: {
onSuccess(payload) {
console.log("Payment successful", payload);
// Send payload to backend for verification
},
onError(error) {
console.error("Payment failed", error);
},
},
};
const checkout = new KhaltiCheckout(config);
checkout.show({ amount: 1000 }); // Amount in paisa
};
Backend Verification (Node.js Example)
const axios = require('axios');
app.post('/verify-payment', async (req, res) => {
const { token, amount } = req.body;
try {
const response = await axios.post(
'https://khalti.com/api/v2/payment/verify/',
{
token: token,
amount: amount,
},
{
headers: {
Authorization: `Key YOUR_KHALTI_SECRET_KEY`,
},
}
);
res.json({ success: true, data: response.data });
} catch (error) {
res.status(400).json({ success: false, error: error.response.data });
}
});
Once integrated, you'll offer users more localized and convenient payment options, improving their checkout experience.
Currently, only stripe is supported. Add more options during the checkout by implementing khalti or esewa nepali payment gateways.