Differences

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

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
developer:sample_codes:php_hosted_payments [2019/07/25 12:57]
branko
developer:sample_codes:php_hosted_payments [2019/07/25 13:06]
branko
Line 35: Line 35:
 <?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 intgerating to the %Gateway HPP in PHP.+# This is a helper file for intgerating to the GatewayHPP ​in PHP.
 require('​%gatewaySampleFileName_hpp_functions.inc'​);​ require('​%gatewaySampleFileName_hpp_functions.inc'​);​
  
Line 44: Line 44:
 $orderId = '';​ #​ This should be unique per transaction. $orderId = '';​ #​ This should be unique per transaction.
 $amount = '';​ #​ This should include the decimal point. $amount = '';​ #​ This should include the decimal point.
 +$dateTime = requestDateTime();​
  
-$email = '';​ # (optional) If this is sent then %Gateway ​will send a receipt to this e-mail address+$autoReady ​= '';​ # (optional) ​Y or N. Automatically set the transaction to a status of Ready in the batch. ​If not present the terminal default ​will be used
-$description = '';​ #​ (optional) This can is a decription for the transaction that will be available in the merchant notification e-mail and in the %SelfCare system. +$description = '';​ #​ (optional) This is a decription for the transaction that will be available in the merchant notification e-mail and in the SelfCare system. 
-$autoReady ​= 'Y'; # (optional) ​Y or N. Automatically set the transaction to status of Ready in the batchIf not present ​the terminal default will be used.+ 
 +$email = '';​ # (optional) ​If this is sent then Gatewaywill send receipt to this e-mail address. 
 +$cardholderName = ''; ​   # (optional) This is the cardholder'​s name if available
  
-$cardholderName = '';​ #​ (optional) If the cardholders name is available it should be populated here. If so it will be pre-populated on the payment page. 
 $address1 = '';​ #​ (optional) This is the first line of the cardholders billing address. $address1 = '';​ #​ (optional) This is the first line of the cardholders billing address.
 $address2 = '';​ #​ (optional) This is the second line of the cardholders billing address. $address2 = '';​ #​ (optional) This is the second line of the cardholders billing address.
 $postcode = '';​ #​ (optional) This is the postcode of the cardholders billing address. $postcode = '';​ #​ (optional) This is the postcode of the cardholders billing address.
-$host = '';​ #​ This should your host eg. http://​localhost:​8000 +
-$dateTime = requestDateTime();​+
  
 # If there'​s no orderId set then generate a unique time-based order ID. # If there'​s no orderId set then generate a unique time-based order ID.
Line 64: Line 65:
 $requestHash = authRequestHash($orderId,​ $amount, $dateTime); $requestHash = authRequestHash($orderId,​ $amount, $dateTime);
  
-$requestURL = $host.'/​merchant/​paymentpage';​ +# Request URL for the gateway 
- # Write the HTML of the submission form +$requestURL = $gateway.'/​merchant/​paymentpage';​ 
-echo "<​html><​body><​form id='%gatewaySampleFileNameform' action='"​ . $requestURL . "'​ method='​post'>​\n";​+ 
 +# Write the HTML of the submission form 
 +echo "<​html><​body><​form id='gatewayform' action='"​ . $requestURL . "'​ method='​post'>​\n";​
 writeHiddenField("​TERMINALID",​ $terminalId);​ writeHiddenField("​TERMINALID",​ $terminalId);​
 writeHiddenField("​CURRENCY",​ $currency); writeHiddenField("​CURRENCY",​ $currency);
Line 75: Line 78:
 if(isset($postcode) && $postcode != ''​) { if(isset($postcode) && $postcode != ''​) {
  writeHiddenField("​ADDRESS1",​ $address1);  writeHiddenField("​ADDRESS1",​ $address1);
- writeHiddenField("​ADDERSS2", $address2);+ writeHiddenField("​ADDRESS2", $address2);
  writeHiddenField("​POSTCODE",​ $postcode);  writeHiddenField("​POSTCODE",​ $postcode);
 } }
