Making Our First Purchase
Purchase is sending a C2B or charging a customer.
Now, let's add a route for making a purchase request:
app.get('/purchase', async (req, res) => {
try {
const chosenHandler: HandlerName = 'edahab';
const handler = getPaymentHandler(chosenHandler)(paymentConfig[chosenHandler]!);
const paymentInfo = await handler.purchase({
accountNumber: "+2526512312341", // must start with `+` followed by country code
amount: 500,
currency: Currency.SLSH,
description: "Test purchase",
// for web handlers, you can optionally provide a return URL
returnUrl: "https://example.com/return",
});
res.send(paymentInfo);
} catch (e) {
console.log(e);
res.status(500).send("Internal Server Error");
}
});
It'll return the same response detail as from credit
method PaymentInfo
object:
-
transactionId
-
paymentStatus
-
referenceId
-
raw
Feel free to incorporate these details into your application's logic based on your specific use case and requirements.