a1pay
  • Introduction
  • Request Authentication
  • User Login
  • User Signup
  • List User's Transactions
  • Initialize Payment
  • List User's Cards
  • Query a Transaction
  • Requery a Transaction
  • Charge Card
  • OTP Validation
  • Accept Payment Using A1Pay
    • Introduction
    • Initialize Payment
    • Query Status With Your Reference
    • Query Status With A1Pay Reference
    • Sample Integration Codes
Powered by GitBook
On this page
  1. Accept Payment Using A1Pay

Sample Integration Codes

import requests
import hashlib



merchantId = "123" 
secret = "xyz"


def getHash(Amount):
    """
    Join input parameter and hash them
    """
    Join_string = Amount+merchantId+secret
    name = hashlib.sha256(Join_string.encode('utf-8')).hexdigest()
    return name

def Query(A1PayReference,Amount):
    hash_code = getHash(Amount)
    request = requests.get("https://a1pay.net/api/Query/Status/?transactionRef="+A1PayReference, headers={"Hash":hash_code})
    return request

def QueryWithMyReference(MyTransactionReference,Amount):
    hash_code = getHash(Amount)
    request = requests.get("https://a1pay.net/api/Query/StatusWithMyReference/?transactionRef="+MyTransactionReference+"&merchantId="+merchantId, headers={"Hash":hash_code})
    return request
    

reference = "xyz"
query = Query(reference,"2000.00") 
print(query.content)
    
<?php

$merchantId = ""; //your merchant id 
$secret = ""; //your merchant secret
$Amount = "2000.00"; // just an amount we are using to test

function get_Hash($Amount){
    global $merchantId;
    global $secret;
    $join_string = $Amount.$merchantId.$secret;
    $hash = hash('sha256',$join_string);
    return $hash;

}

function Query($A1PayReference,$Amount){
    $hash = get_Hash($Amount);
    $headers = array(
        'Hash:'.$hash,
        'Accept: application/json',
        );
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL,'https://a1pay.net/api/Query/Status/?transactionRef='.$A1PayReference);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET"); 
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        $server_output = curl_exec($ch);
        curl_close ($ch);
        return $server_output;

}

function QueryWithMyReference($MyTransactionReference,$Amount){
    global $merchantId;
    $hash = get_Hash($Amount);
    $headers = array(
        'Hash:'.$hash,
        'Accept: application/json',
        );
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL,'https://a1pay.net/api/Query/StatusWithMyReference/?transactionRef='.$MyTransactionReference.'&merchantId='.$merchantId);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET"); 
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        $server_output = curl_exec($ch);
        curl_close ($ch);
        return $server_output;

}

$result = QueryWithMyReference("transaction-reference",$Amount);
echo ($result);
?>
using RestSharp;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Web;
using System.Web.Helpers;
using System.Web.Script.Serialization;

namespace A1PayIntegrationTest
{
    public class A1Pay
    {
        public static string MerchantId = ""; //your merchant ID
        public static string Secret = ""; //your secret key
         public static string BaseURL = "https://a1pay.net/";

        public static string TransactionHash(decimal Amount)
        {
            ////hash= amount+apikey+secret hashed with 256
            try
            {
                return Crypto.SHA256(Amount.ToString("#.00", CultureInfo.InvariantCulture) + MerchantId + Secret);
            }
            catch (Exception ex)
            {
            }
            return null;
        }

        public static A1PayResponse Query(string A1PayReference, decimal Amount)
        {
            try
            {
                var client = new RestClient(BaseURL+ "api/Query/");
                var request = new RestRequest("Status/?transactionRef=" + HttpUtility.UrlEncode(A1PayReference), Method.GET);
                request.AddHeader("Hash", TransactionHash(Amount));
                request.RequestFormat = DataFormat.Json;

                IRestResponse response = client.Execute(request);
                var content = response.Content;
                A1PayTransactionResponse QueryResponse = new JavaScriptSerializer().Deserialize<A1PayTransactionResponse>(content);
                if (QueryResponse == null)
                {
                    return null;
                }
                if (QueryResponse.status.ToLower() == "error")
                {
                    return null;
                }
                string ResponseJson = new JavaScriptSerializer().Serialize(QueryResponse.data);
                A1PayResponse ReturnValue = new JavaScriptSerializer().Deserialize<A1PayResponse>(ResponseJson);
                return ReturnValue;
            }
            catch (Exception ex)
            {
            }
            return null;
        }

