CORS error using fetch api in javascript


#1

Hello everyone, I am trying to use the fetch api to get the payment status from the poll_url. However, when I try to do it on the client side, I a getting a CORS ERROR… Here is the error :

Access to fetch at ‘https://www.paynow.co.zw/Interface/CheckPayment/?guid=xxxxxxxxxxxx’ from origin ‘https://portal.xxxxxx.com’ has been blocked by CORS policy: No ‘Access-Control-Allow-Origin’ header is present on the requested resource. If an opaque response serves your needs, set the request’s mode to ‘no-cors’ to fetch the resource with CORS disabled.

my question is there a way of going around this or is it possible for paynow api to allow Cross Origin Requests from 'https://portal.xxxxxx.com


#2

Good day

Please note that you can for JS you can use our NodeJS module
npm install paynow

If you want to continue to use the fetch API please look into these on how to resolve your error


#3

What if I still want to continue using fetch api, is it not possible for paynow to whitelist on its servers the domain that is trying to request?


#4

In general Paynow discourages the use of polling for payment status. Its not performant and causes increased load on the Paynow infrastructure.

If you want to poll from your clientside (javascript) you should poll your own web service, which should return the payment status which has been returned by Paynow to your specified ResultUrl which you defined when you initiated the transaction.

You should only poll Paynow for status update if you havent had a result prior to transaction expiry from your side i.e. before cancelling a checkout from your ecommerce solution, poll Paynow to ensure the transaction is still unpaid beforehand. Otherwise, you should rely on Paynow’s server to server status update on your ResultUrl