Skip to content

Commit

Permalink
Merge branch 'release/2.9.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
Alima Grine committed Jun 21, 2024
2 parents 4570adf + 44c4ce5 commit 50466c6
Show file tree
Hide file tree
Showing 16 changed files with 111 additions and 42 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
2.9.0, 2024-06-21:
- Added possibility to configure currency used for payment processing.

2.8.8, 2024-05-30:
- Rollback using 500 http code on error for IPN calls.

Expand Down
11 changes: 8 additions & 3 deletions Controller/Payment/Rest/Token.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,15 @@ public function execute()

case self::GET_TOKEN_AMOUNT_IN_CENTS:
// Create token from order data.
$amount = $this->getRequest()->getParam('amount');
$currencyCode = $this->getRequest()->getParam('currency');

$amount = $this->getRequest()->getParam('displayAmount');
$currencyCode = $this->getRequest()->getParam('displayCurrency');
$currency = $currencyCode ? PayzenApi::findCurrencyByAlphaCode($currencyCode) : null;
if (($this->dataHelper->getCommonConfigData('online_transactions_currency') == '2') || (($this->dataHelper->getCommonConfigData('online_transactions_currency') !== '2') && ! $currency)) {
$currencyCode = $this->getRequest()->getParam('baseCurrency');
$currency = $currencyCode ? PayzenApi::findCurrencyByAlphaCode($currencyCode) : null;
$amount = $this->getRequest()->getParam('baseAmount');
}

if ($amount && $currency) {
$amountInCents = $currency->convertAmountToInteger($amount);

Expand Down
9 changes: 8 additions & 1 deletion Controller/Processor/CheckProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,15 @@ public function execute(
$currency->getDecimals()
);

// Check if display currency is used for refund, otherwise use amount in base currency.
if ($order->getOrderCurrencyCode() !== $currency->getAlpha3()) {
$totalOrderAmount = $order->getBaseGrandTotal();
} else {
$totalOrderAmount = $order->getGrandTotal();
}

$orderAmount = round(
$order->getGrandTotal(),
$totalOrderAmount,
$currency->getDecimals()
);

Expand Down
8 changes: 5 additions & 3 deletions Helper/Checkout.php
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ public function setCartData($order, &$payzenRequest)

// Used currency.
$currency = PayzenApi::findCurrencyByNumCode($payzenRequest->get('currency'));
$isDisplayCurrency = ($this->dataHelper->getCommonConfigData('online_transactions_currency') == '1') ? true : false;

$subtotal = 0;

Expand Down Expand Up @@ -278,7 +279,7 @@ public function setCartData($order, &$payzenRequest)
}
}

$priceInCents = $currency->convertAmountToInteger($item->getPrice());
$priceInCents = $isDisplayCurrency ? $currency->convertAmountToInteger($item->getPrice()) : $currency->convertAmountToInteger($item->getBasePrice());
$qty = (int) $item->getQtyOrdered();

$payzenRequest->addProduct(
Expand All @@ -294,13 +295,14 @@ public function setCartData($order, &$payzenRequest)
}

$payzenRequest->set('insurance_amount', 0); // By default, shipping insurance amount is not available in Magento.
$payzenRequest->set('shipping_amount', $currency->convertAmountToInteger($order->getShippingAmount()));
$shippingAmount = $isDisplayCurrency ? $order->getShippingAmount() : $order->getBaseShippingAmount();
$payzenRequest->set('shipping_amount', $currency->convertAmountToInteger($shippingAmount));

// Recalculate tax_amount to avoid rounding problems.
$taxAmount = $payzenRequest->get('amount') - $subtotal - $payzenRequest->get('shipping_amount') -
$payzenRequest->get('insurance_amount');
if ($taxAmount <= 0) { // When order is discounted.
$taxAmount = $currency->convertAmountToInteger($order->getTaxAmount());
$taxAmount = $isDisplayCurrency ? $currency->convertAmountToInteger($order->getTaxAmount()) : $currency->convertAmountToInteger($order->getBaseTaxAmount());
}

$payzenRequest->set('tax_amount', $taxAmount);
Expand Down
25 changes: 15 additions & 10 deletions Model/Method/Payzen.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,16 +214,12 @@ public function getFormFields($order)
// Set order_id.
$this->payzenRequest->set('order_id', $order->getIncrementId());