        public static A1PayResponse QueryWithMyReference(string MyTransactionReference, decimal Amount)
        {
            try
            {
                var client = new RestClient(BaseURL + "api/Query/");
                var request = new RestRequest("StatusWithMyReference/?transactionRef=" + HttpUtility.UrlEncode(MyTransactionReference)+
                    "&merchantId=" + HttpUtility.UrlEncode(MerchantId), Method.GET);
                request.AddHeader("Hash", TransactionHash(Amount));
                request.RequestFormat = DataFormat.Json;

                IRestResponse response = client.Execute(request);
                var content = response.Content;
                A1PayTransactionResponse QueryResponse = new JavaScriptSerializer().Deserialize<A1PayTransactionResponse>(content);
                if (QueryResponse == null)
                {
                    return null;
                }
                if (QueryResponse.status.ToLower() == "error")
                {
                    return null;
                }
                string ResponseJson = new JavaScriptSerializer().Serialize(QueryResponse.data);
                A1PayResponse ReturnValue = new JavaScriptSerializer().Deserialize<A1PayResponse>(ResponseJson);
                return ReturnValue;
            }
            catch (Exception ex)
            {
            }
            return null;
        }
    }

    public class A1PayTransactionResponse
    {
        public string status { get; set; }
        public object data { get; set; }
    }

    public class A1PayResponse
    {
        public decimal AmountPaid { get; set; }
        public string TransactionDate { get; set; }
        public string PaymentReference_Switch { get; set; }
        public string PaymentReference_Local { get; set; }
        public string PayerName { get; set; }
        public string PayerEmail { get; set; }
        public string TransactionType { get; set; }

        public string ResponseCode { get; set; }
        public string ResponseDescription { get; set; }
        public string FriendlyMessage { get; set; }
        public string FurtherExplanation { get; set; }
        public bool IsSuccessful { get; set; }
    }
}

This is a sample HTML form you will need to send payment instruction to A1Pay

<div class="row">
    <div class="col-md-4">
        <h2>Pay</h2>
        <form  method="POST" action="https://a1pay.net/Pay/Pay/">

            <div class="form-group">
                <label class="control-label">Amount</label>
                <input type="number" min="1000" name="Amount" class="form-control">
                <hr>
            </div>
            <div class="form-group">
                <label class="control-label">Transaction Reference</label>
                <input type="text" name="ref" class="form-control">
            </div>
            <div class="form-group">
                <label class="control-label">Surname</label>
                <input type="text"  name="SurName" class="form-control">
            </div>
            <div class="form-group">
                <label class="control-label">Firstname</label>
                <input type="text" name="FirstName" class="form-control">
            </div>
            <div class="form-group">
                <label class="control-label">Othernames</label>
                <input type="text" name="OtherNames" class="form-control">
            </div>

            <div class="form-group">
                <label class="control-label">Email</label>
                <input type="email" name="EmailAddress" class="form-control">
            </div>
            <div class="form-group">
                <label class="control-label">Phone</label>
                <input type="tel"  name="PhoneNumber" class="form-control">
            </div>
            <div class="form-group">
                <hr/>
                <small>This is for demo purposes only, MerchantID, Secret Key and Hash should not be visible to users</small>
            </div>
            <div class="form-group">
                <label class="control-label">Merchant ID</label>
                <input type="text"  name="MerchantId" class="form-control">
            </div>
            <div class="form-group">
                <label class="control-label">Hash <br/> <small>SHA256 of amount+apikey+secretkey</small></label>
                <input type="text"  name="hash" class="form-control" >
            </div>
            <input type="hidden" id="Validity" name="Validity" value="432000">
            <input type="hidden" id="TransType" name="TransType" value="Fees Payment">
            <div class="form-group">
                <button type="submit">Pay now</button>
            </div>
        </form>
    </div>

</div>
PreviousQuery Status With A1Pay Reference

Last updated 4 years ago