From 211ff57fd46f15729a62d94742fb48666b3221e9 Mon Sep 17 00:00:00 2001 From: Jason Judge Date: Wed, 1 Sep 2021 14:10:59 +0100 Subject: [PATCH] Issue #64 extent response factory to work with server requests Since we now have v1 and v2 3DS callbacks, being able to detect which one we have and instantiating the correct response model, is now vert useful. --- src/Factory/ResponseFactory.php | 13 +++++++++++++ src/Request/Model/StrongCustomerAuthentication.php | 2 +- src/Response/Model/Card.php | 2 +- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/Factory/ResponseFactory.php b/src/Factory/ResponseFactory.php index 4e9adb4..e6472ea 100644 --- a/src/Factory/ResponseFactory.php +++ b/src/Factory/ResponseFactory.php @@ -14,6 +14,7 @@ use Academe\Opayo\Pi\Request\AbstractRequest; use Psr\Http\Message\ResponseInterface; use Academe\Opayo\Pi\Response; +use Academe\Opayo\Pi\ServerRequest; use Academe\Opayo\Pi\Helper; use Teapot\StatusCode\Http; @@ -138,6 +139,18 @@ public static function fromData($data, $httpCode = null) return Response\InstructionCollection::fromData($data, $httpCode); } + // A 3DS v2 callback result, aka notification (this is a server request). + + if (Helper::dataGet($data, 'cres')) { + return ServerRequest\Secure3Dv2Notification::fromData($data, $httpCode); + } + + // A 3DS v1 callbacl result (this is a server request). + + if (Helper::dataGet($data, 'PaRes')) { + return ServerRequest\Secure3DAcs::fromData($data, $httpCode); + } + // A 204 with an empty body is a quiet accpetance that what was send is successful. // e.g. returned when a CVV is linked to a card. diff --git a/src/Request/Model/StrongCustomerAuthentication.php b/src/Request/Model/StrongCustomerAuthentication.php index 53dabfb..32db418 100644 --- a/src/Request/Model/StrongCustomerAuthentication.php +++ b/src/Request/Model/StrongCustomerAuthentication.php @@ -115,7 +115,7 @@ public function __construct( string $browserUserAgent, string $challengeWindowSize, string $transType, - array $additionalOptions = [], + array $additionalOptions = [] ) { $this->notificationUrl = $notificationUrl; diff --git a/src/Response/Model/Card.php b/src/Response/Model/Card.php index fcefb0d..58349dd 100644 --- a/src/Response/Model/Card.php +++ b/src/Response/Model/Card.php @@ -19,7 +19,7 @@ class Card implements JsonSerializable /** * @var Flag indicates this is a reusable card identifier; it has been used before. */ - protected $reusable; + protected $reusable = false; /** * @var Captured (safe) details for the card.