Prerequisites
- Node.js 18+
- Express.js 4.x or 5.x
- A ZendFi account with test API keys
Project Setup
1
Create the project
2
Configure TypeScript
tsconfig.json
3
Set up environment variables
.env
4
Create the ZendFi client
src/lib/zendfi.ts
Application Structure
Entry Point
src/index.ts
Payment Routes
src/routes/payments.ts
Webhook Handler
src/routes/webhooks.ts
Error Handler
src/middleware/error-handler.ts
Idempotency
For payment creation, pass an idempotency key to prevent duplicate charges:Idempotency-Key in the request header. If the same key is sent again within 24 hours, ZendFi returns the original response without creating a new payment.
Testing
1
Start the server
2
Start webhook forwarding
3
Create a payment
4
Check the response
Production Checklist
Before going live, verify:- Switch to live API key (
zfi_live_) - Webhook secret is set in production environment
- Webhook endpoint is registered in ZendFi Dashboard
- Error handling covers all SDK error types
- Idempotency keys are used for payment creation
- CORS is restricted to your frontend domain
- Rate limiting is configured on your Express server
- HTTPS is enabled (required for webhook delivery)