Skip to content

Commit

Permalink
jws card handling (#73)
Browse files Browse the repository at this point in the history
  • Loading branch information
krzGablo authored Jun 18, 2024
1 parent b8496cd commit ccf110a
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/Webhook/JWSVerifiedPaymentNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand Down Expand Up @@ -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());
}
}

0 comments on commit ccf110a

Please sign in to comment.