This is my first time trying to integrate Standard Checkout in my website using JS SDK.
I am using the sample code as it is in the help (just changing ClientID with my ClientID). It apparently works ok: buttons are showing in my page, and when I click it it opens paypal login window, I log in with my sandbox personal account, set payment method (paypal balance), then click the button to pay. Then that page closes and I am returned to my website, where an alert pop-ups saying transaction completed etc.
But if I add code for the onError() handler, when I am returned to my website, the onApprove() alert does not show, and it instead shows the alert I did put on the onError() handler...
Here is the code I am using:
<script src="https://www.paypal.com/sdk/js?client-id=MY_CLIENT_ID_HERE¤cy=EUR"></script>
<!-- Set up a container element for the button -->
<div id="paypal-button-container"></div>
<script>
paypal.Buttons({
// Sets up the transaction when a payment button is clicked
createOrder: function (data, actions) {
return actions.order.create({
purchase_units: [{
amount: {
value: '5.25' // Can reference variables or functions. Example: `value: document.getElementById('...').value`
}
}]
});
},
onCancel: function (data) {
alert("inside onCancel() handler...");
console.log("inside onCancel() handler...");
},
onError: function (err) {
alert("inside onError() handler...");
console.log("inside onError() handler...");
},
// Finalize the transaction after payer approval
onApprove: function (data, actions) {
return actions.order.capture().then(function (orderData) {
// Successful capture! For dev/demo purposes:
alert("en el handler onApprove()...");
console.log("en el handler onApprove()...");
console.log('Capture result', orderData, JSON.stringify(orderData, null, 2));
var transaction = orderData.purchase_units[0].payments.captures[0];
alert('Transaction ' + transaction.status + ': ' + transaction.id + '\n\nSee console for all available details');
});
},
}).render('#paypal-button-container');
</script>
What am I doing wrong?
... View more