Created
October 28, 2015 08:59
-
-
Save aabir/9c7c2a8d9e231660a342 to your computer and use it in GitHub Desktop.
SecurePay XML API working with PHP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title> Test Payment </title> | |
</head> | |
<style> | |
#form-success {border: 1px solid #ccc; background: #f8f8f8; display: none; padding: 10px; width: 320px; } | |
</style> | |
<body> | |
<h3> Payment Form </h3> | |
<div id="form-success"></div> | |
<form id="payment_info" method="post"> | |
<input type="hidden" name="purchaseOrderNo" value="ODR1"> | |
<p> <label> Name on Card: </label> | |
<input type="text" name="name" value="" required> | |
</p> | |
<p> <label> Select card type: </label> | |
<select name="cardDescription" required> | |
<option value=" "> Select... </option> | |
<option value="1"> Visa </option> | |
<option value="2"> Master </option> | |
</select> | |
</p> | |
<p> <label> Amount: </label> | |
<input type="text" name="amount" value="" required> | |
</p> | |
<p> <label> Card No: </label> | |
<input type="text" name="cardNumber" value="" required> | |
</p> | |
<p> <label> CVN (or CVV): </label> | |
<input type="text" name="cvv" value="" required> | |
</p> | |
<p> <label> Expires: </label> | |
<select name="expire_month" required> | |
<option value=" "> Select... </option> | |
<option value="01"> 1 - January </option> | |
<option value="02"> 2 - February </option> | |
<option value="03"> 3 - March </option> | |
<option value="04"> 4 - April </option> | |
<option value="05"> 5 - May </option> | |
<option value="06"> 6 - June </option> | |
<option value="07"> 7 - July </option> | |
<option value="08"> 8 - August </option> | |
<option value="09"> 9 - September </option> | |
<option value="10"> 10 - October </option> | |
<option value="11"> 11 - November </option> | |
<option value="12"> 12 - December </option> | |
</select> | |
<select name="expire_year" required> | |
<option value=" "> Select... </option> | |
<?php $year = date('Y'); | |
for($i=0; $i <= 7; $i++){ ?> | |
<option value="<?php echo ($year + $i); ?>"> <?php echo ($year + $i); ?> </option> | |
<?php } ?> | |
?> | |
</select> | |
</p> | |
<p><input type="submit" value="Submit"> </p> | |
</form> | |
<script src="https://code.jquery.com/jquery-2.1.4.min.js"></script> | |
<script> | |
$(function(){ | |
var form = $('#payment_info'); | |
form.on('submit', function(e){ | |
e.preventDefault(); | |
data = form.serialize(); | |
$.ajax({ | |
url: "./process.php", | |
type: "POST", | |
dataType: "json", | |
data: data, | |
success: function(rt){ | |
if(rt && rt.success == true) { | |
$("#form-success").text(rt.msg[1][0]).css('display', 'block'); | |
if(rt.msg[1][0] == "Approved"){ | |
$("#payment_info")[0].reset(); | |
} | |
} else { | |
$("#form-success").html("Some thing went wrong! ").css('color', 'red'); | |
} | |
} | |
}); | |
}) | |
}); | |
</script> | |
</body> | |
</html> | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
extract($_POST); | |
$purchaseOrderNo = $_POST['purchaseOrderNo']; | |
$name = $_POST['name']; | |
$cardDescription = $_POST['cardDescription']; | |
$amount = $_POST['amount']; | |
$cardNumber = $_POST['cardNumber']; | |
$cvv = $_POST['cvv']; | |
$expire_month = $_POST['expire_month']; | |
$expire_year = $_POST['expire_year']; | |
$expire_year = substr($expire_year, 2); // removing first 2 letter from string | |
$expiryDate = $expire_month."/".$expire_year; | |
$cardDescription = ($cardDescription == 1 ? "Visa": "Master"); | |
$amount = $amount.'00'; | |
if(isset($_POST['cardNumber'])) { | |
$xml = '<?xml version="1.0" encoding="UTF-8"?> | |
<SecurePayMessage> | |
<MessageInfo> | |
<messageID>8af793f9af34bea0cf40f5fb5c630c</messageID> | |
<messageTimestamp>20041803161306527000+660</messageTimestamp> | |
<timeoutValue>60</timeoutValue> | |
<apiVersion>xml-4.2</apiVersion> | |
</MessageInfo> | |
<MerchantInfo> | |
<merchantID>abc0001</merchantID> | |
<password>abc123</password> | |
</MerchantInfo> | |
<RequestType>Payment</RequestType> | |
<Payment> | |
<TxnList count="1"> | |
<Txn ID="1"> | |
<txnType>0</txnType> | |
<txnSource>0</txnSource> | |
<amount>'.$amount.'</amount> | |
<currency>AUD</currency> | |
<purchaseOrderNo>'.$purchaseOrderNo.'</purchaseOrderNo> | |
<CreditCardInfo> | |
<cardNumber>'.$cardNumber.'</cardNumber> | |
<cvv>'.$cvv.'</cvv> | |
<expiryDate>'.$expiryDate.'</expiryDate> | |
<cardDescription>'.$cardDescription.'</cardDescription> | |
</CreditCardInfo> | |
<DirectEntryInfo> | |
<accountName>'.$name.'</accountName> | |
</DirectEntryInfo> | |
</Txn> | |
</TxnList> | |
</Payment> | |
</SecurePayMessage>'; | |
$curl = curl_init(); | |
curl_setopt($curl, CURLOPT_URL, "http://test.securepay.com.au/xmlapi/payment"); | |
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, TRUE); // Follow redirects | |
curl_setopt($curl, CURLOPT_POST, TRUE); | |
curl_setopt($curl, CURLOPT_POSTFIELDS, $xml); | |
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE); // Return the HTTP response from the curl_exec function | |
$response = curl_exec($curl); | |
curl_close($curl); | |
//header('Content-type: text/xml'); | |
//echo $response; | |
$oXML = new SimpleXMLElement($response); | |
$responseText[1] = $oXML->Payment[0]->TxnList[0]->Txn[0]->responseText; | |
$responseText[2] = $oXML->Payment[0]->TxnList[0]->Txn[0]->purchaseOrderNo; | |
$response = array( | |
'success' => true, | |
'msg' => $responseText | |
); | |
exit (json_encode($response)); | |
} |
Hi Ineke99,
I'm not sure if the documentation has changed over this period of time. This is a PHP script, not sure if you can run PHP on IIS server. "$(function()" line is JavaScript Jquery I believe this isn't causing an error. The error maybe from other part of the code. Right now can't help you much without knowing details. Let me know if there is a way to help you out. Thanks.
Thank you so much.
Yes, I figured that one out, and then I stumbled across prohibited web-sites on the companies server and proxy-settings.
These got resolved as well. The code with the html and process.php then hung without any error message.
So now I’m struggling to get the most simple php (see attached) to work.
If you can shine any light on that, that would be terrific.
As Secure Pay only sends me in circles by having me change user-id and password.
Kind regards
Ineke
From: Shible Noman Aabir <[email protected]>
Sent: Wednesday, 17 February 2021 5:05 PM
To: aabir <[email protected]>
Cc: Ineke Hamer <[email protected]>; Comment <[email protected]>
Subject: Re: aabir/index.php
@aabir commented on this gist.
…________________________________
Hi Ineke99,
I'm not sure if the documentation has changed over this period of time. This is a PHP script, not sure if you can run PHP on IIS server. "$(function()" line is JavaScript Jquery I believe this isn't causing an error. The error maybe from other part of the code. Right now can't help you much without knowing details. Let me know if there is a way to help you out. Thanks.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub<https://gist.github.com/9c7c2a8d9e231660a342#gistcomment-3634136>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AS26RRSG6FKKGEILMYEP4XDS7OBFJANCNFSM4XSW2X5A>.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi there,
I know, 5 years ago you wrote this, but to me it looks like the best example I've come across so far.
I thought I'd try it out and this code crashes on the $(function line with an Error 405 from IIS on the server that needs to run this code.
I have IT remove the WebDAV from the Windows program features. (Googled that that could be a possible cause).
I am obviously lacking something in the IIS handler mappings. Or there is a typo in the code????
Can someone help me out here. SecurePay support just keep on referring me back to the User manual.
Much appreciated if someone could help me out here.