To load test your payment endpoint responsibly: mock the Paystack API call at your application boundary (return a fake authorization_url without calling Paystack), then run your load test against your server. This measures your server's capacity to handle concurrent checkouts without abusing the Paystack API. For webhook handler load testing, generate valid HMAC-signed webhook payloads and send them at high concurrency to your webhook endpoint.
Your payment flow has two external dependencies: the Paystack API and your database. Load tests should measure your system, not stress Paystack's infrastructure.
For checkout initiation load tests:
For webhook handler load tests:
// load-tests/checkout.js
// Run: k6 run load-tests/checkout.js
import http from 'k6/http';
import { check, sleep } from 'k6';
import { Rate } from 'k6/metrics';
var errorRate = new Rate('errors');
export var options = {
stages: [
{ duration: '30s', target: 10 }, // Ramp up to 10 concurrent users
{ duration: '60s', target: 50 }, // Ramp up to 50 concurrent users
{ duration: '30s', target: 0 }, // Ramp down
],
thresholds: {
http_req_duration: ['p(99)<500'], // 99% of requests under 500ms
errors: ['rate<0.01'], // Less than 1% error rate
},
};
export default function () {
var payload = JSON.stringify({
email: 'loadtest+' + __VU + '@example.com',
amount: 10000,
order_id: Math.floor(Math.random() * 1000000),
});
var res = http.post('https://staging.yourapp.com/api/checkout', payload, {
headers: {
'Content-Type': 'application/json',
// Include auth if needed
},
});
check(res, {
'status is 200': (r) => r.status === 200,
'has authorization_url': (r) => r.json('authorization_url') !== undefined,
});
errorRate.add(res.status !== 200);
sleep(1);
}
Ensure your staging checkout endpoint is configured to mock the Paystack API call during load tests (use PAYSTACK_MOCK=true environment variable).
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 testing 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