The gform_ppcp_webhook Gravity Forms PHP filter allows you to customize the webhook events processed by the Gravity Forms PayPal Checkout Add-On.
Usage
add_filter('gform_ppcp_webhook', 'your_function_name', 10, 2);
Parameters
- $action (array): An associative array containing the event details or an empty array for unsupported event types.
- $event (array): The PayPal Checkout event object for the webhook received. See the PayPal API Reference for details about the event properties.
More information
See Gravity Forms Docs: gform_ppcp_webhook
Examples
Add a note when authorization is cancelled
add_filter('gform_ppcp_webhook', 'ppcp_webhook_action_note', 10, 2);
function ppcp_webhook_action_note($action, $event) {
if (rgar($event, 'event_type') === 'PAYMENT.AUTHORIZATION.VOIDED') {
$action['note'] = sprintf('Authorization has been cancelled (voided). Transaction Id: %s', rgar($action, 'transaction_id'));
}
return $action;
}
Process the PAYMENT.CAPTURE.DECLINED event
add_filter('gform_ppcp_webhook', function($action, $event) {
if (rgar($event, 'event_type') !== 'PAYMENT.CAPTURE.DECLINED' || empty($action['entry_id'])) {
return $action;
}
$entry = GFAPI::get_entry($action['entry_id']);
$payment_status = rgar($entry, 'payment_status');
if (!in_array($payment_status, array('Authorized', 'Pending'))) {
return $action;
}
// Custom code to handle the PAYMENT.CAPTURE.DECLINED event
// ...
return $action;
}, 10, 2);
Handle PAYMENT.CAPTURE.REFUNDED event
add_filter('gform_ppcp_webhook', 'ppcp_webhook_action_refund', 10, 2);
function ppcp_webhook_action_refund($action, $event) {
if (rgar($event, 'event_type') === 'PAYMENT.CAPTURE.REFUNDED') {
// Custom code to handle the PAYMENT.CAPTURE.REFUNDED event
// ...
}
return $action;
}
Handle BILLING.SUBSCRIPTION.PAYMENT.FAILED event
add_filter('gform_ppcp_webhook', 'ppcp_webhook_action_payment_failed', 10, 2);
function ppcp_webhook_action_payment_failed($action, $event) {
if (rgar($event, 'event_type') === 'BILLING.SUBSCRIPTION.PAYMENT.FAILED') {
// Custom code to handle the BILLING.SUBSCRIPTION.PAYMENT.FAILED event
// ...
}
return $action;
}