Skip to content
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
wants to merge 31 commits into
base: develop
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
a7b87c0
feature: add WebhookEvents api
glaubersilva Dec 27, 2024
3e43409
feature: add service provider
glaubersilva Jan 2, 2025
1d4ed35
feature: add subscription events
glaubersilva Jan 2, 2025
5bd3a0a
refactor: remove parameter
glaubersilva Jan 2, 2025
ac58b07
refactor: move setGateway logic to constructor
glaubersilva Jan 2, 2025
be0c8af
refactor: remove status parameters
glaubersilva Jan 2, 2025
b818166
refactor: move register logic to give_init hook
glaubersilva Jan 2, 2025
5a75b35
refactor: extract status logic to action classes
glaubersilva Jan 2, 2025
911936d
refactor: remove unused value object
glaubersilva Jan 2, 2025
13a759d
refactor: better naming
glaubersilva Jan 2, 2025
a3bd5c3
refactor: use sprintf
glaubersilva Jan 2, 2025
de63d93
tests: add tests for the new classes
glaubersilva Jan 3, 2025
c8100d6
refactor: deprecated subscription statuses
glaubersilva Jan 3, 2025
9005cc4
refactor: instantiate the webhook events object
glaubersilva Jan 3, 2025
b51c389
feature: add missing event handler classes for subscription statuses
glaubersilva Jan 3, 2025
1899c09
refactor: change parameter type
glaubersilva Jan 3, 2025
44856df
tests: add new tests for new event handler classes
glaubersilva Jan 3, 2025
160b685
Merge branch 'develop' into fun/gateway-webhook-events-api
glaubersilva Jan 10, 2025
d7e57e1
chore: update composer.lock
glaubersilva Jan 10, 2025
374e0bd
refactor: add new methods for each status and tweak unit tests
glaubersilva Jan 24, 2025
19f03ca
tests: move logic used only on tests and create new tests for the new…
glaubersilva Jan 24, 2025
9d619c0
tests: simplify logic
glaubersilva Jan 24, 2025
e006205
refactor: rename methods related to subscription donations
glaubersilva Jan 24, 2025
aac3de3
feature: add new methods and contract for webhook notifications
glaubersilva Jan 24, 2025
e894899
doc: update unreleased tag
glaubersilva Jan 24, 2025
aee1666
refactor: add $args parameter
glaubersilva Jan 24, 2025
a617c1a
tests: add WebhookTest class
glaubersilva Jan 24, 2025
c91ce8b
doc: tweak comment
glaubersilva Jan 24, 2025
fa2ffe0
refactor: add condition before register route
glaubersilva Jan 24, 2025
dfbf875
fix: wrong condition
glaubersilva Jan 24, 2025
e5d8dcb
refactor: tweak exception message
glaubersilva Jan 24, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
tests: move logic used only on tests and create new tests for the new…
… methods
  • Loading branch information
glaubersilva committed Jan 24, 2025
commit 19f03ca56af0f3426a2c464deaa524f3b363f0cf
46 changes: 12 additions & 34 deletions src/Framework/PaymentGateways/Webhooks/WebhookEvents.php
Original file line number Diff line number Diff line change
@@ -220,23 +220,19 @@ public function setSubscriptionRenewalDonation(
/**
* @unreleased
*
* @param string $returnFormat OBJECT, ARRAY_A, or ids.
*
* @return array
* @return int The webhook event ID. Zero if there was an error setting the event.
*/
public function getAll(string $returnFormat = OBJECT): array
{
return AsBackgroundJobs::getActionsByGroup($this->getGroup(), $returnFormat);
}
protected function setDonationStatus(
DonationStatus $status,
string $gatewayTransactionId,
string $message = '',
$skipRecurringDonations = false
): int {
$hook = sprintf('givewp_%s_webhook_event_donation_status_%s', $this->gatewayId, $status->getValue());
$args = [$gatewayTransactionId, $message, $skipRecurringDonations];
$group = $this->getGroup();

/**
* @unreleased
*
* @return int Total deleted webhook events.
*/
public function deleteAll(): int
{
return AsBackgroundJobs::deleteActionsByGroup($this->getGroup());
return AsBackgroundJobs::enqueueAsyncAction($hook, $args, $group);
}

/**
@@ -262,28 +258,10 @@ protected function setSubscriptionStatus(
return AsBackgroundJobs::enqueueAsyncAction($hook, $args, $group);
}

/**
* @unreleased
*
* @return int The webhook event ID. Zero if there was an error setting the event.
*/
protected function setDonationStatus(
DonationStatus $status,
string $gatewayTransactionId,
string $message = '',
$skipRecurringDonations = false
): int {
$hook = sprintf('givewp_%s_webhook_event_donation_status_%s', $this->gatewayId, $status->getValue());
$args = [$gatewayTransactionId, $message, $skipRecurringDonations];
$group = $this->getGroup();

return AsBackgroundJobs::enqueueAsyncAction($hook, $args, $group);
}

/**
* @unreleased
*/
private function getGroup(): string
protected function getGroup(): string
{
return 'givewp-payment-gateway-' . $this->gatewayId;
}
Loading
Loading