Line 81: Line 84:
 if(isset($description) && $description != ''​) writeHiddenField("​DESCRIPTION",​ $description);​ if(isset($description) && $description != ''​) writeHiddenField("​DESCRIPTION",​ $description);​
 if(isset($autoReady) && $autoReady != ''​) writeHiddenField("​AUTOREADY",​ $autoReady);​ if(isset($autoReady) && $autoReady != ''​) writeHiddenField("​AUTOREADY",​ $autoReady);​
-writeHiddenField("​RECEIPTPAGEURL",​ $receiptPageURL);​+if($receiptPageURL != ''​) ​writeHiddenField("​RECEIPTPAGEURL",​ $receiptPageURL);​
 if($validationURL != ''​) writeHiddenField("​VALIDATIONURL",​ $validationURL);​ if($validationURL != ''​) writeHiddenField("​VALIDATIONURL",​ $validationURL);​
 writeHiddenField("​HASH",​ $requestHash);​ writeHiddenField("​HASH",​ $requestHash);​
Line 88: Line 91:
 # writeHiddenField("​Customer ID", '​32856951'​);​ # writeHiddenField("​Customer ID", '​32856951'​);​
  
-# Write the JavaScript that will submit the form to %Gateway. +# Write the JavaScript that will submit the form to Gateway. 
-echo '</​form>​Submitting order to %Gateway for Payment...<​script language="​JavaScript">​document.getElementById("​%gatewaySampleFileNameform"​).submit();</​script></​body></​html>';​+echo '</​form>​Submitting order to Gateway for Payment...<​script language="​JavaScript">​document.getElementById("​gatewayform"​).submit();</​script></​body></​html>';​
  
 ?> ?>
Line 102: Line 105:
 <?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 intgerating to the %Gateway HPP in PHP.+# This is a helper file for intgerating to the Gateway HPP in PHP.
 require('​%gatewaySampleFileName_hpp_functions.inc'​);​ require('​%gatewaySampleFileName_hpp_functions.inc'​);​
  
-if(authResponseHashIsValid($_REQUEST["​ORDERID"], $_REQUEST["​AMOUNT"​],​ $_REQUEST["​DATETIME"​],​ $_REQUEST["​RESPONSECODE"​],​ $_REQUEST["​RESPONSETEXT"​],​ $_REQUEST["​HASH"​])) { +if(authResponseHashIsValid($_REQUEST["​UNIQUEREF"], $_REQUEST["​AMOUNT"​],​ $_REQUEST["​DATETIME"​],​ $_REQUEST["​RESPONSECODE"​],​ $_REQUEST["​RESPONSETEXT"​],​ $_REQUEST["​HASH"​])) { 
- switch($_REQUEST["​RESPONSECODE"​]) { + # -- Do check to ensure that $_REQUEST["​ORDERID"​] is in the database 
- case "​A"​ : # -- If using local database, update order as Paid/​Successful + if($_REQUEST["​ORDERID"​]) { 
- echo '​Payment Processed successfully. Thanks you for your order.';​ + switch($_REQUEST["​RESPONSECODE"​]) { 
- break; + case "​A"​ : # -- If using local database, update order as Paid/​Successful 
- case "​R"​ : + echo '​Payment Processed successfully. Thanks you for your order.';​ 
- case "​D"​ : + break; 
- case "​C"​ : + case "​R"​ : 
- case "​S"​ : + case "​D"​ : 
- default ​ : # -- If using local database, update order as declined/​failed -- + case "​C"​ : 
- echo '​PAYMENT DECLINED! Please try again with another card. Bank response: ' . $_REQUEST["​RESPONSETEXT"​];​+ case "​S"​ : 
 + default ​ : # -- If using local database, update order as declined/​failed -- 
 + echo '​PAYMENT DECLINED! Please try again with another card. Bank response: ' . $_REQUEST["​RESPONSETEXT"​]
 +
 + } else { 
 + echo 'Order ID: ' . $_REQUEST["​ORDERID"​] . ' not found. Please contact <a href="​mailto:'​ . $adminEmail . '">'​ . $adminEmail . '</​a>​ or call ' . $adminPhone . ' to clarify.'​;
  }  }
 } else { } else {
  echo '​PAYMENT FAILED: INVALID RESPONSE HASH. Please contact <a href="​mailto:'​ . $adminEmail . '">'​ . $adminEmail . '</​a>​ or call ' . $adminPhone . ' to clarify if you will get charged for this order.';​  echo '​PAYMENT FAILED: INVALID RESPONSE HASH. Please contact <a href="​mailto:'​ . $adminEmail . '">'​ . $adminEmail . '</​a>​ or call ' . $adminPhone . ' to clarify if you will get charged for this order.';​
- if(isset($_REQUEST["​ORDERID"​])) echo '​Please quote %Gateway Terminal ID: ' . $terminalId . ', and Order ID: ' . $_REQUEST["​ORDERID"​] . ' when mailling or calling.';​+ if(isset($_REQUEST["​ORDERID"​])) echo '​Please quote Gateway Terminal ID: ' . $terminalId . ', and Order ID: ' . $_REQUEST["​ORDERID"​] . ' when mailling or calling.';​
 } }
  
