diff --git a/src/Payum/Nexi/Action/CaptureAction.php b/src/Payum/Nexi/Action/CaptureAction.php index 5ee6dfb..e33314e 100644 --- a/src/Payum/Nexi/Action/CaptureAction.php +++ b/src/Payum/Nexi/Action/CaptureAction.php @@ -18,6 +18,7 @@ use Payum\Core\Request\Capture; use Payum\Core\Request\GetHttpRequest; use Payum\Core\Security\TokenInterface; +use Psr\Log\LoggerInterface; use Sylius\Bundle\PayumBundle\Request\GetStatus; use Sylius\Component\Core\Model\CustomerInterface; use Sylius\Component\Core\Model\OrderInterface; @@ -42,7 +43,8 @@ final class CaptureAction implements ActionInterface, ApiAwareInterface, Gateway public function __construct( private Signer $signer, private Checker $checker, - private RequestParamsDecoderInterface $decoder + private RequestParamsDecoderInterface $decoder, + private LoggerInterface $logger ) { } @@ -55,6 +57,11 @@ public function setApi($api): void $this->api = $api; } + /** + * This action handle 2 requests: the POST is the server2server from the payment gateway to sylius + * and the GET is from the client browser to sylius. + * The latter contains the information to handle the request from the client browser to the payment gateway + */ public function execute($request): void { RequestNotSupportedException::assertSupports($this, $request); @@ -65,22 +72,25 @@ public function execute($request): void /** @var PaymentInterface $payment */ $payment = $request->getFirstModel(); - $isPost = false; + $isS2S = false; /** @var array $requestParams */ $requestParams = $httpRequest->query; if (count($requestParams) === 0) { /** @var array $requestParams */ $requestParams = $httpRequest->request; - $isPost = true; + $isS2S = true; } $requestParams = $this->decoder->decode($requestParams); + $this->logger->debug('Nexi payment request parameters', ['parameter' => $requestParams, 'isS2S' => $isS2S]); if (isset($requestParams['esito'])) { /** @var ArrayObject $details */ $details = $request->getModel(); + $this->logger->debug('Nexi payment request details', ['details' => $details, 'isS2S' => $isS2S]); if ($requestParams['esito'] === Result::OUTCOME_ANNULLO) { + $this->logger->notice('Nexi payment status from http request is cancelled.'); $details->replace($requestParams); return; @@ -94,7 +104,7 @@ public function execute($request): void ); $details->replace($requestParams); - if ($isPost) { + if ($isS2S) { $this->gateway->execute(new GetStatus($payment)); throw new HttpResponse('200'); @@ -133,6 +143,7 @@ public function execute($request): void ); $this->signer->sign($nexiRequest, $this->api->getMacKey(), SignatureMethod::SHA1_METHOD); + $this->logger->debug('Nexi payment request prepared for the client browser', ['request' => $nexiRequest->getParams()]); throw new HttpPostRedirect( $this->api->getApiEndpoint(), diff --git a/src/Payum/Nexi/Action/StatusAction.php b/src/Payum/Nexi/Action/StatusAction.php index 053018d..baf8312 100644 --- a/src/Payum/Nexi/Action/StatusAction.php +++ b/src/Payum/Nexi/Action/StatusAction.php @@ -24,23 +24,33 @@ public function execute($request): void $details = ArrayObject::ensureArrayObject($request->getModel()); if (count($details->getArrayCopy()) === 0) { + $this->logger->warning('HTTP Request has not payment details'); + return; } if ($details->get('esito') === Result::OUTCOME_OK) { + $this->logger->info( + 'Nexi payment status is ok.', + $details->getArrayCopy() + ); $request->markCaptured(); return; } if ($details->get('esito') === Result::OUTCOME_ANNULLO) { + $this->logger->notice( + 'Nexi payment status is cancelled.', + $details->getArrayCopy() + ); $request->markCanceled(); return; } if (in_array($details->get('esito'), [Result::OUTCOME_KO, Result::OUTCOME_ERRORE], true)) { - $this->logger->error( + $this->logger->warning( 'Nexi payment status is not ok or canceled and will be marked as failed.', $details->getArrayCopy() ); @@ -49,7 +59,10 @@ public function execute($request): void return; } - $this->logger->error('Nexi payment status is invalid and will be marked as unknown.', $details->getArrayCopy()); + $this->logger->warning( + 'Nexi payment status is invalid and will be marked as unknown.', + $details->getArrayCopy() + ); $request->markUnknown(); } diff --git a/src/Resources/config/services.xml b/src/Resources/config/services.xml index 75f8d26..8b5d501 100644 --- a/src/Resources/config/services.xml +++ b/src/Resources/config/services.xml @@ -24,6 +24,7 @@ +