Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
developer:sample_codes:php_hosted_secure_cards [2019/03/22 15:54]
thiago123
developer:sample_codes:php_hosted_secure_cards [2019/07/25 13:16] (current)
branko
Line 31: Line 31:
 <?php <?php
  
-# This is the file that contains the account settings for %Gateway.+# This is the file that contains the account settings for Gateway.
 require('​%gatewaySampleFileName_account.inc'​);​ require('​%gatewaySampleFileName_account.inc'​);​
  
-# This is a helper file for integrating to the %Gateway HPP in PHP.+# This is a helper file for integrating to the Gateway HPP in PHP.
 require('​%gatewaySampleFileName_securecard_functions.inc'​);​ require('​%gatewaySampleFileName_securecard_functions.inc'​);​
  
 $secureCardAction = '';​ #​ "​register"​ or "​update"​. $secureCardAction = '';​ #​ "​register"​ or "​update"​.
 $secureCardMerchantRef = '';​ #​ Unique Merchant Reference for this card. Length is limited to 48 chars. $secureCardMerchantRef = '';​ #​ Unique Merchant Reference for this card. Length is limited to 48 chars.
-$host = '';​ #​ This is your host eg. http://​localhost:​8000 
 $dateTime = requestDateTime();​ $dateTime = requestDateTime();​
  
 # Verification string # Verification string
 $requestHash = secureCardRequestHash($secureCardMerchantRef,​ $dateTime, $secureCardAction);​ $requestHash = secureCardRequestHash($secureCardMerchantRef,​ $dateTime, $secureCardAction);​
-$requestURL = $host."/​merchant/​securecardpage";​+ 
 +# Request URL for the gateway 
 +$requestURL = $gateway."/​merchant/​securecardpage";​ 
 # Write the HTML of the submission form # Write the HTML of the submission form
-echo "<​html><​body><​form id='%gatewaySampleFileNamesecurecardform' action='"​ . $requestURL . "'​ method='​post'>​\n";​+echo "<​html><​body><​form id='gatewaysecurecardform' action='"​ . $requestURL . "'​ method='​post'>​\n";​
 writeHiddenField("​ACTION",​ $secureCardAction);​ writeHiddenField("​ACTION",​ $secureCardAction);​
 writeHiddenField("​TERMINALID",​ $terminalId);​ writeHiddenField("​TERMINALID",​ $terminalId);​
Line 53: Line 55:
 writeHiddenField("​HASH",​ $requestHash);​ writeHiddenField("​HASH",​ $requestHash);​
  
-# Write the JavaScript that will submit the form to %Gateway. +# Write the JavaScript that will submit the form to Gateway. 
-echo '</​form>​Submitting SecureCard request to %Gateway...<​script language="​JavaScript">​document.getElementById("​%gatewaySampleFileNamesecurecardform"​).submit();</​script></​body></​html>';​+echo '</​form>​Submitting SecureCard request to Gateway...<​script language="​JavaScript">​document.getElementById("​gatewaysecurecardform"​).submit();</​script></​body></​html>';​
  
 ?> ?>
- 
 </​file>​ </​file>​
  
Line 69: Line 70:
 <?php <?php
  
-# This is the file that contains the account settings for %Gateway.+# This is the file that contains the account settings for Gateway.
 require('​%gatewaySampleFileName_account.inc'​);​ require('​%gatewaySampleFileName_account.inc'​);​
  
-# This is a helper file for integrating to the %Gateway HPP in PHP.+# This is a helper file for integrating to the Gateway HPP in PHP.
 require('​%gatewaySampleFileName_securecard_functions.inc'​);​ require('​%gatewaySampleFileName_securecard_functions.inc'​);​
  
-$secureCardAction = ''; ​           # "register" ​or "update". +if($_REQUEST["RESPONSECODE"] != "A") echo 'AN ERROR OCCURED! Your SecureCard request failedError message: ​' . $_REQUEST["​RESPONSETEXT"​];
-$secureCardMerchantRef = '';    # Unique Merchant Reference for this cardLength is limited to 48 chars. +
-$dateTime = requestDateTime();+
  
