Initialize a transaction from your backend by preparing the necessary parameters for the payment gateway.
<?php
$email="";
$amount="";
$payment_type="";
$callback_url="";
$mac = "";
$mystring = $email . $amount. $payment_type . $callback_url;
$hash = hash_hmac('sha512', $mystring, $mac, false);
import * as CryptoJS from 'crypto-js';
function generateHash(email, amount, payment_type, callback_url, mac) {
const myString = email + amount + payment_type + callback_url;
return CryptoJS.HmacSHA512(myString, mac).toString(CryptoJS.enc.Hex);
}
Generate a secure hash for transaction verification using HMAC-SHA512 algorithm.
Sample Payload
// Some code
let initiated = `https://app.moneta.ng/api/v1/transaction/initialize?hash=${hash}`;
let payload = {
amount: 800000, // Amount in kobo (the user is paying 8000)
email: "payer's email",
callback_url: "your callback URL",
payment_type: "card",
channel: "card",
metadata: "",
customerinfo: "",
serviceCode: "", // Service code
serviceType: "", // What are you paying for
serviceCategory: "", // Category of service
json: "true",
use_split: ""
};
// Success Response
{
"status": "success",
"responseCode": "00",
"url": "your callback URL",
"ref_no": "Moneta Reference",
"type": "card",
"authorization_url": "payment link"
}
Confirm the status of a transaction
// We will request to this URL
let paydate = "2023-09-18 13:09:20";
let url = `your_callback_url?reference=${reference}&status=${status}&paydate=${paydate}`;
// NB: When a notification is received at your callback URL, verifying it at the endpoint is strongly recommended.
// Some code
// #channel: bank or card
// Endpoint: https://app.moneta.ng/api/v1/transaction/verify/{{channel}}{{transaction_reference}}
// In the customer object watch for the Status field:
// Status=1 paid, Status=0 unpaid
// Sample Request
// #updated_at is payment date (2023-09-18 13:09:20)
let token = '';
let channel = '';
let reference = '';
var myHeaders = new Headers();
myHeaders.append("Authorization", `Bearer ${token}`);
var requestOptions = {
method: 'GET',
headers: myHeaders,
redirect: 'follow'
};
fetch(`https://app.moneta.ng/api/v1/transaction/verify/${channel}/${reference}`, requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
// Expected Response from the Moneta verification endpoint
{
"status": "success",
"responseCode": "00",
"customer": {
"SN": 2705801,
"api_token": "",
"Customer_Id": "transaction reference",
"callback_url": "your_callback_url",
"gateway": null,
"splitrecord": "",
"FirstName": "",
"OtherName": "",
"LastName": "",
"Email": "",
"Phone": "",
"Status": 1,
"requery": 0,
"AmountDue": "",
"AmountPaid": "",
"rrr": "",
"remitalog": "",
"nibss": 0,
"ubamobilemoney": 0,
"bankmodule": 0,
"coral": 0,
"coral_refcode": null,
"coral_transid": null,
"coral_payload": null,
"direct": null,
"direct_complete": null,
"merchant_response": "",
"serviceCode": "",
"serviceType": "",
"serviceCategory": null,
"moneta_agent_id": null,
"created_at": "",
"updated_at": "",
"deleted_at": null,
"saved_fee": "",
"settlement_date": null,
"settlement_type_id": 1,
"sales_amount": "0",
"commission_amount": null,
"residue_amount": "0",
"merchant_name": "",
"fees": "",
"use_split": "",
"acc_name": [ ],
"gate_way_used": "PayDirect"
},
"transaction": {
"SN": 533020,
"PaymentLogId": "",
"CustReference": "",
"AlternateCustReference": "",
"Amount": "",
"PaymentStatus": "0",
"PaymentMethod": "",
"PaymentReference": "",
"TerminalId": "",
"ChannelName": "",
"Location": "",
"IsReversal": "",
"PaymentDate": "",
"SettlementDate": "",
"InstitutionId": "MNTA",
"InstitutionName": "MONETA",
"BranchName": "",
"BankName": "",
"FeeName": "",
"CustomerName": "",
"OtherCustomerInfo": "",
"ReceiptNo": "",
"CollectionsAccount": "",
"ThirdPartyCode": "",
"BankCode": "",
"CustomerAddress": "",
"CustomerPhoneNumber": "",
"DepositorName": "",
"DepositSlipNumber": "",
"PaymentCurrency": "NGN",
"OriginalPaymentLogId": "",
"OriginalPaymentReference": "",
"REASON": null,
"TREATED": null,
"created_at": "2023-09-17T20:02:28.000000Z",
"updated_at": "2023-09-17T20:02:28.000000Z",
"deleted_at": null
}
}