diff --git a/examples/Notifications/AllNotificationsExample.php b/examples/Notifications/AllNotificationsExample.php index 1870fe9..b780017 100644 --- a/examples/Notifications/AllNotificationsExample.php +++ b/examples/Notifications/AllNotificationsExample.php @@ -6,8 +6,10 @@ use PSX\Cache\SimpleCache; use Tpay\Example\ExamplesConfig; use Tpay\OpenApi\Model\Objects\NotificationBody\BasicPayment; +use Tpay\OpenApi\Model\Objects\NotificationBody\BlikAliasExpired; use Tpay\OpenApi\Model\Objects\NotificationBody\BlikAliasRegister; use Tpay\OpenApi\Model\Objects\NotificationBody\BlikAliasUnregister; +use Tpay\OpenApi\Model\Objects\NotificationBody\BlikAliasUpdated; use Tpay\OpenApi\Model\Objects\NotificationBody\MarketplaceTransaction; use Tpay\OpenApi\Model\Objects\NotificationBody\Tokenization; use Tpay\OpenApi\Model\Objects\NotificationBody\TokenUpdate; @@ -106,6 +108,28 @@ public function getVerifiedNotification() exit('TRUE'); } + if ($notification instanceof BlikAliasUpdated) { + // Notification about change in blik expiry date + + $value = $notification->value->getValue(); + // The above example will check the notification and return the value of deleted token + // You can access any notification field by $notification->fieldName + + // $blikAliasUpdatedProcessor->process($notification) + exit('TRUE'); + } + + if ($notification instanceof BlikAliasExpired) { + // Notification about blik alias expiry + + $value = $notification->value->getValue(); + // The above example will check the notification and return the value of deleted token + // You can access any notification field by $notification->fieldName + + // $blikAliasExpiredProcessor->process($notification) + exit('TRUE'); + } + // Ignore and silence other notification types if not expected http_response_code(404); exit('FALSE'); diff --git a/src/Model/Objects/NotificationBody/AbstractBlikAlias.php b/src/Model/Objects/NotificationBody/AbstractBlikAlias.php new file mode 100644 index 0000000..d7c4e9b --- /dev/null +++ b/src/Model/Objects/NotificationBody/AbstractBlikAlias.php @@ -0,0 +1,54 @@ + Value::class, + 'type' => Type::class, + 'expirationDate' => ExpirationDate::class, + ]; + + /** @var Value */ + public $value; + + /** @var Type */ + public $type; + + /** @var ExpirationDate */ + public $expirationDate; + + static protected $requiresExpirationDate = false; + + public function getRequiredFields() + { + $fields = [ + $this->value, + $this->type, + ]; + if (static::$requiresExpirationDate) { + $fields[] = $this->expirationDate; + } + + return $fields; + } + + public function toArray() + { + $data = [ + 'value' => $this->value->getValue(), + 'type' => $this->type->getValue(), + ]; + if (static::$requiresExpirationDate) { + $data['expirationDate'] = $this->expirationDate->getValue(); + } + + return $data; + } +} diff --git a/src/Model/Objects/NotificationBody/BlikAliasExpired.php b/src/Model/Objects/NotificationBody/BlikAliasExpired.php new file mode 100644 index 0000000..fea0a37 --- /dev/null +++ b/src/Model/Objects/NotificationBody/BlikAliasExpired.php @@ -0,0 +1,8 @@ + Value::class, - 'type' => Type::class, - 'expirationDate' => ExpirationDate::class, - ]; - - /** @var Value */ - public $value; - - /** @var Type */ - public $type; - - /** @var ExpirationDate */ - public $expirationDate; - - public function getRequiredFields() - { - return [ - $this->value, - $this->type, - $this->expirationDate, - ]; - } - - public function toArray() - { - return [ - 'value' => $this->value->getValue(), - 'type' => $this->type->getValue(), - 'expirationDate' => $this->expirationDate->getValue(), - ]; - } + static protected $requiresExpirationDate = true; } diff --git a/src/Model/Objects/NotificationBody/BlikAliasUnregister.php b/src/Model/Objects/NotificationBody/BlikAliasUnregister.php index 7e8f587..d3c2fd0 100644 --- a/src/Model/Objects/NotificationBody/BlikAliasUnregister.php +++ b/src/Model/Objects/NotificationBody/BlikAliasUnregister.php @@ -2,36 +2,7 @@ namespace Tpay\OpenApi\Model\Objects\NotificationBody; -use Tpay\OpenApi\Model\Fields\Notification\BlikAlias\Type; -use Tpay\OpenApi\Model\Fields\Notification\BlikAlias\Value; -use Tpay\OpenApi\Model\Objects\Objects; - -class BlikAliasUnregister extends Objects +class BlikAliasUnregister extends AbstractBlikAlias { - const OBJECT_FIELDS = [ - 'value' => Value::class, - 'type' => Type::class, - ]; - - /** @var Value */ - public $value; - - /** @var Type */ - public $type; - - public function getRequiredFields() - { - return [ - $this->value, - $this->type, - ]; - } - - public function toArray() - { - return [ - 'value' => $this->value->getValue(), - 'type' => $this->type->getValue(), - ]; - } + static protected $requiresExpirationDate = false; } diff --git a/src/Model/Objects/NotificationBody/BlikAliasUpdated.php b/src/Model/Objects/NotificationBody/BlikAliasUpdated.php new file mode 100644 index 0000000..93acb0d --- /dev/null +++ b/src/Model/Objects/NotificationBody/BlikAliasUpdated.php @@ -0,0 +1,8 @@ +