'fetch' is undefined
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I'm doing the paypal integration in the server side, using java, got stuck in the following code in the front end with the javascript erro of - 'fetch' is undefined
The paypal popup screen appears then disappears.
Any help please?
<script src="https://www.paypal.com/sdk/js?client-id=my-idxxxxxxxx"></script>
<div id="paypal-button-container"></div>
<script>
paypal.Buttons({
createOrder: function() {
return fetch('<%=request.getContextPath()%>/paypalCreateOrder.htm', {
method: 'post',
headers: {
'content-type': 'application/json'
}
}).then(function(res) {
return res.json();
}).then(function(data) {
return data.orderID;
});
},
onApprove: function(data) {
return fetch('<%=request.getContextPath()%>/paypalCaptureOrder.htm', {
method: 'post',
headers: {
'content-type': 'application/json'
},
body: JSON.stringify({
orderID: data.orderID
})
}).then(function(res) {
return res.json();
}).then(function(details) {
alert('Transaction approved by ' + details.payer_given_name);
});
}
}).render('#paypal-button-container');
</script>
- Labels:
-
PayPal HTML Buttons
Haven't Found your Answer?
It happens. Hit the "Login to Ask the community" button to create a question for the PayPal community.
- Passing Internal Order ID Between Webhooks (CHECKOUT.ORDER.APPROVED & PAYMENT.CAPTURE.COMPLETED) in REST APIs
- Add Others data in SDKs
- When I do PayPal capture Order, I keep on getting Invalid Request Connection in REST APIs
- API TRANSACTION_REFUSED in Sandbox when Capturing Payment in REST APIs
- Error: "Unable to change shipping method. Please try again." in PayPal popup in REST APIs