// Amount in current order currency.
$online_transactions_currency = $this->dataHelper->getCommonConfigData('online_transactions_currency');
$amount = $order->getGrandTotal();

// Set currency.
$currency = PayzenApi::findCurrencyByAlphaCode($order->getOrderCurrencyCode());
if (! $currency) {
// If currency is not supported, use base currency.
if (($online_transactions_currency == '2') || (($online_transactions_currency !== '2') && ! $currency)) {
// Use base currency.
$currency = PayzenApi::findCurrencyByAlphaCode($order->getBaseCurrencyCode());

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

Expand Down Expand Up @@ -1080,12 +1076,21 @@ public function refund(\Magento\Payment\Model\InfoInterface $payment, $amount)
$commentText .= '; ' . $comment->getComment();
}

$online_transactions_currency = $this->dataHelper->getCommonConfigData('online_transactions_currency', $storeId);
$amountInCurrencyCode = $payment->getCreditmemo()->getGrandTotal();
$currencyCode = $order->getOrderCurrencyCode();
$currency = PayzenApi::findCurrencyByAlphaCode($currencyCode);
if (($online_transactions_currency == '2') || (($online_transactions_currency !== '2') && ! $currency)) {
$currencyCode = $order->getBaseCurrencyCode();
$amountInCurrencyCode = $payment->getCreditmemo()->getBaseGrandTotal();
}

$payzenOrderInfo = new PayzenOrderInfo();
$payzenOrderInfo->setOrderRemoteId($order->getIncrementId());
$payzenOrderInfo->setOrderId($order->getIncrementId());
$payzenOrderInfo->setOrderReference($order->getIncrementId());
$payzenOrderInfo->setOrderCurrencyIsoCode($order->getBaseCurrencyCode());
$payzenOrderInfo->setOrderCurrencySign($order->getBaseCurrencyCode());
$payzenOrderInfo->setOrderCurrencyIsoCode($currencyCode);
$payzenOrderInfo->setOrderCurrencySign($currencyCode);
$payzenOrderInfo->setOrderUserInfo($commentText);

$refundApi = new PayzenRefund(
Expand All @@ -1098,7 +1103,7 @@ public function refund(\Magento\Payment\Model\InfoInterface $payment, $amount)

// Do online refund.
$order->setPayment($payment);
$refundApi->refund($payzenOrderInfo, $amount);
$refundApi->refund($payzenOrderInfo, $amountInCurrencyCode);
} catch (\Exception $e) {
throw new \Exception($e->getMessage());
}
Expand Down
30 changes: 10 additions & 20 deletions Model/Method/Standard.php
Original file line number Diff line number Diff line change
Expand Up @@ -374,16 +374,11 @@ public function getDisplayTitle()

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

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

// ... and order total in order currency.
$amount = $quote->getGrandTotal();
$amount = $quote->getGrandTotal();
$currency = \Lyranetwork\Payzen\Model\Api\Form\Api::findCurrencyByAlphaCode($quote->getQuoteCurrencyCode());
if (($this->dataHelper->getCommonConfigData('online_transactions_currency') == '2') || (($this->dataHelper->getCommonConfigData('online_transactions_currency') !== '2') && ! $currency)) {
$currency = \Lyranetwork\Payzen\Model\Api\Form\Api::findCurrencyByAlphaCode($quote->getBaseCurrencyCode());
$amount = $quote->getBaseGrandTotal();
}

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

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

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

// ... and order total in order currency.
$amount = $order->getGrandTotal();
$amount = $order->getGrandTotal();
$currency = \Lyranetwork\Payzen\Model\Api\Form\Api::findCurrencyByAlphaCode($order->getOrderCurrencyCode());
if (($this->dataHelper->getCommonConfigData('online_transactions_currency') == '2') || (($this->dataHelper->getCommonConfigData('online_transactions_currency') !== '2') && ! $currency)) {
$currency = \Lyranetwork\Payzen\Model\Api\Form\Api::findCurrencyByAlphaCode($order->getBaseCurrencyCode());
$amount = $order->getBaseGrandTotal();
}

if (! $currency) {
Expand Down
28 changes: 28 additions & 0 deletions Model/System/Config/Source/OnlineTransactionsCurrency.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php
/**
* Copyright © Lyra Network.
* This file is part of PayZen plugin for Magento 2. See COPYING.md for license details.
*
* @author Lyra Network (https://www.lyra.com/)
* @copyright Lyra Network
* @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/

namespace Lyranetwork\Payzen\Model\System\Config\Source;

class OnlineTransactionsCurrency implements \Magento\Framework\Option\ArrayInterface
{
public function toOptionArray()
{
return [
[
'value' => '1',
'label' => __('Display currency')
],
[
'value' => '2',
'label' => __('Base currency')
]
];
}
}
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.8",
"version" : "2.9.0",
"license" : "OSL-3.0",
"autoload" : {
"files" : [
Expand Down
7 changes: 7 additions & 0 deletions etc/adminhtml/system/general.xml
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,13 @@
<config_path>payzen/general/customer_data</config_path>
<backend_model>Lyranetwork\Payzen\Model\System\Config\Backend\Serialized\ArraySerialized\ConfigArraySerialized</backend_model>
</field>

<field id="online_transactions_currency" translate="label comment" type="select" sortOrder="186" showInDefault="1" showInWebsite="1" showInStore="1">
<label><![CDATA[Online transactions currency]]></label>
<comment><![CDATA[Currency used for PayZen payment transactions processing. Possible values:<br /><b>Display currency: </b>The store view or display currency for buyer.<br /><b>Base currency: </b>The base currency of Magento.]]></comment>
<source_model>Lyranetwork\Payzen\Model\System\Config\Source\OnlineTransactionsCurrency</source_model>
<config_path>payzen/general/online_transactions_currency</config_path>
</field>
</group>
</group>
</include>
4 changes: 3 additions & 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.8</plugin_version>
<plugin_version>2.9.0</plugin_version>
<gateway_version>V2</gateway_version>
<cms_identifier>Magento_2.x</cms_identifier>
<enable_logs>1</enable_logs>
Expand Down Expand Up @@ -63,6 +63,8 @@

<send_cart_detail>1</send_cart_detail>
<common_category>FOOD_AND_GROCERY</common_category>

<online_transactions_currency>1</online_transactions_currency>
</general>
</payzen>

Expand Down
4 changes: 4 additions & 0 deletions i18n/de_DE.csv
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,10 @@
"> 1 hour","> 1 Stunde"
"Immediate","Sofortig"
"24/7","24/7"
"Online transactions currency","Währung für Online-Transaktionen"
"Currency used for PayZen payment transactions processing. Possible values:<br /><b>Display currency: </b>The store view or display currency for buyer.<br /><b>Base currency: </b>The base currency of Magento.","Für die Verarbeitung von PayZen Zahlungstransaktionen verwendete Währung. Mögliche Werte:<br /><b>Anzeigewährung: </b>Die Store-Ansicht oder Anzeigewährung für den Käufer.<br /><b>Basiswährung: </b>Die Basiswährung von Magento."
"Display currency","Anzeigewährung"
"Base currency","Basiswährung"
"DISPLAY OPTIONS","ANZEIGEOPTIONEN"
"Activation","Aktiviert"
"Enables / disables this payment method.","Aktiviert / Deaktiviert dieses Zahlungsmodus."
Expand Down
4 changes: 4 additions & 0 deletions i18n/en_US.csv
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@
"> 1 hour","> 1 hour"
"Immediate","Immediate"
"24/7","24/7"
"Online transactions currency","Online transactions currency"
"Currency used for PayZen payment transactions processing. Possible values:<br /><b>Display currency: </b>The store view or display currency for buyer.<br /><b>Base currency: </b>The base currency of Magento.","Currency used for PayZen payment transactions processing. Possible values:<br /><b>Display currency: </b>The store view or display currency for buyer.<br /><b>Base currency: </b>The base currency of Magento."
"Display currency","Display currency"
"Base currency","Base currency"
"DISPLAY OPTIONS","DISPLAY OPTIONS"
"Activation","Activation"
"Enables / disables this payment method.","Enables / disables this payment method."
Expand Down
4 changes: 4 additions & 0 deletions i18n/es_ES.csv
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@
"> 1 hour","> 1 hora"
"Immediate","Inmediato"
"24/7","24/7"
"Online transactions currency","Moneda de las transacciones en línea"
"Currency used for PayZen payment transactions processing. Possible values:<br /><b>Display currency: </b>The store view or display currency for buyer.<br /><b>Base currency: </b>The base currency of Magento.","Moneda utilizada para el procesamiento de transacciones de pago de PayZen. Valores posibles:<br /><b>Moneda de visualización: </b>La vista de la tienda o la moneda de visualización para el comprador.<br /><b>Moneda base: </b>La moneda base de Magento."
"Display currency","Moneda de visualización"
"Base currency","Moneda base"
"DISPLAY OPTIONS","OPCIONES DE VISUALIZACIÓN"
"Activation","Activación"
"Enables / disables this payment method.","Habilita/deshabilita este método de pago."
Expand Down
4 changes: 4 additions & 0 deletions i18n/fr_FR.csv
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@
"> 1 hour","> 1 heure"
"Immediate","Immédiat"
"24/7","24h/24, 7j/7"
"Online transactions currency","Devise des transactions en ligne"
"Currency used for PayZen payment transactions processing. Possible values:<br /><b>Display currency: </b>The store view or display currency for buyer.<br /><b>Base currency: </b>The base currency of Magento.","Devise utilisée pour le traitement des opérations de paiement PayZen. Valeurs possibles :<br /><b>Devise d'affichage: </b>La devise de vue du magasin ou d'affichage pour l'acheteur.<br /><b>Devise de base: </b>La devise de base de Magento."
"Display currency","Devise d'affichage"
"Base currency","Devise de base"
"DISPLAY OPTIONS","OPTIONS D'AFFICHAGE"
"Activation","Activation"
"Enables / disables this payment method.","Active / désactive cette méthode de paiement."
Expand Down
4 changes: 4 additions & 0 deletions i18n/pt_BR.csv
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@
"> 1 hour","> 1 hora"
"Immediate","Imediato"
"24/7","24horas 7dias por semana"
"Online transactions currency","Moeda de transações on-line"
"Currency used for PayZen payment transactions processing. Possible values:<br /><b>Display currency: </b>The store view or display currency for buyer.<br /><b>Base currency: </b>The base currency of Magento.","Moeda usada para processamento de transações de pagamento PayZen. Valores possíveis:<br /><b>Moeda de exibição: </b>A visualização da loja ou moeda de exibição para o comprador.<br /><b>Moeda Base: </b>A moeda base do Magento."
"Display currency","Moeda de exibição"
"Base currency","Moeda Base"
"DISPLAY OPTIONS","OPÇÕES DE EXIBIÇÃO"
"Activation","Ativação"
"Enables / disables this payment method.","Ativa / desativa este método de pagamento."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ define(
// Check if form token amount is up to date.
var totals = quote.getTotals()();
if (totals) {
me.checkTokenAmount(totals['grand_total'], totals['base_currency_code'], KR_RAW_DNA.amount);
me.checkTokenAmount(totals['grand_total'], totals['quote_currency_code'], totals['base_grand_total'], totals['base_currency_code'], KR_RAW_DNA.amount);
}

return;
Expand Down Expand Up @@ -559,11 +559,11 @@ define(
});
},

checkTokenAmount: function(amount, currency, krAmount) {
checkTokenAmount: function(displayAmount, displayCurrency, baseAmount, baseCurrency, krAmount) {
var me = this;

storage.post(
url.build('payzen/payment_rest/token?payzen_action=get_token_amount_in_cents' + '&amount=' + amount + '&currency=' + currency + '&form_key=' + $.mage.cookies.get('form_key'))
url.build('payzen/payment_rest/token?payzen_action=get_token_amount_in_cents' + '&displayAmount=' + displayAmount + '&displayCurrency=' + displayCurrency + '&baseAmount=' + baseAmount + '&baseCurrency=' + baseCurrency + '&form_key=' + $.mage.cookies.get('form_key'))
).done(function(response) {
if (response.amountincents && krAmount && response.amountincents !== krAmount) {
// Refresh token since the amount in the embedded form is not up to date.
Expand Down

0 comments on commit 50466c6

Please sign in to comment.