-
Notifications
You must be signed in to change notification settings - Fork 193
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature: add API for gateway webhook events #7664
Open
glaubersilva
wants to merge
31
commits into
develop
Choose a base branch
from
fun/gateway-webhook-events-api
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
+1,730
−238
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Draft
5 tasks
@jonwaldstein Your last comment inspired me to refactor it and now we have the following approach for methods related to webhook events:
For general methods related to webhooks, we have this:
This is ready for re-review. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Sample using this API in a practical way: impress-org/givewp-addon-boilerplate#67
Description
This PR implements a new webhook events API and attaches it to the GiveWP gateways API, the main goal here is to facilitate the process of handling webhook notifications sent by external payment gateways to GiveWP gateway integrations.
Before we needed to create an async job through our Action Scheduler facade class explicitly, so the code for a webhook notification related to the transaction status change would be something like this:
However, the code above didn't make everything work automatically. We also needed to attach an event handler class to the hook created in the code above.
So in the service provider, we need to add something like this:
This approach is ok, but when you have a bunch of different types of notifications/events to handle you need to pay attention to creating a lot of hooks with certain naming standards.
Also, it's a common thing to implement a custom function to prevent repeating the custom action scheduler group string on each place you need to create an async background job.
This raises the question...
Why a 3rd party developer integrating a a gateway with GiveWP be concerned about it?
In fact, they even need to know (if they don't want to) that GiveWP is using Action Scheduler under the hood.
So, the new gateway webhook events API allows developers to handle the webhook notifications/events easily, just doing something like this:
Inside the gateway class, you can do it like this:
Is just that! They don't need to more spend time naming hooks and enqueueing them with the proper event handler class attached to it, they even need to know anything about Action Scheduler.
Bonus feature:
Another repetitive task related to the gateway webhook is related to the notification URL and the listening notifications method.
In each integration we need to set a route, a method to retrieve the webhook notification URL and then create a method with the same name of the route as in this sample:
Now, all you need to do is this:
And, if you wish to retrieve the webhook notification URL in any place you can use it:
Inside the gateway class, you can do it like this:
If your gateway class doesn't implement the implements
WebhookNotificationsListener
interface the following error will be thrown when you try to use thegetNotificationUrl()
method:Affects
It will make the new gateway integrations easier.
Visuals
Testing Instructions
composer test -- --filter WebhookEvents
command in your terminal;Pre-review Checklist
@unreleased
tags included in DocBlocks