Skip to content

Commit

Permalink
Merge branch 'hotfix/2.8.7'
Browse files Browse the repository at this point in the history
  • Loading branch information
Hadjer Chabane committed May 10, 2024
2 parents abadd71 + b6e8224 commit da7b198
Show file tree
Hide file tree
Showing 16 changed files with 131 additions and 52 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
2.8.7, 2024-05-10:
- Bug fix: Fix error 400 related to other payment means validation.
- Bug fix: Fix order info for email template.
- Bug fix: Fix payment means logos management.
- Bug fix: Fix refunding order issue in case of multi-currency Magento Shop.
- [embedded] Bug fix: Fix update order status on each payment attempt.
- Added new transaction status REFUND_TO_RETRY.

2.8.6, 2024-04-10:
- [embedded] Take into account the notification URL on payment abandoned by buyer.
- [smartform] Bug fix: Fix error related to display Smartform in a popin.
Expand Down
9 changes: 1 addition & 8 deletions Controller/Processor/CheckProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,7 @@ public function execute(
];

if ($order->isCanceled() && $response->isAcceptedPayment() && $response->getExtInfo('update_order')) {
// Un-cancel order items.
$orderItems = $order->getAllItems();
foreach ($orderItems as $item) {
$item->setData("qty_canceled",0)->save();
}

// Save order and optionally create invoice.
$this->paymentHelper->registerOrder($order, $response);
$this->paymentHelper->unCancelOrder($order, $response);

// Display notification URL confirmation message.
return 'payment_ok';
Expand Down
15 changes: 1 addition & 14 deletions Controller/Processor/ResponseProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,20 +107,7 @@ public function execute(
$this->dataHelper->log("Payment for order #{$order->getIncrementId()} has been confirmed by client return !" .
" This means the notification URL did not work.", \Psr\Log\LogLevel::WARNING);

// Un-cancel order items.
$orderItems = $order->getAllItems();
foreach ($orderItems as $item) {
$item->setData("qty_canceled",0)->save();
}

// Save order and optionally create invoice.
$this->paymentHelper->registerOrder($order, $response);

// Un-cancel order items.
$orderItems = $order->getAllItems();
foreach ($orderItems as $item) {
$item->setData("qty_canceled",0)->save();
}
$this->paymentHelper->unCancelOrder($order, $response);

// Display success page.
return [
Expand Down
2 changes: 1 addition & 1 deletion Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ public function getCcTypeImageSrc($card)
{
$name = strtolower($card) . '.png';

if ($this->isUploadFileImageExists('cc/' . $card)) {
if ($this->isUploadFileImageExists('cc/' . $name)) {
return $this->storeManager->getStore()->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA) .
'payzen/images/cc/' . $name;
} else {
Expand Down
72 changes: 71 additions & 1 deletion Helper/Payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,21 @@ class Payment
*/
protected $updateCouponUsages;

/**
* @var \Magento\Framework\Registry
* */
protected $registry;

/**
* @var \Magento\Quote\Model\QuoteRepository
*/
protected $quoteRepository;

/**
* @var \Magento\Sales\Api\OrderManagementInterface
*/
protected $orderManagement;

/**
* @param \Magento\Framework\Event\ManagerInterface $eventManager
* @param \Magento\Sales\Api\TransactionRepositoryInterface $transactionRepository
Expand All @@ -133,6 +148,9 @@ class Payment
* @param \Magento\Sales\Model\Order\Config $orderConfig
* @param \Magento\Framework\Stdlib\DateTime\TimezoneInterface $timezone
* @param \Magento\SalesRule\Model\Coupon\UpdateCouponUsages $updateCouponUsages
* @param \Magento\Framework\Registry $registry
* @param \Magento\Quote\Model\QuoteRepository $quoteRepository
* @param \Magento\Sales\Api\OrderManagementInterface $orderManagement
*/
public function __construct(
\Magento\Framework\Event\ManagerInterface $eventManager,
Expand All @@ -146,7 +164,10 @@ public function __construct(
\Magento\Framework\DataObject\Factory $dataObjectFactory,
\Magento\Sales\Model\Order\Config $orderConfig,
\Magento\Framework\Stdlib\DateTime\TimezoneInterface $timezone,
\Magento\SalesRule\Model\Coupon\UpdateCouponUsages $updateCouponUsages
\Magento\SalesRule\Model\Coupon\UpdateCouponUsages $updateCouponUsages,
\Magento\Framework\Registry $registry,
\Magento\Quote\Model\QuoteRepository $quoteRepository,
\Magento\Sales\Api\OrderManagementInterface $orderManagement
) {
$this->eventManager = $eventManager;
$this->transactionRepository = $transactionRepository;
Expand All @@ -160,6 +181,9 @@ public function __construct(
$this->orderConfig = $orderConfig;
$this->timezone = $timezone;
$this->updateCouponUsages = $updateCouponUsages;
$this->registry = $registry;
$this->quoteRepository = $quoteRepository;
$this->orderManagement = $orderManagement;
}

/**
Expand All @@ -172,6 +196,9 @@ public function registerOrder(
\Magento\Sales\Model\Order $order,
\Lyranetwork\Payzen\Model\Api\Form\Response $response
) {
$this->registry->unregister('current_order');
$this->registry->register('current_order', $order);

$this->dataHelper->log("Saving payment for order #{$order->getIncrementId()}.");

// Update authorized amount.
Expand Down Expand Up @@ -830,6 +857,49 @@ public function cancelOrder(
}
}

/**
* Un-cancel order.
*
* @param \Magento\Sales\Model\Order $order
* @param \Lyranetwork\Payzen\Model\Api\Form\Response $response
*/
public function unCancelOrder(
\Magento\Sales\Model\Order $order,
\Lyranetwork\Payzen\Model\Api\Form\Response $response
) {
$order = $this->orderManagement->place($order);

// Un-cancel order items.
foreach ($order->getAllItems() as $item) {
$item->setTaxCanceled(0);
$item->setDiscountTaxCompensationCanceled(0);
$item->setData("qty_canceled", 0)->save();
}

// Reset order attribute set when cancelled.
$order->setSubtotalCanceled(0);
$order->setBaseSubtotalCanceled(0);
$order->setTaxCanceled(0);
$order->setBaseTaxCanceled(0);
$order->setShippingCanceled(0);
$order->setBaseShippingCanceled(0);
$order->setDiscountCanceled(0);
$order->setBaseDiscountCanceled(0);
$order->setTotalCanceled(0);
$order->setBaseTotalCanceled(0);

// Save order and optionally create invoice.
$this->registerOrder($order, $response);

$this->eventManager->dispatch(
'checkout_submit_all_after',
[
'order' => $order,
'quote' => $this->quoteRepository->get($order->getQuoteId())
]
);
}

/**
* Prepare transaction data and call \Magento\Sales\Model\Order\Payment::addTransaction.
*
Expand Down
11 changes: 10 additions & 1 deletion Helper/Payment/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public function getPaymentMethods()
];
}

$payzenOtherTitle = $methods['payzen_other']['title']; // Get multi payment general title.
$payzenOtherTitle = $methods['payzen_other']['title']; // Get other payment means general title.
unset($methods['payzen_other']);

// Add other payment virtual methods to the list.
Expand All @@ -91,4 +91,13 @@ public function getPaymentMethods()

return $methods;
}

public function getMethodInstance($code)
{
if (strpos($code, 'payzen_other_') === 0) {
return parent::getMethodInstance('payzen_other');
}

return parent::getMethodInstance($code);
}
}
5 changes: 3 additions & 2 deletions Model/Api/Form/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,8 @@ public static function getPendingStatuses()
'WAITING_FOR_PAYMENT',
'AUTHORISED_TO_VALIDATE',
'SUSPENDED',
'PENDING'
'PENDING',
'REFUND_TO_RETRY'
);
}

Expand All @@ -304,7 +305,7 @@ public static function getCancelledStatuses()
public static function getToValidateStatuses()
{
return array(
'WAITING_AUTHORISATION_TO_VALIDATE',
'WAITING_AUTHORISATION_TO_VALIDATE',
'AUTHORISED_TO_VALIDATE'
);
}
Expand Down
7 changes: 4 additions & 3 deletions Model/Method/Other.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,12 @@ public function assignData(\Magento\Framework\DataObject $data)
$info = $this->getInfoInstance();
$payzenData = $this->extractPaymentData($data);

// Load option informations.
// Load option information.
$option = $this->_getMeans($payzenData->getData('payzen_other_option'));
if ($option) {
$info->setCcType($option['means'])->setAdditionalInformation(\Lyranetwork\Payzen\Helper\Payment::OTHER_OPTION, serialize($option));
}

$info->setCcType($option['means'])
->setAdditionalInformation(\Lyranetwork\Payzen\Helper\Payment::OTHER_OPTION, serialize($option));
return $this;
}

Expand Down
4 changes: 2 additions & 2 deletions Model/Method/Payzen.php
Original file line number Diff line number Diff line change
Expand Up @@ -1084,8 +1084,8 @@ public function refund(\Magento\Payment\Model\InfoInterface $payment, $amount)
$payzenOrderInfo->setOrderRemoteId($order->getIncrementId());
$payzenOrderInfo->setOrderId($order->getIncrementId());
$payzenOrderInfo->setOrderReference($order->getIncrementId());
$payzenOrderInfo->setOrderCurrencyIsoCode($order->getOrderCurrencyCode());
$payzenOrderInfo->setOrderCurrencySign($order->getOrderCurrencyCode());
$payzenOrderInfo->setOrderCurrencyIsoCode($order->getBaseCurrencyCode());
$payzenOrderInfo->setOrderCurrencySign($order->getBaseCurrencyCode());
$payzenOrderInfo->setOrderUserInfo($commentText);

$refundApi = new PayzenRefund(
Expand Down
24 changes: 12 additions & 12 deletions Model/Method/Standard.php
Original file line number Diff line number Diff line change
Expand Up @@ -374,16 +374,16 @@ public function getDisplayTitle()

protected function getRestApiFormTokenData($quote)
{
$amount = $quote->getGrandTotal();
$amount = $quote->getBaseGrandTotal();

// Currency.
$currency = \Lyranetwork\Payzen\Model\Api\Form\Api::findCurrencyByAlphaCode($quote->getQuoteCurrencyCode());
$currency = \Lyranetwork\Payzen\Model\Api\Form\Api::findCurrencyByAlphaCode($quote->getBaseCurrencyCode());
if (! $currency) {
// If currency is not supported, use base currency.
$currency = \Lyranetwork\Payzen\Model\Api\Form\Api::findCurrencyByAlphaCode($quote->getBaseCurrencyCode());
// If currency is not supported, use order currency.
$currency = \Lyranetwork\Payzen\Model\Api\Form\Api::findCurrencyByAlphaCode($quote->getQuoteCurrencyCode());

// ... and order total in base currency.
$amount = $quote->getBaseGrandTotal();
// ... and order total in order currency.
$amount = $quote->getGrandTotal();
}

if (! $currency) {
Expand Down Expand Up @@ -486,16 +486,16 @@ protected function getRestApiFormTokenData($quote)

protected function getTokenDataForOrder($order)
{
$amount = $order->getGrandTotal();
$amount = $order->getBaseGrandTotal();

// Currency.
$currency = \Lyranetwork\Payzen\Model\Api\Form\Api::findCurrencyByAlphaCode($order->getQuoteCurrencyCode());
$currency = \Lyranetwork\Payzen\Model\Api\Form\Api::findCurrencyByAlphaCode($order->getBaseCurrencyCode());
if (! $currency) {
// If currency is not supported, use base currency.
$currency = \Lyranetwork\Payzen\Model\Api\Form\Api::findCurrencyByAlphaCode($order->getBaseCurrencyCode());
// If currency is not supported, use order currency.
$currency = \Lyranetwork\Payzen\Model\Api\Form\Api::findCurrencyByAlphaCode($order->getOrderCurrencyCode());

// ... and order total in base currency.
$amount = $order->getBaseGrandTotal();
// ... and order total in order currency.
$amount = $order->getGrandTotal();
}

if (! $currency) {
Expand Down
2 changes: 1 addition & 1 deletion Observer/UpdateOtherPaymentObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
class UpdateOtherPaymentObserver implements ObserverInterface
{
/**
* Update payment method ID to set installments number if multi payment.
* Update payment method ID to set payment means if other payment means method.
*
* @param Observer $observer
* @return void
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.6",
"version" : "2.8.7",
"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.6</plugin_version>
<plugin_version>2.8.7</plugin_version>
<gateway_version>V2</gateway_version>
<cms_identifier>Magento_2.x</cms_identifier>
<enable_logs>1</enable_logs>
Expand Down
6 changes: 6 additions & 0 deletions etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@
</arguments>
</type>

<type name="Magento\Payment\Model\Info">
<arguments>
<argument name="paymentData" xsi:type="object">Lyranetwork\Payzen\Helper\Payment\Data</argument>
</arguments>
</type>

<type name="Magento\Framework\App\Request\CsrfValidator">
<plugin name="payzen_skip_csrf_validator" type="Lyranetwork\Payzen\Controller\Plugin\CsrfValidator" />
</type>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ define(
selectOptionPaymentMethod: function(option) {
var method = this.getCode() + '_' + option;

selectPaymentMethodAction(this.getOptionData(method));
selectPaymentMethodAction(this.getOptionData('payzen_other'));
checkoutData.setSelectedPaymentMethod(method);

return true;
Expand All @@ -80,6 +80,10 @@ define(

getRegroupMode: function() {
return window.checkoutConfig.payment.payzen_other.regroupMode;
},

payzenOptionChecked: function() {
return checkoutData.getSelectedPaymentMethod();
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
*/
-->
<!-- ko foreach: {data: getAvailableOptions(), as: 'option'} -->
<div class="payment-method" data-bind="css: {'_active': ($parent.getOptionCode(option.key) == $parent.isChecked())}">
<div class="payment-method" data-bind="css: {'_active': ($parent.getOptionCode(option.key) == $parent.payzenOptionChecked())}">
<div class="payment-method-title field choice">
<input type="hidden"
<input type="hidden"
name="payment[payzen_other_option]"
data-bind="value: option.key" />

Expand All @@ -20,7 +20,7 @@
class="radio"
data-bind="attr: {id: $parent.getOptionCode(option.key)},
value: $parent.getOptionCode(option.key),
checked: $parent.isChecked,
checked: $parent.payzenOptionChecked(),
click: function() { $parent.selectOptionPaymentMethod(option.key);
$parent.payzenOtherOption(option.key);
return true; },
Expand All @@ -29,7 +29,7 @@
<label data-bind="attr: {for: $parent.getOptionCode(option.key)}" class="label payzen-card">
<img data-bind="attr: {src: option.icon}"
class="payment-icon"
style="height: 36px;"/>
style="height: 36px;" />

<span data-bind="text: option.label"></span>
</label>
Expand Down

0 comments on commit da7b198

Please sign in to comment.