Getting this error when using paynow.sendMobile()


#1

TypeError: Failed to fetch

       let paynow = new Paynow("xxx", "xxxxxxxxxxxxxx");

// Set return and result urls
      paynow.resultUrl = "http://example.com/gateways/paynow/update";
      paynow.returnUrl = "http://example.com/return?gateway=paynow";

// Create a new payment
      let payment = paynow.createPayment("Invoice 35",'test@gmail.com');

// Add items to the payment list passing in the name of the item and it's price
      payment.add("Bananas", 2.5);
      payment.add("Apples", 3.4);

// Send off the payment to Paynow
      paynow.sendMobile(

          // The payment to send to Paynow
          payment,

          // The phone number making payment
          '0775658123',

          // The mobile money method to use.
          'ecocash',


      ).then(function(response) {
          if(response.success) {
              // These are the instructions to show the user.
              // Instruction for how the user can make payment
              let instructions = response.instructions // Get Payment instructions for the selected mobile money method

              // Get poll url for the transaction. This is the url used to check the status of the transaction.
              // You might want to save this, we recommend you do it
              let pollUrl = response.pollUrl;

              console.log(instructions)

          } else {
              console.log(response.error)
          }
      }).catch(ex => {
          // Ahhhhhhhhhhhhhhh
          // *freak out*
          console.log('Your application has broken an axle', ex.message)
      });
  }

#2

Ive tried both the sendMobile() and send(). The sendMobile() doesnt return anything, whilst the send() works but the pollstatus doesnt return anything so no way of knowing if transactions successful. Theres something wrong with this nodejs SDK. The support team is slow to respond. Very Poor


#3

Hi @kudzanaim.

Can you please send a snippet of your payment code? I have a REPL set up using the NodeJS SDK and I’m not running into any issues. A code sample could help the community assist with the issue you’re running into

PS: Will be deleting the integration keys in a day or so. Just wanted to demo this


#4

So the idea here is if I do sendMoney(), i am returned an object with instructions and pollURL which i can then use to check if transaction is complete, which isnt working. I’ve tried implementing your documented code in my code and getting same error. When I pass pollURL into pollTransaction(x), an error occurs saying “Invalid URI”. ive posted my code in the other question.


#5

Hi Kudzanai.

I’m looking into that error. I’ll have an update for by end of today


#6

Any updates on the issue. I think its a problem with paynow node sdk


#7

Hey Kudzanai. Keep an eye on this GitHub issue. Working out the kink right now.


#8

The issue should be resolved in version 1.0.7 of the SDK. It might take about 30 minutes to an hour before the new version shows up on npm though

Let me know if you’re still facing issues.


#9

@kudzanaim. new version is now on npm.


#10

Thanks alot bro. Will test it out again and let u know.


#11

Hi,
The new sdk fixed the “sendMobile()” method and that now works. Only issue is the “pollTransactionStatus(x).paid()” method still throws error saying “.paid()” isn’t a function. The sendMobile() does make the payment, but i am in testing environment, i have no way of knowing if the transaction worked or not.


#12

Hey Kudzanai.

The pollTransaction method returns a PromiseLike<StatusResponse> | Promise<StatusResponse>. So you’d have to use it like this:

paynow.pollTransaction(url).then(transaction => {
  if(transaction.status === 'paid') {
     // User showed us the doe
  }
});

Or if you’re in an async function

let transaction = await paynow.pollTransaction(url);

if(transaction.status === 'paid') {
     // User showed us the doe
}

I’ll submit a PR to the docs site to reflect those changes in the SDK. Let me know if that gives you issues still