xendit / xendit-node

Xendit REST API Client for Node.js - Card, Virtual Account, Invoice, Disbursement, Recurring Payments, Payout, EWallet, Balance, Retail Outlets, QR Codes, Direct Debit
https://developers.xendit.co/api-reference/
115 stars 63 forks source link

CORS error on using this https://api.xendit.co/ewallets/charges #152

Closed Kimmydoray closed 2 years ago

Kimmydoray commented 2 years ago

Here's my code:

        const resp = await ew.createEWalletCharge({
            referenceID: 'test-reference-id',
            currency: 'PHP',
            amount: 1000,
            checkoutMethod: 'ONE_TIME_PAYMENT',
            channelCode: 'PH_GCASH',
            channelProperties: {
                successRedirectURL: 'http://localhost:8000',
            },
            metadata: {
                branch_code: 'tree_branch'
            }
        });
        console.log(resp);

but it always showing this error once I fire the function at the top, need answers please and thank you.

image
mesmur commented 2 years ago

This is a CORS error not an SDK issue. Please read up on CORS, the Xendit API doesn't allow requests from browser like environments.

Here's a similar issue you can read up on: Stackoverflow Issue

Kimmydoray commented 2 years ago

Good day,

Thank you for your response, I would like to know what is the best solution for this issue, cause the idea is once the user click the "Pay" button the api request will fire.

Thank you, Edzel

On Sun, Apr 3, 2022, 01:41 Maahir Ur Rahman @.***> wrote:

This is a CORS error not an SDK issue. Please read up on CORS, the Xendit API doesn't allow requests from browser like environments.

Here's a similar issue you can read up on: Stackoverflow Issue https://stackoverflow.com/questions/53684484/posting-to-external-api-throws-cors-but-it-works-from-postman

— Reply to this email directly, view it on GitHub https://github.com/xendit/xendit-node/issues/152#issuecomment-1086687571, or unsubscribe https://github.com/notifications/unsubscribe-auth/AKQVJYX2IAXYLVVIHRQMQ7LVDCBDFANCNFSM5SLBOXAQ . You are receiving this because you authored the thread.Message ID: @.***>

Kimmydoray commented 2 years ago

Cause it is so weird that they created api for it then they don't allow browser to send request?

On Sun, Apr 3, 2022, 01:48 edzel abliter @.***> wrote:

Good day,

Thank you for your response, I would like to know what is the best solution for this issue, cause the idea is once the user click the "Pay" button the api request will fire.

Thank you, Edzel

On Sun, Apr 3, 2022, 01:41 Maahir Ur Rahman @.***> wrote:

This is a CORS error not an SDK issue. Please read up on CORS, the Xendit API doesn't allow requests from browser like environments.

Here's a similar issue you can read up on: Stackoverflow Issue https://stackoverflow.com/questions/53684484/posting-to-external-api-throws-cors-but-it-works-from-postman

— Reply to this email directly, view it on GitHub https://github.com/xendit/xendit-node/issues/152#issuecomment-1086687571, or unsubscribe https://github.com/notifications/unsubscribe-auth/AKQVJYX2IAXYLVVIHRQMQ7LVDCBDFANCNFSM5SLBOXAQ . You are receiving this because you authored the thread.Message ID: @.***>

mesmur commented 2 years ago

You'll have to do more research to figure this out, but it looks like this is a vue frontend. You can try routing this request through a server you've created. vue frontend -> node backend -> api request to Xendit

There might be a better way to go about it, CORS is standard, it's not just for the Xendit API.

Kimmydoray commented 2 years ago

Good day Maahir,

Yeah, what I did instead of triggering the request thru front end I just trigger it on my backend laravel. Thank you for your response.

On Sun, Apr 3, 2022 at 11:03 AM Maahir Ur Rahman @.***> wrote:

You'll have to do more research to figure this out, but it looks like this is a vue frontend. You can try routing this request through a server you've created. vue frontend -> node backend -> api request to Xendit

There might be a better way to go about it, CORS is standard, it's not just for the Xendit API.

— Reply to this email directly, view it on GitHub https://github.com/xendit/xendit-node/issues/152#issuecomment-1086766317, or unsubscribe https://github.com/notifications/unsubscribe-auth/AKQVJYSV3LR4QVDGH47ZG53VDEC75ANCNFSM5SLBOXAQ . You are receiving this because you authored the thread.Message ID: @.***>

mesmur commented 2 years ago

Glad to hear that, I'll be closing the issue now.

Kimmydoray commented 2 years ago

Thanks I also follow you on linked, your the best <3