createOrder not being directed to OnApprove actions.redirect
FormaServe
Contributor
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Posted on
Oct-13-2023
12:41 AM
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 + '>otal=' + gtotal + '&amount=' + amount + '¤cy=' + 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> 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> Error - PayPal payment error - Please try again.</span>");
window.location.href = "ordering-error.php";
}
Labels:
- Labels:
-
PayPal HTML Buttons
2 REPLIES 2
FormaServe
Contributor
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Oct-16-2023
02:02 AM
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 😞
Phdc
Member
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Oct-19-2024
02:29 PM
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.
Haven't Found your Answer?
It happens. Hit the "Login to Ask the community" button to create a question for the PayPal community.
Related Content
- Are there any restrictions to charge using only html, vanilla javascript and php with rest api? in REST APIs
- PayPal integration with Next, Lambda and API Gateway - 400 Invalid Request in Sandbox Environment
- paypal angular sandbox, receiving not approved order ,when Capture even OnApprove is triggered in Sandbox Environment
- Prevent changing shipping address via SET_PROVIDED_ADDRESS not working. Orders V2 Advanced Checkout in REST APIs
- How long is OrderID valid? in REST APIs