Skip to content

Commit

Permalink
[BOT] Migrate hotfix 2.8.4 to GitHub.
Browse files Browse the repository at this point in the history
  • Loading branch information
Hadjer Chabane committed Feb 13, 2024
1 parent acc2531 commit 86c2c25
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 19 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
2.8.4, 2024-02-13:
- Improve IPN errors management.

2.8.3, 2024-01-03:
- Set return mode to POST by default.
- [technical] Improve features management by plugin variant.
Expand Down
5 changes: 5 additions & 0 deletions Controller/Adminhtml/Payment/Check.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ public function execute()
$response = $data['response'];

$case = $this->checkProcessor->execute($order, $response);
if ($case === 'payment_ko_on_order_ok') {
header(\Lyranetwork\Payzen\Helper\Payment::HEADER_ERROR_500);
die($response->getOutputForGateway($case));
}

return $this->renderResponse($response->getOutputForGateway($case));
} catch (\Lyranetwork\Payzen\Model\ResponseException $e) {
return $this->renderResponse($e->getMessage());
Expand Down
5 changes: 5 additions & 0 deletions Controller/Payment/Check.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ public function execute()
$response = $data['response'];

$case = $this->checkProcessor->execute($order, $response);
if ($case === 'payment_ko_on_order_ok') {
header(\Lyranetwork\Payzen\Helper\Payment::HEADER_ERROR_500);
die($response->getOutputForGateway($case));
}

return $this->renderResponse($response->getOutputForGateway($case));
} catch (\Lyranetwork\Payzen\Model\ResponseException $e) {
return $this->renderResponse($e->getMessage());
Expand Down
25 changes: 17 additions & 8 deletions Controller/Payment/Rest/Check.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
*/
namespace Lyranetwork\Payzen\Controller\Payment\Rest;

use \Lyranetwork\Payzen\Helper\Payment as PayzenPaymentHelper;
use Lyranetwork\Payzen\Model\ResponseException;
use Magento\Framework\DataObject;

Expand Down Expand Up @@ -89,13 +90,15 @@ protected function prepareResponse($params)
// Check the validity of the request.
if (! $this->restHelper->checkResponseFormat($params)) {
$this->dataHelper->log('Invalid response received. Content: ' . json_encode($params), \Psr\Log\LogLevel::ERROR);
throw new ResponseException('<span style="display:none">KO-Invalid IPN request received.'."\n".'</span>');
header(PayzenPaymentHelper::HEADER_ERROR_500);
die('<span style="display:none">KO-Invalid IPN request received.'."\n".'</span>');
}

$answer = json_decode($params['kr-answer'], true);
if (! is_array($answer)) {
$this->dataHelper->log('Invalid response received. Content: ' . json_encode($params), \Psr\Log\LogLevel::ERROR);
throw new ResponseException('<span style="display:none">KO-Invalid IPN request received.' . "\n" . '</span>');
header(PayzenPaymentHelper::HEADER_ERROR_500);
die('<span style="display:none">KO-Invalid IPN request received.' . "\n" . '</span>');
}

// Wrap payment result to use traditional order creation tunnel.
Expand All @@ -115,7 +118,8 @@ protected function prepareResponse($params)
$orderId = (int) $response->get('order_id');
if (! $orderId) {
$this->dataHelper->log("Received empty Order ID.", \Psr\Log\LogLevel::ERROR);
throw new ResponseException('Order ID is empty.');
header(PayzenPaymentHelper::HEADER_ERROR_500);
die('Order ID is empty.');
}

$order = $this->orderFactory->create();
Expand All @@ -126,7 +130,8 @@ protected function prepareResponse($params)
if ($quoteId = (int) $response->getExtInfo('quote_id')) {
if ($this->quoteRepository->get($quoteId)->getId()) {
$this->dataHelper->log("Quote not found with ID #{$quoteId}.", \Psr\Log\LogLevel::ERROR);
throw new ResponseException($response->getOutputForGateway('order_not_found'));
header(PayzenPaymentHelper::HEADER_ERROR_500);
die($response->getOutputForGateway('order_not_found'));
}

$quote = $this->quoteRepository->get($quoteId);
Expand All @@ -149,11 +154,13 @@ protected function prepareResponse($params)
$order->loadByIncrementId($quote->getReservedOrderId());
if (! $order->getId()) {
$this->dataHelper->log("Order cannot be created. Quote ID: #{$quoteId}, reserved order ID: #{$quote->getReservedOrderId()}.", \Psr\Log\LogLevel::ERROR);
throw new ResponseException($response->getOutputForGateway('ko', 'Error when trying to create order.'));
header(PayzenPaymentHelper::HEADER_ERROR_500);
die($response->getOutputForGateway('ko', 'Error when trying to create order.'));
}
} else {
$this->dataHelper->log("Order not found with ID #{$orderId}.", \Psr\Log\LogLevel::ERROR);
throw new ResponseException("Order not found with ID #{$orderId}.");
header(PayzenPaymentHelper::HEADER_ERROR_500);
die("Order not found with ID #{$orderId}.");
}
}

Expand Down Expand Up @@ -186,7 +193,8 @@ protected function prepareResponse($params)
\Psr\Log\LogLevel::ERROR
);

throw new ResponseException($response->getOutputForGateway('auth_fail'));
header(PayzenPaymentHelper::HEADER_ERROR_500);
die($response->getOutputForGateway('auth_fail'));
}

