NodeJS mobile payment status tracking


#1

So im trying to initate a mobile transcation using the nodejs sdk , everything is working ok but the problem is coming when i want to track the payment status of the pollUrl inorder to print it on screen once the user has either cancelled ,paid etc . so when i run my code below

    async function makePaymentRequest(number){

    let paynow = new Paynow(“integration id”, “key”);

    paynow.resultUrl = “paynow result url”;

    paynow.returnUrl = “return url”;

    const ref = new Date().getTime();

    const payment = paynow.createPayment(Invoice ${ref}, ‘emailaddresshere’);

    payment.add(“Oranges”, 5);

    payment.add(“Bread”, 10);

    try {

        const response = await paynow.sendMobile(payment, ‘0773665920’, ‘ecocash’);

        if (response && response.success) {

            let instructions = response.instructions

            let pollUrl = response.pollUrl;

            console.log(instructions);

            console.log(pollUrl);

            console.log(response)

            let status = await paynow.pollTransaction(pollUrl);

       

           console.log("Status: " + status);

           // Get payment status

           http.get(pollUrl, (response) => {

            let data = ‘’;

         

            response.on(‘data’, (chunk) => {

              data += chunk;

            });

         

            response.on(‘end’, () => {

             

              const parsedData = new URLSearchParams(data);

         

              const status = parsedData.get(‘status’);

              console.log(‘Payment status:’, status);

            });

          }).on(‘error’, (error) => {

            console.error(‘Error retrieving payment status:’, error);

          });

        } else {

            console.log(response);

        }

    } catch (e) {

        console.log(e);

    }

    }

I get the following error when i have paid or cancelled

InitResponse {
status: ‘ok’,
success: true,
hasRedirect: false,
pollUrl: ‘pollurl here’,
instructions: ‘Dial 1512*4# and enter your EcoCash PIN. Once you have authorized the payment via your handset, please click Check For Payment below to conclude this transaction’
}
RequestError: Error: read ECONNRESET
at new RequestError (C:\Users\windows 10\Desktop\APIWHATSAPP\node_modules\request-promise-core\lib\errors.js:14:15)
at Request.plumbing.callback (C:\Users\windows 10\Desktop\APIWHATSAPP\node_modules\request-promise-core\lib\plumbing.js:87:29)
at Request.RP$callback [as _callback] (C:\Users\windows 10\Desktop\APIWHATSAPP\node_modules\request-promise-core\lib\plumbing.js:46:31)
at self.callback (C:\Users\windows \Desktop\APIWHATSAPP\node_modules\request\request.js:185:22)
at Request.emit (node:events:527:28)
at Request.onRequestError (C:\Users\windows \Desktop\APIWHATSAPP\node_modules\request\request.js:877:8)
at ClientRequest.emit (node:events:527:28)
at TLSSocket.socketErrorListener (node:_http_client:454:9)
at TLSSocket.emit (node:events:527:28)
at emitErrorNT (node:internal/streams/destroy:157:8) {
cause: Error: read ECONNRESET
at TLSWrap.onStreamRead (node:internal/stream_base_commons:217:20) {
errno: -4077,
code: ‘ECONNRESET’,
syscall: ‘read’
},
error: Error: read ECONNRESET
at TLSWrap.onStreamRead (node:internal/stream_base_commons:217:20) {
errno: -4077,
code: ‘ECONNRESET’,
syscall: ‘read’
},
options: {
method: ‘POST’,
uri: ‘https://www.paynow.co.zw/Interface/CheckPayment/?guid=0dff4e01-8df1-4fd5-a68c-d001128ca280’,
form: null,
json: false,
callback: [Function: RP$callback],
transform: undefined,
simple: true,
resolveWithFullResponse: false,
transform2xxOnly: false
},
response: undefined
}
Error: socket hang up
at connResetException (node:internal/errors:692:14)
at TLSSocket.socketOnEnd (node:_http_client:478:23)
at TLSSocket.emit (node:events:539:35)
at endReadableNT (node:internal/streams/readable:1345:12)
at processTicksAndRejections (node:internal/process/task_queues:83:21) {
code: ‘ECONNRESET’
}

Any help will be appreciated

Or has anyone done it.