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_subscriptions [2017/11/02 11:16]
127.0.0.1 external edit
developer:sample_codes:php_hosted_subscriptions [2019/07/25 13:20] (current)
branko
Line 8: Line 8:
  
 # These values are used to identify and validate the account that you are using. They are mandatory. # These values are used to identify and validate the account that you are using. They are mandatory.
-$gateway = '';​ # This is the %Gateway payments ​gateway ​that you should use, assigned to the site by %Gateway+$gateway = ''; ​         # This is the Gateway payments ​URL that you should use, assigned to the site. 
-$terminalId = '';​ # This is the Terminal ID assigned to the site by %Gateway. +$terminalId = ''; ​      ​# This is the Terminal ID assigned to the site by Gateway. 
-$currency = '';​ # This is the 3 digit ISO currency code for the above Terminal ID. +$currency = ''; ​        ​# This is the 3 digit ISO currency code for the above Terminal ID. 
-$secret = '';​ # This shared secret is used when generating the hash validation strings.  +$secret = ''; ​          ​# This shared secret is used when generating the hash validation strings.  
- # It must be set exactly as it is in the %Gateway ​%SelfCare system. +                        # It must be set exactly as it is in the Gateway SelfCare system. 
-$testAccount ​true;+ 
 +# This should contain the URL of the receipt page and validation page 
 +$host ''​;                    # This should be your host eg. http://​localhost:​8000 
 +$receiptPageURL = $host.''; ​   # This should be the path to your receipt page 
 +$validationURL = $host.''; ​    # This should be the path to your validation page
  
 # These are used only in the case where the response hash is incorrect, which should # These are used only in the case where the response hash is incorrect, which should
Line 21: Line 25:
  
 ?> ?>
- 
 </​file>​ </​file>​
 ---- ----
Line 31: Line 34:
 <?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.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_subscription_functions.inc'​);​ require('​%gatewaySampleFileName_subscription_functions.inc'​);​
  
-$subscriptionAction = '';​ # "​register"​ or "​update"​. +$subscriptionAction = ''; ​            ​# "​register"​ or "​update"​. 
-$subscriptionMerchantRef = '';​      # Unique Merchant Reference for this subscription. Length is limited to 48 chars. +$subscriptionMerchantRef = ''; ​       # Unique Merchant Reference for this subscription. Length is limited to 48 chars. 
-$storedSubscriptionMerchantRef = '';​      # The Merchant Reference for the Stored Subscription (Subscription template/​payment plan) that you would like this subscription to run under. +$storedSubscriptionMerchantRef = ''; ​ # The Merchant Reference for the Stored Subscription (Subscription template/​payment plan) that you would like this subscription to run under. 
-$secureCardMerchantRef = '';​      # The Merchant Reference of the SecureCard that the Subscription is to be set up on. +$secureCardMerchantRef = ''; ​         # The Merchant Reference of the SecureCard that the Subscription is to be set up on. 
-$startDate = '';​          # The date the Subscription is to start on (note the setup payment will still be taken immediately if it is >0). Format: DD-MM-YYYY +$startDate = ''; ​                     # The date the Subscription is to start on (note the setup payment will still be taken immediately if it is >0). Format: DD-MM-YYYY
-$host ='';​ #​ This is your host eg. http://​localhost:​8000+
 $dateTime = requestDateTime();​ $dateTime = requestDateTime();​
  
Line 48: Line 50:
 $requestHash = subscriptionRequestHash($subscriptionMerchantRef,​$secureCardMerchantRef,​ $dateTime, $startDate);​ $requestHash = subscriptionRequestHash($subscriptionMerchantRef,​$secureCardMerchantRef,​ $dateTime, $startDate);​
  
-$requestURL = $host."/​merchant/​subscriptionpage/"​.$subscriptionAction;​+# Request URL for the Gateway 
 +$requestURL = $gateway."/​merchant/​subscriptionpage/"​.$subscriptionAction;​ 
 # Write the HTML of the submission form # Write the HTML of the submission form
-echo "<​html><​body><​form id='%gatewaySampleFileNamesubscriptionform' action='"​ . $requestURL . "'​ method='​post'>​\n";​+echo "<​html><​body><​form id='gatewaysubscriptionform' action='"​ . $requestURL . "'​ method='​post'>​\n";​
 writeHiddenField("​TERMINALID",​ $terminalId);​ writeHiddenField("​TERMINALID",​ $terminalId);​
 writeHiddenField("​MERCHANTREF",​ $subscriptionMerchantRef);​ writeHiddenField("​MERCHANTREF",​ $subscriptionMerchantRef);​
Line 59: Line 63:
 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 Subscription setup request to %Gateway...<​script language="​JavaScript">​document.getElementById("​%gatewaySampleFileNamesubscriptionform"​).submit();</​script></​body></​html>';​+echo '</​form>​Submitting Subscription setup request to Gateway...<​script language="​JavaScript">​document.getElementById("​gatewaysubscriptionform"​).submit();</​script></​body></​html>';​
  
 ?> ?>
Line 73: Line 77:
 <?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_subscription_functions.inc'​);​ require('​%gatewaySampleFileName_subscription_functions.inc'​);​
  
 if($_REQUEST["​RESPONSECODE"​] != "​A"​) echo 'AN ERROR OCCURED! Your Subscription setup request failed. Error message: ' . $_REQUEST["​RESPONSETEXT"​];​ if($_REQUEST["​RESPONSECODE"​] != "​A"​) echo 'AN ERROR OCCURED! Your Subscription setup request failed. Error message: ' . $_REQUEST["​RESPONSETEXT"​];​
-} elseif(subscriptionResponseHashIsValid($_REQUEST["​RESPONSECODE"​],​ $_REQUEST["​RESPONSETEXT"​],​ $_REQUEST["​MERCHANTREF"​],​ $_REQUEST["​DATETIME"​],​ $_REQUEST["​HASH"​])) {+ 
 +if(subscriptionResponseHashIsValid($_REQUEST["​RESPONSECODE"​],​ $_REQUEST["​RESPONSETEXT"​],​ $_REQUEST["​MERCHANTREF"​],​ $_REQUEST["​DATETIME"​],​ $_REQUEST["​HASH"​])) {
  switch($_REQUEST["​RESPONSECODE"​]) {  switch($_REQUEST["​RESPONSECODE"​]) {
  case "​A"​ : # Subscription setup suceeded. You should store the following details against the user account:  case "​A"​ : # Subscription setup suceeded. You should store the following details against the user account:
Line 91: Line 96:
 } else { } else {
  echo '​SUBSCRIPTION REGISTRATION FAILED: INVALID RESPONSE HASH. Please contact ' . $adminEmail . ' or call ' . $adminPhone . ' to inform them of this error.';​  echo '​SUBSCRIPTION 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 Subscription Merchant Reference: ' . $_REQUEST["​MERCHANTREF"​] . ' when mailling or calling.';​+ if(isset($_REQUEST["​ORDERID"​])) echo '​Please quote Gateway Terminal ID: ' . $terminalId . ', and Subscription 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 subscriptionURL($subscriptionAction) { 
- 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/​subscriptionpage/'​.$subscriptionAction;​ 
- 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 143: Line 133:
  
 ?> ?>
- 
 </​file>​ </​file>​
Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 4.0 International