diff --git a/CHANGELOG.md b/CHANGELOG.md
index 2f144b7..ed19175 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -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.
diff --git a/Controller/Payment/Rest/Token.php b/Controller/Payment/Rest/Token.php
index d9c756a..426c513 100644
--- a/Controller/Payment/Rest/Token.php
+++ b/Controller/Payment/Rest/Token.php
@@ -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);
diff --git a/Controller/Processor/CheckProcessor.php b/Controller/Processor/CheckProcessor.php
index 432cd08..9ec6cd8 100644
--- a/Controller/Processor/CheckProcessor.php
+++ b/Controller/Processor/CheckProcessor.php
@@ -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()
);
diff --git a/Helper/Checkout.php b/Helper/Checkout.php
index e0c0931..3c9a2bb 100644
--- a/Helper/Checkout.php
+++ b/Helper/Checkout.php
@@ -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;
@@ -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(
@@ -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);
diff --git a/Model/Method/Payzen.php b/Model/Method/Payzen.php
index 0e9eb81..6ed6ede 100644
--- a/Model/Method/Payzen.php
+++ b/Model/Method/Payzen.php
@@ -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();
}
@@ -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(
@@ -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());
}
diff --git a/Model/Method/Standard.php b/Model/Method/Standard.php
index f5f45fd..ab68be5 100644
--- a/Model/Method/Standard.php
+++ b/Model/Method/Standard.php
@@ -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) {
@@ -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) {
diff --git a/Model/System/Config/Source/OnlineTransactionsCurrency.php b/Model/System/Config/Source/OnlineTransactionsCurrency.php
new file mode 100644
index 0000000..7daa2e1
--- /dev/null
+++ b/Model/System/Config/Source/OnlineTransactionsCurrency.php
@@ -0,0 +1,28 @@
+ '1',
+ 'label' => __('Display currency')
+ ],
+ [
+ 'value' => '2',
+ 'label' => __('Base currency')
+ ]
+ ];
+ }
+}
diff --git a/composer.json b/composer.json
index 5d74eb3..ec19032 100644
--- a/composer.json
+++ b/composer.json
@@ -5,7 +5,7 @@
"php" : "~7|~8"
},
"type" : "magento2-module",
- "version" : "2.8.8",
+ "version" : "2.9.0",
"license" : "OSL-3.0",
"autoload" : {
"files" : [
diff --git a/etc/adminhtml/system/general.xml b/etc/adminhtml/system/general.xml
index 329425d..417aa93 100644
--- a/etc/adminhtml/system/general.xml
+++ b/etc/adminhtml/system/general.xml
@@ -390,6 +390,13 @@
payzen/general/customer_data
Lyranetwork\Payzen\Model\System\Config\Backend\Serialized\ArraySerialized\ConfigArraySerialized
+
+
+
+ Display currency: The store view or display currency for buyer.
Base currency: The base currency of Magento.]]>
+ Lyranetwork\Payzen\Model\System\Config\Source\OnlineTransactionsCurrency
+ payzen/general/online_transactions_currency
+
\ No newline at end of file
diff --git a/etc/config.xml b/etc/config.xml
index 1974087..89eb32c 100644
--- a/etc/config.xml
+++ b/etc/config.xml
@@ -25,7 +25,7 @@
- 2.8.8
+ 2.9.0
V2
Magento_2.x
1
@@ -63,6 +63,8 @@
1
FOOD_AND_GROCERY
+
+ 1
diff --git a/i18n/de_DE.csv b/i18n/de_DE.csv
index 96988fa..19768f8 100644
--- a/i18n/de_DE.csv
+++ b/i18n/de_DE.csv
@@ -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:
Display currency: The store view or display currency for buyer.
Base currency: The base currency of Magento.","Für die Verarbeitung von PayZen Zahlungstransaktionen verwendete Währung. Mögliche Werte:
Anzeigewährung: Die Store-Ansicht oder Anzeigewährung für den Käufer.
Basiswährung: 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."
diff --git a/i18n/en_US.csv b/i18n/en_US.csv
index 81aff0f..fe8951e 100644
--- a/i18n/en_US.csv
+++ b/i18n/en_US.csv
@@ -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:
Display currency: The store view or display currency for buyer.
Base currency: The base currency of Magento.","Currency used for PayZen payment transactions processing. Possible values:
Display currency: The store view or display currency for buyer.
Base currency: 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."
diff --git a/i18n/es_ES.csv b/i18n/es_ES.csv
index 587107d..8d44065 100644
--- a/i18n/es_ES.csv
+++ b/i18n/es_ES.csv
@@ -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:
Display currency: The store view or display currency for buyer.
Base currency: The base currency of Magento.","Moneda utilizada para el procesamiento de transacciones de pago de PayZen. Valores posibles:
Moneda de visualización: La vista de la tienda o la moneda de visualización para el comprador.
Moneda base: 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."
diff --git a/i18n/fr_FR.csv b/i18n/fr_FR.csv
index 5bae25c..8be715e 100644
--- a/i18n/fr_FR.csv
+++ b/i18n/fr_FR.csv
@@ -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:
Display currency: The store view or display currency for buyer.
Base currency: The base currency of Magento.","Devise utilisée pour le traitement des opérations de paiement PayZen. Valeurs possibles :
Devise d'affichage: La devise de vue du magasin ou d'affichage pour l'acheteur.
Devise de base: 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."
diff --git a/i18n/pt_BR.csv b/i18n/pt_BR.csv
index 1005f54..b5e0f2e 100644
--- a/i18n/pt_BR.csv
+++ b/i18n/pt_BR.csv
@@ -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:
Display currency: The store view or display currency for buyer.
Base currency: The base currency of Magento.","Moeda usada para processamento de transações de pagamento PayZen. Valores possíveis:
Moeda de exibição: A visualização da loja ou moeda de exibição para o comprador.
Moeda Base: 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."
diff --git a/view/frontend/web/js/view/payment/method-renderer/payzen-standard.js b/view/frontend/web/js/view/payment/method-renderer/payzen-standard.js
index c33e321..2b7aaf7 100644
--- a/view/frontend/web/js/view/payment/method-renderer/payzen-standard.js
+++ b/view/frontend/web/js/view/payment/method-renderer/payzen-standard.js
@@ -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;
@@ -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 + '¤cy=' + 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.