Thanks a lot @adrian
I followed all your pointers, after copying your code and further testing, my problem seems to emanate from somewhere else. If I change products from
payment.add("Oranges", 30);
payment.add("Bread", 15);
to
payment.add("10 to 1", 0.5);
payment.add("CG Summer Cut Day 1", 1);
then I am getting the error. Leaving “Oranges” and “Bread” then there isn’t any problem. However, I don’t want to sell Bread and Oranges
Might this be another testing criteria?
Below is my entire edited code
const express = require('express');
const app = express();
var http = require('http').createServer(app);
var cors = require('cors');
const { Paynow } = require("paynow");
const port = process.env.PORT || 3000;
const paynow = new Paynow(__ID__, __TOKEN___); // Replaced these before i uploaded here
const base_url = "http://3.15.41.118";
paynow.resultUrl = `${base_url}/gateways/paynow/update`;
paynow.returnUrl = `${base_url}/return`;
app.use(cors());
app.options('*', cors());
app.use(express.urlencoded({ extended: true }));
app.use(express.json());
app.post("/payment/ecocash", async function(req, res, next) {
const invoice = new Date().getTime();
const items = req.body.items;
let payment = paynow.createPayment(`Invoice ${invoice}`, 'k1muza@gmail.com');
payment.add("10 to 1", 0.5);
payment.add("CG Summer Cut Day 1", 1);
// payment.add("Oranges", 0.5);
// payment.add("Bread", 1);
const response = await paynow.sendMobile(payment, '0771111111', 'ecocash');
if (response && response.success) {
let instructions = response.instructions
let pollUrl = response.pollUrl;
console.log('PollUrl', pollUrl);
console.log('Instructions', instructions)
let status = await paynow.pollTransaction(pollUrl);
console.log('Status', status);
if (status.paid()) {
res.json('Yay! Transaction was paid for');
}
else {
res.json("Why you no pay?");
}
}
else {
console.log('Error', response.error);
res.json(response.error);
}
});
app.get('/return', (req, res) => {
console.log('Return', req.query);
res.json(req.query);
})
app.get('/gateways/paynow/update', (req, res) => {
console.log('Results', req.query);
res.json(req.query);
})
http.listen(port, function() {
console.log(`listening on ${port}`);
});