-
Notifications
You must be signed in to change notification settings - Fork 193
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
876d90d
commit a7b87c0
Showing
3 changed files
with
178 additions
and
0 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
29 changes: 29 additions & 0 deletions
29
src/Framework/PaymentGateways/Webhooks/ValueObjects/WebhookEventStatus.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,29 @@ | ||
<?php | ||
|
||
namespace Give\Framework\PaymentGateways\Webhooks\ValueObjects; | ||
|
||
use ActionScheduler_Store; | ||
use Give\Framework\Support\ValueObjects\Enum; | ||
|
||
/** | ||
* @unreleased | ||
* | ||
* @method static WebhookEventStatus COMPLETE() | ||
* @method static WebhookEventStatus PENDING() | ||
* @method static WebhookEventStatus RUNNING() | ||
* @method static WebhookEventStatus FAILED() | ||
* @method static WebhookEventStatus CANCELED() | ||
* @method bool isComplete() | ||
* @method bool isPending() | ||
* @method bool isRunning() | ||
* @method bool isFailed() | ||
* @method bool isCanceled() | ||
*/ | ||
class WebhookEventStatus extends Enum | ||
{ | ||
const COMPLETE = ActionScheduler_Store::STATUS_COMPLETE; | ||
const PENDING = ActionScheduler_Store::STATUS_PENDING; | ||
const RUNNING = ActionScheduler_Store::STATUS_RUNNING; | ||
const FAILED = ActionScheduler_Store::STATUS_FAILED; | ||
const CANCELED = ActionScheduler_Store::STATUS_CANCELED; | ||
} |
130 changes: 130 additions & 0 deletions
130
src/Framework/PaymentGateways/Webhooks/WebhookEvents.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,130 @@ | ||
<?php | ||
|
||
namespace Give\Framework\PaymentGateways\Webhooks; | ||
|
||
use Give\Donations\ValueObjects\DonationStatus; | ||
use Give\Framework\PaymentGateways\PaymentGateway; | ||
use Give\Framework\Support\Facades\ActionScheduler\AsBackgroundJobs; | ||
use Give\Subscriptions\ValueObjects\SubscriptionStatus; | ||
|
||
/** | ||
* @unreleased | ||
*/ | ||
class WebhookEvents | ||
{ | ||
/** | ||
* @var PaymentGateway | ||
*/ | ||
protected $gateway; | ||
|
||
/** | ||
* @unreleased | ||
*/ | ||
public function __construct(PaymentGateway $gateway) | ||
{ | ||
$this->gateway = $gateway; | ||
} | ||
|
||
/** | ||
* @unreleased | ||
* | ||
* @return int The webhook event ID. Zero if there was an error setting the event. | ||
*/ | ||
public function setDonationStatus( | ||
DonationStatus $status, | ||
string $gatewayTransactionId, | ||
string $message = '', | ||
$skipRecurringDonations = false | ||
): int { | ||
$hook = "givewp_{$this->gateway::id()}_webhook_event_donation_{$status->getValue()}"; | ||
$args = [$gatewayTransactionId, $message, $skipRecurringDonations]; | ||
$group = $this->getGroup(); | ||
|
||
return AsBackgroundJobs::enqueueAsyncAction($hook, $args, $group); | ||
} | ||
|
||
/** | ||
* @unreleased | ||
* | ||
* @return int The webhook event ID. Zero if there was an error setting the event. | ||
*/ | ||
public function setSubscriptionStatus( | ||
SubscriptionStatus $status, | ||
string $gatewaySubscriptionId, | ||
string $message = '', | ||
bool $initialDonationShouldBeCompleted = false | ||
): int { | ||
$hook = "givewp_{$this->gateway::id()}_webhook_event_subscription_{$status->getValue()}"; | ||
$args = [$gatewaySubscriptionId, $message, $initialDonationShouldBeCompleted]; | ||
$group = $this->getGroup(); | ||
|
||
return AsBackgroundJobs::enqueueAsyncAction($hook, $args, $group); | ||
} | ||
|
||
/** | ||
* @unreleased | ||
* | ||
* @return int The webhook event ID. Zero if there was an error setting the event. | ||
*/ | ||
public function setSubscriptionFirstDonation( | ||
string $gatewayTransactionId, | ||
string $message = '', | ||
bool $setSubscriptionActive = true | ||
): int { | ||
$hook = "givewp_{$this->gateway::id()}_webhook_event_subscription_first_donation"; | ||
$args = [$gatewayTransactionId, $message, $setSubscriptionActive]; | ||
$group = $this->getGroup(); | ||
|
||
return AsBackgroundJobs::enqueueAsyncAction($hook, $args, $group); | ||
} | ||
|
||
/** | ||
* @unreleased | ||
* | ||
* @return int The webhook event ID. Zero if there was an error setting the event. | ||
*/ | ||
public function setSubscriptionRenewalDonation( | ||
string $gatewaySubscriptionId, | ||
string $gatewayTransactionId, | ||
string $message = '' | ||
): int { | ||
$hook = "givewp_{$this->gateway::id()}_webhook_event_subscription_renewal_donation"; | ||
$args = [$gatewaySubscriptionId, $gatewayTransactionId, $message]; | ||
$group = $this->getGroup(); | ||
|
||
return AsBackgroundJobs::enqueueAsyncAction($hook, $args, $group); | ||
} | ||
|
||
/** | ||
* @unreleased | ||
* | ||
* @param string $returnFormat OBJECT, ARRAY_A, or ids. | ||
* @param string $status ActionScheduler_Store::STATUS_COMPLETE, ActionScheduler_Store::STATUS_PENDING, ActionScheduler_Store::STATUS_RUNNING, ActionScheduler_Store::STATUS_FAILED, ActionScheduler_Store::STATUS_CANCELED | ||
* | ||
* @return array | ||
*/ | ||
public function getAll(string $returnFormat = OBJECT, string $status = ''): array | ||
{ | ||
return AsBackgroundJobs::getActionsByGroup($this->getGroup(), $status); | ||
} | ||
|
||
/** | ||
* @unreleased | ||
* | ||
* @param string $status ActionScheduler_Store::STATUS_COMPLETE, ActionScheduler_Store::STATUS_PENDING, ActionScheduler_Store::STATUS_RUNNING, ActionScheduler_Store::STATUS_FAILED, ActionScheduler_Store::STATUS_CANCELED | ||
* | ||
* @return int Total deleted webhook events. | ||
*/ | ||
public function deleteAll(string $status = ''): int | ||
{ | ||
return AsBackgroundJobs::deleteActionsByGroup($this->getGroup(), $status); | ||
} | ||
|
||
/** | ||
* @unreleased | ||
*/ | ||
private function getGroup(): string | ||
{ | ||
return 'give-' . $this->gateway::id(); | ||
} | ||
} |