a1pay
Search…
Sample Integration Codes
Python
PHP
C#
HTML
1
import requests
2
import hashlib
3
4
5
6
merchantId = "123"
7
secret = "xyz"
8
9
10
def getHash(Amount):
11
"""
12
Join input parameter and hash them
13
"""
14
Join_string = Amount+merchantId+secret
15
name = hashlib.sha256(Join_string.encode('utf-8')).hexdigest()
16
return name
17
18
def Query(A1PayReference,Amount):
19
hash_code = getHash(Amount)
20
request = requests.get("https://a1pay.net/api/Query/Status/?transactionRef="+A1PayReference, headers={"Hash":hash_code})
21
return request
22
23
def QueryWithMyReference(MyTransactionReference,Amount):
24
hash_code = getHash(Amount)
25
request = requests.get("https://a1pay.net/api/Query/StatusWithMyReference/?transactionRef="+MyTransactionReference+"&merchantId="+merchantId, headers={"Hash":hash_code})
26
return request
27
28
29
reference = "xyz"
30
query = Query(reference,"2000.00")
31
print(query.content)
32
Copied!
1
<?php
2
3
$merchantId = ""; //your merchant id
4
$secret = ""; //your merchant secret
5
$Amount = "2000.00"; // just an amount we are using to test
6
7
function get_Hash($Amount){
8
global $merchantId;
9
global $secret;
10
$join_string = $Amount.$merchantId.$secret;
11
$hash = hash('sha256',$join_string);
12
return $hash;
13
14
}
15
16
function Query($A1PayReference,$Amount){
17
$hash = get_Hash($Amount);
18
$headers = array(
19
'Hash:'.$hash,
20
'Accept: application/json',
21
);
22
$ch = curl_init();
23
curl_setopt($ch, CURLOPT_URL,'https://a1pay.net/api/Query/Status/?transactionRef='.$A1PayReference);
24
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
25
curl_setopt($ch, CURLOPT_HEADER, 0);
26
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
27
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
28
$server_output = curl_exec($ch);
29
curl_close ($ch);
30
return $server_output;
31
32
}
33
34
function QueryWithMyReference($MyTransactionReference,$Amount){
35
global $merchantId;
36
$hash = get_Hash($Amount);
37
$headers = array(
38
'Hash:'.$hash,
39
'Accept: application/json',
40
);
41
$ch = curl_init();
42
curl_setopt($ch, CURLOPT_URL,'https://a1pay.net/api/Query/StatusWithMyReference/?transactionRef='.$MyTransactionReference.'&merchantId='.$merchantId);
43
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
44
curl_setopt($ch, CURLOPT_HEADER, 0);
45
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
46
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
47
$server_output = curl_exec($ch);
48
curl_close ($ch);
49
return $server_output;
50
51
}
52
53
$result = QueryWithMyReference("transaction-reference",$Amount);
54
echo ($result);
55
?>
Copied!
1
using RestSharp;
2
using System;
3
using System.Collections.Generic;
4
using System.Globalization;
5
using System.Linq;
6
using System.Web;
7
using System.Web.Helpers;
8
using System.Web.Script.Serialization;
9
10
namespace A1PayIntegrationTest
11
{
12
public class A1Pay
13
{
14
public static string MerchantId = ""; //your merchant ID
15
public static string Secret = ""; //your secret key
16
public static string BaseURL = "https://a1pay.net/";
17
18
public static string TransactionHash(decimal Amount)
19
{
20
////hash= amount+apikey+secret hashed with 256
21
try
22
{
23
return Crypto.SHA256(Amount.ToString("#.00", CultureInfo.InvariantCulture) + MerchantId + Secret);
24
}
25
catch (Exception ex)
26
{
27
}
28
return null;
29
}
30
31
public static A1PayResponse Query(string A1PayReference, decimal Amount)
32
{
33
try
34
{
35
var client = new RestClient(BaseURL+ "api/Query/");
36
var request = new RestRequest("Status/?transactionRef=" + HttpUtility.UrlEncode(A1PayReference), Method.GET);
37
request.AddHeader("Hash", TransactionHash(Amount));
38
request.RequestFormat = DataFormat.Json;
39
40
IRestResponse response = client.Execute(request);
41
var content = response.Content;
42
A1PayTransactionResponse QueryResponse = new JavaScriptSerializer().Deserialize<A1PayTransactionResponse>(content);
43
if (QueryResponse == null)
44
{
45
return null;
46
}
47
if (QueryResponse.status.ToLower() == "error")
48
{
49
return null;
50
}
51
string ResponseJson = new JavaScriptSerializer().Serialize(QueryResponse.data);
52
A1PayResponse ReturnValue = new JavaScriptSerializer().Deserialize<A1PayResponse>(ResponseJson);
53
return ReturnValue;
54
}
55
catch (Exception ex)
56
{
57
}
58
return null;
59
}
60
61
public static A1PayResponse QueryWithMyReference(string MyTransactionReference, decimal Amount)
62
{
63
try
64
{
65
var client = new RestClient(BaseURL + "api/Query/");
66
var request = new RestRequest("StatusWithMyReference/?transactionRef=" + HttpUtility.UrlEncode(MyTransactionReference)+
67
"&merchantId=" + HttpUtility.UrlEncode(MerchantId), Method.GET);
68
request.AddHeader("Hash", TransactionHash(Amount));
69
request.RequestFormat = DataFormat.Json;
70
71
IRestResponse response = client.Execute(request);
72
var content = response.Content;
73
A1PayTransactionResponse QueryResponse = new JavaScriptSerializer().Deserialize<A1PayTransactionResponse>(content);
74
if (QueryResponse == null)
75
{
76
return null;
77
}
78
if (QueryResponse.status.ToLower() == "error")
79
{
80
return null;
81
}
82
string ResponseJson = new JavaScriptSerializer().Serialize(QueryResponse.data);
83
A1PayResponse ReturnValue = new JavaScriptSerializer().Deserialize<A1PayResponse>(ResponseJson);
84
return ReturnValue;
85
}
86
catch (Exception ex)
87
{
88
}
89
return null;
90
}
91
}
92
93
public class A1PayTransactionResponse
94
{
95
public string status { get; set; }
96
public object data { get; set; }
97
}
98
99
public class A1PayResponse
100
{
101
public decimal AmountPaid { get; set; }
102
public string TransactionDate { get; set; }
103
public string PaymentReference_Switch { get; set; }
104
public string PaymentReference_Local { get; set; }
105
public string PayerName { get; set; }
106
public string PayerEmail { get; set; }
107
public string TransactionType { get; set; }
108
109
public string ResponseCode { get; set; }
110
public string ResponseDescription { get; set; }
111
public string FriendlyMessage { get; set; }
112
public string FurtherExplanation { get; set; }
113
public bool IsSuccessful { get; set; }
114
}
115
}
Copied!
This is a sample HTML form you will need to send payment instruction to A1Pay
1
<div class="row">
2
<div class="col-md-4">
3
<h2>Pay</h2>
4
<form method="POST" action="https://a1pay.net/Pay/Pay/">
5
6
<div class="form-group">
7
<label class="control-label">Amount</label>
8
<input type="number" min="1000" name="Amount" class="form-control">
9
<hr>
10
</div>
11
<div class="form-group">
12
<label class="control-label">Transaction Reference</label>
13
<input type="text" name="ref" class="form-control">
14
</div>
15
<div class="form-group">
16
<label class="control-label">Surname</label>
17
<input type="text" name="SurName" class="form-control">
18
</div>
19
<div class="form-group">
20
<label class="control-label">Firstname</label>
21
<input type="text" name="FirstName" class="form-control">
22
</div>
23
<div class="form-group">
24
<label class="control-label">Othernames</label>
25
<input type="text" name="OtherNames" class="form-control">
26
</div>
27
28
<div class="form-group">
29
<label class="control-label">Email</label>
30
<input type="email" name="EmailAddress" class="form-control">
31
</div>
32
<div class="form-group">
33
<label class="control-label">Phone</label>
34
<input type="tel" name="PhoneNumber" class="form-control">
35
</div>
36
<div class="form-group">
37
<hr/>
38
<small>This is for demo purposes only, MerchantID, Secret Key and Hash should not be visible to users</small>
39
</div>
40
<div class="form-group">
41
<label class="control-label">Merchant ID</label>
42
<input type="text" name="MerchantId" class="form-control">
43
</div>
44
<div class="form-group">
45
<label class="control-label">Hash <br/> <small>SHA256 of amount+apikey+secretkey</small></label>
46
<input type="text" name="hash" class="form-control" >
47
</div>
48
<input type="hidden" id="Validity" name="Validity" value="432000">
49
<input type="hidden" id="TransType" name="TransType" value="Fees Payment">
50
<div class="form-group">
51
<button type="submit">Pay now</button>
52
</div>
53
</form>
54
</div>
55
56
</div>
Copied!
Copy link