<?php
ob_start();
class Soap_client_view {
    protected $DevID;
    protected $MerchantID;
    protected $MerchantCode;
    protected $TransactionID;
    protected $ItemCode;
    protected $salt;
    protected $MAC;

    public function __construct() {

        $this->DevID = "UPPER-DES34K56L";
        $this->MerchantID = "9"; //done
        $this->MerchantCode = "NSE"; //done
        $this->salt = $this->DevID . "|" . $this->MerchantID . "|" . $this->MerchantCode . "|";
        
    }

    public function logTransaction($param) {
//ob_start();
        extract($param);
        $this->salt.=$transactionID;
        $installmentID=$this->returnInstallmentID();
        $this->MAC=hash("SHA512", $this->salt);
         //$client = new SoapClient(null, array('location' => "http://www.branchcollect.com/branchcollect_test/pay/",                                     'uri'      => "http://branchcollect.com/pay")); 
        $client = new SoapClient("http://www.branchcollect.com/pay/?wsdl");

        $bankdetails = <<<XML
        <BankDetails BankID="8">
    <AccountDetails AccountID="408" AccountName="Nigerian Society Of Engineers" AccountNo="3552108250" SplitAmount="$schoolShare" />
    <AccountDetails AccountID="409" AccountName="Upperlink Limited" AccountNo="0992000267" SplitAmount="200" />
    <AccountDetails AccountID="410" AccountName="Ecobank Nigeria Income Account" AccountNo="ECO0000000" SplitAmount="100" />
</BankDetails>

XML;


        $string = <<<XML
<?xml version="1.0"  encoding="UTF-8"?> 
<BranchCollectRequest>
<MerchantDetails>
     <Merchant DevID="$this->DevID" MerchantID="$this->MerchantID" MerchantCode="$this->MerchantCode" />
</MerchantDetails>
<TransactionDetails>
     <Transaction TransactionID="$transactionID" MAC="$this->MAC" TotalAmount="$totalAmount" CustomerID="$applicantID" CustomerSurname="$surname" CustomerFirstname="$firstname" CustomerOthernames="$othernames" CustomerEmail="$email" CustomerGSM="$phone" UpdateURL="http://www.nse.org.ng/payment/updatepay/update.php" UpdateURLThirdParty='http://www.nse.org.ng/payment/updatePay3rd.php' />
</TransactionDetails>
<ItemDetails ItemCode="NSE01" ItemDescription="$description" InstallmentID="1" Split="false" ExpiryDate="2293-12-12">
    <Item ItemName="All Fees" ItemAmount="$schoolShare" />
    <Item ItemName="Transaction Charge" ItemAmount="$transCharge" />
</ItemDetails>

<CustomFieldDetails>
    <CustomField CustomFieldLabel="Home Address" CustomFieldValue="" />
    <CustomField CustomFieldLabel="Contact Address" CustomFieldValue="" />
    <CustomField CustomFieldLabel="State" CustomFieldValue="" />
    <CustomField CustomFieldLabel="Country" CustomFieldValue="" />
</CustomFieldDetails>

<CollectionBankDetails>
     <CollectionBank CBankID="8" />
</CollectionBankDetails>

<BankAccounts>
$bankdetails
</BankAccounts>
</BranchCollectRequest>
XML;
        ?> 

        <?php
		//die($string);
        //echo "<pre>".print_r($string,TRUE);
        $params = array('XMLRequest' => $string);
        try {
            $objectresult = $client->__soapCall("GenerateTransactionTP", $params);
            $xml = simplexml_load_string($objectresult);
            $pCode = 'NSE01'; //web_service_api::QuickTellerCode($ItemCode);
            $referenceID=$xml->ReferenceID;
            echo "<!-- *************$xml->Message ************ $xml->RespCode -->";
            return array('xml'=>$string,'referenceID'=>$referenceID,'message'=>$xml->Message,'responseCode' => $xml->RespCode, 'QTCode' => $pCode);
        } catch (Exception $e) {
            return array('response' => $e->getMessage());
        }
    }


// method end
//method end
    public function returnInstallmentID(){
    $drandStringLength = 5;
	$timestring = microtime();
	$secondsSinceEpoch=(integer) substr($timestring, strrpos($timestring, " "), 100);
	$microseconds=(double) $timestring;
	$seed = mt_rand(0,1000000000) + 10000000 * $microseconds + $secondsSinceEpoch;
	mt_srand($seed);
	$drandstring = "";
	for($i=0; $i < $drandStringLength; $i++)
		{
		$drandstring .= mt_rand(0, 9);
		}
$drand =$drandstring;
return $drand;
}
}

//class end

?>