Prometheus Computing
Development, Support, Consultancy

Manually Interacting with PayPal Webhooks

Laravel

Published: May 27, 2024

Author: Andrew Arscott

If you choose to implement your own webhook handlers you can use the builder to setup the webhooks and instruct it to listen to specific events. Unlike the built in command, you can create multiple webhook listeners pointing to different URLs. Please note, if you do use the command to register the built in handlers, this will remove any webhooks registered by this method.

To register a webhook for a given URL, you may do the following:

$webhook = Webhook::builder()
			->setUrl('https://example.com/example_webhook')
			->setEvents(
				[
					WebhookEventEnum::PAYMENT_AUTHORIZATION_CREATED,
					WebhookEventEnum::PAYMENT_CAPTURE_COMPLETED,
				]
			)
			->create();

The setUrl method will be the URL where the webhook event will be sent. The setEvents method accepts an array or Collection of WebhookEventEnum. The list of those currently supported is:

<?php

namespace Drewdan\Paypal\Webhooks\Enums;

enum WebhookEventEnum: string {

	// Payments V2

	case PAYMENT_AUTHORIZATION_CREATED = 'PAYMENT.AUTHORIZATION.CREATED';
	case PAYMENT_AUTHORIZATION_VOIDED = 'PAYMENT.AUTHORIZATION.VOIDED';
	case PAYMENT_CAPTURE_DECLINED = 'PAYMENT.CAPTURE.DECLINED';
	case PAYMENT_CAPTURE_COMPLETED = 'PAYMENT.CAPTURE.COMPLETED';
	case PAYMENT_CAPTURE_PENDING = 'PAYMENT.CAPTURE.PENDING';
	case PAYMENT_CAPTURE_REFUNDED = 'PAYMENT.CAPTURE.REFUNDED';
	case PAYMENT_CAPTURE_REVERSED = 'PAYMENT.CAPTURE.REVERSED';

	// Orders V2

	case CHECKOUT_ORDER_COMPLETED = 'CHECKOUT.ORDER.COMPLETED';
	case CHECKOUT_ORDER_APPROVED = 'CHECKOUT.ORDER.APPROVED';
	case CHECKOUT_ORDER_SAVED = 'CHECKOUT.ORDER.SAVED';
	case CHECKOUT_ORDER_VOIDED = 'CHECKOUT.ORDER.VOIDED';

	case CHECKOUT_PAYMENT_APPROVAL_REVERSED = 'CHECKOUT.PAYMENT-APPROVAL.REVERSED';

	// Disputes

	case CUSTOMER_DISPUTE_CREATED = 'CUSTOMER.DISPUTE.CREATED';

	case CUSTOMER_DISPUTE_RESOLVED = 'CUSTOMER.DISPUTE.RESOLVED';

	case CUSTOMER_DISPUTE_UPDATED = 'CUSTOMER.DISPUTE.UPDATED';

	/**
	 * @deprecated
	 */
	case RISK_DISPUTE_CREATED = 'RISK.DISPUTE.CREATED'; // Deprecated Hook

}

Finally, calling create will create these webhooks in your PayPal. You will then need to make sure your route can handling the incoming webhook events.