I have a small query. When ever my customer enters amount to add funds to his account, the entire amount is added to his balance. I actually want to subtract "x%" as processing/payment gateway fee and add the remaining balance to his account.
Two options are mentioned in the below code. i.e selling currency amount and accounting currency amount. Selling will be the amount he is entering and the accounting currency amount is the amount which will be added to his account balance after subtraction of "x%".
I have tried $_SESSION['accountingcurencyamount']=$sellingCurrencyAmount - ($sellingCurrencyAmount * (3/100));
.
Following is the code :
<?php session_start();
@session_save_path("./"); ?>
<?php
include('config.php');
require('functions.php');
include('payment.php')?>
<?php
error_reporting(0);
/*Reseller Club Fields starts*/
$paymentTypeId = $_GET["paymenttypeid"]; //payment type id
$transId = $_GET["transid"]; //This refers to a unique transaction ID which we generate for each transaction
$userId = $_GET["userid"]; //userid of the user who is trying to make the payment
$userType = $_GET["usertype"]; //This refers to the type of user perofrming this transaction. The possible values are "Customer" or "Reseller"
$transactionType = $_GET["transactiontype"]; //Type of transaction (ResellerAddFund/CustomerAddFund/ResellerPayment/CustomerPayment)
$invoiceIds = $_GET["invoiceids"]; //comma separated Invoice Ids, This will have a value only if the transactiontype is "ResellerPayment" or "CustomerPayment"
$debitNoteIds = $_GET["debitnoteids"]; //comma separated DebitNotes Ids, This will have a value only if the transactiontype is "ResellerPayment" or "CustomerPayment"
$description = $_GET["description"];
$sellingCurrencyAmount = $_GET["sellingcurrencyamount"]; //This refers to the amount of transaction in your Selling Currency
// echo "Amount: " .$sellingCurrencyAmount;
$accountingCurrencyAmount = $_GET["accountingcurrencyamount"]; //This refers to the amount of transaction in your Accounting Currency
$redirectUrl = $_GET["redirecturl"]; //This is the URL on our server, to which you need to send the user once you have finished charging him
$checksuma = $_GET["checksum"]; //checksum for validation
/*Reseller Club Fields ends*/
$order_id=$_GET["transid"];
$amount= $_GET["sellingcurrencyamount"];
$currency=$currency;
$cancel_url=$redirect_url;
$language="EN";
$billing_name=$_GET["name"];
$billing_address=$_GET["address1"] ;
$billing_city=$_GET["city"];
$billing_state=$_GET["state"];
$billing_zip=$_GET["zip"];
$billing_country=$_GET["country"];
$billing_tel=$_POST["telNoCc"] . $_GET["telNo"];
$billing_email=$_GET["emailAddr"];
$delivery_name=$billing_name;
$delivery_address=$billing_address;
$delivery_city=$billing_city;
$delivery_state=$billing_state;
$delivery_zip=$billing_zip;
$delivery_country= $billing_country;
$delivery_tel=$billing_tel;
$merchant_param1="";
$merchant_param2="";
$merchant_param3="";
$merchant_param4="";
$merchant_param5="";
$promo_code="";
$customer_Id="";
/*Reseller Club code starts*/
if(verifyChecksum1($paymentTypeId, $transId, $userId, $userType, $transactionType, $invoiceIds, $debitNoteIds, $description, $sellingCurrencyAmount, $accountingCurrencyAmount, $key, $checksuma))
{
$_SESSION['redirecturl']=$redirectUrl;
$_SESSION['transid']=$transId;
$_SESSION['sellingcurrencyamount']=$sellingCurrencyAmount;
$_SESSION['accountingcurencyamount']=$accountingCurrencyAmount;
// $_SESSION['accountingcurencyamount']=$sellingCurrencyAmount - ($sellingCurrencyAmount * (3/100));
$checksumStatus=1;
}
else
{
$checksumStatus=0;
$base_url="";
}
//echo "Check: ".$checksumStatus;
//
// echo "<br/>Pay Id: ". $paymentTypeId;
// echo "<br/>Tran Id: ". $transId;
// echo "<br/>User Id: ". $userId;
// echo "<br/>User Type: ". $userType;
// echo "<br/>Tramscation Type: ". $transactionType;
// echo "<br/>Invoice ID: ". $invoiceIds;
// echo "<br/>debit note: ". $debitNoteIds;
// echo "<br/>Description: ". $description;
// echo "<br/>Selling Currency: ". $sellingCurrencyAmount;
// echo "<br/>Account currency: ". $accountingCurrencyAmount;
// echo "<br/>Key: ". $key;
// echo "<br/>Checksum: ". $checksuma;
/*Reseller Club code ends*/
class ProcessPayment {
function __construct(){
$this->paymentConfig = new payment_config();
}
function requestMerchant(){
$payment = new payment();
$datenow = date("d/m/Y h:m:s");
$modifiedDate = str_replace(" ", "%20", $datenow);
$payment->url = $this->paymentConfig->base_url;//$this->paymentConfig->Url;
$postFields = "";
$postFields .= "&login=".$this->paymentConfig->login_id;//$this->paymentConfig->Login;
$postFields .= "&pass=".$this->paymentConfig->password;//$this->paymentConfig->Password;
$postFields .= "&ttype=NBFundTransfer";//.$_POST['TType'];
$postFields .= "&prodid=HILL";//.$_POST['product'];
$postFields .= "&amt=".$GLOBALS['sellingCurrencyAmount'];
$postFields .= "&txncurr=".$this->paymentConfig->currency;//.$this->paymentConfig->TxnCurr;
$postFields .= "&txnscamt=".$this->paymentConfig->trn_service;//$this->paymentConfig->TxnScAmt;
$postFields .= "&clientcode=".urlencode(base64_encode($GLOBALS['billing_name']));
$postFields .= "&txnid=".rand(0,999999);
$postFields .= "&date=".$modifiedDate;
$postFields .= "&ru=".$this->paymentConfig->redirect_url;
$postFields .= "&custacc=".$GLOBALS['billing_tel'];
// Not required for merchant
//$postFields .= "&bankid=".$_POST['bankid'];
$sendUrl = $payment->url."?".substr($postFields,1)."
";
$this->writeLog($sendUrl);
$returnData = $payment->sendInfo($postFields);
$this->writeLog($returnData."
");
$xmlObjArray = $this->xmltoarray($returnData);
$url = $xmlObjArray['url'];
$postFields = "";
$postFields .= "&ttype=NBFundTransfer";//.$_POST['TType'];
$postFields .= "&tempTxnId=".$xmlObjArray['tempTxnId'];
$postFields .= "&token=".$xmlObjArray['token'];
$postFields .= "&txnStage=1";
$url = $payment->url."?".$postFields;
$this->writeLog($url."
");
//echo "URL ". $url;
//echo "amount: " . $GLOBALS['sellingCurrencyAmount'];
//echo "<br/>Base URL ". $this->paymentConfig->base_url;
header("Location: ".$url);
}
function writeLog($data){
$fileName = date("Y-m-d").".txt";
$fp = fopen("log/".$fileName, 'a+');
$data = date("Y-m-d H:i:s")." - ".$data;
fwrite($fp,$data);
fclose($fp);
}
function xmltoarray($data){
$parser = xml_parser_create('');
xml_parser_set_option($parser, XML_OPTION_TARGET_ENCODING, "UTF-8");
xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
xml_parse_into_struct($parser, trim($data), $xml_values);
xml_parser_free($parser);
$returnArray = array();
$returnArray['url'] = $xml_values[3]['value'];
$returnArray['tempTxnId'] = $xml_values[5]['value'];
$returnArray['token'] = $xml_values[6]['value'];
return $returnArray;
}
}
$processPayment = new ProcessPayment();
$processPayment->requestMerchant();
?>