Skip to content

Instantly share code, notes, and snippets.

@HostedPCI
Last active May 2, 2016 05:44
Show Gist options
  • Save HostedPCI/cc44927e16e4fb5686ba to your computer and use it in GitHub Desktop.
Save HostedPCI/cc44927e16e4fb5686ba to your computer and use it in GitHub Desktop.
Php code samples
<?php
$params = new stdClass;
$params->hpci_site_host_name = baseurl();
$params->hpci_site_id = '520900';
$params->hpci_location = 'checkout1';
$params->hpci_query_string = $_SERVER['QUERY_STRING'];
$params->hpci_api_host = 'https://api-wisvis1stg.c1.hostedpci.com/';
$params->hpci_api_uid = 'ObtainTestAccount';
$params->hpci_api_pwd = '*****';
?>
<?php
$params = new stdClass;
$params->hpci_site_host_name = baseurl();
$params->hpci_site_id = '520820';
$params->hpci_location = 'checkout1';
$params->hpci_query_string = $_SERVER['QUERY_STRING'];
$params->hpci_api_host = 'https://api-ichk1stg.c1.hostedpci.com/';
$params->hpci_api_uid = 'ObtainTestAccount';
$params->hpci_api_pwd = '******';
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<?php
error_reporting(E_ALL);
ini_Set('display_errors', '1');
require("hpci.php");
require("config.php");
?>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>HPCI Express Checkout - PHP Example</title>
</head>
<body>
<?php echo '<h2>HostedPCI Express Checkout - PHP Example POST Results.</h2>'; ?>
<h3>Mapped Credit Card Number: <?php echo emptyIfNullFromRequest("ccNum"); ?></h3>
<h3>Mapped CVV Code: <?php echo emptyIfNullFromRequest("ccCVV"); ?></h3>
<h3>Test Auth Amount: <?php echo emptyIfNullFromRequest("amount"); ?></h3>
<h3>Validate 3DS: <?php echo emptyIfNullFromRequest("3ds"); ?></h3>
<h3>3DS Action Specified: <?php echo emptyIfNullFromRequest("3dsAction"); ?></h3>
<h3>3DS Authorization Transaction ID: <?php echo emptyIfNullFromRequest("3dsAuthTxnId"); ?></h3>
<pre>
<?php
//call to HPCI
$orderId = '100';
$processorRefId = authOnly($params->hpci_api_host, $params->hpci_api_uid, $params->hpci_api_pwd, emptyIfNullFromRequest("ccNum"),emptyIfNullFromRequest("ccCVV"), $orderId, emptyIfNullFromRequest("amount"), emptyIfNullFromRequest("3ds"), emptyIfNullFromRequest("3dsAction"), emptyIfNullFromRequest("3dsAuthTxnId")); //test order 100
?>
</pre>
<h3>Test Auth Response: <?php echo $processorRefId; ?></h3>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<?php
error_reporting(E_ALL);
ini_Set('display_errors', '1');
require("hpci.php");
require("config.php");
//set the 3D Secure action if it's not passed in
//the checkbox on the credit card form will indicate
//if 3DS should be used, or not.
$ThreeDSecureAction = ACTIONNAME_VERIFYENROLL;
if (isset($_REQUEST["3dsAction"])) {
$ThreeDSecureAction = $_REQUEST["3dsAction"];
}
?>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>HPCI Express Checkout - PHP Example</title>
<!-- required JavaScript to enable HPCI IFRAME functionality -->
<script src="https://cc.hostedpci.com/WBSStatic/site60/proxy/js/jquery-1.4.1.min.js" type="text/javascript" charset="utf-8"></script>
<script src="https://cc.hostedpci.com/WBSStatic/site60/proxy/js/jquery.ba-postmessage.min.js" type="text/javascript" charset="utf-8"></script>
<script src="https://cc.hostedpci.com/WBSStatic/site60/proxy/js/hpci-cciframe-1.0.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
var hpciCCFrameHost = "https://cc.hostedpci.com";
var hpciCCFrameFullUrl = "https://cc.hostedpci.com/iSynSApp/showPxyPage!ccFrame.action?pgmode1=prod&locationName=<?php echo $params->hpci_location; ?>&sid=<?php echo $params->hpci_site_id; ?>&fullParentHost=<?php echo $params->hpci_site_host_name; ?>&fullParentQStr=<?php echo $params->hpci_query_string; ?>";
var hpciCCFrameName = "ccframe"; // use the name of the frame containing the credit card
var hpciSiteErrorHandler = function (errorCode, errorMsg){
// Please the following alert to properly display the error message
alert("Error while processing credit card code:" + errorCode + "; msg:" + errorMsg);
}
var hpciSiteSuccessHandler = function (mappedCCValue, mappedCVVValue){
// Please pass the values to the document input and then submit the form
// name of the input (hidden) field required by ecommerce site
// Typically this is a hidden input field.
var ccNumInput = document.getElementById("ccNum");
ccNumInput.value = mappedCCValue;
// name of the input (hidden) field required by ecommerce site
// Typically this is a hidden input field.
var ccCVVInput = document.getElementById("ccCVV");
ccCVVInput.value = mappedCVVValue;
// name of the form submission for ecommerce site
var pendingForm = document.getElementById("CCAcceptForm");
alert('HPCI Mapped Value: ' + mappedCCValue);
pendingForm.submit();
}
//3D Secure Handlers
var hpci3DSitePINSuccessHandler = function (){
var pendingForm = document.getElementById("CCAcceptForm");
alert("Received confirmation from 3DS Iframe, proceeding.");
pendingForm.submit();
}
var hpci3DSitePINErrorHandler = function (){
var pendingForm = document.getElementById("CCAcceptForm");
alert("Could not verify PIN received from 3DS Iframe, continuing authorization.");
pendingForm.submit();
}
</script>
</head>
<body>
<h3>HostedPCI Express Checkout - PHP Example</h3>
<form id="CCAcceptForm" class="form" name="company_form" action="hpci-test-post.php" method="POST">
<?php
/*
Check if 3D Secure PIN Verification is required. In this case, a credit card will not be
presented. Rather, a PIN verification form will be displayed by the HPCI IFRAME based on
the 3DS Authorization Transaction ID (3dsAuthId) parameter.
*/
if ($ThreeDSecureAction == ACTIONNAME_REQUESTPIN) { //3D Secure Request PIN IFRAME
// change the next action to verify response. This will be passed back into
// the authorization call to check if the PIN was verified.
$ThreeDSecureAction = ACTIONNAME_VERIFYRESP; //will be set in the form later
$authTxnId = emptyIfNullFromRequest("3dsAuthId");
echo "
<input type=\"hidden\" name=\"3dsAuthTxnId\" value=\"$authTxnId\" />
<input type=\"hidden\" id=\"ccNum\" name=\"ccNum\" value=\"" . emptyIfNullFromRequest('ccNum') . "\" />
<input type=\"hidden\" maxlength=\"4\" id=\"ccCVV\" name=\"ccCVV\" value=\"" . emptyIfNullFromRequest('ccCVV') ."\" />
<input type=\"hidden\" id=\"3ds\" name=\"3ds\" value=\"Y\" />
<input type=\"hidden\" id=\"amount\" name=\"amount\" value=\"" . emptyIfNullFromRequest('amount') ."\"/>
<iframe id=\"threeDSecFrame\" name=\"threeDSecFrame\" onload=\"receivePINMsg()\"" .
"src=\"https://cc.hostedpci.com/iSynSApp/appUserVerify3DResp!verificationForm.action?sid=$params->hpci_site_id&authTxnId=$authTxnId".
"&fullParentHost=$params->hpci_site_host_name&fullParentQStr=$params->hpci_query_string\" width=\"450\" height=\"325\" ".
"scrolling=\"NO\" frameBorder=\"0\">
If you can see this, your browser doesn't understand IFRAME.
</iframe>
<p>
Transaction Test Amount: " . emptyIfNullFromRequest("amount") . "<p>
3D Secure Auth ID: $authTxnId <p>
"; //END of echo
} //END: Request PIN
else { //HPCI CC IFRAME
/*
Display the standard HPCI IFRAME that will prompt the user for the credit card and CVV numbers.
Once entered, the user will click the "Submit" button which will call JS function sendHPCIMsg()
The form will be returned control once HPCI completes the tokenization process. Both ccNum and ccCVV
fields will be populated with the tokenized values. The form action will recieve these values
for authorization processing.
*/
echo "
<input type=\"hidden\" id=\"ccNum\" name=\"ccNum\" />
<input type=\"hidden\" maxlength=\"4\" id=\"ccCVV\" name=\"ccCVV\" />
<iframe id=\"ccframe\" name=\"ccframe\" " .
"src=\"https://cc.hostedpci.com/iSynSApp/showPxyPage!ccFrame.action?pgmode1=prod&locationName=$params->hpci_location&sid=$params->hpci_site_id&" .
"fullParentHost=$params->hpci_site_host_name&fullParentQStr=$params->hpci_query_string\" width=\"480\" height=\"75\" scrolling=\"NO\" " .
"frameBorder=\"0\">
If you can see this, your browser doesn't understand IFRAME.
</iframe>
</p>
Test Auth Amount <input type=\"text\" maxlength=\"10\" id=\"amount\" name=\"amount\" value=\"" . emptyIfNullFromRequest('amount') ."\"/>
<input type=\"checkbox\" name=\"3ds\" value=\"Y\" ";
if ($ThreeDSecureAction == ACTIONNAME_REQUESTPIN) {
echo " disabled=\"true\" checked=\"true\" ";
}
echo "> Authenticate with 3D Secure
</p>
<input type=\"button\" value=\"Submit Credit Card Data\" onClick='return sendHPCIMsg();' />
"; //END of echo
} //END: HPCI CC IFRAME
?>
<input type="hidden" name="3dsAction" value = "<?php echo $ThreeDSecureAction ?>">
</form> <!-- CC Accept Form -->
</body>
</html>
<?php
// define service constants
define("PXY_AUTH", "/iSynSApp/paymentAuth.action");
define("PXY_SALE", "/iSynSApp/paymentSale.action");
define("PXY_CAPTURE", "/iSynSApp/paymentCapture.action");
define("PXY_CREDIT", "/iSynSApp/paymentCredit.action");
define("PXY_VOID", "/iSynSApp/paymentVoid.action");
define("PXYPARAM_APIVERSION", "apiVersion");
define("PXYPARAM_APITYPE", "apiType");
define("PXYPARAM_APITYPE_PXYHPCI", "pxyhpci");
define("PXYPARAM_USERNAME", "userName");
define("PXYPARAM_USERPASSKEY", "userPassKey");
define("PXYPARAM_PXY_TRANSACTION_CUSISO", "pxyTransaction.txnCurISO");
define("PXYPARAM_PXY_TRANSACTION_AMOUNT", "pxyTransaction.txnAmount");
define("PXYPARAM_PXY_TRANSACTION_MER_REFID_NAME", "pxyTransaction.merchantRefIdName");
define("PXYPARAM_PXY_TRANSACTION_MER_REFID", "pxyTransaction.merchantRefId");
define("PXYPARAM_PXY_TRANSACTION_PROCESSOR_REFID", "pxyTransaction.processorRefId");
//3D Secure Constants
define("PXYPARAM_PXY_3DSECAUTH_ACTIONNAME", "pxyThreeDSecAuth.actionName");
define("PXYPARAM_PXY_3DSECAUTH_AUTHTXNID", "pxyThreeDSecAuth.authTxnId");
define("PXYPARAM_PXY_3DSECAUTH_AUTHSTATUS", "pxyThreeDSecAuth.authStatus");
define("PXYPARAM_PXY_3DSECAUTH_SIGNATURESTATUS", "pxyThreeDSecAuth.signatureStatus");
define("PXYPARAM_PXY_3DSECAUTH_AUTHCAVV", "pxyThreeDSecAuth.authCAVV");
define("PXYPARAM_PXY_3DSECAUTH_AUTHECI", "pxyThreeDSecAuth.authECI");
define("PXYPARAM_PXY_3DSECAUTH_AUTHACSURL", "pxyThreeDSecAuth.authAcsUrl");
define("PXYPARAM_PXY_3DSECAUTH_PAREQ", "pxyThreeDSecAuth.paReq");
define("PXYPARAM_PXY_3DSECAUTH_PARES", "pxyThreeDSecAuth.paRes");
define("PXYPARAM_PXY_3DSECAUTH_AUTHSIGN_COMBOLIST", "pxyThreeDSecAuth.authSignComboList");
define("PXYPARAM_PXY_CC_CARDTYPE", "pxyCreditCard.cardType");
define("PXYPARAM_PXY_CC_NUMBER", "pxyCreditCard.creditCardNumber");
define("PXYPARAM_PXY_CC_EXPMONTH", "pxyCreditCard.expirationMonth");
define("PXYPARAM_PXY_CC_EXPYEAR", "pxyCreditCard.expirationYear");
define("PXYPARAM_PXY_CC_CVV", "pxyCreditCard.cardCodeVerification");
define("PXYPARAM_PXY_CUSTINFO_CUSTOMERID", "pxyCustomerInfo.customerId");
define("PXYPARAM_PXY_CUSTINFO_EMAIL", "pxyCustomerInfo.email");
define("PXYPARAM_PXY_CUSTINFO_INSTR", "pxyCustomerInfo.instructions");
define("PXYPARAM_PXY_CUSTINFO_CUSTIP", "pxyCustomerInfo.customerIP");
define("PXYPARAM_PXY_CUSTINFO_BILLADDR_FIRSTNAME", "pxyCustomerInfo.billingLocation.firstName");
define("PXYPARAM_PXY_CUSTINFO_BILLADDR_LASTNAME", "pxyCustomerInfo.billingLocation.lastName");
define("PXYPARAM_PXY_CUSTINFO_BILLADDR_COMPANYNAME", "pxyCustomerInfo.billingLocation.companyName");
define("PXYPARAM_PXY_CUSTINFO_BILLADDR_ADDRESS", "pxyCustomerInfo.billingLocation.address");
define("PXYPARAM_PXY_CUSTINFO_BILLADDR_CITY", "pxyCustomerInfo.billingLocation.city");
define("PXYPARAM_PXY_CUSTINFO_BILLADDR_STATE", "pxyCustomerInfo.billingLocation.state");
define("PXYPARAM_PXY_CUSTINFO_BILLADDR_ZIPCODE", "pxyCustomerInfo.billingLocation.zipCode");
define("PXYPARAM_PXY_CUSTINFO_BILLADDR_COUNTRY", "pxyCustomerInfo.billingLocation.country");
define("PXYPARAM_PXY_CUSTINFO_BILLADDR_PHONENUMBER", "pxyCustomerInfo.billingLocation.phoneNumber");
define("PXYPARAM_PXY_CUSTINFO_BILLADDR_FAX", "pxyCustomerInfo.billingLocation.fax");
define("PXYPARAM_PXY_CUSTINFO_BILLADDR_TAX1", "pxyCustomerInfo.billingLocation.tax1");
define("PXYPARAM_PXY_CUSTINFO_BILLADDR_TAX2", "pxyCustomerInfo.billingLocation.tax2");
define("PXYPARAM_PXY_CUSTINFO_BILLADDR_TAX3", "pxyCustomerInfo.billingLocation.tax3");
define("PXYPARAM_PXY_CUSTINFO_SHIPADDR_FIRSTNAME", "pxyCustomerInfo.shippingLocation.firstName");
define("PXYPARAM_PXY_CUSTINFO_SHIPADDR_LASTNAME", "pxyCustomerInfo.shippingLocation.lastName");
define("PXYPARAM_PXY_CUSTINFO_SHIPADDR_COMPANYNAME", "pxyCustomerInfo.shippingLocation.companyName");
define("PXYPARAM_PXY_CUSTINFO_SHIPADDR_ADDRESS", "pxyCustomerInfo.shippingLocation.address");
define("PXYPARAM_PXY_CUSTINFO_SHIPADDR_CITY", "pxyCustomerInfo.shippingLocation.city");
define("PXYPARAM_PXY_CUSTINFO_SHIPADDR_STATE", "pxyCustomerInfo.shippingLocation.state");
define("PXYPARAM_PXY_CUSTINFO_SHIPADDR_ZIPCODE", "pxyCustomerInfo.shippingLocation.zipCode");
define("PXYPARAM_PXY_CUSTINFO_SHIPADDR_COUNTRY", "pxyCustomerInfo.shippingLocation.country");
define("PXYPARAM_PXY_CUSTINFO_SHIPADDR_PHONENUMBER", "pxyCustomerInfo.shippingLocation.phoneNumber");
define("PXYPARAM_PXY_CUSTINFO_SHIPADDR_FAX", "pxyCustomerInfo.shippingLocation.fax");
define("PXYPARAM_PXY_CUSTINFO_SHIPADDR_TAX1", "pxyCustomerInfo.shippingLocation.tax1");
define("PXYPARAM_PXY_CUSTINFO_SHIPADDR_TAX2", "pxyCustomerInfo.shippingLocation.tax2");
define("PXYPARAM_PXY_CUSTINFO_SHIPADDR_TAX3", "pxyCustomerInfo.shippingLocation.tax3");
define("PXYPARAM_PXY_ORDER_INVNUM", "pxyOrder.invoiceNumber");
define("PXYPARAM_PXY_ORDER_DESC", "pxyOrder.description");
define("PXYPARAM_PXY_ORDER_TOTALAMT", "pxyOrder.totalAmount");
define("PXYPARAM_PXY_ORDER_SHIPPINGAMT", "pxyOrder.shippingAmount");
define("PXYPARAM_PXY_ORDER_ORDERITEMS", "pxyOrder.orderItems[");
define("PXYPARAM_PXY_ORDER_ORDERITEM_ID", "].itemId");
define("PXYPARAM_PXY_ORDER_ORDERITEM_NAME", "].itemName");
define("PXYPARAM_PXY_ORDER_ORDERITEM_DESC", "].itemDescription");
define("PXYPARAM_PXY_ORDER_ORDERITEM_QTY", "].itemQuantity");
define("PXYPARAM_PXY_ORDER_ORDERITEM_PRICE", "].itemPrice");
define("PXYPARAM_PXY_ORDER_ORDERITEM_TAXABLE", "].itemTaxable");
define("PXYRESP_CALL_STATUS", "status");
define("PXYRESP_RESPONSE_STATUS", "pxyResponse_responseStatus");
define("PXYRESP_PROCESSOR_REFID", "pxyResponse_processorRefId");
define("PXYRESP_RESPSTATUS_NAME", "pxyResponse_responseStatus_name");
define("PXYRESP_RESPSTATUS_CODE", "pxyResponse_responseStatus_code");
define("PXYRESP_RESPSTATUS_DESCRIPTION", "pxyResponse_responseStatus_description");
//3D Secure responses
define("PXYRESP_3DS_ACS_URL", "pxyResponse_threeDSAcsUrl");
define("PXYRESP_3DS_TRANS_ID", "pxyResponse_threeDSTransactionId");
define("PXYRESP_3DS_PA_REQ", "pxyResponse_threeDSPARequest");
//3D Secure Actions
define("ACTIONNAME_VERIFYENROLL", "verifyenroll");
define("ACTIONNAME_REQUESTPIN", "requestpin");
define("ACTIONNAME_VERIFYRESP", "verifyresp");
define("PXYRESP_CALL_STATUS_SUCCESS", "success");
define("PXYRESP_CALL_STATUS_ERROR", "error");
define("PXYRESP_CALL_ERRID", "errId");
define("PXYRESP_CALL_ERRMSG", "errMsg");
define("PXYRESP_RESPONSE_STATUS_APPROVED", "approved");
define("PXYRESP_RESPONSE_STATUS_DECLINED", "declined");
define("PXYRESP_RESPONSE_STATUS_ERROR", "error");
define("PXYRESP_RESPONSE_STATUS_REVIEW", "review");
define("PXYRESP_RESPONSE_STATUS_3DSECURE", "3dsecure");
define("NL", "\n");
// define global values
$amountToAuthStr = "4.25";
function baseurl() {
// output: /myproject/index.php
$currentPath = $_SERVER['PHP_SELF'];
// output: Array ( [dirname] => /myproject [basename] => index.php [extension] => php [filename] => index )
$pathInfo = pathinfo($currentPath);
// output: localhost
$hostName = $_SERVER['HTTP_HOST'];
// output: http://
$protocol = strtolower(substr($_SERVER["SERVER_PROTOCOL"],0,5))=='https://'?'https://':'http://';
// return: http://localhost/myproject/
return $protocol.$hostName.$pathInfo['dirname']."/";
}
function emptyIfNullFromRequest($s) {
if (isset($_REQUEST["$s"])) {
$r = $_REQUEST["$s"];
}
else {
$r = "";
}
return $r;
}
/**
* Send a POST requst using cURL
* @param string $url to request
* @param array $post values to send
* @param array $options for cURL
* @return string
*/
function callUrl($url, array $post = NULL, array $options = array()) {
// prepare the CURL options
$defaults = array(
CURLOPT_POST => 1,
CURLOPT_HEADER => 0,
CURLOPT_URL => $url,
CURLOPT_FRESH_CONNECT => 1,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_FORBID_REUSE => 1,
CURLOPT_TIMEOUT => 10,
CURLOPT_POSTFIELDS => http_build_query($post)
);
//echo (" input: ".http_build_query($post) );
// make a call
$ch = curl_init($url);
curl_setopt_array($ch, ($options + $defaults));
if( ! $result = curl_exec($ch))
{
trigger_error(curl_error($ch));
}
// close the CURL
curl_close($ch);
// parse the url
//echo( "result:" . $result . NL);
parse_str($result, $resultMap);
// return the parsed map
return $resultMap;
}
// perform authorization using the mapped credit card
function authOnly($serviceUrl, $userName, $passKey, $mappedCCNum, $mappedCCCVV, $merchantTxnRef, $authAmount, $use3DS, $action3DS, $authTxnId)
{
global $amountToAuthStr;
$amountToAuthStr = $authAmount;
// if the authorization request id
$resultCode = "";
echo( "amountToAuthStr:" . $amountToAuthStr . NL);
echo( "passKey:" . $passKey . NL);
// make the remote call
$callUrl = $serviceUrl . PXY_AUTH;
// prepare the parameter array
$paramMap = array();
$paramMap[PXYPARAM_APIVERSION] = "1.0.1";
$paramMap[PXYPARAM_APITYPE] = PXYPARAM_APITYPE_PXYHPCI;
$paramMap[PXYPARAM_USERNAME] = $userName;
$paramMap[PXYPARAM_USERPASSKEY] = $passKey;
$paramMap[PXYPARAM_PXY_CC_CARDTYPE] = "visa";
$paramMap[PXYPARAM_PXY_CC_NUMBER] = $mappedCCNum;
$paramMap[PXYPARAM_PXY_CC_EXPMONTH] = "01";
$paramMap[PXYPARAM_PXY_CC_EXPYEAR] = "2015";
$paramMap[PXYPARAM_PXY_CC_CVV] = $mappedCCCVV;
$paramMap[PXYPARAM_PXY_TRANSACTION_AMOUNT] = $amountToAuthStr;
$paramMap[PXYPARAM_PXY_TRANSACTION_CUSISO] = "USD";
$paramMap[PXYPARAM_PXY_TRANSACTION_MER_REFID] = "merRef:" . $merchantTxnRef;
$paramMap[PXYPARAM_PXY_CUSTINFO_EMAIL] = "[email protected]";
$paramMap[PXYPARAM_PXY_CUSTINFO_CUSTOMERID] = "hpcitest1";
// setup addresses
$paramMap[PXYPARAM_PXY_CUSTINFO_BILLADDR_FIRSTNAME] = "FirstName";
$paramMap[PXYPARAM_PXY_CUSTINFO_BILLADDR_LASTNAME] = "LastName";
$paramMap[PXYPARAM_PXY_CUSTINFO_BILLADDR_ADDRESS] = "123 Elm Street";
$paramMap[PXYPARAM_PXY_CUSTINFO_BILLADDR_CITY] = "Beverly Hills";
$paramMap[PXYPARAM_PXY_CUSTINFO_BILLADDR_STATE] = "CA";
$paramMap[PXYPARAM_PXY_CUSTINFO_BILLADDR_ZIPCODE] = "90210";
$paramMap[PXYPARAM_PXY_CUSTINFO_BILLADDR_COUNTRY] = "US";
$paramMap[PXYPARAM_PXY_CUSTINFO_SHIPADDR_FIRSTNAME] = "FirstName";
$paramMap[PXYPARAM_PXY_CUSTINFO_SHIPADDR_LASTNAME] = "LastName";
$paramMap[PXYPARAM_PXY_CUSTINFO_SHIPADDR_ADDRESS] = "123 Elm Street";
$paramMap[PXYPARAM_PXY_CUSTINFO_SHIPADDR_CITY] = "Beverly Hills";
$paramMap[PXYPARAM_PXY_CUSTINFO_SHIPADDR_STATE] = "CA";
$paramMap[PXYPARAM_PXY_CUSTINFO_SHIPADDR_ZIPCODE] = "90210";
$paramMap[PXYPARAM_PXY_CUSTINFO_SHIPADDR_COUNTRY] = "US";
// following are optional parameters
$paramMap[PXYPARAM_PXY_CUSTINFO_CUSTIP] = "173.32.21.248";
$paramMap[PXYPARAM_PXY_ORDER_INVNUM] = "Order:" . $merchantTxnRef;
$paramMap[PXYPARAM_PXY_ORDER_DESC] = "Test Order";
$paramMap[PXYPARAM_PXY_ORDER_TOTALAMT] = $amountToAuthStr;
$paramMap[PXYPARAM_PXY_ORDER_SHIPPINGAMT] = "1.00";
// item 1
$paramMap[PXYPARAM_PXY_ORDER_ORDERITEMS . "0" . PXYPARAM_PXY_ORDER_ORDERITEM_ID] = "Item-1-" . $merchantTxnRef;
$paramMap[PXYPARAM_PXY_ORDER_ORDERITEMS . "0" . PXYPARAM_PXY_ORDER_ORDERITEM_NAME] = "Item-Name1";
$paramMap[PXYPARAM_PXY_ORDER_ORDERITEMS . "0" . PXYPARAM_PXY_ORDER_ORDERITEM_DESC] = "Item Description 1";
$paramMap[PXYPARAM_PXY_ORDER_ORDERITEMS . "0" . PXYPARAM_PXY_ORDER_ORDERITEM_QTY] = "1";
$paramMap[PXYPARAM_PXY_ORDER_ORDERITEMS . "0" . PXYPARAM_PXY_ORDER_ORDERITEM_PRICE] = "2.00";
$paramMap[PXYPARAM_PXY_ORDER_ORDERITEMS . "0" . PXYPARAM_PXY_ORDER_ORDERITEM_TAXABLE] = "N"; // Y/N
// item 2
$paramMap[PXYPARAM_PXY_ORDER_ORDERITEMS . "1" . PXYPARAM_PXY_ORDER_ORDERITEM_ID] = "Item-2-" . $merchantTxnRef;
$paramMap[PXYPARAM_PXY_ORDER_ORDERITEMS . "1" . PXYPARAM_PXY_ORDER_ORDERITEM_NAME] = "Item-Name2";
$paramMap[PXYPARAM_PXY_ORDER_ORDERITEMS . "1" . PXYPARAM_PXY_ORDER_ORDERITEM_DESC] = "Item Description 2";
$paramMap[PXYPARAM_PXY_ORDER_ORDERITEMS . "1" . PXYPARAM_PXY_ORDER_ORDERITEM_QTY] = "1";
$paramMap[PXYPARAM_PXY_ORDER_ORDERITEMS . "1" . PXYPARAM_PXY_ORDER_ORDERITEM_PRICE] = "1.25";
$paramMap[PXYPARAM_PXY_ORDER_ORDERITEMS . "1" . PXYPARAM_PXY_ORDER_ORDERITEM_TAXABLE] = "N"; // Y/N
//3DS parameters
if ($use3DS=="Y") {
echo ("Setting 3DS Parameters; Action :" . $action3DS . NL);
$paramMap[PXYPARAM_PXY_3DSECAUTH_ACTIONNAME] = $action3DS;
$paramMap[PXYPARAM_PXY_3DSECAUTH_AUTHTXNID] = $authTxnId;
//if the 3DS action is to verify the response from the
//authentication, we have to provide HPCI the acceptible
//results from 3DS in the form on character-pairs. The first
//char represents the result of the authentication. Possible
//values include (Y,A,U,N). The second char represents the
//call signiture validation, and the results should always be Y
//or the transaction should NOT be accepted. Any value other
//then Y means the call has been tampered with.
if ($action3DS == ACTIONNAME_VERIFYRESP) {
$paramMap[PXYPARAM_PXY_3DSECAUTH_AUTHSIGN_COMBOLIST . "[0]"] = "YY";
$paramMap[PXYPARAM_PXY_3DSECAUTH_AUTHSIGN_COMBOLIST . "[1]"] = "AY";
$paramMap[PXYPARAM_PXY_3DSECAUTH_AUTHSIGN_COMBOLIST . "[2]"] = "UY";
// paramMap.put(PXYPARAM_PXY_3DSECAUTH_AUTHSIGN_COMBOLIST +"[3]", "NY");
} //END: Set combo list
}
echo ("Make the call: " . $callUrl . NL);
print_r($paramMap);
$resultMap = callUrl($callUrl, $paramMap);
echo ("Call result:" . print_r($resultMap) . NL);
// get the network call status
$callStatus = $resultMap[PXYRESP_CALL_STATUS];
// get the payment processing status
$paymentStatus = $resultMap[PXYRESP_RESPONSE_STATUS];
$processorRefId = "";
echo ("Result callStatus :" . $callStatus . NL);
echo ("Result paymentStatus :" . $paymentStatus . NL);
//print_r($resultMap);
if ($callStatus == PXYRESP_CALL_STATUS_SUCCESS && $paymentStatus == PXYRESP_RESPONSE_STATUS_APPROVED) {
echo("Successful transaction" . NL);
$processorRefId = $resultMap[PXYRESP_PROCESSOR_REFID];
echo("Auth Processor Ref Id:" . $processorRefId . NL);
}
else {
if ($callStatus == PXYRESP_CALL_STATUS_ERROR && $paymentStatus == PXYRESP_RESPONSE_STATUS_3DSECURE) {
echo ("Card enrolled. 3DS Authorization Code:" . $resultMap[PXYRESP_3DS_TRANS_ID] . NL);
$processorRefId = $resultMap[PXYRESP_3DS_TRANS_ID];
echo ("<h3><a href='hpci-test.php?3dsAction=".ACTIONNAME_REQUESTPIN."&3dsAuthId=$processorRefId&amount=$authAmount&ccNum=$mappedCCNum&ccCVV=$mappedCCCVV'>Click here to Redirect and Authenticate</a></h3>");
} //END: 3DS card enrolled, authentication required
else {
echo("Unsuccessful transaction" . NL);
$resultCode = $paymentStatus;
$statusCode = $resultMap[PXYRESP_RESPSTATUS_CODE];
$statusName = $resultMap[PXYRESP_RESPSTATUS_NAME];
$statusDesc = $resultMap[PXYRESP_RESPSTATUS_DESCRIPTION];
echo("Auth Status Code:" + statusCode . NL);
echo("Auth Status Name:" + statusName . NL);
echo("Auth Status Desc:" + statusDesc . NL);
} //END: Error condition, not authorized
}
return $processorRefId;
}
// perform capture on the transaction reference
function captureOnly($serviceUrl, $userName, $passKey, $authProcessorRefId, $merchantTxnRef) {
global $amountToAuthStr;
// make the remote call to the url
$callUrl = $serviceUrl . PXY_CAPTURE;
// get the auth to capture
// prepare the parameter array
$paramMap = array();
$paramMap[PXYPARAM_APIVERSION] = "1.0.1";
$paramMap[PXYPARAM_APITYPE] = PXYPARAM_APITYPE_PXYHPCI;
$paramMap[PXYPARAM_USERNAME] = $userName;
$paramMap[PXYPARAM_USERPASSKEY] = $passKey;
// format amount
$paramMap[PXYPARAM_PXY_TRANSACTION_AMOUNT] = $amountToAuthStr;
$paramMap[PXYPARAM_PXY_TRANSACTION_CUSISO] = "USD";
$paramMap[PXYPARAM_PXY_TRANSACTION_MER_REFID] = "merRef:" . $merchantTxnRef;
$paramMap[PXYPARAM_PXY_TRANSACTION_PROCESSOR_REFID] = $authProcessorRefId;
echo("Make the call: " . $callUrl . NL);
$resultMap = callUrl($callUrl, $paramMap);
echo("Call result:" . $callResult . NL);
// get the network call status
$callStatus = $resultMap[PXYRESP_CALL_STATUS];
// get the payment processing status
$paymentStatus = $resultMap[PXYRESP_RESPONSE_STATUS];
$processorRefId = "";
echo ("Result callStatus :" . $callStatus . NL);
echo ("Result paymentStatus :" . $paymentStatus . NL);
print_r($resultMap);
if ($callStatus == PXYRESP_CALL_STATUS_SUCCESS && $paymentStatus == PXYRESP_RESPONSE_STATUS_APPROVED) {
echo("Successful transaction" . NL);
$processorRefId = $resultMap[PXYRESP_PROCESSOR_REFID];
echo("Capture Processor Ref Id:" . $processorRefId . NL);
}
else {
echo("Unsuccessful transaction" . NL);
$resultCode = $paymentStatus;
$statusCode = $resultMap[PXYRESP_RESPSTATUS_CODE];
$statusName = $resultMap[PXYRESP_RESPSTATUS_NAME];
$statusDesc = $resultMap[PXYRESP_RESPSTATUS_DESCRIPTION];
echo("Capture Status Code:" + statusCode . NL);
echo("Capture Status Name:" + statusName . NL);
echo("Capture Status Desc:" + statusDesc . NL);
}
}
// perform void on the transaction reference
function voidOnly($serviceUrl, $userName, $passKey, $authProcessorRefId, $merchantTxnRef) {
global $amountToAuthStr;
// make the remote call to the url
$callUrl = $serviceUrl . PXY_VOID;
// get the auth to void
// prepare the parameter array
$paramMap = array();
$paramMap[PXYPARAM_APIVERSION] = "1.0.1";
$paramMap[PXYPARAM_APITYPE] = PXYPARAM_APITYPE_PXYHPCI;
$paramMap[PXYPARAM_USERNAME] = $userName;
$paramMap[PXYPARAM_USERPASSKEY] = $passKey;
// format amount
$paramMap[PXYPARAM_PXY_TRANSACTION_AMOUNT] = $amountToAuthStr;
$paramMap[PXYPARAM_PXY_TRANSACTION_CUSISO] = "USD";
$paramMap[PXYPARAM_PXY_TRANSACTION_MER_REFID] = "merRef:" . $merchantTxnRef;
$paramMap[PXYPARAM_PXY_TRANSACTION_PROCESSOR_REFID] = $authProcessorRefId;
echo("Make the call: " . $callUrl . NL);
$resultMap = callUrl($callUrl, $paramMap);
echo("Call result:" . $callResult . NL);
// get the network call status
$callStatus = $resultMap[PXYRESP_CALL_STATUS];
// get the payment processing status
$paymentStatus = $resultMap[PXYRESP_RESPONSE_STATUS];
$processorRefId = "";
echo ("Result callStatus :" . $callStatus . NL);
echo ("Result paymentStatus :" . $paymentStatus . NL);
print_r($resultMap);
if ($callStatus == PXYRESP_CALL_STATUS_SUCCESS && $paymentStatus == PXYRESP_RESPONSE_STATUS_APPROVED) {
echo("Successful transaction" . NL);
$processorRefId = $resultMap[PXYRESP_PROCESSOR_REFID];
echo("Void Processor Ref Id:" . $processorRefId . NL);
}
else {
echo("Unsuccessful transaction" . NL);
$resultCode = $paymentStatus;
$statusCode = $resultMap[PXYRESP_RESPSTATUS_CODE];
$statusName = $resultMap[PXYRESP_RESPSTATUS_NAME];
$statusDesc = $resultMap[PXYRESP_RESPSTATUS_DESCRIPTION];
echo("Void Status Code:" + statusCode . NL);
echo("Void Status Name:" + statusName . NL);
echo("Void Status Desc:" + statusDesc . NL);
}
}
// perform capture on the transaction reference
function creditOnly($serviceUrl, $userName, $passKey, $captureProcessorRefId, $merchantTxnRef) {
global $amountToAuthStr;
// make the remote call to the url
$callUrl = $serviceUrl . PXY_CREDIT;
// get the capture to credit
// prepare the parameter array
$paramMap = array();
$paramMap[PXYPARAM_APIVERSION] = "1.0.1";
$paramMap[PXYPARAM_APITYPE] = PXYPARAM_APITYPE_PXYHPCI;
$paramMap[PXYPARAM_USERNAME] = $userName;
$paramMap[PXYPARAM_USERPASSKEY] = $passKey;
// format amount
$paramMap[PXYPARAM_PXY_TRANSACTION_AMOUNT] = $amountToAuthStr;
$paramMap[PXYPARAM_PXY_TRANSACTION_CUSISO] = "USD";
$paramMap[PXYPARAM_PXY_TRANSACTION_MER_REFID] = "merRef:" . $merchantTxnRef;
$paramMap[PXYPARAM_PXY_TRANSACTION_PROCESSOR_REFID] = $captureProcessorRefId;
echo("Make the call: " . $callUrl . NL);
$resultMap = callUrl($callUrl, $paramMap);
echo("Call result:" . $callResult . NL);
// get the network call status
$callStatus = $resultMap[PXYRESP_CALL_STATUS];
// get the payment processing status
$paymentStatus = $resultMap[PXYRESP_RESPONSE_STATUS];
$processorRefId = "";
echo ("Result callStatus :" . $callStatus . NL);
echo ("Result paymentStatus :" . $paymentStatus . NL);
print_r($resultMap);
if ($callStatus == PXYRESP_CALL_STATUS_SUCCESS && $paymentStatus == PXYRESP_RESPONSE_STATUS_APPROVED) {
echo("Successful transaction" . NL);
$processorRefId = $resultMap[PXYRESP_PROCESSOR_REFID];
echo("Credit Processor Ref Id:" . $processorRefId . NL);
}
else {
echo("Unsuccessful transaction" . NL);
$resultCode = $paymentStatus;
$statusCode = $resultMap[PXYRESP_RESPSTATUS_CODE];
$statusName = $resultMap[PXYRESP_RESPSTATUS_NAME];
$statusDesc = $resultMap[PXYRESP_RESPSTATUS_DESCRIPTION];
echo("Credit Status Code:" + statusCode . NL);
echo("Credit Status Name:" + statusName . NL);
echo("Credit Status Desc:" + statusDesc . NL);
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment