====== PHP XML Payments with 3D Secure ====== In this section, you can find sample code for the **3D Secure** redirect before the payment. Once you receive the response to the "MPI Receipt URL" you will have an MPIREF parameter. You should then process a payment and include that parameter. The sample code for the **XML payment stage** is [[developer:sample_codes:php_xml_payments|here]]. You should also use this [[developer:integration_docs:testing-guide|Testing Guide]] that also contains test card details. **Settings file (%gatewaySampleFileName_account.inc):** ---- \\ **3D Secure redirect (%gatewaySampleFileName_payment.php):**
\n"; writeHiddenField("TERMINALID", $terminalId); writeHiddenField("CARDNUMBER", $cardNumber); writeHiddenField("CARDTYPE", $cardType); writeHiddenField("CARDEXPIRY", $cardExpiry); writeHiddenField("AMOUNT", $amount); writeHiddenField("CURRENCY", $currency); writeHiddenField("ORDERID", $orderId); if(isset($cvv) && $cvv != '') writeHiddenField("CVV", $cvv); writeHiddenField("DATETIME", $dateTime); writeHiddenField("HASH", $requestHash); # Write the JavaScript that will submit the form to %Gateway. echo '
Submitting order to %Gateway for Payment...'; ?>
---- \\ Response page (**%gatewaySampleFileName_mpi_response.php**) (URL for this page is setup as “MPI Receipt URL” through Terminal Setup in the %SelfCare): ' . $adminEmail . ' or call ' . $adminPhone . ' to inform them of this error.'; if(isset($_REQUEST["ORDERID"])) echo 'Please quote %Gateway Terminal ID: ' . $terminalId . ', and Order ID: ' . $_REQUEST["ORDERID"] . ' when mailling or calling.'; } ?> ---- \\ **Helper file (%gatewaySampleFileName_hpp_functions.inc):** \r"; } # This generates a DATETIME value in the correct format expected in the request. function requestDateTime() { return date('d-m-Y:H:i:s:000'); } # If you are not using your own Order ID's and need to use unique random ones, this function will generate one for you. function generateUniqueOrderId() { $seconds = date('H')*3600+date('i')*60+date('s'); return date('zy') . $seconds; } # This is used to generate the Authorisation Request Hash. function mpiRequestHash($orderId, $cardNumber, $cardExpiry, $cardType, $amount, $dateTime) { global $terminalId, $secret; return md5($terminalId . $orderId . $cardNumber . $cardExpiry . $cardType . $amount . $dateTime . $secret); } # This function is used to validate that the MPI Response Hash from the server is correct. # If mpiResponseHashIsValid(...) != $_REQUEST["HASH"] then an error should be shown and the 3D Secure should not be validated. function mpiResponseHashIsValid($result, $mpiRef, $orderId, $dateTime, $responseHash) { global $secret; return (md5($result . $mpiRef . $orderId . $dateTime . $secret)==$responseHash); } ?>