Line 135: Line 143:
  
 <?php <?php
- 
-# This function returns the URL that should be used as the "​action"​ for the form posting the %Gateway'​s servers. 
-function requestURL() { 
- global $gateway, $testAccount;​ 
- $url = '​https://';​ 
- if($testAccount) $url .= '​test';​ 
- switch (strtolower($gateway)) { 
- case '​cashflows'​ : $url .= '​cashflows.%gatewayTestURL';​ break; 
- case '​payius'​ : $url .= '​payments.payius.com';​ break; 
- default : 
- case '​%gatewaySampleFileName' ​ : $url .= '​payments.%gatewayTestURL';​ break; 
- } 
- $url .= '/​merchant/​paymentpage';​ 
- 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 . "'​ />";​
 } }
  
Line 191: Line 184:
 <?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 intgerating to the %Gateway HPP in PHP.+# This is a helper file for intgerating to the Gateway HPP in PHP.
 require('​%gatewaySampleFileName_hpp_functions.inc'​);​ require('​%gatewaySampleFileName_hpp_functions.inc'​);​
  
-if(authResponseHashIsValid($_REQUEST["​ORDERID"], $_REQUEST["​AMOUNT"​],​ $_REQUEST["​DATETIME"​],​ $_REQUEST["​RESPONSECODE"​],​ $_REQUEST["​RESPONSETEXT"​],​ $_REQUEST["​HASH"​])) { +if(authResponseHashIsValid($_REQUEST["​UNIQUEREF"], $_REQUEST["​AMOUNT"​],​ $_REQUEST["​DATETIME"​],​ $_REQUEST["​RESPONSECODE"​],​ $_REQUEST["​RESPONSETEXT"​],​ $_REQUEST["​HASH"​])) { 
- if( ) {                                    ​# -- Do check to ensure that $_REQUEST["​ORDERID"​] is in the database+ # -- Do check to ensure that $_REQUEST["​ORDERID"​] is in the database 
 + if($_REQUEST["​ORDERID"​]) {
  switch($_REQUEST["​RESPONSECODE"​]) {  switch($_REQUEST["​RESPONSECODE"​]) {
  case "​A"​ : # -- Update order in database as paid/​sucessful --  case "​A"​ : # -- Update order in database as paid/​sucessful --
Line 206: Line 200:
  case "​D"​ :  case "​D"​ :
  case "​C"​ :  case "​C"​ :
 + case "​S"​ :
  default ​ : # -- Update order in database as declined/​failed --  default ​ : # -- Update order in database as declined/​failed --
  echo '​OK';​  echo '​OK';​
Line 217: Line 212:
  
 ?> ?>
 +
  
 </​file>​ </​file>​
Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 4.0 International