diff --git a/src/Webhook/JWSVerifiedPaymentNotification.php b/src/Webhook/JWSVerifiedPaymentNotification.php index 0d66778..9286959 100644 --- a/src/Webhook/JWSVerifiedPaymentNotification.php +++ b/src/Webhook/JWSVerifiedPaymentNotification.php @@ -8,6 +8,7 @@ use Tpay\OriginApi\Utilities\Util; use Tpay\OriginApi\Validators\FieldsConfigValidator; use Tpay\OriginApi\Validators\PaymentTypes\PaymentTypeBasic; +use Tpay\OriginApi\Validators\PaymentTypes\PaymentTypeCard; /** * @psalm-suppress UndefinedClass @@ -45,6 +46,10 @@ public function __construct($merchantSecret, $productionMode = true) */ public function getNotification() { + if (isset($_POST['card'])) { + return $this->getCardNotification(); + } + $notification = $this->getNotificationObject(); $this->checkMd5($notification); @@ -53,6 +58,14 @@ public function getNotification() return $notification; } + public function getCardNotification() + { + $notification = $this->getCardNotificationObject(); + $this->checkJwsSignature(); + + return $notification; + } + protected function checkJwsSignature() { $jws = isset($_SERVER['HTTP_X_JWS_SIGNATURE']) ? $_SERVER['HTTP_X_JWS_SIGNATURE'] : null; @@ -164,4 +177,13 @@ private function getNotificationObject() return $this->getResponse(new PaymentTypeBasic()); } + + private function getCardNotificationObject() + { + if (!isset($_POST['card']) && !isset($_POST['order_id'])) { + throw new TException('Not recognised or invalid notification type. POST: '.json_encode($_POST)); + } + + return $this->getResponse(new PaymentTypeCard()); + } }