-# Verification string +if(secureCardResponseHashIsValid($_REQUEST["​RESPONSECODE"​], $_REQUEST["​RESPONSETEXT"​], $_REQUEST["​MERCHANTREF"​],​ $_REQUEST["​CARDREFERENCE"​],​ $_REQUEST["​DATETIME"​],​ $_REQUEST["​HASH"​])) { 
-$requestHash = secureCardRequestHash($secureCardMerchantRef, $dateTime, $secureCardAction); + switch($_REQUEST["RESPONSECODE"]) { 
-$requestURL = $gateway."/​merchant/​securecardpage"; + case "​A"​ : SecureCard registration suceeded. You should store the following details against ​the user account: 
-Write the HTML of the submission form + $secureCardMerchantRef ​= $_REQUEST["MERCHANTREF"]
-echo "<​html><​body><​form id='​%gatewaySampleFileNamesecurecardform'​ action='"​ . $requestURL . "' method='​post'>​\n"; + $secureCardCardRef = $_REQUEST["CARDREFERENCE"]
-writeHiddenField("ACTION", $secureCardAction)+ $secureCardCardType = $_REQUEST["CARDTYPE"]
-writeHiddenField("TERMINALID", $terminalId)+ $secureCardMaskedCardNumber = $_REQUEST["MASKEDCARDNUMBER"]
-writeHiddenField("MERCHANTREF", $secureCardMerchantRef)+ $secureCardCardCardExpiry = $_REQUEST["CARDEXPIRY"]
-writeHiddenField("DATETIME", $dateTime)+ echo ​"Success! Card Type: " . $secureCardCardType . ", ​Masked Card number: " . $secureCardMaskedCardNumber . ", expires (MMYY): " . $secureCardCardCardExpiry
-writeHiddenField("HASH", $requestHash); + break; 
- + default ​ : SecureCard registration failed
-Write the JavaScript that will submit the form to %Gateway+ echo 'SECURECARD REGISTRATION FAILED! Error Code: ' ​$_REQUEST["​RESPONSECODE"​] ​', Response text: ' ​$_REQUEST["RESPONSETEXT"'​.';​ 
-echo '</​form>​Submitting SecureCard request to %Gateway...<script language="JavaScript">​document.getElementById("%gatewaySampleFileNamesecurecardform").submit();</​script></​body></​html>​';+
 +} else { 
 + echo '​SECURECARD REGISTRATION FAILED: INVALID RESPONSE HASH. Please contact ' . $adminEmail . ' or call ' . $adminPhone . ' to inform them of this error.';​ 
 + if(isset($_REQUEST["ORDERID"])) echo '​Please quote Gateway Terminal ID: ' . $terminalId . ', and SecureCard Merchant Reference: ' . $_REQUEST["​MERCHANTREF"​] . ' when mailling or calling.'; 
 +}
  
 ?> ?>
 +
  
 </​file>​ </​file>​
Line 104: Line 108:
  
 <?php <?php
- 
-# This function returns the URL that should be used as the "​action"​ for the form posting the %Gateway'​s servers. 
-function secureCardURL() { 
- global $gateway, $testAccount;​ 
- $url = '​https://';​ 
- if($testAccount) $url .= '​test';​ 
- switch (strtolower($gateway)) { 
- default : 
- case '​%gatewaySampleFileName' ​ : $url .= '​payments';​ break; 
- case '​cashflows'​ : $url .= '​cashflows';​ break; 
- } 
- $url .= '​.%gatewayTestURL/​merchant/​securecardpage';​ 
- return $url; 
-} 
  
 # This simply reduces the PHP code required to build the form. # This simply reduces the PHP code required to build the form.
 function writeHiddenField($fieldName,​ $fieldValue) { function writeHiddenField($fieldName,​ $fieldValue) {
- echo "<​input type='​hidden'​ name='"​ . $fieldName . "'​ value='"​ . $fieldValue . "'​ />\r";+ echo "<​input type='​hidden'​ name='"​ . $fieldName . "'​ value='"​ . $fieldValue . "'​ />";​
 } }
  
Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 4.0 International