Skip to main content

Initialize Payment

The initialize payment endpoint allows you to create a payment request and get a payment URL that customers can use to complete their payment.

Endpoint

POST https://api.resolutpay.com/transaction/initialize

Request Parameters

ParameterTypeRequiredDescription
amountintegerYesAmount in pesewas (smallest currency unit)
emailstringYesCustomer's email address
referencestringYesUnique reference for the transaction
callback_urlstringYesURL to redirect customer after payment
currencystringNoCurrency code (default: GHS)
metadataobjectNoAdditional data to store with transaction
channelsarrayNoPayment channels to enable
split_codestringNoSplit payment code
subaccountstringNoSubaccount code
transaction_chargeintegerNoTransaction charge in pesewas
bearerstringNoWho bears the transaction charge

Example Request

const axios = require("axios");

const initializePayment = async () => {
try {
const response = await axios.post(
"https://api.resolutpay.com/transaction/initialize",
{
amount: 5000, // 50 GHS in pesewas
email: "customer@example.com",
reference: "REF_" + Date.now(),
callback_url: "https://yourwebsite.com/verify",
currency: "GHS",
metadata: {
custom_fields: [
{
display_name: "Invoice ID",
variable_name: "invoice_id",
value: "INV-001",
},
],
},
channels: [
"card",
"bank",
"ussd",
"qr",
"mobile_money",
"bank_transfer",
],
},
{
headers: {
Authorization: "Bearer YOUR_SECRET_KEY",
"Content-Type": "application/json",
},
}
);

console.log("Payment URL:", response.data.data.authorization_url);
return response.data;
} catch (error) {
console.error("Error:", error.response.data);
throw error;
}
};

Example Response

{
"status": true,
"message": "Authorization URL created",
"data": {
"authorization_url": "https://checkout.resolutpay.com/0/peJh7nXxKz",
"access_code": "0/peJh7nXxKz",
"reference": "REF_1234567890"
}
}

Payment Channels

You can specify which payment methods to enable:

ChannelDescription
cardCredit and debit cards
bankBank transfers
ussdUSSD payments
qrQR code payments
mobile_moneyMobile money
bank_transferDirect bank transfers

Metadata

Use the metadata field to store additional information with your transaction:

metadata: {
custom_fields: [
{
display_name: 'Customer Name',
variable_name: 'customer_name',
value: 'John Doe'
},
{
display_name: 'Order ID',
variable_name: 'order_id',
value: 'ORD-123'
}
],
referrer: 'website',
cancel_action: 'https://yourwebsite.com/cancel'
}

Split Payments

For split payments, include the split_code parameter:

{
amount: 5000,
email: 'customer@example.com',
reference: 'REF_' + Date.now(),
callback_url: 'https://yourwebsite.com/verify',
split_code: 'SPL_xxxxxxxxxx'
}

Subaccounts

To process payments for a subaccount:

{
amount: 5000,
email: 'customer@example.com',
reference: 'REF_' + Date.now(),
callback_url: 'https://yourwebsite.com/verify',
subaccount: 'ACCT_xxxxxxxxxx'
}

Transaction Charges

Specify who bears the transaction charge:

{
amount: 5000,
email: 'customer@example.com',
reference: 'REF_' + Date.now(),
callback_url: 'https://yourwebsite.com/verify',
transaction_charge: 100, // 1 GHS in pesewas
bearer: 'account' // 'account', 'subaccount', or 'customer'
}

Error Responses

Common error responses:

{
"status": false,
"message": "Invalid amount",
"data": null
}
ErrorDescription
Invalid amountAmount is less than minimum or invalid
Invalid emailEmail format is invalid
Invalid referenceReference already exists
Invalid callback_urlCallback URL is invalid

Complete Example

Here's a complete example with error handling:

const express = require("express");
const axios = require("axios");
const app = express();

app.use(express.json());

app.post("/initialize-payment", async (req, res) => {
try {
const { amount, email, reference } = req.body;

// Validate required fields
if (!amount || !email || !reference) {
return res.status(400).json({
success: false,
message: "Amount, email, and reference are required",
});
}

// Validate amount (minimum 100 pesewas = 1 GHS)
if (amount < 100) {
return res.status(400).json({
success: false,
message: "Amount must be at least 100 pesewas (1 GHS)",
});
}

const response = await axios.post(
"https://api.resolutpay.com/transaction/initialize",
{
amount: amount,
email: email,
reference: reference,
callback_url: "https://yourwebsite.com/verify",
currency: "GHS",
channels: ["card", "bank", "ussd", "mobile_money"],
metadata: {
custom_fields: [
{
display_name: "Customer Name",
variable_name: "customer_name",
value: req.body.customer_name || "Anonymous",
},
],
},
},
{
headers: {
Authorization: `Bearer ${process.env.RESOLUTPAY_SECRET_KEY}`,
"Content-Type": "application/json",
},
}
);

res.json({
success: true,
data: response.data.data,
});
} catch (error) {
console.error(
"Payment initialization error:",
error.response?.data || error.message
);

res.status(500).json({
success: false,
message: error.response?.data?.message || "Failed to initialize payment",
});
}
});

app.listen(3000, () => {
console.log("Server running on port 3000");
});

Next Steps