Create a Paystack Transaction Split group with the restaurant subaccount (food price share) and rider subaccount (delivery fee share). Pass the split_code when initializing a customer order. Your platform keeps the commission residual. On charge.success, mark the order as paid and notify both restaurant and rider. Rider payouts can be real-time via the split or batched daily via transfers.
// Create a Transaction Split group for an order
async function createOrderSplit(restaurantSubaccount, riderSubaccount, orderTotal, deliveryFee) {
var restaurantAmount = orderTotal - deliveryFee;
var platformCommissionRate = 0.08; // 8%
var restaurantShare = restaurantAmount * (1 - platformCommissionRate);
var response = await fetch('https://api.paystack.co/split', {
method: 'POST',
headers: { Authorization: 'Bearer ' + process.env.PAYSTACK_SECRET_KEY, 'Content-Type': 'application/json' },
body: JSON.stringify({
name: 'Order split',
type: 'flat', // flat kobo amounts
currency: 'NGN',
subaccounts: [
{ subaccount: restaurantSubaccount, share: Math.round(restaurantShare * 100) },
{ subaccount: riderSubaccount, share: Math.round(deliveryFee * 100) },
],
bearer_type: 'account',
}),
});
var data = await response.json();
return data.data.split_code; // e.g., SPL_xxxxxx
}
// Initialize order payment with the split
app.post('/api/orders', async (req, res) => {
var { restaurantId, riderId, items, email } = req.body;
var restaurant = await db.restaurants.findById(restaurantId);
var rider = await db.riders.findById(riderId);
var orderTotal = items.reduce((s, i) => s + i.price * i.qty, 0);
var deliveryFee = 500; // NGN 500
var splitCode = await createOrderSplit(
restaurant.subaccount_code,
rider.subaccount_code,
orderTotal,
deliveryFee
);
var response = await fetch('https://api.paystack.co/transaction/initialize', {
method: 'POST',
headers: { Authorization: 'Bearer ' + process.env.PAYSTACK_SECRET_KEY, 'Content-Type': 'application/json' },
body: JSON.stringify({
email,
amount: Math.round((orderTotal + deliveryFee) * 100),
split_code: splitCode,
metadata: { order_id: 'ord_' + Date.now(), restaurant_id: restaurantId },
}),
});
var data = await response.json();
res.json({ authorization_url: data.data.authorization_url });
});
if (event.event === 'charge.success') {
var orderId = event.data.metadata?.order_id;
if (!orderId) return;
await db.orders.update({ status: 'paid', paid_at: new Date() }, { where: { reference: event.data.reference } });
// Notify restaurant to start preparing
await notifyRestaurant(orderId);
// Notify rider to go pick up
await notifyRider(orderId);
}
Get weekly developer tips
Join 25,000+ developers. Practical guides, job tips, and new content — straight to your inbox.
No spam. Unsubscribe anytime.
This guide is part of the Paystack split payments guide.
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