Smart Button wont work if cart contains more than six items *****SEEMS TO BE WORKING NOW!

wezken
Contributor
Contributor

Hello, I have incorporated Smart Buttons into my shopping cart and they work perfectly up to a maximum of 5 items in the cart. However if I go above that number the PayPal browser opens momentarily then closes again. My button code is as follows:

<script> function initPayPalButton() { paypal.Buttons({ style: { shape: 'pill', color: 'gold', layout: 'vertical', label: 'paypal', size: 'responsive', label: 'checkout', }, createOrder: function(data, actions) { /* tpvar gets the $total_price amount from the Cart*/ var tpvar = <?php echo json_encode($total_price); ?>; var descrvar = <?php echo json_encode($description); ?>; return actions.order.create({ purchase_units: [{"description":"Your FalnaMusic Order","amount":{"currency_code":"GBP","value":tpvar}}] }); }, onApprove: function(data, actions) { return actions.order.capture().then(function(orderData) { // Full available details console.log('Capture result', orderData, JSON.stringify(orderData, null, 2)); actions.redirect('https://www.fmtest.info/after_payment.php'); }); }, onError: function(err) { console.log(err); } }).render('#paypal-button-container'); } initPayPalButton(); </script>

I have tried this in production and sandbox environments but the result is the same in both. I have also tested with different total prices to see if there was a limit on that, but it doesn't make any difference.  The problem therefore seems to be with the actual number of items in the cart, but the Smart Button doesnt access this, only the total cost of the transaction, so I'm baffled.

Could anyone help with this please?

*******EDIT******

Now I've returned to my computer after a break of around 4 hours and would you believe it, it all seems to be working normally now, even though I haven't changed anything in the code during that time.  If it stops working again I'll come back to this, but hopefully I wont need to trouble you any more!

Login to Me Too
1 REPLY 1

MTS_Jennifer
Moderator
Moderator

Hello,

Thank you for posting to the PayPal Sandbox Community.

Over the last few months, PayPal has been migrating the Sandbox Community. As a result from time to time there are some errors.

Most likely your issue was related to the Sandbox migration.

Thank you for confirming that the issue is currently resolved.

Thank you,

Jennifer

MTS

PayPal

Login to Me Too

Haven't Found your Answer?

It happens. Hit the "Login to Ask the community" button to create a question for the PayPal community.