Introduction

The PayPal Webhooks for WordPress plugin is a foundation for building tools that automate tasks when transactions occur on your PayPal account.

It is extensible using WordPress hooks based on the name of the PayPal Webhook.  These hooks allow you to trigger functions within your own plugins or themes when PayPal sends a Webhook to you.

If you have not already done so, you may want to review our install guide and setup guide to get the plugin ready for use.

PayPal Webhook Data Collection

All PayPal Webhook data sent to your site will be saved in the PayPal Webhooks section of your WordPress admin panel.

Click to view the details of any PayPal Webhook and you will find all of the raw data associated with that webhook, as well as a hook function template that can be used to quickly prepare a hook function for that particular Webhook event type.

PayPal Webhook Raw Data

WordPress Hook Function Template

PayPal Webhook Events – WordPress Hooks

PayPal provides many different Webhooks based on all the different events available within PayPal.  Review the PayPal Webhook Event Names documentation for a list of all the available Webhook events.

For each PayPal Webhook Event provided, our plugins creates a WordPress action hook that will trigger when this event occurs.  Our action hook names follow this format, where {event_name} is replaced by the PayPal Webhook event name.

[angelleye_paypal_webhooks_{event_name}]

For example, to trigger a function when the PayPal PAYMENT.SALE.COMPLETED Webhook is triggered, you would use the following WordPress hook function:

[angelleye_paypal_webhooks_payment_sale_completed]

Hook Function Template Usage

Within the Webhook details screen, you will find a hook template you can use to quickly setup a function that will trigger when that Webhook is triggered.

Copy/paste the hook function to your own plugin or theme as a quick start to building PayPal Webhooks functionality.

The following example would create a hook into the plugin that is triggered when the PAYMENT.SALE.COMPLETED Webhook is triggered by PayPal.

Hook Function Template Sample
add_action('angelleye_paypal_webhooks_payment_sale_completed', 'my_function_name', 10, 1);
function my_function_name($webhook_data) {

// Parse data from webhook's $webhook_data array

$webhook_id               = isset($webhook_data['id']) ? $webhook_data['id'] : '';
$webhook_create_time      = isset($webhook_data['create_time']) ? $webhook_data['create_time'] : '';
$webhook_event_type       = isset($webhook_data['event_type']) ? $webhook_data['event_type'] : '';
$webhook_resource_type    = isset($webhook_data['resource_type']) ? $webhook_data['resource_type'] : '';
$webhook_resource_version = isset($webhook_data['resource_version']) ? $webhook_data['resource_version'] : '';
$webhook_summary          = isset($webhook_data['summary']) ? $webhook_data['summary'] : '';
$webhook_resource         = isset($webhook_data['resource']) ? $webhook_data['resource'] : '';
$webhook_links            = isset($webhook_data['links']) ? $webhook_data['links'] : '';
$webhook_zts              = isset($webhook_data['zts']) ? $webhook_data['zts'] : '';
$webhook_event_version    = isset($webhook_data['event_version']) ? $webhook_data['event_version'] : '';


/**
* At this point you can use the data to generate email notifications,
* update your local database, hit 3rd party web services, or anything
* else you might want to automate based on this type of Webhook Event.
*
* View the raw data for a Webhook event to see what data is available,
* and where it's add in the array. Then parse it accordingly, and use
* it within your script as needed. */ }

PayPal Webhook Data Accessibility

Within your WordPress hook functions, the PayPal Webhook data will be available to you in a $webhook_data[] array.

For example, consider the following PayPal webhook received:

PayPal PAYMENT.SALE.COMPLETED Webhook Raw Data
Array
(
    [id] => WH-96Y17588TU965163D-3DU69097E4803123D
    [create_time] => Array
        (
            [0] => 2019-05-24T10:35:01.000Z
        )

    [event_type] => Array
        (
            [0] => PAYMENT.SALE.COMPLETED
        )

    [resource_type] => Array
        (
            [0] => sale
        )

    [resource_version] => Array
        (
            [0] => 
        )

    [summary] => Array
        (
            [0] => Payment completed for $ 17.5 USD
        )

    [resource] => Array
        (
            [0] => Array
                (
                    [id] => 31K39213LT572370J
                    [state] => completed
                    [amount] => Array
                        (
                            [total] => 17.50
                            [currency] => USD
                            [details] => Array
                                (
                                    [subtotal] => 17.50
                                )

                        )

                    [payment_mode] => INSTANT_TRANSFER
                    [protection_eligibility] => ELIGIBLE
                    [protection_eligibility_type] => ITEM_NOT_RECEIVED_ELIGIBLE,UNAUTHORIZED_PAYMENT_ELIGIBLE
                    [payment_hold_status] => RELEASED
                    [transaction_fee] => Array
                        (
                            [value] => 0.81
                            [currency] => USD
                        )

                    [invoice_number] => AEINV-207
                    [custom] => CUST-PayPalFashions
                    [create_time] => 2019-05-24T10:30:52Z
                    [update_time] => 2019-05-24T10:35:00Z
                    [links] => Array
                        (
                            [0] => Array
                                (
                                    [href] => https://api.sandbox.paypal.com/v1/payments/sale/31K39213LT572370J
                                    [rel] => self
                                    [method] => GET
                                )

                            [1] => Array
                                (
                                    [href] => https://api.sandbox.paypal.com/v1/payments/sale/31K39213LT572370J/refund
                                    [rel] => refund
                                    [method] => POST
                                )

                        )

                )

        )

    [links] => Array
        (
            [0] => Array
                (
                    [0] => Array
                        (
                            [href] => https://api.sandbox.paypal.com/v1/notifications/webhooks-events/WH-96Y17588TU965163D-3DU69097E4803123D
                            [rel] => self
                            [method] => GET
                        )

                    [1] => Array
                        (
                            [href] => https://api.sandbox.paypal.com/v1/notifications/webhooks-events/WH-96Y17588TU965163D-3DU69097E4803123D/resend
                            [rel] => resend
                            [method] => POST
                        )

                )

        )

    [zts] => Array
        (
            [0] => 
        )

    [event_version] => Array
        (
            [0] => 1.0
        )

    [event_verified_status] => Array
        (
            [0] => SUCCESS
        )

)

In this example, if you want to pull the PayPal Webhook ID from the data, you would use:

$webhook_id = isset($webhook_data['id']) ? $webhook_data['id'] : '';

 

If you want to pull the invoice number you would use:

$invoice_number = isset($webhook_data['resource'][0]['invoice_number']) ? $webhook_data['resource'][0]['invoice_number'] : '';

 The same method can be used to pull any other data you need out of the Webhook POST from PayPal.

Need More Help?

If you are confused about how to use this plugin or have additional questions, feel free to submit a ticket to our help desk.  Our support team will be happy to help!

AngellEYE PayPal Newsletter Signup

Subscribe To Our Newsletter

Join our list for the latest promotions, news, and updates from AngellEYE and PayPal!

You have Successfully Subscribed!

Pin It on Pinterest