Search code examples
paypalpaypal-rest-sdk

Paypal Implement refunds


I'm trying to integrate "Paypal smart buttons" in my webpage which was with a deprecated paypal implementation. On this new integration I'm using server-side SDK and I can create and capture an order and save data in my DB.

The problem I have now is to implement the refund. On my last implementation I had an IPN Listener and whenever I get a refund I could register it in my BD. Since now IPN listener is deprecated, how can I implemented the "listener function"? Is the webhooks the new approach to implement the listener? I know that with Webhooks Management API I can list all webhooks events, but then how can I related them with the payment made and registered before in my BD?

I've already read lots of official paypal documentation but this is no clear to me, yet.


Solution

  • Register a webhook listener URL for the events you want, including refunds.

    When you receive a refund webhook event at that URL, the body of the webhook will contain information about the capture/payment object (transaction id) that was refunded.

    If in addition to the capture/transaction id you need some additional id for reconciliation purposes, there are two pieces of information you can include in the original order creation.

    • an invoice_id, which is essentially your system's unique order ID. It must be unique, never used before for a successful completed transaction since it is used to block any future duplicate (accidental) payment attempts of the same ID.
    • a custom_id, which can have any arbitrary value and is not indexed and not visible to the payer.