Reputation: 807
According to the documentation on PayPal's Developer site under Advanced server integration, redirect URLs must be provided in a payment call but:
(…) PayPal does not automatically call these URLs. PayPal invokes your onAuthorize function when the buyer authorizes the payment. that are provided will not be used.
So I developed my code assuming this to be true, and on my local setup this works fine. But when I push it to my staging server, the redirect URLs being passed in the SDK are being called, and my onAuthorize
function ignored. It's even opening a new popup window and then opening my payment-execute.php
script there, with appended GET
queries, ignoring my POST
ed values.
Here's a sample of the JS I'm using:
paypal.Button.render({
env: 'sandbox',
payment: function(resolve, reject) {
paypal.request.post(
'/path-to-inc/payment.php',
{
action: 'create_paypal_payment',
orderId: order_id,
postId: post_id,
}
)
.then(function(data) {
resolve(data.paymentID);
})
.catch(function(err) {
reject(err);
});
},
onAuthorize: function(data) {
paypal.request.post('/path-to-inc/payment-execute.php',
{
paymentID: data.paymentID,
payerID: data.payerID,
postId: post_id
})
.then(function(data) {
window.location.reload();
})
.catch(function(err) {
console.log('Error');
});
}
}, '#paypal-button');
And a snippet from the PHP file:
$redirectUrls = new RedirectUrls();
$redirectUrls->setReturnUrl('http://website.com/payment-execute.php')
->setCancelUrl('http://website.com/checkout');
$payment = new Payment();
$payment->setIntent('sale')
->setPayer($payer)
->setRedirectUrls($redirectUrls)
->setTransactions(array($transaction));
try {
$payment->create($apiContext);
echo json_encode( ['paymentID' => $payment->id] );
} catch (Exception $e) {
error_log( 'Payment error: ' . $e->getMessage() );
}
Upvotes: 1
Views: 704
Reputation: 46
I have the same issue since 1 day ago, I was working with onAuthorize call in old tests
Edit 1: Well testing with the old script versions and I get the expected result using this one https://www.paypalobjects.com/api/checkout.4.0.38.js
Upvotes: 1