diff --git a/modules/gateways/callback/paymes.php b/modules/gateways/callback/paymes.php index 6b700f8..1bdce49 100644 --- a/modules/gateways/callback/paymes.php +++ b/modules/gateways/callback/paymes.php @@ -15,12 +15,49 @@ // Paymes return post data $invoiceId = $_POST['id']; $transactionId = $_POST["payuPaymentReference"]; -$paymentAmount = $_POST["amount"]; +$paymentAmount1 = $_POST["amount"]; $paymentFee = 0; $currency = $_POST["currency"]; $message = $_POST["message"]; $success = $_POST['status'] == '3DS_ENROLLED'; +/** + * If useInvoiceAmountAsPaid enabled, use the invoice amount, + * as paid amount this to avoid currency conversion issue on non-Default WHMCS Currency transaction + */ + +if ($gatewayParams['useInvoiceAmountAsPaid'] == 'on') { + $invoice_result = mysql_fetch_assoc(select_query('tblinvoices', 'total, userid', array("id"=>$order_id))); + $invoice_amount = $invoice_result['total']; + $paymentAmount = $invoice_amount; +} + +/** + * If tryToConvertCurrencyBack enabled + * Try to convert amount back to Default WHMCS Currency, if not Default WHMCS Currency + */ +if ($gatewayParams['tryToConvertCurrencyBack'] == 'on') { + try { + $invoice_result = mysql_fetch_assoc(select_query('tblinvoices', 'total, userid', array("id"=>$order_id))); + $invoice_amount = $invoice_result['total']; + $client_result = mysql_fetch_assoc(select_query('tblclients', 'currency', array("id"=>$invoice_result['userid']))); + $currency_id = $client_result['currency']; + $idr_currency_id = $gatewayParams['convertto']; + if($currency_id != $idr_currency_id) { + $converted_amount = convertCurrency( + $paymentAmount1, + $idr_currency_id, + $currency_id + ); + } else { + $converted_amount = $paymentAmount1; + } + $paymentAmount = $converted_amount; + } catch (Exception $e) { + echo "fail to tryToConvertCurrencyBack"; + } +} + $transactionStatus = $success ? 'Success' : 'Failure'; $invoiceId = checkCbInvoiceID($invoiceId, $gatewayParams['name']); diff --git a/modules/gateways/paymes.php b/modules/gateways/paymes.php index 89e173e..6cbfb4a 100644 --- a/modules/gateways/paymes.php +++ b/modules/gateways/paymes.php @@ -26,6 +26,16 @@ function paymes_config() 'Default' => '', 'Description' => 'paym.es\'in verdiği size özel kodu (Secret Key) buraya girin', ), + 'useInvoiceAmountAsPaid' => array( + 'FriendlyName' => 'Fatura tutarını ödenen tutar olarak kullan', + 'Type' => 'yesno', + 'Description' => 'Bunu yalnızca varsayılan para biriminiz TL değilken ve ödenen faturada tutar uyuşmazlığı sorunuyla karşılaşırsanız kullanın, bu seçenek, ödenen tutar olarak fatura tutarını kullanır (önerilen ayar: kapalı)', + ), + 'tryToConvertCurrencyBack' => array( + 'FriendlyName' => 'Sanal Pos\'tan gelen tutarı dönüştür', + 'Type' => 'yesno', + 'Description' => 'Bunu yalnızca varsayılan para biriniz TL değilken ve ödenen faturada tutar uyuşmazlığı sorunuyla karşılaşırsanız kullanın, bu seçenek, sanal pos\'tan gelen tutarı orijinal fatura para birimi tutarına geri çevirir. (önerilen ayar: kapalı)', + ), ); } @@ -64,6 +74,8 @@ function paymes_3dsecure($params) $companyName = $params['companyname']; $moduleName = $params['paymentmethod']; $langPayNow = $params['langpaynow']; + $useInvoiceAmountAsPaid = $params['useInvoiceAmountAsPaid']; + $tryToConvertCurrencyBack = $params['tryToConvertCurrencyBack']; if(!empty($address2)) { $address1 .= " " . $address2;