-
Notifications
You must be signed in to change notification settings - Fork 194
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: add new methods and contract for webhook notifications
- Loading branch information
1 parent
e006205
commit aac3de3
Showing
3 changed files
with
87 additions
and
6 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
src/Framework/PaymentGateways/Contracts/WebhookNotificationsListener.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,18 @@ | ||
<?php | ||
|
||
namespace Give\Framework\PaymentGateways\Contracts; | ||
|
||
/** | ||
* @since 2.20.0 | ||
*/ | ||
interface WebhookNotificationsListener | ||
{ | ||
/** | ||
* Update subscription payment method. | ||
* | ||
* | ||
* @unreleased | ||
*/ | ||
public function webhookNotificationsListener(); | ||
} | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
namespace Give\Framework\PaymentGateways\Webhooks; | ||
|
||
use Give\Framework\Exceptions\Primitives\Exception; | ||
use Give\Framework\PaymentGateways\PaymentGateway; | ||
|
||
/** | ||
* @unreleased | ||
*/ | ||
class Webhook | ||
{ | ||
/** | ||
* @unreleased | ||
* | ||
* @var string $webhookNotificationsListener | ||
*/ | ||
private $webhookNotificationsListener = 'webhookNotificationsListener'; | ||
|
||
/** | ||
* @unreleased | ||
* | ||
* @var PaymentGateway $paymentGateway | ||
*/ | ||
private $paymentGateway; | ||
|
||
/** | ||
* @unreleased | ||
* | ||
* @var WebhookEvents $webhookEvents | ||
*/ | ||
public $events; | ||
|
||
public function __construct(PaymentGateway &$paymentGateway) | ||
{ | ||
$paymentGateway->routeMethods[] = $this->webhookNotificationsListener; | ||
$this->paymentGateway = &$paymentGateway; | ||
$this->events = new WebhookEvents($paymentGateway::id()); | ||
} | ||
|
||
/** | ||
* @unreleased | ||
* | ||
* @throws Exception | ||
*/ | ||
public function getNotificationUrl(): string | ||
{ | ||
if ( ! $this->paymentGateway->canListeningWebhookNotifications()) { | ||
throw new Exception('Gateway does not support listening webhook notifications.'); | ||
} | ||
|
||
return $this->paymentGateway->generateGatewayRouteUrl($this->webhookNotificationsListener); | ||
} | ||
} |