[insert_php]

#******************************************************************************
#* Name : PxPay_Sample_Curl.php
#* Description : Direct Payment Solutions Payment Express PxPay PHP cURL Sample
#* Copyright : Direct Payment Solutions 2009(c)
#* Date : 2009-10-21
#* References : http://www.paymentexpress.com/technical_resources/ecommerce_hosted/pxpay.html
#*@version : 1.0
#* Author : Thomas Treadwell
#******************************************************************************

# This file is a sample demonstrating integration with the PxPay interface using PHP with the cURL extension installed.
#Inlcude PxPay objects
include (“/home/ccnzdev/PxPay.php”);

$PxPay_Url = “https://sec.windcave.com/pxaccess/pxpay.aspx”;
$PxPay_Userid = “ChorusCallNZ2”; #Important! Update with your UserId
$PxPay_Key = “0eb7751ca9fc0485edcb37132e1f49ab4b75ca7ae3b80e73a04b2922c2a31e4b”; #Important! Update with your Key

#
# MAIN
#

$pxpay = new PxPay_Curl( $PxPay_Url, $PxPay_Userid, $PxPay_Key );

if (isset($_REQUEST[“result”]))
{
# this is a redirection from the payments page.
print_result($pxpay);
}
elseif (isset($_POST[“submit”])) #isset($_REQUEST[“Submit”])
{
# this is a post back — redirect to payments page.
redirect_form($pxpay);
}
else
{
# this is a fresh request — display the purchase form.
print_form();
}

#******************************************************************************
# This function receives information back from the payments page,
# and displays it to the user.
#******************************************************************************
function print_result($pxpay)
{
$enc_hex = $_REQUEST[“result”];
#getResponse method in PxPay object returns PxPayResponse object
#which encapsulates all the response data
$rsp = $pxpay->getResponse($enc_hex);

# the following are the fields available in the PxPayResponse object
$Success = $rsp->getSuccess(); # =1 when request succeeds
$AmountSettlement = $rsp->getAmountSettlement();
$AuthCode = $rsp->getAuthCode(); # from bank
$CardName = $rsp->getCardName(); # e.g. “Visa”
$CardNumber = $rsp->getCardNumber(); # Truncated card number
$DateExpiry = $rsp->getDateExpiry(); # in mmyy format
$DpsBillingId = $rsp->getDpsBillingId();
$BillingId = $rsp->getBillingId();
$CardHolderName = $rsp->getCardHolderName();
$DpsTxnRef = $rsp->getDpsTxnRef();
$TxnType = $rsp->getTxnType();
$TxnData1 = $rsp->getTxnData1();
$TxnData2 = $rsp->getTxnData2();
$TxnData3 = $rsp->getTxnData3();
$SurchargeOrg = $rsp->getTxnData2()*0.03;
$SurchargeRounded = number_format((float)$SurchargeOrg, 2, ‘.’, ”);
$CurrencySettlement= $rsp->getCurrencySettlement();
$ClientInfo = $rsp->getClientInfo(); # The IP address of the user who submitted the transaction
$TxnId = $rsp->getTxnId();
$CurrencyInput = $rsp->getCurrencyInput();
$EmailAddress = $rsp->getEmailAddress();
$MerchantReference = $rsp->getMerchantReference();
$ResponseText = $rsp->getResponseText();
$TxnMac = $rsp->getTxnMac(); # An indication as to the uniqueness of a card used in relation to others

if ($rsp->getSuccess() == “1”)
{
$result = “The transaction was successful.”;

# Sending invoices/updating order status within database etc.

if (!isProcessed($TxnId))
{
# Send emails, generate invoices, update order status etc.
}

}
else
{
$result = “The transaction was declined.”;
}

print <<<HTMLEOF

NZBN: 94 290 411 323 19
Suite 8074, 17B Farnham Street,
Parnell, Auckland 1052, New Zealand
Ph: 0800 453 630 Email: nzsupport@choruscall.com


Print The Receipt

$result
Company Name: $TxnData1
Accoutn Number: $TxnData3
Invoice Number(s): $MerchantReference
Total (Inc. GST): $TxnData2
Surcharge (3%): $SurchargeRounded
Total Charge: $AmountSettlement
Please call us if you need any assistance on 0800 453 630
or Email nzsupport@choruscall.com

HTMLEOF;
}

