Search code examples
javascriptpaypalpaypal-webhooks

Paypal JS SDK and WebHooks - get payer details


I'm integrating the new Paypal smart payment button

<script src="https://www.paypal.com/sdk/js?...>
paypal.Buttons({
createOrder(data, actions) {
// ...
onApprove: function(data, actions) {
// Capture the funds from the transaction
 return actions.order.capture().then(function(details) {
 // Show a success message to your buyer
 alert('Transaction completed by ' + details.payer.name.given_name);
 });
 }
).render('#paypal-button');

I created an app in Sandbox and registered Webhooks to all events. When a payment is triggered I get everything working and a webhook event of type PAYMENT.CAPTURE.COMPLETED is fired.

I'm sure I'm missing something in the process but I can't link this payment to the payer details. I don't know where the payer details are so I can't process the order on my side.

I searched the whole Google and PP documentation without success, anyone can help me? Thanks!!


Solution

  • You don't need to use Webhooks for this. The response of the payment capture is returned right on onApprove callback. Just print your "details" variable and you will see it.

    If you still want to use Webhooks, you can match the payment id with the one received in the webhook.

    Example: https://jsfiddle.net/pedrinho/frgc93x2/1/code