mockpay
v0.2.0
Published
Local mock Paystack and Flutterwave servers for offline testing
Downloads
192
Readme
mockpay
Local mock Paystack and Flutterwave servers for offline/local testing. Use this in development to replace live gateway URLs and to simulate payment outcomes, errors, and webhooks.
Default base URLs:
- Paystack-like:
http://localhost:4010 - Flutterwave-like:
http://localhost:4020
Hosted checkout (served by mockpay):
- http://localhost:4010/checkout
- http://localhost:4020/checkout
Quick Start
npm i -g mockpay
mockpay startServers:
- Paystack: http://localhost:4010
- Flutterwave: http://localhost:4020
Integration Goal
Replace live gateway URLs in development:
- Instead of
https://api.paystack.co, usehttp://localhost:4010 - Instead of
https://api.flutterwave.com/v3, usehttp://localhost:4020
Typical flow:
- Initialize payment from your backend.
- Open the hosted checkout link in the browser.
- Complete payment in the mock checkout UI.
- Verify from your backend.
CLI Commands
mockpay start
mockpay stop
mockpay status
mockpay pay success|fail|cancel
mockpay error 500|timeout|network
mockpay webhook resend
mockpay webhook config --delay 1000 --retry 2 --retry-delay 2000 --duplicate --drop
mockpay reset
mockpay logsNotes:
mockpay pay ...applies to the next payment only, then resets tosuccess.mockpay error ...applies to the next API request only, then resets tonone.mockpay logsstreams live logs over SSE from the Paystack server.
Environment
Copy .env.example to .env and adjust if needed.
Key settings:
MOCKPAY_PAYSTACK_PORTMOCKPAY_FLUTTERWAVE_PORTMOCKPAY_FRONTEND_URLMOCKPAY_DATA_DIRMOCKPAY_DEFAULT_WEBHOOK_URL
Webhook controls:
MOCKPAY_WEBHOOK_DELAY_MSMOCKPAY_WEBHOOK_RETRY_COUNTMOCKPAY_WEBHOOK_RETRY_DELAY_MSMOCKPAY_WEBHOOK_DUPLICATEMOCKPAY_WEBHOOK_DROP
API Coverage
Paystack
POST /transaction/initializeGET /transaction/verify/:referencePOST /transaction/verify/:referencePOST /transferGET /banks
Flutterwave
POST /paymentsGET /transactions/verify_by_reference?tx_ref=...GET /transactions/:id/verifyPOST /transfers
Payment Flow
Paystack-style flow
POST /transaction/initialize- Open
data.authorization_url - Complete payment on checkout (
success/failed/cancelled) - Verify on your backend with
/transaction/verify/:reference
Flutterwave-style flow
POST /payments- Open
data.link - Complete payment on checkout (
success/failed/cancelled) - Verify on your backend using:
/transactions/verify_by_reference?tx_ref=...or/transactions/:id/verify
Example Requests
Paystack initialize
curl -X POST http://localhost:4010/transaction/initialize \
-H "Content-Type: application/json" \
-d '{
"amount": 5000,
"currency": "NGN",
"email": "[email protected]",
"name": "Ada Lovelace",
"callback_url": "http://localhost:3000/paystack/callback"
}'Paystack verify
curl http://localhost:4010/transaction/verify/PSK_1234567890_abcdefFlutterwave payments
curl -X POST http://localhost:4020/payments \
-H "Content-Type: application/json" \
-d '{
"amount": 5000,
"currency": "NGN",
"customer": {
"email": "[email protected]",
"name": "Ada Lovelace"
},
"redirect_url": "http://localhost:3000/flutterwave/callback"
}'Flutterwave verify by reference
curl "http://localhost:4020/transactions/verify_by_reference?tx_ref=FLW_1234567890_abcdef"Flutterwave verify by id
curl "http://localhost:4020/transactions/<transaction_id>/verify"Error Simulation
Simulate one request failure:
mockpay error 500
mockpay error timeout
mockpay error networkNotes:
networkwill drop the socket without a response.timeoutwaits 15 seconds before responding with504.
Webhooks
Set a default webhook URL:
MOCKPAY_DEFAULT_WEBHOOK_URL=http://localhost:3000/webhooks/mockpayConfigure behavior at runtime:
mockpay webhook config --delay 1000 --retry 2 --retry-delay 2000 --duplicate --dropResend last webhook:
mockpay webhook resendDevelopment
npm install
npm run devBuilding the Hosted Checkout
The checkout UI is in template/ and should be built before publishing:
npm --prefix template install
npm --prefix template run buildNotes
- ChronoDB is used for file-based persistence. Data is stored under
MOCKPAY_DATA_DIR(default.mockpay/data). - Hosted checkout URLs include transaction details (
ref,amount,currency,email,name, provider).
