File: /data/www/webtemplate/wtv2/codedoc/wtTransaction.php
<?php
/**
* WebTemplate Core
*
* @version 2.0
* @module WebTemplate Core
*/
require_once($GLOBALS["WTDIRECTORY"] . "include/ctel/ctel.php");
require_once($GLOBALS["WTDIRECTORY"] . "include/migs/migs.php");
function ctelPayment($args) {
if(!array_key_exists("Merchant", $args)) {
$merchant = $GLOBALS["WT"]->getNode("/Config/Settings/Ctel/Merchant");
if($merchant != NULL) {
$args["Merchant"] = $merchant->getAttribute("Value");
}
}
if(!array_key_exists("Username", $args)) {
$username = $GLOBALS["WT"]->getNode("/Config/Settings/Ctel/Username");
if($username != NULL) {
$args["Username"] = $username->getAttribute("Value");
}
}
if(!array_key_exists("Password", $args)) {
$password = $GLOBALS["WT"]->getNode("/Config/Settings/Ctel/Password");
if($password != NULL) {
$args["Password"] = $password->getAttribute("Value");
}
}
$successful = 0;
$description = '';
$response = wtCtelTransaction($args);
$successful = $response->Successful;
if(!$successful) {
$successful = 0;
} else {
$successful = 1;
}
$receipt = $response->Receipt;
$description = $response->ResponseDescription;
ob_start();
print_r($response);
$responseString = ob_get_contents();
ob_end_clean();
$args["Password"] = "";
$args["CardNumber"] = "";
$args["CardSecurityNumber"] = "xxx";
ob_start();
print_r($args);
$request = ob_get_contents();
ob_end_clean();
return Array("Request" => $request, "Response" => $responseString, "Successful ID" => $successful, "Description" => $description, "Receipt" => $receipt);
}
function migsPayment($args) {
$args["Merchant"] = WTConfig::get("MiGS/Merchant");
$args["MerchantAccessCode"] = WTConfig::get("MiGS/Merchant Access Code");
$expiry = $args["CardExpiry"];
$expiryMonth = substr($expiry, 0, 2);
$expiryYear = substr($expiry, 2);
$args["CardExpiry"] = $expiryYear . $expiryMonth;
$successful = 0;
$description = '';
//print_r($args);
//exit("");
$response = wtMigsTransaction($args);
//vpc_TxnResponseCode
if(array_key_exists("vpc_TxnResponseCode", $response) && is_numeric($response["vpc_TxnResponseCode"]) && $response["vpc_TxnResponseCode"] == 0) {
$successful = 1;
} else {
$successful = 0;
}
$receipt = $response["vpc_ReceiptNo"];
$description = $response["vpc_Message"];
ob_start();
print_r($response);
$responseString = ob_get_contents();
ob_end_clean();
// $args["Password"] = "";
$args["CardNumber"] = "";
$args["CardSecurityNumber"] = "xxx";
ob_start();
print_r($args);
$request = ob_get_contents();
ob_end_clean();
return Array("Request" => $request, "Response" => $responseString, "Successful ID" => $successful, "Description" => $description, "Receipt" => $receipt);
}
/**
* The class representing wtTransaction Nodes
*
* @class WTTransaction
* @extends WTNode
*/
class WTTransaction extends WTNode
{
/**
* Process a transation using either migs or ctel
*
* @method ccPayment
* @static
* @param {Array} An Associative array with the keys "Amount", "CardHolderName", "CardNumber", "CardExpiry", "CustomerReference", "CardSecurityNumber"
* @return {Object} The new transaction node
*/
public static function ccPayment($args)
{
if ( function_exists('_ccPayment') ) {
return _ccPayment($args);
}
$error = "";
if(!array_key_exists("Amount", $args)) {
$error .= "No Amount Specified\n";
}
if(!array_key_exists("CardHolderName", $args)) {
$error .= "No Card Holder Specified\n";
}
if(!array_key_exists("CardNumber", $args)) {
$error .= "No Card Number Specified\n";
}
if(!array_key_exists("CardExpiry", $args)) {
$error .= "No Card Expiry Specified\n";
}
if(!array_key_exists("CustomerReference", $args)) {
$error .= "No Customer Reference Specified\n";
}
if(!$error) {
$transactions = $GLOBALS["WT"]->getNode("/Transactions");
if(!$transactions ) {
$root = $GLOBALS["WT"]->getNode("/");
$transactions = $root->createChild("wtNode", Array("Node Name" => "Transactions"));
}
if($transactions) {
if($GLOBALS["WT"]->getNode("/Config/Settings/MiGS")) {
$transactionData = migsPayment($args);
} else {
$transactionData = ctelPayment($args);
}
return $transactions->createChild("wtTransaction", $transactionData);
}
}
}
public static function ____ccPayment($args) {
if ( function_exists('_ccPayment') ) {
return _ccPayment($args);
}
$error = "";
if(!array_key_exists("Merchant", $args)) {
$merchant = $GLOBALS["WT"]->getNode("/Config/Settings/Ctel/Merchant");
if($merchant != NULL) {
$args["Merchant"] = $merchant->getAttribute("Value");
}
}
if(!array_key_exists("Username", $args)) {
$username = $GLOBALS["WT"]->getNode("/Config/Settings/Ctel/Username");
if($username != NULL) {
$args["Username"] = $username->getAttribute("Value");
}
}
if(!array_key_exists("Password", $args)) {
$password = $GLOBALS["WT"]->getNode("/Config/Settings/Ctel/Password");
if($password != NULL) {
$args["Password"] = $password->getAttribute("Value");
}
}
if(!array_key_exists("Amount", $args)) {
$error .= "No Amount Specified\n";
}
if(!array_key_exists("CardHolderName", $args)) {
$error .= "No Card Holder Specified\n";
}
if(!array_key_exists("CardNumber", $args)) {
$error .= "No Card Number Specified\n";
}
if(!array_key_exists("CardExpiry", $args)) {
$error .= "No Card Expiry Specified\n";
}
if(!array_key_exists("CustomerReference", $args)) {
$error .= "No Customer Reference Specified\n";
}
$successful = 0;
$description = '';
if($error == "") {
$return = wtCtelTransaction($args);
// $successful = $return["Successful"];
$successful = $return->Successful;
if(!$successful) {
$successful = 0;
} else {
$successful = 1;
}
$receipt = $return->Receipt;
$description = $return->ResponseDescription;
ob_start();
print_r($return);
$response = ob_get_contents();
ob_end_clean();
} else {
$response = $error;
}
// if(array_key_exists("Debug", $args) || $args["Debug"] != 1) {
$args["Password"] = "";
$args["CardNumber"] = "";
// }
ob_start();
print_r($args);
$request = ob_get_contents();
ob_end_clean();
$transactions = $GLOBALS["WT"]->getNode("/Transactions");
if($transactions == NULL) {
$root = $GLOBALS["WT"]->getNode("/");
$transactions = $root->createChild("wtNode", Array("Node Name" => "Transactions"));
}
return $transactions->createChild("wtTransaction", Array("Request" => $request, "Response" => $response, "Successful ID" => $successful, "Description" => $description, "Receipt" => $receipt));
}
}
?>