Hi, I’m trying to use Xendit for the payment process on my app. I’ve tried using custom JS and REST api request, both of which are to no avail. Whenever I use the REST api request, I always stumble upon a network error and when I try to make the request through a server, it returns an error 500.
As for the custom JS, I get blocked by the CORS policy.
Attached are some screenshots, JS code, and the api I’m trying to use:
https://developers.xendit.co/api-reference/?javascript#invoices
let body =
{
'external_id': 'testFee',
'amount': 1000,
'description': 'TestInvoiceFee',
'customer': {
'given_names': 'John Waldo',
'surname': 'Magalona',
'email': 'waldo.magalona@ahglab.com'
},
'customer_notification_preference': {
'invoice_created': [
'email'
],
'invoice_reminder': [
'email'
],
'invoice_paid': [
'email'
],
'invoice_expired': [
'email'
]
},
'success_redirect_url': window.location.href,
'failure_redirect_url': window.location.href,
'currency': 'PHP'
};
fetch('https://api.xendit.co/v2/invoices', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: 'Basic eG5kX2RldmVsb3BtZW50X0ZnenRmdlkwWFJONXFrZDBGRVhxcXJZZ0tWblgyUmJrbWt5Vlh2bjhrUW8zYklzcFVSTWllMjFxbTZCTlg9PTo='
},
body: JSON.stringify(body),
})
.then((response) => response.json())
.then((data) => {
console.log('Success:', data);
})
.catch((error) => {
console.error('Error:', error);
});```
![image|690x333](upload://t1a1aFJOYN1G5VHfOmEkG0X8GVm.jpeg)
![image|690x332](upload://AmfjjPdL2zF0JtYTwqv7rXIzV2y.jpeg)
![image|690x331](upload://3rgP3nqWt3H1Iz5yxfRzCddLClI.jpeg)