Skip to content

Instantly share code, notes, and snippets.

@mafam1024
Created December 29, 2017 04:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mafam1024/aef07fed3fa9a43c77ec8593e83e7480 to your computer and use it in GitHub Desktop.
Save mafam1024/aef07fed3fa9a43c77ec8593e83e7480 to your computer and use it in GitHub Desktop.
<?php
// ----------------------------------------------------------------------------
// This function uses the QSI Response code retrieved from the Digital
// Receipt and returns an appropriate description for the QSI Response Code
//
// @param $responseCode String containing the QSI Response Code
//
// @return String containing the appropriate description
//
function getResultDescription($responseCode) {
switch ($responseCode) {
case "0" : $result = "Transaction Successful"; break;
case "?" : $result = "Transaction status is unknown"; break;
case "E" : $result = "Referred"; break;
case "1" : $result = "Transaction Declined"; break;
case "2" : $result = "Bank Declined Transaction"; break;
case "3" : $result = "No Reply from Bank"; break;
case "4" : $result = "Expired Card"; break;
case "5" : $result = "Insufficient funds"; break;
case "6" : $result = "Error Communicating with Bank"; break;
case "7" : $result = "Payment Server detected an error"; break;
case "8" : $result = "Transaction Type Not Supported"; break;
case "9" : $result = "Bank declined transaction (Do not contact Bank)"; break;
case "A" : $result = "Transaction Aborted"; break;
case "B" : $result = "Fraud Risk Blocked"; break;
case "C" : $result = "Transaction Cancelled"; break;
case "D" : $result = "Deferred transaction has been received and is awaiting processing"; break;
case "E" : $result = "Transaction Declined - Refer to card issuer"; break;
case "F" : $result = "3D Secure Authentication failed"; break;
case "I" : $result = "Card Security Code verification failed"; break;
case "L" : $result = "Shopping Transaction Locked (Please try the transaction again later)"; break;
case "M" : $result = "Transaction Submitted (No response from acquirer)"; break;
case "N" : $result = "Cardholder is not enrolled in Authentication scheme"; break;
case "P" : $result = "Transaction has been received by the Payment Adaptor and is being processed"; break;
case "R" : $result = "Transaction was not processed - Reached limit of retry attempts allowed"; break;
case "S" : $result = "Duplicate SessionID (Amex Only)"; break;
case "T" : $result = "Address Verification Failed"; break;
case "U" : $result = "Card Security Code Failed"; break;
case "V" : $result = "Address Verification and Card Security Code Failed"; break;
default : $result = "Unable to be determined";
}
return $result;
}
// ----------------------------------------------------------------------------
// This function uses the QSI AVS Result Code retrieved from the Digital
// Receipt and returns an appropriate description for this code.
// @param avsResultCode String containing the QSI AVS Result Code
// @return description String containing the appropriate description
function getAVSResultDescription($avsResultCode) {
if ($avsResultCode != "") {
switch ($avsResultCode) {
Case "Unsupported" : $result = "AVS not supported or there was no AVS data provided"; break;
Case "X" : $result = "Exact match - address and 9 digit ZIP/postal code"; break;
Case "Y" : $result = "Exact match - address and 5 digit ZIP/postal code"; break;
Case "W" : $result = "9 digit ZIP/postal code matched, Address not Matched"; break;
Case "S" : $result = "Service not supported or address not verified (international transaction)"; break;
Case "G" : $result = "Issuer does not participate in AVS (international transaction)"; break;
Case "C" : $result = "Street Address and Postal Code not verified for International Transaction due to incompatible formats."; break;
Case "I" : $result = "Visa Only. Address information not verified for international transaction."; break;
Case "A" : $result = "Address match only"; break;
Case "Z" : $result = "5 digit ZIP/postal code matched, Address not Matched"; break;
Case "R" : $result = "Issuer system is unavailable"; break;
Case "U" : $result = "Address unavailable or not verified"; break;
Case "E" : $result = "Address and ZIP/postal code not provided"; break;
Case "B" : $result = "Street Address match for international transaction. Postal Code not verified due to incompatible formats."; break;
Case "N" : $result = "Address and ZIP/postal code not matched"; break;
Case "0" : $result = "AVS not requested"; break;
Case "D" : $result = "Street Address and postal code match for international transaction."; break;
Case "M" : $result = "Street Address and postal code match for international transaction."; break;
Case "P" : $result = "Postal Codes match for international transaction but street address not verified due to incompatible formats."; break;
Case "K" : $result = "Card holder name only matches."; break;
Case "F" : $result = "Street address and postal code match. Applies to U.K. only."; break;
default : $result = "Unable to be determined";
}
} else {
$result = "null response";
}
return $result;
}
// ----------------------------------------------------------------------------
// This function uses the QSI CSC Result Code retrieved from the Digital
// Receipt and returns an appropriate description for this code.
// @param cscResultCode String containing the QSI CSC Result Code
// @return description String containing the appropriate description
function getCSCResultDescription($cscResultCode) {
if ($cscResultCode != "") {
switch ($cscResultCode) {
Case "Unsupported" : $result = "CSC not supported or there was no CSC data provided"; break;
Case "M" : $result = "Exact code match"; break;
Case "S" : $result = "Merchant has indicated that CSC is not present on the card (MOTO situation)"; break;
Case "P" : $result = "Code not processed"; break;
Case "U" : $result = "Card issuer is not registered and/or certified"; break;
Case "N" : $result = "Code invalid or not matched"; break;
default : $result = "Unable to be determined"; break;
}
} else {
$result = "null response";
}
return $result;
}
// -----------------------------------------------------------------------------
?>
<?php
// Initialisation
// ==============
//
include('VPCPaymentConnection.php');
$conn = new VPCPaymentConnection();
// This is secret for encoding the SHA256 hash
// This secret will vary from merchant to merchant
$secureSecret = "7E5C2F4D270600C61F5386167ECB8DA6";
// Set the Secure Hash Secret used by the VPC connection object
$conn->setSecureSecret($secureSecret);
// Set the error flag to false
$errorExists = false;
// *******************************************
// START OF MAIN PROGRAM
// *******************************************
// This is the title for display
$title = $_GET["Title"];
// Add VPC post data to the Digital Order
foreach($_GET as $key => $value) {
if (($key!="vpc_SecureHash") && ($key != "vpc_SecureHashType") && ((substr($key, 0,4)=="vpc_") || (substr($key,0,5) =="user_"))) {
$conn->addDigitalOrderField($key, $value);
}
}
// Obtain a one-way hash of the Digital Order data and
// check this against what was received.
$serverSecureHash = array_key_exists("vpc_SecureHash", $_GET) ? $_GET["vpc_SecureHash"] : "";
$secureHash = $conn->hashAllFields();
if ($secureHash==$serverSecureHash) {
$hashValidated = "<font color='#00AA00'><strong>CORRECT</strong></font>";
} else {
$hashValidated = "<font color='#FF0066'><strong>INVALID HASH</strong></font>";
$errorsExist = true;
}
/* If there has been a merchant secret set then sort and loop through all the
data in the Virtual Payment Client response. while we have the data, we can
append all the fields that contain values (except the secure hash) so that
we can create a hash and validate it against the secure hash in the Virtual
Payment Client response.
NOTE: If the vpc_TxnResponseCode in not a single character then
there was a Virtual Payment Client error and we cannot accurately validate
the incoming data from the secure hash.
// remove the vpc_TxnResponseCode code from the response fields as we do not
// want to include this field in the hash calculation
if (secureSecret != null && secureSecret.length() > 0 &&
(fields.get("vpc_TxnResponseCode") != null || fields.get("vpc_TxnResponseCode") != "No Value Returned")) {
// create secure hash and append it to the hash map if it was created
// remember if secureSecret = "" it wil not be created
String secureHash = vpc3conn.hashAllFields(fields);
// Validate the Secure Hash (remember hashes are not case sensitive)
if (vpc_Txn_Secure_Hash.equalsIgnoreCase(secureHash)) {
// Secure Hash validation succeeded, add a data field to be
// displayed later.
hashValidated = "<font color='#00AA00'><strong>CORRECT</strong></font>";
} else {
// Secure Hash validation failed, add a data field to be
// displayed later.
errorExists = true;
hashValidated = "<font color='#FF0066'><strong>INVALID HASH</strong></font>";
}
} else {
// Secure Hash was not validated,
hashValidated = "<font color='orange'><strong>Not Calculated - No 'SECURE_SECRET' present.</strong></font>";
}
*/
// Extract the available receipt fields from the VPC Response
// If not present then let the value be equal to 'Unknown'
// Standard Receipt Data
$Title = array_key_exists("Title", $_GET) ? $_GET["Title"] : "";
$againLink = array_key_exists("AgainLink", $_GET) ? $_GET["AgainLink"] : "";
$amount = array_key_exists("vpc_Amount", $_GET) ? $_GET["vpc_Amount"] : "";
$locale = array_key_exists("vpc_Locale", $_GET) ? $_GET["vpc_Locale"] : "";
$batchNo = array_key_exists("vpc_BatchNo", $_GET) ? $_GET["vpc_BatchNo"] : "";
$command = array_key_exists("vpc_Command", $_GET) ? $_GET["vpc_Command"] : "";
$message = array_key_exists("vpc_Message", $_GET) ? $_GET["vpc_Message"] : "";
$version = array_key_exists("vpc_Version", $_GET) ? $_GET["vpc_Version"] : "";
$cardType = array_key_exists("vpc_Card", $_GET) ? $_GET["vpc_Card"] : "";
$orderInfo = array_key_exists("vpc_OrderInfo", $_GET) ? $_GET["vpc_OrderInfo"] : "";
$receiptNo = array_key_exists("vpc_ReceiptNo", $_GET) ? $_GET["vpc_ReceiptNo"] : "";
$merchantID = array_key_exists("vpc_Merchant", $_GET) ? $_GET["vpc_Merchant"] : "";
$merchTxnRef = array_key_exists("vpc_MerchTxnRef", $_GET) ? $_GET["vpc_MerchTxnRef"] : "";
$authorizeID = array_key_exists("vpc_AuthorizeId", $_GET) ? $_GET["vpc_AuthorizeId"] : "";
$transactionNo = array_key_exists("vpc_TransactionNo", $_GET) ? $_GET["vpc_TransactionNo"] : "";
$acqResponseCode = array_key_exists("vpc_AcqResponseCode", $_GET) ? $_GET["vpc_AcqResponseCode"] : "";
$txnResponseCode = array_key_exists("vpc_TxnResponseCode", $_GET) ? $_GET["vpc_TxnResponseCode"] : "";
$riskOverallResult = array_key_exists("vpc_RiskOverallResult", $_GET) ? $_GET["vpc_RiskOverallResult"]: "";
// Obtain the 3DS response
$vpc_3DSECI = array_key_exists("vpc_3DSECI", $_GET) ? $_GET["vpc_3DSECI"] : "";
$vpc_3DSXID = array_key_exists("vpc_3DSXID", $_GET) ? $_GET["vpc_3DSXID"] : "";
$vpc_3DSenrolled = array_key_exists("vpc_3DSenrolled", $_GET) ? $_GET["vpc_3DSenrolled"] : "";
$vpc_3DSstatus = array_key_exists("vpc_3DSstatus", $_GET) ? $_GET["vpc_3DSstatus"] : "";
$vpc_VerToken = array_key_exists("vpc_VerToken", $_GET) ? $_GET["vpc_VerToken"] : "";
$vpc_VerType = array_key_exists("vpc_VerType", $_GET) ? $_GET["vpc_VerType"] : "";
$vpc_VerStatus = array_key_exists("vpc_VerStatus", $_GET) ? $_GET["vpc_VerStatus"] : "";
$vpc_VerSecurityLevel = array_key_exists("vpc_VerSecurityLevel", $_GET) ? $_GET["vpc_VerSecurityLevel"] : "";
// CSC Receipt Data
$cscResultCode = array_key_exists("vpc_CSCResultCode", $_GET) ? $_GET["vpc_CSCResultCode"] : "";
$ACQCSCRespCode = array_key_exists("vpc_AcqCSCRespCode", $_GET) ? $_GET["vpc_AcqCSCRespCode"] : "";
// Get the descriptions behind the QSI, CSC and AVS Response Codes
// Only get the descriptions if the string returned is not equal to "No Value Returned".
$txnResponseCodeDesc = "";
$cscResultCodeDesc = "";
$avsResultCodeDesc = "";
if ($txnResponseCode != "No Value Returned") {
$txnResponseCodeDesc = getResultDescription($txnResponseCode);
}
if ($cscResultCode != "No Value Returned") {
$cscResultCodeDesc = getCSCResultDescription($cscResultCode);
}
$error = "";
// Show this page as an error page if error condition
if ($txnResponseCode=="7" || $txnResponseCode=="No Value Returned" || $errorExists) {
$error = "Error ";
}
// FINISH TRANSACTION - Process the VPC Response Data
// =====================================================
// For the purposes of demonstration, we simply display the Result fields on a
// web page.
?> <!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN'>
<html>
<head><title><?php echo($title) ?> - VPC Response <?php echo($error) ?>Page</title>
<meta http-equiv='Content-Type' content='text/html, charset=iso-8859-1'>
<style type='text/css'>
<!--
h1 { font-family:Arial,sans-serif; font-size:20pt; font-weight:600; margin-bottom:0.1em; color:#08185A;}
h2 { font-family:Arial,sans-serif; font-size:14pt; font-weight:100; margin-top:0.1em; color:#08185A;}
h2.co { font-family:Arial,sans-serif; font-size:24pt; font-weight:100; margin-top:0.1em; margin-bottom:0.1em; color:#08185A}
h3 { font-family:Arial,sans-serif; font-size:16pt; font-weight:100; margin-top:0.1em; margin-bottom:0.1em; color:#08185A}
h3.co { font-family:Arial,sans-serif; font-size:16pt; font-weight:100; margin-top:0.1em; margin-bottom:0.1em; color:#FFFFFF}
body { font-family:Verdana,Arial,sans-serif; font-size:10pt; background-color:#FFFFFF; color:#08185A}
th { font-family:Verdana,Arial,sans-serif; font-size:8pt; font-weight:bold; background-color:#CED7EF; padding-top:0.5em; padding-bottom:0.5em; color:#08185A}
tr { height:25px; }
.shade { height:25px; background-color:#CED7EF }
.title { height:25px; background-color:#0074C4 }
td { font-family:Verdana,Arial,sans-serif; font-size:8pt; color:#08185A }
td.red { font-family:Verdana,Arial,sans-serif; font-size:8pt; color:#FF0066 }
td.green { font-family:Verdana,Arial,sans-serif; font-size:8pt; color:#008800 }
p { font-family:Verdana,Arial,sans-serif; font-size:10pt; color:#FFFFFF }
p.blue { font-family:Verdana,Arial,sans-serif; font-size:7pt; color:#08185A }
p.red { font-family:Verdana,Arial,sans-serif; font-size:7pt; color:#FF0066 }
p.green { font-family:Verdana,Arial,sans-serif; font-size:7pt; color:#008800 }
div.bl { font-family:Verdana,Arial,sans-serif; font-size:7pt; color:#0074C4 }
div.red { font-family:Verdana,Arial,sans-serif; font-size:7pt; color:#FF0066 }
li { font-family:Verdana,Arial,sans-serif; font-size:8pt; color:#FF0066 }
input { font-family:Verdana,Arial,sans-serif; font-size:8pt; color:#08185A; background-color:#CED7EF; font-weight:bold }
select { font-family:Verdana,Arial,sans-serif; font-size:8pt; color:#08185A; background-color:#CED7EF; font-weight:bold; }
textarea { font-family:Verdana,Arial,sans-serif; font-size:8pt; color:#08185A; background-color:#CED7EF; font-weight:normal; scrollbar-arrow-color:#08185A; scrollbar-base-color:#CED7EF }
-->
</style>
</head>
<body>
<!-- Start Branding Table -->
<table width="100%" border="2" cellpadding="2" class="title">
<tr>
<td class="shade" width="90%"><h2 class="co">&nbsp;MasterCard Virtual Payment Client Example</h2></td>
</tr>
</table>
<!-- End Branding Table -->
<center><h1><?php echo($title); ?> <?php echo($error); ?>Response Page</H1></center>
<table width="85%" align='center' cellpadding='5' border='0'>
<tr class='title'>
<td colspan="2" height="25"><p><strong>&nbsp;Standard Transaction Fields</strong></p></td>
</tr>
<tr>
<td align='right' width='50%'><strong><i>VPC API Version: </i></strong></td>
<td width='50%'><?php echo($version); ?></td>
</tr>
<tr class='shade'>
<td align='right'><strong><i>Command: </i></strong></td>
<td><?php echo($command); ?></td>
</tr>
<tr>
<td align='right'><strong><i>Merchant Transaction Reference: </i></strong></td>
<td><?php echo($merchTxnRef); ?></td>
</tr>
<tr class='shade'>
<td align='right'><strong><i>Merchant ID: </i></strong></td>
<td><?php echo($merchantID); ?></td>
</tr>
<tr>
<td align='right'><strong><i>Order Information: </i></strong></td>
<td><?php echo($orderInfo); ?></td>
</tr>
<tr class='shade'>
<td align='right'><strong><i>Transaction Amount: </i></strong></td>
<td><?php echo($amount); ?></td>
</tr>
<tr>
<td align='right'><strong><i>Locale: </i></strong></td>
<td><?php echo($locale); ?></td>
</tr>
<tr>
<td colspan='2' align='center'><font color='#0074C4'>Fields above are the primary request values.<br/></font><hr/>
</td>
</tr>
<tr class='shade'>
<td align='right'><strong><i>VPC Transaction Response Code: </i></strong></td>
<td><?php echo($txnResponseCode); ?></td>
</tr>
<tr>
<td align='right'><strong><i>Transaction Response Code Description: </i></strong></td>
<td><?php echo($txnResponseCodeDesc); ?></td>
</tr>
<tr class='shade'>
<td align='right'><strong><i>Message: </i></strong></td>
<td><?php echo($message); ?></td>
</tr>
<?php
// only display the following fields if not an error condition
if ($txnResponseCode!="7" && $txnResponseCode!="No Value Returned") {
?>
<tr>
<td align='right'><strong><i>Receipt Number: </i></strong></td>
<td><?php echo($receiptNo); ?></td>
</tr>
<tr class='shade'>
<td align='right'><strong><i>Transaction Number: </i></strong></td>
<td><?php echo($transactionNo); ?></td>
</tr>
<tr>
<td align='right'><strong><i>Acquirer Response Code: </i></strong></td>
<td><?php echo($acqResponseCode); ?></td>
</tr>
<tr class='shade'>
<td align='right'><strong><i>Bank Authorization ID: </i></strong></td>
<td><?php echo($authorizeID); ?></td>
</tr>
<tr>
<td align='right'><strong><i>Batch Number: </i></strong></td>
<td><?php echo($batchNo); ?></td>
</tr>
<tr class='shade'>
<td align='right'><strong><i>Card Type: </i></strong></td>
<td><?php echo($cardType); ?></td>
</tr>
<tr>
<td align='right'><strong><i>Risk Overall Result: </i></strong></td>
<td><?php echo($riskOverallResult); ?></td>
</tr>
<tr>
<td colspan='2' align='center'><font color='#0074C4'>Fields above are for a standard transaction.<br/><hr/>
Fields below are additional fields for extra functionality.</font><br/></td>
</tr>
<tr class='title'>
<td colspan="2" height="25"><p><strong>&nbsp;Card Security Code Fields</strong></p></td>
</tr>
<tr class='shade'>
<td align='right'><strong><i>CSC Acquirer Response Code: </i></strong></td>
<td><?php echo($ACQCSCRespCode); ?></td>
</tr>
<tr>
<td align='right'><strong><i>CSC QSI Result Code: </i></strong></td>
<td><?php echo($cscResultCode); ?></td>
</tr>
<tr class='shade'>
<td align='right'><strong><i>CSC Result Description: </i></strong></td>
<td><?php echo($cscResultCodeDesc); ?></td>
</tr>
<tr class="title">
<td colspan="2" height="25"><P><strong>&nbsp;3-D Secure Fields</strong></P></td>
</tr>
<tr>
<td align="right"><strong><i>Unique 3DS transaction identifier (xid): </i></strong></td>
<td class="red"><?php echo($vpc_3DSXID); ?></td>
</tr>
<tr class="shade">
<td align="right"><strong><i>3DS Authentication Verification Value: </i></strong></td>
<td class="red"><?php echo($vpc_VerToken); ?></td>
</tr>
<tr>
<td align="right"><strong><i>3DS Electronic Commerce Indicator (ECI): </i></strong></td>
<td class="red"><?php echo($vpc_3DSECI); ?></td>
</tr>
<tr class="shade">
<td align="right"><strong><i>3DS Authentication Scheme: </i></strong></td>
<td class="red"><?php echo($vpc_VerType); ?></td>
</tr>
<tr>
<td align="right"><strong><i>3DS Security level used in the AUTH message: </i></strong></td>
<td class="red"><?php echo($vpc_VerSecurityLevel); ?></td>
</tr>
<tr class="shade">
<td align="right">
<strong><i>3DS CardHolder Enrolled: </strong>
<br>
<font size="1">Takes values: <strong>Y</strong> - Yes <strong>N</strong> - No</i></font>
</td>
<td class="red"><?php echo($vpc_3DSenrolled); ?></td>
</tr>
<tr>
<td align="right">
<i><strong>Authenticated Successfully: </strong><br>
<font size="1">Only returned if CardHolder Enrolled = <strong>Y</strong>. Takes values:<br>
<strong>Y</strong> - Yes <strong>N</strong> - No <strong>A</strong> - Attempted to Check <strong>U</strong> - Unavailable for Checking</font></i>
</td>
<td class="red"><?php echo($vpc_3DSstatus); ?></td>
</tr>
<tr class="shade">
<td align="right"><strong><i>Payment Server 3DS Authentication Status Code: </i></strong></td>
<td class="green"><?php echo($vpc_VerStatus); ?></td>
</tr>
<tr>
<td colspan="2" class="red" align="center">
<br>The 3-D Secure values shown in red are those values that are important values to store in case of future transaction repudiation.
</td>
</tr>
<tr>
<td colspan="2" class="green" align="center">
The 3-D Secure values shown in green are for information only and are not required to be stored.
</td>
</tr>
<tr><td colspan = '2'><hr/></td></tr>
<tr>
<td colspan = '2'><hr/></td>
</tr>
<tr class='title'>
<td colspan="2" height="25"><p><strong>&nbsp;Hash Validation</strong></p></td>
</tr>
<tr>
<td align="right"><strong><i>Hash Validated Correctly: </i></strong></td>
<td><?php echo($hashValidated); ?></td>
</tr>
<?php } ?></table><br/>
<center><P><A HREF='PHP_VPC_3Party_Order.html'>New Transaction</A></P></center>
</body>
</html>
<?php
require('PaymentCodesHelper.php');
class VPCPaymentConnection {
// Define Variables
// ----------------
private $errorExists = false; // Indicates if an error exists
private $errorMessage; // The error message
private $postData; // Data to be posted to the payment server
private $responseMap; // Array of receipt data
private $secureHashSecret; // Used for one way hashing in 3-party transactions
private $hashInput;
private $message;
public function addDigitalOrderField($field, $value) {
if (strlen($value) == 0) return false; // Exit the function if no $value data is provided
if (strlen($field) == 0) return false; // Exit the function if no $value data is provided
// Add the digital order information to the data to be posted to the Payment Server
$this->postData .= (($this->postData=="") ? "" : "&") . urlencode($field) . "=" . urlencode($value);
// Add the key's value to the hash input (only used for 3 party)
$this->hashInput .= $field . "=" . $value . "&";
return true;
}
public function sendMOTODigitalOrder($vpcURL, $proxyHostAndPort = "", $proxyUserPwd = "") {
$message = "";
// Generate and Send Digital Order (& receive DR)
// *******************************************************
// Exit if there is no data to send to the Virtual Payment Client
if (strlen($this->postData) == 0) return false;
// Get a HTTPS connection to VPC Gateway and do transaction
// turn on output buffering to stop response going to browser
ob_start();
// initialise Client URL object
$ch = curl_init();
// set the URL of the VPC
curl_setopt ($ch, CURLOPT_URL, $vpcURL);
curl_setopt ($ch, CURLOPT_POST, 1);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $this->postData);
if (strlen($proxyHostAndPort) > 0) {
if (strlen($proxyUserPwd) > 0) {
// (optional) set the proxy IP address, port and proxy username and password
curl_setopt ($ch, CURLOPT_PROXY, $proxyHostAndPort, CURLOPT_PROXYUSERPWD, $proxyUserPwd);
}
else {
// (optional) set the proxy IP address and port without proxy authentication
curl_setopt ($ch, CURLOPT_PROXY, $proxyHostAndPort);
}
}
// (optional) certificate validation
// trusted certificate file
//curl_setopt($ch, CURLOPT_CAINFO, "c:/temp/ca-bundle.crt");
//turn on/off cert validation
// 0 = don't verify peer, 1 = do verify
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0);
// 0 = don't verify hostname, 1 = check for existence of hostame, 2 = verify
curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);
// connect
curl_exec ($ch);
// get response
$response = ob_get_contents();
// turn output buffering off.
ob_end_clean();
// set up message paramter for error outputs
$this->errorMessage = "";
// serach if $response contains html error code
if(strchr($response,"<HTML>") || strchr($response,"<html>")) {;
$this->errorMessage = $response;
} else {
// check for errors from curl
if (curl_error($ch))
$this->errorMessage = "curl_errno=". curl_errno($ch) . " (" . curl_error($ch) . ")";
}
// close client URL
curl_close ($ch);
// Extract the available receipt fields from the VPC Response
// If not present then let the value be equal to 'No Value Returned'
$this->responseMap = array();
// process response if no errors
if (strlen($message) == 0) {
$pairArray = explode("&", $response);
foreach ($pairArray as $pair) {
$param = explode("=", $pair);
$this->responseMap[urldecode($param[0])] = urldecode($param[1]);
}
return true;
} else {
return false;
}
}
public function getDigitalOrder($vpcURL) {
$redirectURL = $vpcURL."?".$this->postData;
return $redirectURL;
}
public function decryptDR($digitalReceipt) {
// Decrypt Digital Receipt
// ********************************
if (!$this->socketCreated) return false; // Exit function if an the socket connection hasn't been created
if ($this->errorExists) return false; // Exit function if an error exists
// (This primary command to decrypt the Digital Receipt)
$cmdResponse = $this->sendCommand("3,$digitalReceipt");
if (substr($cmdResponse,0,1) != "1") {
// Retrieve the Payment Client Error (There may be none to retrieve)
$cmdResponse = $this->sendCommand("4,PaymentClient.Error");
if (substr($cmdResponse,0,1) == "1") {$exception = substr($cmdResponse,2);}
$this->errorMessage = "(11) Digital Order has not created correctly - decryptDR($digitalReceipt) failed - $exception";
$this->errorExists = true;
return false;
}
// Set the socket timeout value to normal
$this->payClientTimeout = $this->SHORT_SOCKET_TIMEOUT;
// Automatically call the nextResult function
$this->nextResult();
return true;
}
public function getResultField($field) {
return $this->null2unknown($field);
//return substr($cmdResponse,0,1) == "1" ? substr($cmdResponse,2) : "";
}
public function getErrorMessage() {
return $this->errorMessage;
}
public function setSecureSecret($secret) {
$this->secureHashSecret = $secret;
}
public function hashAllFields() {
$this->hashInput=rtrim($this->hashInput,"&");
return strtoupper(hash_hmac('SHA256',$this->hashInput, pack("H*",$this->secureHashSecret)));
}
private function null2unknown($key) {
// This subroutine takes a data String and returns a predefined value if empty
// If data Sting is null, returns string "No Value Returned", else returns input
// @param $in String containing the data String
// @return String containing the output String
if (array_key_exists($key, $this->responseMap)) {
if (!is_null($this->responseMap[$key])) {
return $this->responseMap[$key];
}
}
return "No Value Returned";
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment