I am trying to handle the event in which the user clicks the cancel button when he opens the PayPal client.
The integration is done with Braintree.
Here is the setup:
braintree.paypal.create({
client: clientInstance
}
},
I've seen that braintree has a handle for this event (called 'onCacncelled') but works only on v2. I have asked them what to do, but their solution does not work because uses the setup
property of briantree object, which does not exist in v3. Or at least this is what js error tells me.
Full disclosure: I work at Braintree. If you have any further questions, feel free to contact support.
In v3 you must tokenize the PayPal instance to launch the PayPal login flow. Instead of the onCancelled
callback function like in v2, in v3 it is in the error handling where you can direct tokenization errors or premature flow closures for added control.
See example and link below:
https://braintree.github.io/braintree-web/3.11.0/PayPal.html#tokenize
paypalInstance.tokenize({
flow: 'vault' // Required
// Any other tokenization options
}, function (tokenizeErr, payload) {
button.removeAttribute('disabled');
if (tokenizeErr) {
// Handle tokenization errors or premature flow closure
switch (tokenizeErr.code) {
case 'PAYPAL_POPUP_CLOSED':
console.error('Customer closed PayPal popup.');
break;
case 'PAYPAL_ACCOUNT_TOKENIZATION_FAILED':
console.error('PayPal tokenization failed. See details:', tokenizeErr.details);
break;
case 'PAYPAL_FLOW_FAILED':
console.error('Unable to initialize PayPal flow. Are your options correct?', tokenizeErr.details);
break;
default:
console.error('Error!', tokenizeErr);
}
} else {
// Submit payload.nonce to your server
}
});