createOrder not being directed to OnApprove actions.redirect

FormaServe
Contributor
Contributor

Using paypal.Buttons when creating an order through createOrder pp successfully processes our request then returns to our original page, not the onApprove actions.redirect page we specify.  The error processing function does not come into play also.

 

Works fine in the sandbox. 

 

Any ideas what is happening? TIA

 

                       // Sets up the transaction when a payment button is clicked
                          createOrder: function(data, actions) {
                            var gtotal = document.getElementById('gtotal').value;
                            gtotal = gtotal.replace('£', '');
                            var sessionID = document.getElementById('sessionID').value;
                            var discount = document.getElementById('discount').value;
                            discount = discount.replace('£', '');

                            return actions.order.create({
                              purchase_units: [{
                                amount: {
                                  value: gtotal
                                }
                              }]
                            });
                          },

                          // Finalise the transaction after payer approval
                          onApprove: function(data, actions) {
                            return actions.order.capture().then(function(orderData) {
                              // Successful capture!
                              var transaction = orderData.purchase_units[0].payments.captures[0];
     
                              // All done - over to email page ...
                              actions.redirect(server + 'ordering6pp.php?transactionstatus=' + transaction.status + '&transactionid=' + transaction.id + '&sessionID=' + sessionID + '&discount=' + discount + '&gtotal=' + gtotal + '&amount=' + amount + '&currency=' + currency + '&orderNumber=' + orderNumber);
                            });
                          },

                          // Error handling - Cancelled
                          onCancel: function(data) {
                            // Show a cancel page, or return to cart
                            $('#errMessage').html("<span class='alert alert-danger fs-round fw-bold mt-5 mb-2'><span class='material-icons'>report</span>&nbsp;Error - PayPal payment cancelled - Choose another payment method.</span>");
                          },

                          // Error handling
                          onError: function(err) {
                            $('#errMessage').html("<span class='alert alert-danger fs-round fw-bold mt-5 mb-2'><span class='material-icons'>report</span>&nbsp;Error - PayPal payment error - Please try again.</span>");
                            window.location.href = "ordering-error.php";
                          }
Login to Me Too
2 REPLIES 2

FormaServe
Contributor
Contributor

Forgot to say, this has been working fine for years in production. Yesterday one order came through file, the rest didn't.  Very fustrating, difficult to debug as working fine in sandbox 😞

Login to Me Too

Phdc
Member
Member
Did you ever find a solution to this? My page has been working fine for months, but suddenly successful transactions are firing onCancel instead of onApprove. Sounds similar to your issue.
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.