![]() <?php /* Example code for using HTTPS POST method for performing purchases through SecurePayTech Note: You will definitely need to have the cURL extension installed in PHP in order to use this */ /* $vars is an associative array containing the post variables */ function http_post($method,$server, $port, $url, $vars) { $postdata = ""; foreach($vars as $key => $value) { $postdata .= urlencode($key) . "=" . urlencode($value) . "&"; } $postdata = substr($postdata,0,-1); $content_length = strlen($postdata); $headers = "POST $url HTTP/1.1\r\n". "Accept: */*\r\n". "Accept-Language: en-nz\r\n". "Content-Type: application/x-www-form-urlencoded\r\n". "Host: $server\r\n". "Connection: Keep-Alive\r\n". "Cache-Control: no-cache\r\n". "Content-Length: $content_length\r\n\r\n"; $ch = curl_init(); curl_setopt ($ch, CURLOPT_URL, $method . '://' . $server .":". $port . $url); curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ch, CURLOPT_POST, 1); curl_setopt ($ch, CURLOPT_POSTFIELDS, $postdata); $ret = curl_exec($ch); curl_close($ch); return $ret; } $merchantID = "YOUR_VPS_MERCHANT_ID_HERE"; $merchantKey = "YOUR_PASSKEY_HERE"; //If 'do' is set, process the form if(isset($_GET["do"])) { $orderRef = $_POST["OrderReference"]; $cardNo = $_POST["CardNumber"]; $cardExp = $_POST["CardExpiry"]; $cardHolder = $_POST["CardHolderName"]; $amt = $_POST["Amount"]; $cardType = $_POST["CardType"]; $currency = "NZD"; $postvars = array( 'OrderReference' => $orderRef, 'CardNumber' => $cardNo, 'CardExpiry' => $cardExp, 'CardHolderName' => $cardHolder, 'CardType' => $cardType, 'MerchantID' => $merchantID, 'MerchantKey' => $merchantKey, 'Amount' => $amt, 'Currency' => $currency ); //Just display the raw string that is returned - you will need to process these results echo "Result: "; echo http_post("https","tx.securepaytech.com",8443,"/web/HttpPostPurchase",$postvars); echo "<br /><br />"; } ?> <html> <head> <title>SecurePayTech HTTPS POST Example</title> </head> <body> <form action="httpsPostPurchase.php?do=yes" method="post"> OrderRef: <input type="text" name="OrderReference" /><br /><br /> Card Type: <select name="CardType"> <option value="1">Visa</option> <option value="2">Mastercard</option> <option value="3">American Express</option> <option value="4">Diners Club</option> </select> <br /><br /> Card Number: <input type="text" name="CardNumber" /><br /><br /> Expiry: <input type="text" name="CardExpiry" value="0607"/><br /><br /> Holder: <input type="text" name="CardHolderName" /><br /><br /> Amount: <input type="text" name="Amount" /><br /><br /> <input type="submit" value="Place Order" /> </form> </body> </html> |