-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: add webhook notification logic
- Loading branch information
1 parent
8fdfbe6
commit 90c4420
Showing
6 changed files
with
138 additions
and
25 deletions.
There are no files selected for viewing
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
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
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
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
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
58 changes: 58 additions & 0 deletions
58
src/OffSiteGateway/Webhooks/OffSiteGatewaysWebhookNotificationHandler.php
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
|
||
namespace GiveAddon\OffSiteGateway\Webhooks; | ||
|
||
use Give\Framework\Support\Facades\ActionScheduler\AsBackgroundJobs; | ||
use GiveAddon\OffSiteGateway\DataTransferObjects\OffSiteGatewayWebhookNotification; | ||
|
||
/** | ||
* @unreleased | ||
*/ | ||
class OffSiteGatewaysWebhookNotificationHandler | ||
{ | ||
/** | ||
* @unreleased | ||
*/ | ||
public function __invoke(OffSiteGatewayWebhookNotification $webhookNotification) | ||
{ | ||
/** | ||
* Allow developers to handle the webhook notification. | ||
* | ||
* @unreleased | ||
* | ||
* @param OffSiteGatewayWebhookNotification $webhookNotification | ||
*/ | ||
do_action("givewp_off-site_gateway_sample_webhook_notification_handler", $webhookNotification); | ||
|
||
// We will handle recurring donations in a separate submodule sample that will enable Subscription on the Off-site gateway sample. | ||
if ($this->isRecurringDonation($webhookNotification)) { | ||
return; | ||
} | ||
|
||
switch (strtolower($webhookNotification->paymentStatus)) { | ||
case 'complete': | ||
AsBackgroundJobs::enqueueAsyncAction( | ||
'givewp_off-site_gateway_sample_event_donation_completed', | ||
[$webhookNotification->gatewayPaymentId], | ||
'ADDON_TEXTDOMAIN' | ||
); | ||
break; | ||
case 'failed': | ||
// Handle failed transactions here... | ||
break; | ||
case 'cancelled': | ||
// Handle cancelled transactions here... | ||
break; | ||
default: | ||
break; | ||
} | ||
} | ||
|
||
/** | ||
* @unreleased | ||
*/ | ||
private function isRecurringDonation(OffSiteGatewayWebhookNotification $webhookNotification): bool | ||
{ | ||
return 'subscription' === $webhookNotification->notificationType; | ||
} | ||
} |