Verify Payment
The verify payment endpoint allows you to check the status of a transaction using its reference. This is essential for confirming that payments have been completed successfully.
Endpoint
GET https://api.resolutpay.com/transaction/verify/{reference}
Parameters
Parameter | Type | Required | Description |
---|---|---|---|
reference | string | Yes | The transaction reference to verify |
Example Request
const axios = require("axios");
const verifyPayment = async (reference) => {
try {
const response = await axios.get(
`https://api.resolutpay.com/transaction/verify/${reference}`,
{
headers: {
Authorization: "Bearer YOUR_SECRET_KEY",
},
}
);
const transaction = response.data.data;
if (transaction.status === "success") {
console.log("Payment successful:", transaction);
// Update your database, send confirmation email, etc.
} else {
console.log("Payment failed or pending:", transaction);
}
return transaction;
} catch (error) {
console.error("Verification error:", error.response.data);
throw error;
}
};
// Usage
verifyPayment("REF_1234567890");
Example Response
{
"status": true,
"message": "Verification successful",
"data": {
"id": 123456,
"domain": "test",
"amount": 5000,
"currency": "GHS",
"due_date": null,
"has_invoice": false,
"invoice_number": null,
"description": null,
"tx_ref": "REF_1234567890",
"flw_ref": "FLW1234567890",
"status": "successful",
"payment_type": "card",
"created_at": "2023-01-01T12:00:00.000Z",
"updated_at": "2023-01-01T12:05:00.000Z",
"customer": {
"id": 123,
"name": "John Doe",
"phone_number": "+2348012345678",
"email": "customer@example.com",
"created_at": "2023-01-01T12:00:00.000Z",
"updated_at": "2023-01-01T12:00:00.000Z"
},
"meta": {
"custom_fields": [
{
"display_name": "Invoice ID",
"variable_name": "invoice_id",
"value": "INV-001"
}
]
}
}
}
Transaction Statuses
Status | Description | Action Required |
---|---|---|
successful | Payment completed successfully | Process order, send confirmation |
pending | Payment is being processed | Wait for webhook or check again later |
failed | Payment failed or was declined | Inform customer, retry payment |
abandoned | Customer abandoned the payment | Contact customer, offer assistance |
reversed | Payment was reversed/refunded | Update order status, process refund |
Complete Example with Express.js
const express = require("express");
const axios = require("axios");
const app = express();
app.use(express.json());
// Verify payment endpoint
app.get("/verify/:reference", async (req, res) => {
try {
const { reference } = req.params;
if (!reference) {
return res.status(400).json({
success: false,
message: "Reference is required",
});
}
const response = await axios.get(
`https://api.resolutpay.com/transaction/verify/${reference}`,
{
headers: {
Authorization: `Bearer ${process.env.RESOLUTPAY_SECRET_KEY}`,
},
}
);
const transaction = response.data.data;
// Handle different payment statuses
switch (transaction.status) {
case "successful":
// Payment successful - update database, send confirmation
await updateOrderStatus(reference, "paid");
await sendConfirmationEmail(transaction.customer.email);
res.json({
success: true,
message: "Payment verified successfully",
data: transaction,
});
break;
case "pending":
// Payment still processing
res.json({
success: true,
message: "Payment is being processed",
data: transaction,
});
break;
case "failed":
// Payment failed
await updateOrderStatus(reference, "failed");
res.json({
success: false,
message: "Payment failed",
data: transaction,
});
break;
case "abandoned":
// Payment abandoned
await updateOrderStatus(reference, "abandoned");
res.json({
success: false,
message: "Payment was abandoned",
data: transaction,
});
break;
default:
res.json({
success: false,
message: "Unknown payment status",
data: transaction,
});
}
} catch (error) {
console.error(
"Payment verification error:",
error.response?.data || error.message
);
res.status(500).json({
success: false,
message: error.response?.data?.message || "Failed to verify payment",
});
}
});
// Helper functions
async function updateOrderStatus(reference, status) {
// Update your database with the payment status
console.log(`Updating order ${reference} to status: ${status}`);
}
async function sendConfirmationEmail(email) {
// Send confirmation email to customer
console.log(`Sending confirmation email to: ${email}`);
}
app.listen(3000, () => {
console.log("Server running on port 3000");
});
Error Responses
Common error responses:
{
"status": false,
"message": "Transaction not found",
"data": null
}
Error | Description |
---|---|
Transaction not found | Reference doesn't exist |
Invalid reference | Reference format is invalid |
Unauthorized | Invalid API key |
Best Practices
1. Always Verify on Your Server
Never rely solely on client-side verification. Always verify payments on your server:
// ❌ Don't do this (client-side only)
if (response.status === "success") {
// Process order
}
// ✅ Do this (server-side verification)
const verification = await verifyPayment(reference);
if (verification.status === "successful") {
// Process order
}
2. Use Webhooks for Real-time Updates
Combine verification with webhooks for real-time payment updates:
// Webhook handler
app.post("/webhook", async (req, res) => {
const { event, data } = req.body;
if (event === "charge.success") {
// Payment successful - verify and process
const verification = await verifyPayment(data.reference);
if (verification.status === "successful") {
await processOrder(verification);
}
}
res.status(200).send("OK");
});
3. Handle Retries Gracefully
Some payment methods may take time to process:
const verifyWithRetry = async (reference, maxRetries = 3) => {
for (let i = 0; i < maxRetries; i++) {
const transaction = await verifyPayment(reference);
if (transaction.status === "successful") {
return transaction;
}
if (transaction.status === "failed") {
throw new Error("Payment failed");
}
// Wait before retrying
await new Promise((resolve) => setTimeout(resolve, 5000 * (i + 1)));
}
throw new Error("Payment verification timeout");
};
4. Store Transaction Data
Store important transaction data in your database:
const transactionData = {
reference: transaction.tx_ref,
amount: transaction.amount,
currency: transaction.currency,
status: transaction.status,
payment_type: transaction.payment_type,
customer_email: transaction.customer.email,
customer_name: transaction.customer.name,
created_at: transaction.created_at,
metadata: transaction.meta,
};
Next Steps
- Transaction Status - Learn about different transaction statuses
- Refund Payment - Learn how to refund payments
- Webhooks - Set up real-time payment notifications