Skip to content

Commit

Permalink
Fix for wrong displayed currency in backoffice actions
Browse files Browse the repository at this point in the history
  • Loading branch information
AllanWLie committed May 30, 2018
1 parent 580ee58 commit 4da7f37
Showing 1 changed file with 21 additions and 16 deletions.
37 changes: 21 additions & 16 deletions epay/epay.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@

class EPay extends PaymentModule
{
const MODULE_VERSION = '5.0.5';
const MODULE_VERSION = '5.0.6';
const V15 = '15';
const V16 = '16';
const V17 = '17';

public function __construct()
{
$this->name = 'epay';
$this->version = '5.0.5';
$this->version = '5.0.6';
$this->author = 'Bambora Online';
$this->tab = 'payments_gateways';

Expand Down Expand Up @@ -1361,21 +1361,21 @@ private function buildTransactionFormBodyNoApiAccessEnd()
/**
* Build the start of the Transaction Form Body
*
* @param mixed $orderId
* @param mixed $order
* @param mixed $transactionId
* @param mixed $fraud
* @param mixed $cardType
* @param mixed $cardno
* @param mixed $amountInMinorunits
* @return string
*/
private function buildTransactionFormBodyStart($orderId, $transactionId, $fraud, $cardType, $cardno, $amountInMinorunits)
private function buildTransactionFormBodyStart($order, $transactionId, $fraud, $cardType, $cardno, $amountInMinorunits)
{
$html = '';
if ($transactionId) {
$html .= '<table class="table" cellspacing="0" cellpadding="0">';
$html .= $this->transactionInfoTableRow($this->l('ePay Administration'), '<a href="https://admin.ditonlinebetalingssystem.dk/admin/login.asp" title="ePay login" target="_blank">' . $this->l('Open') . '</a>');
$html .= $this->transactionInfoTableRow($this->l('ePay "Order ID"'), $orderId);
$html .= $this->transactionInfoTableRow($this->l('ePay "Order ID"'), $order->id);
$html .= $this->transactionInfoTableRow($this->l('ePay "Transaction ID"'), $transactionId);

if ($fraud) {
Expand All @@ -1397,8 +1397,9 @@ private function buildTransactionFormBodyStart($orderId, $transactionId, $fraud,
$paymentTypeColumn .= '</div></div>';
$html .= $this->transactionInfoTableRow($this->l('Payment type'), $paymentTypeColumn);

$currency_code = $this->context->currency->iso_code;
$minorunits = EpayTools::getCurrencyMinorunits($currency_code);
$currency = new Currency($order->id_currency);
$currencyIsoCode = $currency->iso_code;
$minorunits = EpayTools::getCurrencyMinorunits($currencyIsoCode);
$amount = EpayTools::convertPriceFromMinorUnits($amountInMinorunits, $minorunits);

$html .= $this->transactionInfoTableRow($this->l('Authorized amount'), Tools::displayPrice($amount));
Expand All @@ -1413,20 +1414,22 @@ private function buildTransactionFormBodyStart($orderId, $transactionId, $fraud,
* @param mixed $epayTransaction
* @return string
*/
private function buildTransactionFormBodyActions($epayTransaction)
private function buildTransactionFormBodyActions($epayTransaction, $order)
{
$html = '';
try {
$currency_code = $this->context->currency->iso_code;
$minorunits = EpayTools::getCurrencyMinorunits($currency_code);

$currency = new Currency($order->id_currency);
$currencyIsoCode = $currency->iso_code;
$minorunits = EpayTools::getCurrencyMinorunits($currencyIsoCode);

$capturedAmount = EpayTools::convertPriceFromMinorUnits($epayTransaction->capturedamount, $minorunits);
$html .= $this->transactionInfoTableRow($this->l('Captured amount'), Tools::displayPrice($capturedAmount));
$creditedAmount = EpayTools::convertPriceFromMinorUnits($epayTransaction->creditedamount, $minorunits);
$html .= $this->transactionInfoTableRow($this->l('Credited amount'), Tools::displayPrice($creditedAmount));
$html .= "</table>";

$html .= $this->buildButtonsForm($epayTransaction, $currency_code);
$html .= $this->buildButtonsForm($epayTransaction, $currencyIsoCode);

$html .= '</div>';
$html .= '<div class="col-xs-12 col-sm-12 col-md-6 col-lg-5">';
Expand Down Expand Up @@ -1805,7 +1808,8 @@ private function displayPaymentRequestForm($params)
{
$order = new Order($params['id_order']);
$employee = new Employee($this->context->cookie->id_employee);

$currency = new Currency($order->id_currency);
$currencyIsoCode = $currency->iso_code;
// Get default Language
$default_lang = (int)Configuration::get('PS_LANG_DEFAULT');

Expand Down Expand Up @@ -1865,7 +1869,7 @@ private function displayPaymentRequestForm($params)
'label' => $this->l('Amount'),
'name' => 'epay_paymentrequest_amount',
'size' => 20,
'suffix' => $this->context->currency->iso_code,
'suffix' => $currencyIsoCode,
'required' => true,
'readonly' => false
),
Expand Down Expand Up @@ -1924,14 +1928,15 @@ private function createPaymentRequest($order)
try {
$orderid = $order->id;
$amount = Tools::getValue('epay_paymentrequest_amount');
$currency = $this->context->currency->iso_code;
$currency = new Currency($order->id_currency);
$currencyIsoCode = $currency->iso_code;
$requester = Tools::getValue('epay_paymentrequest_requester_name');
$comment = Tools::getValue('epay_paymentrequest_requester_comment');
$recipient_email = Tools::getValue('epay_paymentrequest_recipient_email');
$recipient_name = Tools::getValue('epay_paymentrequest_recipient_name');
$replyto_email = Tools::getValue('epay_paymentrequest_replyto_email');
$replyto_name = Tools::getValue('epay_paymentrequest_replyto_name');
$minorunits = EpayTools::getCurrencyMinorunits($currency);
$minorunits = EpayTools::getCurrencyMinorunits($currencyIsoCode);
$languageIso = Language::getIsoById($this->context->language->id);

//Get ordernumber
Expand All @@ -1954,7 +1959,7 @@ private function createPaymentRequest($order)
$amountSanitized = (float)str_replace(',', '.', $amount);
$params["paymentrequest"]["parameters"]["amount"] = EpayTools::convertPriceToMinorUnits($amountSanitized, $minorunits, Configuration::get('EPAY_ROUNDING_MODE'));
$params["paymentrequest"]["parameters"]["callbackurl"] = $this->context->link->getModuleLink($this->name, 'paymentrequest', array('id_cart' => $order->id_cart), true);
$params["paymentrequest"]["parameters"]["currency"] = $currency;
$params["paymentrequest"]["parameters"]["currency"] = $currencyIsoCode;
$params["paymentrequest"]["parameters"]["group"] = Configuration::get('EPAY_GROUP');
$params["paymentrequest"]["parameters"]["instantcapture"] = Configuration::get('EPAY_INSTANTCAPTURE') == "1" ? "automatic" : "manual";
$params["paymentrequest"]["parameters"]["orderid"] = $orderid . "PAYREQ" . $orderPostfix;
Expand Down

0 comments on commit 4da7f37

Please sign in to comment.