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_payments [2019/07/25 12:59]
branko
developer:sample_codes:php_hosted_payments [2019/07/25 13:06] (current)
branko
Line 105: 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 138: 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 194: 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 209: 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 220: 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