khalti / docs.khalti.com

Khalti Payment Gateway Documentation
https://docs.khalti.com
54 stars 63 forks source link

Getting CORS error for verification. #19

Open Suraez opened 3 years ago

Suraez commented 3 years ago

i am getting cors error while making POST request to merchant API for verification. And when i try to use reverse proxy i.e. https://cors-anywhere.herokuapp.com , i got 403 unuathorized error

Access to XMLHttpRequest at 'https://khalti.com/api/v2/payment/verify/' from origin 'http://localhost:3000/' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.

while using reverse proxy Failed to load resource: the server responded with a status of 403 (Forbidden)

aaeronn commented 3 years ago

Are you trying to communicate api from client side ??

Suraez commented 3 years ago

yeah

Suraez commented 3 years ago

I tried to implement from the server but no luck. Got this

xhr.js:184 GET http://localhost:7655/khalti/M6aERNTpGNk9wukyi8n22a/1000/my_secret_key (Internal Server Error)

above is my own API which eventually calls merchant API with token, amount and secret key in req.params. I extract these from req.params and call the API as:

let data = {
        token: req.params.token,
        amount: req.params.amount,
      };

    let config = {
    headers: {
        Authorization: "MY-TEST-SECRET-KEY",
    },
    };
    axios
        .post(
        "https://khalti.com/api/v2/payment/verify/",
        data,
        config
        )
        .then((response) => {
        console.log(response.data);
        console.log("Yay!, It's done");
        })
        .catch((error) => {
        console.log(error);
        });
inquisitive-stha commented 2 years ago

Any update on this??

Abhinav0057 commented 2 years ago

any update?

Roopaish commented 1 year ago

geez, it's still an open issue