I'm trying to integrate PayPal Express Checkout using their checkout.js and instructions provided here: https://developer.paypal.com/docs/integration/direct/express-checkout/integration-jsv4/advanced-integration/
Whenever I click the 'PayPal' button, I get an error about indexOf of undefined coming from the checkout.js script. I do get the modal popup flash very quickly and then disappear.
TypeError: Cannot read property 'indexOf' of undefined
at Object.onSuccess (https://www.paypalobjects.com/api/checkout.js:11449:30)
at _loop2 (https://www.paypalobjects.com/api/checkout.js:1670:62)
at SyncPromise.dispatch (https://www.paypalobjects.com/api/checkout.js:1700:29)
at SyncPromise.then (https://www.paypalobjects.com/api/checkout.js:1718:18)
at Component.buildUrl (https://www.paypalobjects.com/api/checkout.js:11448:40)
at Object.onSuccess (https://www.paypalobjects.com/api/checkout.js:8770:57)
at _loop2 (https://www.paypalobjects.com/api/checkout.js:1670:62)
at SyncPromise.dispatch (https://www.paypalobjects.com/api/checkout.js:1700:29)
at SyncPromise.then (https://www.paypalobjects.com/api/checkout.js:1718:18)
at Function.syncPromiseTry [as try] (https://www.paypalobjects.com/api/checkout.js:1763:42)"
The line it's referencing is within checkout.js:
return props.payment().then(function(token) {
if (token.indexOf("BA-") === 0) {
The code I'm using is straight from PayPal's documentation:
paypal.Button.render({
env: 'sandbox', // Specify 'sandbox' for the test environment
payment: function() {
var CREATE_PAYMENT_URL = '/api/checkout/create-express-payment';
paypal.request.post(CREATE_PAYMENT_URL)
.then(function(data) {
console.log('Payment ID: ', data.paymentId);
resolve(data.paymentId);
})
.catch(function(err) {
reject(err);
});
},
onAuthorize: function(data, actions) {
// Execute the payment here, when the buyer approves the transaction
}
}, '#paypal-button');
I can confirm data.paymentId is in fact coming back with a proper Payment ID, and I've even tried hard coding it into the resolve
call. This error seems to occur before my internal API even gets called to get the payment ID (and then again after it gets called).
I have been trying to reach PayPal technical support for a week now and have not even received an acknowledgement after many requests. Additionally I can't test the REST APIs on Heroku because their sandbox takes over 30 seconds to respond and Heroku times out. This will be the last time I ever use PayPal on a project... and at this rate looks like I need to change from this project ASAP.