#******************************************************************************
# Database lookup to check the status of the order or shopping cart
#******************************************************************************

function isProcessed($TxnId)
{
# Check database if order relating to TxnId has alread been processed
return false;
}

#******************************************************************************
# This function prints a blank purchase form.
#******************************************************************************
function print_form()
{
print <<<HTMLEOF

Company Name:

Invoice Number(s):[tippy img=”https://www.choruscall.co.nz/wp-content/uploads/2017/02/info.png”]Located upper Left on Invoice.
If paying multiple invoices, please separate each with a comma ( , ) Maximum of four (4) allowed.
[/tippy]
Account Number:[tippy img=”https://www.choruscall.co.nz/wp-content/uploads/2017/02/info.png”]Located upper Left on Invoice. Maximum of four (4) allowed.
[/tippy]
Total on Invoice(s) (Inc. GST):[tippy img=”https://www.choruscall.co.nz/wp-content/uploads/2017/02/info.png”]Total amount Inc. GST
[/tippy] $  
Credit Card Surcharge*:
$  
Total Charge:
$  

Secure Payment via Commonwealth BankChorus Call New Zealand uses a secured payment gateway via Payment Express.


*Please Note: A 3% surcharge, Inc. GST, is applied to all Credit Card payments. Please use alternative payment methods to avoid this bank processing fee.

HTMLEOF;
}

#******************************************************************************
# This function formats data into a request and redirects to the
# Payments Page.
#******************************************************************************
function redirect_form($pxpay)
{

$request = new PxPayRequest();

$http_host = getenv(“HTTP_HOST”);
$request_uri = getenv(“SCRIPT_NAME”);
$server_url = “https://$http_host”;
#$script_url = “$server_url/$request_uri”; //using this code before PHP version 4.3.4
#$script_url = “$server_url$request_uri”; //Using this code after PHP version 4.3.4
$script_url = (version_compare(PHP_VERSION, “4.3.4”, “>=”)) ?”$server_url$request_uri” : “$server_url/$request_uri”;

# the following variables are read from the form

$ComName = $_REQUEST[“ComName”];
$MerchantReference = $_REQUEST[“InvNum”];
$AccNum = $_REQUEST[“AccNum”];
$InvTotal = $_REQUEST[“InvTotal”];
$Surcharge = $_REQUEST[“Surcharge”];
$AmountInput = $_REQUEST[“AmountInput”];

#Generate a unique identifier for the transaction
$TxnId = uniqid(“ID”);

#Set PxPay properties

$request->setMerchantReference($MerchantReference);
$request->setAmountInput($AmountInput);
$request->setTxnData1($ComName);
$request->setTxnData2($InvTotal);
$request->setTxnData3($AccNum);
$request->setTxnType(“Purchase”);
$request->setCurrencyInput(“NZD”);
$request->setUrlFail($script_url); # can be a dedicated failure page
$request->setUrlSuccess($script_url); # can be a dedicated success page
$request->setTxnId($TxnId);

#The following properties are not used in this case
# $request->setEnableAddBillCard($EnableAddBillCard);
# $request->setBillingId($BillingId);
# $request->setOpt($Opt);

#Call makeRequest function to obtain input XML
$request_string = $pxpay->makeRequest($request);

#Obtain output XML
$response = new MifMessage($request_string);

#Parse output XML
$url = $response->get_element_text(“URI”);
$valid = $response->get_attribute(“valid”);

#Redirect to payment page
header(“Location: “.$url);
}
[/insert_php]