0

I'm setting up PayPal's REST API using checkout.js --

<div id="paypal-button"></div>
<script src="https://www.paypalobjects.com/api/checkout.js"></script>
<script>
paypal.Button.render({
  env: 'sandbox',
  client: {
    sandbox: 'XXXXXXXX'
  },
  payment: function (data, actions) {
    return actions.payment.create({
      transactions: [{
        amount: {
          total: '10.00',
          currency: 'USD'
        }
      }]
    });
  },
  onAuthorize: function (data, actions) {
    return actions.payment.execute()
      .then(function () {
        window.alert('Thank you for your purchase!');
      });
  }
}, '#paypal-button');
</script>

The page works great when I test it. I set up a webhook listener and get:

...
[resource_type] => sale
[event_type] => PAYMENT.SALE.COMPLETED
...

Other stuff in there too, but it does not include anything about the buyer! Mostly I need their email address.

I do get the buyer's info if I use PayPal's webhook simulator and tell it to send me a CHECKOUT.ORDER.COMPLETED (instead of a PAYMENT.SALE.COMPLETED) which comes with everything:

...
[resource_type] => checkout-order
[event_type] => CHECKOUT.ORDER.COMPLETED
...
[payer] => (Everything I need)

So this question is: Is there a way to change my transaction from a PAYMENT.SALE.COMPLETED to a CHECKOUT.ORDER.COMPLETED, or at least to tell that I want the email address included in the webhook?

CaymanCarver
  • 389
  • 3
  • 14
  • I'm having the exact same issue... were you able to find a resolution to this problem? – FerX32 Nov 10 '18 at 18:35
  • 1
    No I was not. I had to make a second API call to pull the details of the transaction. Annoying, but it addressed my needs. – CaymanCarver Nov 11 '18 at 19:02
  • 2
    Gotcha. Thanks for getting back to me on that. Would you happen to remember what API you've called, and what you've passed in (OrderID, PaymentID, or)? – FerX32 Nov 11 '18 at 19:14
  • 1
    P.S. I feel like this could be a common problem for others in the future as well. If you'd like to make an answer (answering your own question), I'm sure it would help others. – FerX32 Nov 11 '18 at 19:15
  • same issue here. did you find a solution using webhook? or can you explain your workaround with sample code? – silk May 31 '19 at 21:58

1 Answers1

2

The only answer I found was to follow this up with a second call, this time to the GetExpressCheckoutDetails NVP API. Gets the job done, but it really shouldn't be necessary.

CaymanCarver
  • 389
  • 3
  • 14