diff --git a/CHANGELOG.md b/CHANGELOG.md index 0a889bf..cfc5ae4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/Controller/Processor/CheckProcessor.php b/Controller/Processor/CheckProcessor.php index aefef7f..f46d2d7 100644 --- a/Controller/Processor/CheckProcessor.php +++ b/Controller/Processor/CheckProcessor.php @@ -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'; diff --git a/Controller/Processor/ResponseProcessor.php b/Controller/Processor/ResponseProcessor.php index 6f5d195..056668b 100644 --- a/Controller/Processor/ResponseProcessor.php +++ b/Controller/Processor/ResponseProcessor.php @@ -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 [ diff --git a/Helper/Data.php b/Helper/Data.php index a056f3d..98b4fb5 100644 --- a/Helper/Data.php +++ b/Helper/Data.php @@ -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 { diff --git a/Helper/Payment.php b/Helper/Payment.php index 15bae19..a52e48b 100644 --- a/Helper/Payment.php +++ b/Helper/Payment.php @@ -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 @@ -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, @@ -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; @@ -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; } /** @@ -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. @@ -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. * diff --git a/Helper/Payment/Data.php b/Helper/Payment/Data.php index b799645..2839adf 100644 --- a/Helper/Payment/Data.php +++ b/Helper/Payment/Data.php @@ -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. @@ -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); + } } diff --git a/Model/Api/Form/Api.php b/Model/Api/Form/Api.php index 993b7bf..cf67798 100644 --- a/Model/Api/Form/Api.php +++ b/Model/Api/Form/Api.php @@ -280,7 +280,8 @@ public static function getPendingStatuses() 'WAITING_FOR_PAYMENT', 'AUTHORISED_TO_VALIDATE', 'SUSPENDED', - 'PENDING' + 'PENDING', + 'REFUND_TO_RETRY' ); } @@ -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' ); } diff --git a/Model/Method/Other.php b/Model/Method/Other.php index 6c8735d..e809520 100644 --- a/Model/Method/Other.php +++ b/Model/Method/Other.php @@ -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; } diff --git a/Model/Method/Payzen.php b/Model/Method/Payzen.php index 8856bd2..0e9eb81 100644 --- a/Model/Method/Payzen.php +++ b/Model/Method/Payzen.php @@ -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( diff --git a/Model/Method/Standard.php b/Model/Method/Standard.php index 9eea843..f5f45fd 100644 --- a/Model/Method/Standard.php +++ b/Model/Method/Standard.php @@ -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) { @@ -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) { diff --git a/Observer/UpdateOtherPaymentObserver.php b/Observer/UpdateOtherPaymentObserver.php index 9694dbc..cbb3bf3 100644 --- a/Observer/UpdateOtherPaymentObserver.php +++ b/Observer/UpdateOtherPaymentObserver.php @@ -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 diff --git a/composer.json b/composer.json index c94c0f7..5dda36c 100644 --- a/composer.json +++ b/composer.json @@ -5,7 +5,7 @@ "php" : "~7|~8" }, "type" : "magento2-module", - "version" : "2.8.6", + "version" : "2.8.7", "license" : "OSL-3.0", "autoload" : { "files" : [ diff --git a/etc/config.xml b/etc/config.xml index 85a4ecb..de3191f 100644 --- a/etc/config.xml +++ b/etc/config.xml @@ -25,7 +25,7 @@ - 2.8.6 + 2.8.7 V2 Magento_2.x 1 diff --git a/etc/di.xml b/etc/di.xml index 92d04bb..d9fe7f7 100644 --- a/etc/di.xml +++ b/etc/di.xml @@ -26,6 +26,12 @@ + + + Lyranetwork\Payzen\Helper\Payment\Data + + + diff --git a/view/frontend/web/js/view/payment/method-renderer/payzen-other.js b/view/frontend/web/js/view/payment/method-renderer/payzen-other.js index e2b6e9a..cec73a5 100644 --- a/view/frontend/web/js/view/payment/method-renderer/payzen-other.js +++ b/view/frontend/web/js/view/payment/method-renderer/payzen-other.js @@ -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; @@ -80,6 +80,10 @@ define( getRegroupMode: function() { return window.checkoutConfig.payment.payzen_other.regroupMode; + }, + + payzenOptionChecked: function() { + return checkoutData.getSelectedPaymentMethod(); } }); } diff --git a/view/frontend/web/template/payment/payzen-other-separated.html b/view/frontend/web/template/payment/payzen-other-separated.html index d42ddf8..3e2e13a 100644 --- a/view/frontend/web/template/payment/payzen-other-separated.html +++ b/view/frontend/web/template/payment/payzen-other-separated.html @@ -9,9 +9,9 @@ */ --> -
+
- @@ -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; }, @@ -29,7 +29,7 @@