paypal.Button onAuthorize: Alternative to get shipping-addr and payer_id?
Martho
Contributor
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Posted on
May-01-2018
09:03 AM
Hello!
I'm using the paypal-Button. My js-code is like:
paypal.Button.render( { <?php if ($this->test) print "env:'sandbox'"; else print "env:'production'"; ?>, locale: 'de_DE', style: { size: 'medium', color: 'gold', shape: 'pill', label: 'checkout' }, payment: function(resolve, reject) { paypal.request.post('create-payment.php'+q, {}) .then(function(data) { if (data.status == 'Ok') { resolve(data.paymentID); } else { reject(data.msg); alert("Error: "+data.msg); } }) .catch(function(err) { reject(err); }); }, onAuthorize: function(data, actions) { actions.payment.get() .then(function(payment) { var data = payment.payer; data['paymentID'] = payment.id; $.ajax( { type:'POST', url: '/fetchuserdata.php', data: data, cache: false, dataType: 'json', success: function(data, textStatus) { if (data.status == "Ok") { document.location.href = "/continue-checkout.php"; } else { alert("Error: "+data.msg); } }, error: function( jqXHR, textStatus, errorThrown ) { alert('Connection-Error: '+textStatus+' '+errorThrown); } }); }); }, onCancel: function() { // Do nothing } }, '#paypal-express-button');
In fetchuserdata.php I'm doing something like:
$payer_info = $_POST["payer_info"]; $PayerId = $payer_info['payer_id'];
$name = $payer_info['shipping_address']['recipient_name'];
$street = $payer_info['shipping_address']['line1'];
...
My problem is that out of 20 orders today with the Paypal-button, I got 2 where fetchuserdata.php was not called, but the user was sent to "/continue-checkout.php" anyway (which shouldn't be possible...), but got no payer_id so the ExecutePayment went wrong.
Is there a way to get the info stored in "data" in OnAuthorize in PHP via REST API to make really really sure all data is available before checkout?
0 REPLIES 0

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
- Create Pay Links using PayPal API in REST APIs
- Is there a current alternative for deprecated GetRecurringPaymentsProfileDetails? in REST APIs
- Issues constructing authorization endpoint for PayPal login button in SDKs
- The same transaction shows in three accounts. Why in PayPal Payments Standard
- Can you use PayPal Payouts as a Sole Proprietor in REST APIs