Build a car hire booking system using Paystack's two-step charge: first, authorize a card to hold the damage deposit (the customer sees a pending amount but is not yet charged); on return, capture the exact amount due. Use the Paystack Charge endpoint with authorization_code for returning customers, or a one-time card authorization flow for new customers.
// On vehicle return — charge damage deposit or excess fees using saved auth code
async function processReturn(rentalId, damageAssessment) {
var rental = await db.rentals.findById(rentalId);
var depositAmount = rental.deposit_amount;
if (damageAssessment.total > 0) {
// Charge damage using saved authorization code (no card re-entry needed)
var chargeAmount = Math.min(damageAssessment.total, depositAmount);
var res = await fetch('https://api.paystack.co/charge/authorization', {
method: 'POST',
headers: { Authorization: 'Bearer ' + process.env.PAYSTACK_SECRET_KEY, 'Content-Type': 'application/json' },
body: JSON.stringify({
email: rental.customer_email,
amount: chargeAmount,
authorization_code: rental.authorization_code,
metadata: { rental_id: rentalId, purpose: 'damage_charge', description: damageAssessment.notes },
}),
});
var data = await res.json();
await db.rentals.update(rentalId, {
status: 'returned_with_damage',
damage_charge: chargeAmount,
paystack_damage_ref: data.data.reference,
});
} else {
// No damage — just close the rental
await db.rentals.update(rentalId, { status: 'returned_clean' });
}
await db.vehicles.update(rental.vehicle_id, { status: 'available' });
}
The charge/authorization endpoint charges the card without the customer needing to re-enter their details. This is what makes car hire feasible on Paystack — you charge the rental up front and charge damages on return without a second checkout flow.
Get weekly developer tips
Join 25,000+ developers. Practical guides, job tips, and new content — straight to your inbox.
No spam. Unsubscribe anytime.
See build a hotel booking and deposit system for the deposit-and-balance pattern in accommodation bookings.
KES 2,999
The definitive guide to building payment systems with Paystack — from your first transaction to production-grade payment infrastructure across Africa. 9 modules, 47 lessons. Free preview available.
Start Paystack Course