From 1360df1a1f78d0d1b99018b85b9061b9e53f19e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9opold=20Baillard?= Date: Thu, 7 Nov 2019 16:47:23 +0100 Subject: [PATCH 1/2] Allow FIELD_VADS_URL_CHECK option to be modified through Payum gateway config --- src/Action/CaptureAction.php | 7 ++++++- src/Api.php | 1 + src/SystemPayGatewayFactory.php | 1 + 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Action/CaptureAction.php b/src/Action/CaptureAction.php index 209dcc2..d140e22 100644 --- a/src/Action/CaptureAction.php +++ b/src/Action/CaptureAction.php @@ -36,12 +36,17 @@ public function execute($request) return; } - if (null === $details[Api::FIELD_VADS_URL_CHECK] && $request->getToken() instanceof TokenInterface) { + if ($request->getToken() instanceof TokenInterface) { $notifyToken = $this->tokenFactory->createNotifyToken( $request->getToken()->getGatewayName(), $request->getToken()->getDetails() ); + } + if ($this->api && null !== $this->api->getOption($details->toUnsafeArray(), Api::FIELD_VADS_URL_CHECK)) { + $details[Api::FIELD_VADS_URL_CHECK] = $this->api->getOption($details->toUnsafeArray(), Api::FIELD_VADS_URL_CHECK) . $notifyToken->getHash(); + } + elseif (null === $details[Api::FIELD_VADS_URL_CHECK]) { $details[Api::FIELD_VADS_URL_CHECK] = $notifyToken->getTargetUrl(); } diff --git a/src/Api.php b/src/Api.php index 915f36f..736ab34 100644 --- a/src/Api.php +++ b/src/Api.php @@ -268,6 +268,7 @@ public function doPayment(array $details): void $details[self::FIELD_VADS_PAGE_ACTION] = $this->getOption($details, self::FIELD_VADS_PAGE_ACTION); $details[self::FIELD_VADS_PAYMENT_CONFIG] = $this->getOption($details, self::FIELD_VADS_PAYMENT_CONFIG); $details[self::FIELD_VADS_VERSION] = $this->getOption($details, self::FIELD_VADS_VERSION); + $details[self::FIELD_VADS_URL_CHECK] = $this->getOption($details, self::FIELD_VADS_URL_CHECK); $details['signature'] = $this->signatureGenerator->generate($details, $this->getCertificate()); diff --git a/src/SystemPayGatewayFactory.php b/src/SystemPayGatewayFactory.php index 64053f1..c55e08d 100644 --- a/src/SystemPayGatewayFactory.php +++ b/src/SystemPayGatewayFactory.php @@ -38,6 +38,7 @@ protected function populateConfig(ArrayObject $config): void Api::FIELD_VADS_PAGE_ACTION => Api::PAGE_ACTION_PAYMENT, Api::FIELD_VADS_PAYMENT_CONFIG => Api::PAYMENT_CONFIG_SINGLE, Api::FIELD_VADS_VERSION => Api::V2, + Api::FIELD_VADS_URL_CHECK => null, 'sandbox' => true, 'certif_prod' => null, 'certif_test' => null, From f8434821162a1c769a34644b8a969866443371c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9opold=20Baillard?= Date: Thu, 7 Nov 2019 16:47:58 +0100 Subject: [PATCH 2/2] Payement status AUTHORIZED must be considered as captured under certain conditions. --- src/Action/StatusAction.php | 2 +- src/Api.php | 4 +- src/Request/RequestStatusApplier.php | 55 ++++++++++++++++++---------- 3 files changed, 38 insertions(+), 23 deletions(-) diff --git a/src/Action/StatusAction.php b/src/Action/StatusAction.php index c41b8cb..8327aaa 100644 --- a/src/Action/StatusAction.php +++ b/src/Action/StatusAction.php @@ -32,7 +32,7 @@ public function execute($request) $model = ArrayObject::ensureArrayObject($request->getModel()); - $this->requestStatusApplier->apply($model[Api::FIELD_VADS_TRANS_STATUS], $request); + $this->requestStatusApplier->apply($model[Api::FIELD_VADS_TRANS_STATUS], $request, $model); } /** diff --git a/src/Api.php b/src/Api.php index 736ab34..92aee3e 100644 --- a/src/Api.php +++ b/src/Api.php @@ -297,9 +297,9 @@ protected function getCertificate(): string /** * @return mixed */ - protected function getOption(array $details, string $name) + public function getOption(array $details, string $name) { - if (array_key_exists($name, $details)) { + if (array_key_exists($name, $details) && null !== $details[$name]) { return $details[$name]; } diff --git a/src/Request/RequestStatusApplier.php b/src/Request/RequestStatusApplier.php index 85f7369..9361522 100644 --- a/src/Request/RequestStatusApplier.php +++ b/src/Request/RequestStatusApplier.php @@ -1,6 +1,6 @@ > */ protected $appliers = []; - public function __construct() + /** @var \ArrayAccess|null */ + protected $model; + + public function __construct () { - $this->appliers[Api::STATUS_ABANDONED] = function (Request $request) { $request->markCanceled(); }; - $this->appliers[Api::STATUS_AUTHORISED] = function (Request $request) { $request->markAuthorized(); }; - $this->appliers[Api::STATUS_AUTHORISED_TO_VALIDATE] = function (Request $request) { $request->markPending(); }; - $this->appliers[Api::STATUS_CANCELLED] = function (Request $request) { $request->markCanceled(); }; - $this->appliers[Api::STATUS_CAPTURED] = function (Request $request) { $request->markCaptured(); }; - $this->appliers[Api::STATUS_CAPTURE_FAILED] = function (Request $request) { $request->markFailed(); }; - $this->appliers[Api::STATUS_EXPIRED] = function (Request $request) { $request->markExpired(); }; - $this->appliers[Api::STATUS_INITIAL] = function (Request $request) { $request->markNew(); }; - $this->appliers[Api::STATUS_NOT_CREATED] = function (Request $request) { $request->markUnknown(); }; - $this->appliers[Api::STATUS_REFUSED] = function (Request $request) { $request->markCanceled(); }; - $this->appliers[Api::STATUS_SUSPENDED] = function (Request $request) { $request->markSuspended(); }; - $this->appliers[Api::STATUS_UNDER_VERIFICATION] = function (Request $request) { $request->markPending(); }; - $this->appliers[Api::STATUS_WAITING_AUTHORISATION] = function (Request $request) { $request->markPending(); }; - $this->appliers[Api::STATUS_WAITING_AUTHORISATION_TO_VALIDATE] = function (Request $request) { $request->markPending(); }; + $this->appliers[Api::STATUS_ABANDONED] = function ( Request $request ) { $request->markCanceled(); }; + $this->appliers[Api::STATUS_AUTHORISED] = function ( Request $request ) { $this->checkPaymentAuthorized( $request ); }; + $this->appliers[Api::STATUS_AUTHORISED_TO_VALIDATE] = function ( Request $request ) { $request->markPending(); }; + $this->appliers[Api::STATUS_CANCELLED] = function ( Request $request ) { $request->markCanceled(); }; + $this->appliers[Api::STATUS_CAPTURED] = function ( Request $request ) { $request->markCaptured(); }; + $this->appliers[Api::STATUS_CAPTURE_FAILED] = function ( Request $request ) { $request->markFailed(); }; + $this->appliers[Api::STATUS_EXPIRED] = function ( Request $request ) { $request->markExpired(); }; + $this->appliers[Api::STATUS_INITIAL] = function ( Request $request ) { $request->markNew(); }; + $this->appliers[Api::STATUS_NOT_CREATED] = function ( Request $request ) { $request->markUnknown(); }; + $this->appliers[Api::STATUS_REFUSED] = function ( Request $request ) { $request->markCanceled(); }; + $this->appliers[Api::STATUS_SUSPENDED] = function ( Request $request ) { $request->markSuspended(); }; + $this->appliers[Api::STATUS_UNDER_VERIFICATION] = function ( Request $request ) { $request->markPending(); }; + $this->appliers[Api::STATUS_WAITING_AUTHORISATION] = function ( Request $request ) { $request->markPending(); }; + $this->appliers[Api::STATUS_WAITING_AUTHORISATION_TO_VALIDATE] = function ( Request $request ) { $request->markPending(); }; } - public function apply(?string $status, Request $request): void + public function apply ( ?string $status, Request $request, ?\ArrayAccess $model ) + : void { - if (null === $status) { + if ( null === $status ) { $request->markNew(); return; } - if (!array_key_exists($status, $this->appliers)) { + if ( !array_key_exists( $status, $this->appliers ) ) { $request->markUnknown(); return; } - $this->appliers[$status]($request); + $this->model = $model; + + $this->appliers[$status]( $request ); + } + + private function checkPaymentAuthorized ( Request $request ) + { + if ( $this->model && $this->model[Api::FIELD_VADS_RESULT] === "00" ) { + $request->markCaptured(); + } else { + $request->markAuthorized(); + } } }