return [
Expand All @@ -206,7 +214,8 @@ protected function saveOrderForQuote($quote)
$this->onepage->saveOrder();
} catch (Exception $e) {
$this->dataHelper->log("Order cannot be created. Quote ID: #{$quote->getId()}, reserved order ID: #{$quote->getReservedOrderId()}.", \Psr\Log\LogLevel::ERROR);
throw new ResponseException('Error when trying to create order.');
header(PayzenPaymentHelper::HEADER_ERROR_500);
die('Error when trying to create order.');
}
}
}
15 changes: 9 additions & 6 deletions Controller/Processor/CheckProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
*/
namespace Lyranetwork\Payzen\Controller\Processor;

use \Lyranetwork\Payzen\Helper\Payment as PayzenPaymentHelper;
use \Lyranetwork\Payzen\Model\Api\Form\Api as PayzenApi;
use Lyranetwork\Payzen\Model\ResponseException;

class CheckProcessor
{
Expand Down Expand Up @@ -60,7 +60,7 @@ class CheckProcessor
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
* @param \Magento\Store\Model\App\Emulation $emulation
* @param \Lyranetwork\Payzen\Helper\Data $dataHelper
* @param \Lyranetwork\Payzen\Helper\Payment $paymentHelper
* @param PayzenPaymentHelper $paymentHelper
* @param \Magento\Sales\Model\OrderFactory $orderFactory
* @param \Lyranetwork\Payzen\Model\Api\Form\ResponseFactory $payzenResponseFactory
* @param \Magento\Sales\Model\Order\CreditmemoFactory $creditmemoFactory
Expand All @@ -70,7 +70,7 @@ public function __construct(
\Magento\Store\Model\StoreManagerInterface $storeManager,
\Magento\Store\Model\App\Emulation $emulation,
\Lyranetwork\Payzen\Helper\Data $dataHelper,
\Lyranetwork\Payzen\Helper\Payment $paymentHelper,
PayzenPaymentHelper $paymentHelper,
\Magento\Sales\Model\OrderFactory $orderFactory,
\Lyranetwork\Payzen\Model\Api\Form\ResponseFactory $payzenResponseFactory,
\Magento\Sales\Model\Order\CreditmemoFactory $creditmemoFactory,
Expand Down Expand Up @@ -275,7 +275,8 @@ public function prepareResponse($params)
\Psr\Log\LogLevel::ERROR
);

throw new ResponseException($response->getOutputforGateway('auth_fail'));
header(PayzenPaymentHelper::HEADER_ERROR_500);
die($response->getOutputforGateway('auth_fail'));
}

return [
Expand All @@ -290,7 +291,8 @@ private function findOrder($params)
$orderId = key_exists('vads_order_id', $params) ? $params['vads_order_id'] : null;
if (! $orderId) {
$this->dataHelper->log('Order ID is empty. Content: ' . json_encode($params), \Psr\Log\LogLevel::ERROR);
throw new ResponseException('<span style="display:none">KO-Invalid IPN request received.'."\n".'</span>');
header(PayzenPaymentHelper::HEADER_ERROR_500);
die('<span style="display:none">KO-Invalid IPN request received.'."\n".'</span>');
}

// Loading order.
Expand All @@ -299,7 +301,8 @@ private function findOrder($params)

if (! $order->getId()) {
$this->dataHelper->log("Order not found with ID #{$orderId}.", \Psr\Log\LogLevel::ERROR);
throw new ResponseException('<span style="display:none">KO-Order not found.' . "\n" . '</span>');
header(PayzenPaymentHelper::HEADER_ERROR_500);
die('<span style="display:none">KO-Order not found.' . "\n" . '</span>');
}

return $order;
Expand Down
2 changes: 2 additions & 0 deletions Helper/Payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ class Payment

const BRAND_USER_CHOICE = 'payzen_brand_user_choice';

const HEADER_ERROR_500 = 'HTTP/1.1 500 Internal Server Error';

const SUCCESS = 1;
const FAILURE = 2;
const CANCEL = 3;
Expand Down
14 changes: 11 additions & 3 deletions Model/Api/Form/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,6 @@ public static function getSuccessStatuses()
{
return array(
'AUTHORISED',
'AUTHORISED_TO_VALIDATE', // TODO is this a pending status?
'CAPTURED',
'ACCEPTED',
'PARTIALLY_AUTHORISED'
Expand All @@ -279,6 +278,8 @@ public static function getPendingStatuses()
'UNDER_VERIFICATION',
'PRE_AUTHORISED',
'WAITING_FOR_PAYMENT',
'AUTHORISED_TO_VALIDATE',
'SUSPENDED',
'PENDING'
);
}
Expand All @@ -289,7 +290,11 @@ public static function getPendingStatuses()
*/
public static function getCancelledStatuses()
{
return array('ABANDONED');
return array(
'ABANDONED',
'NOT_CREATED',
'CANCELLED'
);
}

/**
Expand All @@ -298,7 +303,10 @@ public static function getCancelledStatuses()
*/
public static function getToValidateStatuses()
{
return array('WAITING_AUTHORISATION_TO_VALIDATE', 'AUTHORISED_TO_VALIDATE');
return array(
'WAITING_AUTHORISATION_TO_VALIDATE',
'AUTHORISED_TO_VALIDATE'
);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"php" : "~7|~8"
},
"type" : "magento2-module",
"version" : "2.8.3",
"version" : "2.8.4",
"license" : "OSL-3.0",
"autoload" : {
"files" : [
Expand Down
2 changes: 1 addition & 1 deletion etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<payzen>
<general>
<support_email><![CDATA[[email protected]]]></support_email>
<plugin_version>2.8.3</plugin_version>
<plugin_version>2.8.4</plugin_version>
<gateway_version>V2</gateway_version>
<cms_identifier>Magento_2.x</cms_identifier>
<enable_logs>1</enable_logs>
Expand Down

0 comments on commit 86c2c25

Please sign in to comment.