The HTTP Services Interface offers a REST-style API via a simple HTTP request with "Query String" parameters.
Via the "format" parameter, values can be returned as JSON, XML or (by default) Query String.
All functions return a "result" node/ property which will be set to "OK" if the call has been successful, or else an error message. (Your code should always check this!)
Orders
Add
Create a new payment order
https://go2pay.uk/Services/Http/Order.ashx?function=ADD&format=JSON
https://go2pay.uk/Services/Http/Order.ashx
C#/ ASP.NET Example
using (var client = new WebClient())
{
// Build "ADD" call
client.QueryString["function"] = "ADD";
client.QueryString["account"] = "DEMO99";
client.QueryString["user"] = "demo";
client.QueryString["password"] = "user";
// Amount in PENNIES/ CENTS
client.QueryString["amount"] = "1000";
client.QueryString["reference"] = DateTime.Now.Ticks.ToString();
var service = "https://go2pay.uk/Services/Http/Order.ashx";
// Call "ADD"
var result = HttpUtility.ParseQueryString(client.DownloadString(service));
// Check result/ status
if (result["result"] != "OK")
{
throw new ApplicationException(result["result"]);
}
/*
At this point you should save the "id" from the result to the database - if you don't
get a result back after 15 minutes you should "clean-up" by querying the result!
(Remember... this is the internet - if it CAN go wrong... at some point it will!!)
*/
// Build return back to Result.aspx
var returnUrl = "https://MY_SITE/Result.aspx?id=" + result["id"];
// For "link" payments, SMS parameter contains just the URL
var redirect = result["sms"] + "&" + HttpUtility.UrlEncode(returnUrl);
// Redirect to payment URL
Response.Redirect(redirect);
}
PHP Example
// Build Parameters
$data = array(
'function' =˃ 'add',
'format' =˃ 'JSON',
'account' =˃ 'DEMO99',
'user' =˃ 'demo',
'password' =˃ 'user',
'amount' =˃ '1000',
'reference' =˃ time());
$service = 'https://go2pay.uk/Services/Http/Order.ashx?';
// Build URL
$url = $service . http_build_query($data);
// Call service + parse result
$result = json_decode(file_get_contents(url));
if($result-˃result !== 'OK')
{
throw new Exception($result-˃result);
}
/*
At this point you should save the "id" from the result to the database - if you don't
get a result back after 15 minutes you should "clean-up" by querying the result!
(Remember... this is the internet - if it CAN go wrong... at some point it will!!)
*/
// Build return back to Result.php
$returnUrl = 'https://MY_SITE/Result.php?id=' . $result-˃id;
// For "link" payments, SMS parameter contains just the URL
$redirect = $result-˃sms . '&' . urlencode($returnUrl);
// Redirect to payment URL
header('Location: ' . $redirect);
Query
Query the status of an payment order
https://go2pay.uk/Services/Http/Order.ashx?function=QUERY&format=XML
C#/ ASP.NET Example
using (var client = new WebClient())
{
// Build "QUERY" call
client.QueryString["function"] = "QUERY";
client.QueryString["account"] = "DEMO99";
client.QueryString["user"] = "demo";
client.QueryString["password"] = "user";
// The ID we received back from the "ADD" call
client.QueryString["id"] = Request.QueryString["id"];
var service = "https://go2pay.uk/Services/Http/Order.ashx";
// Call "QUERY"
var result = HttpUtility.ParseQueryString(client.DownloadString(service));
// Check result/ status
if (result["result"] != "OK")
{
throw new ApplicationException(result["result"]);
}
/*
At this point, you should update the database with the id/ result
*/
PaymentStatus status = (PaymentStatus)Enum.Parse(typeof(PaymentStatus), result["status"]);
if(status == PaymentStatus.Authorised)
{
lblResult.Text = "THANK YOU FOR YOUR PAYMENT";
}
else if (status == PaymentStatus.Declined)
{
lblResult.Text = "SORRY - YOUR PAYMENT WAS DECLINED";
}
else
{
lblResult.Text = "SORRY - YOUR PAYMENT FAILED - PLEASE CONTACT US";
}
// Print Authorisation Info
var fields = new string[] { "MPOSID", "Amount", "Paid", "Surcharge", "CardNo",
"CardExpiry", "Token", "CardType", "AuthCode" };
foreach (string key in fields)
{
txtAuthInfo.Text += key + ": " + result[key] + Environment.NewLine;
}
}
public enum PaymentStatus
{
Unknown = 999,
Awaiting = -999,
Verifying = -888,
Pending = 0,
Authorised = 1,
Declined = -1,
Error = 2,
Cancelled = 3,
Expiring = 7,
Expired = 8,
Abandoned = 9
}
PHP Example
// Build "QUERY" call
// NB the id we recieved back from the "ADD" call
$data = array(
'function' =˃ 'QUERY',
'format' =˃ 'JSON',
'account' =˃ 'DEMO99',
'user' =˃ 'demo',
'password' =˃ 'user',
'id' =˃ XXXXX['id']);
$service = 'https://go2pay.uk/Services/Http/Order.ashx?';
// Build URL
$url = $service . http_build_query($data);
// Call service + parse result
$result = json_decode(file_get_contents(url));
if($result-˃result !== 'OK')
{
throw new Exception($result-˃result);
}
/*
At this point, you should update the database with the id/ result
*/
// Check result/ status
if($result-˃status == 1)
{
echo 'THANK YOU FOR YOUR PAYMENT';
}
else if ($result-˃status == -1)
{
echo 'SORRY - YOUR PAYMENT WAS DECLINED';
}
else
{
echo 'SORRY - YOUR PAYMENT FAILED - PLEASE CONTACT US';
}
// Print Authorisation Info
echo 'MPOSID: ' . $result-˃MPOSID . '; ';
echo 'Amount: ' . $result-˃Amount . '; ';
echo 'Paid: ' . $result-˃Paid . '; ';
echo 'Surcharge: ' . $result-˃Surcharge . '; ';
echo 'CardNo: ' . $result-˃CardNo . '; ';
echo 'CardExpiry: ' . $result-˃CardExpiry . '; ';
echo 'Token: ' . $result-˃Token . '; ';
echo 'CardType: ' . $result-˃CardType . '; ';
echo 'AuthCode: ' . $result-˃AuthCode . '; ';
Delete
Delete an unfulfilled payment order
https://go2pay.uk/Services/Http/Order.ashx?function=DELETE&format=...
Pay
Pay an order, using a token generated from a previous payment
https://go2pay.uk/Services/Http/Orders.ashx?function=PAY&format=...
Refund
Refund a "paid" order, up to the original amount
History
List recent orders
https://go2pay.uk/Services/Http/Order.ashx?function=HISTORY&format=...
Totals (End of Day)
List totals from recent days
https://go2pay.uk/Services/Http/Order.ashx?function=TOTALS&format=...
Transactions
Individual Transactions:
https://go2pay.uk/Services/Http/Transaction.ashx
Transaction Lists:
https://go2pay.uk/Services/Http/Transactions.ashx