This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision | |||
|
developer:sample_codes:php_hosted_secure_cards [2018/12/03 10:26] 127.0.0.1 external edit |
developer:sample_codes:php_hosted_secure_cards [2019/05/21 12:36] (current) robinc Updated Secure Card URL section content |
||
|---|---|---|---|
| Line 69: | Line 69: | ||
| <?php | <?php | ||
| + | |||
| # This is the file that contains the account settings for Nuvei. | # This is the file that contains the account settings for Nuvei. | ||
| require('nuvei_account.inc'); | require('nuvei_account.inc'); | ||
| + | |||
| # This is a helper file for integrating to the Nuvei HPP in PHP. | # This is a helper file for integrating to the Nuvei HPP in PHP. | ||
| require('nuvei_securecard_functions.inc'); | require('nuvei_securecard_functions.inc'); | ||
| - | + | ||
| - | if($_REQUEST["RESPONSECODE"] != "A") echo 'AN ERROR OCCURED! Your SecureCard request failed. Error message: ' . $_REQUEST["RESPONSETEXT"]; | + | $secureCardAction = ''; # "register" or "update". |
| - | elseif(secureCardResponseHashIsValid($_REQUEST["RESPONSECODE"], $_REQUEST["RESPONSETEXT"], $_REQUEST["MERCHANTREF"], $_REQUEST["CARDREFERENCE"], $_REQUEST["DATETIME"], $_REQUEST["HASH"])) { | + | $secureCardMerchantRef = ''; # Unique Merchant Reference for this card. Length is limited to 48 chars. |
| - | switch($_REQUEST["RESPONSECODE"]) { | + | $dateTime = requestDateTime(); |
| - | case "A" : # SecureCard registration suceeded. You should store the following details against the user account: | + | |
| - | $secureCardMerchantRef = $_REQUEST["MERCHANTREF"]; | + | # Verification string |
| - | $secureCardCardRef = $_REQUEST["CARDREFERENCE"]; | + | $requestHash = secureCardRequestHash($secureCardMerchantRef, $dateTime, $secureCardAction); |
| - | $secureCardCardType = $_REQUEST["CARDTYPE"]; | + | $requestURL = $gateway."/merchant/securecardpage"; |
| - | $secureCardMaskedCardNumber = $_REQUEST["MASKEDCARDNUMBER"]; | + | # Write the HTML of the submission form |
| - | $secureCardCardCardExpiry = $_REQUEST["CARDEXPIRY"]; | + | echo "<html><body><form id='nuveisecurecardform' action='" . $requestURL . "' method='post'>\n"; |
| - | echo "Success! Card Type: " . $secureCardCardType . ", Masked Card number: " . $secureCardMaskedCardNumber . ", expires (MMYY): " . $secureCardCardCardExpiry; | + | writeHiddenField("ACTION", $secureCardAction); |
| - | break; | + | writeHiddenField("TERMINALID", $terminalId); |
| - | default : # SecureCard registration failed. | + | writeHiddenField("MERCHANTREF", $secureCardMerchantRef); |
| - | echo 'SECURECARD REGISTRATION FAILED! Error Code: ' . $_REQUEST["RESPONSECODE"] . ', Response text: ' . $_REQUEST["RESPONSETEXT"] . '.'; | + | writeHiddenField("DATETIME", $dateTime); |
| - | } | + | writeHiddenField("HASH", $requestHash); |
| - | } else { | + | |
| - | echo 'SECURECARD REGISTRATION FAILED: INVALID RESPONSE HASH. Please contact ' . $adminEmail . ' or call ' . $adminPhone . ' to inform them of this error.'; | + | # Write the JavaScript that will submit the form to Nuvei. |
| - | if(isset($_REQUEST["ORDERID"])) echo 'Please quote Nuvei Terminal ID: ' . $terminalId . ', and SecureCard Merchant Reference: ' . $_REQUEST["MERCHANTREF"] . ' when mailling or calling.'; | + | echo '</form>Submitting SecureCard request to Nuvei...<script language="JavaScript">document.getElementById("nuveisecurecardform").submit();</script></body></html>'; |
| - | } | + | |
| ?> | ?> | ||