# v2: Sample Code

{% tabs %}
{% tab title="HTML" %}
Sample HTML to send payment to Collecta

```markup
<div class="row">
    <div class="col-md-4">
        <h2>Pay</h2>
        <form  method="POST" action="https://app.collecta.com.ng/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>
```

{% endtab %}

{% tab title="PHP" %}

```php
<?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($CollectaReference,$Amount){
    $hash = get_Hash($Amount);
    $headers = array(
        'Hash:'.$hash,
        'Accept: application/json',
        );
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL,'https://app.collecta.com.ng/api/Query/Status/?transactionRef='.$CollectaReference);
        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://app.collecta.com.ng/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);
?>
```

{% endtab %}

{% tab title="Python" %}

```python
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(CollectaReference,Amount):
    hash_code = getHash(Amount)
    request = requests.get("https://app.collecta.com.ng/api/Query/Status/?transactionRef="+CollectaReference, headers={"Hash":hash_code})
    return request

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

reference = "xyz"
query = Query(reference,"2000.00") 
print(query.content)
    
```

{% endtab %}

{% tab title="C#" %}

```csharp
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 CollectaPayment
{
    public class Collecta
    {
        public static string MerchantId = ""; //your merchant ID
        public static string Secret = ""; //your secret key
         public static string BaseURL = "https://app.collecta.com.ng/";

        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 CollectaResponse Query(string CollectaReference, decimal Amount)
        {
            try
            {
                var client = new RestClient(BaseURL+ "api/Query/");
                var request = new RestRequest("Status/?transactionRef=" + HttpUtility.UrlEncode(CollectaReference), Method.GET);
                request.AddHeader("Hash", TransactionHash(Amount));
                request.RequestFormat = DataFormat.Json;

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

        public static CollectaResponse 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;
                TransactionResponse QueryResponse = new JavaScriptSerializer().Deserialize<TransactionResponse>(content);
                if (QueryResponse == null)
                {
                    return null;
                }
                if (QueryResponse.status.ToLower() == "error")
                {
                    return null;
                }
                string ResponseJson = new JavaScriptSerializer().Serialize(QueryResponse.data);
                CollectaResponse ReturnValue = new JavaScriptSerializer().Deserialize<CollectaResponse>(ResponseJson);
                return ReturnValue;
            }
            catch (Exception ex)
            {
            }
            return null;
        }
    }

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

    public class CollectaResponse
    {
        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; }
    }
}
```

{% endtab %}
{% endtabs %}
