Provider Integration Guide
Version: 1.0
Date: December 2024
Status: Draft
Table of Contents
- Overview
- Paystack Integration
- Stripe Integration
- Flutterwave Integration
- Common Patterns
- Error Mapping
1. Overview
1.1 Integration Model
Aggregator Model:
- Customers provide their own provider API keys
- We store keys encrypted (AWS KMS)
- We call provider APIs using customer keys
- Money flows directly to customer's provider account
1.2 Adapter Pattern
All providers implement the IPaymentProvider interface:
interface IPaymentProvider {
createPayment(request: PaymentRequest): Promise<PaymentResponse>;
getPaymentStatus(paymentId: string): Promise<PaymentStatus>;
refundPayment(request: RefundRequest): Promise<RefundResponse>;
verifyWebhookSignature(payload: string, signature: string): boolean;
parseWebhookEvent(payload: any): WebhookEvent;
healthCheck(): Promise<boolean>;
}
1.3 Provider Selection
Priority-Based (V1):
- Providers have priority (lower number = higher priority)
- Select provider based on priority and currency support
- Fallback to next provider on failure (if enabled)
2. Paystack Integration
2.1 Overview
Base URL:
- Test:
https://api.paystack.co - Live:
https://api.paystack.co(same URL, different keys)
Authentication:
- Header:
Authorization: Bearer {secret_key} - Secret key format:
sk_test_xxxorsk_live_xxx
Supported Currencies:
- NGN (Nigeria)
- GHS (Ghana)
- ZAR (South Africa)
- USD (Limited)
Supported Countries:
- NG (Nigeria)
- GH (Ghana)
- ZA (South Africa)
Supported Payment Methods:
- Card payments
- Bank transfers
- USSD
- Bank account (direct debit)
2.2 API Endpoints
Initialize Transaction
Endpoint: POST /transaction/initialize
Request:
{
"email": "customer@example.com",
"amount": 10000,
"currency": "NGN",
"reference": "unique_reference_123",
"callback_url": "https://merchant.com/callback",
"metadata": {
"custom_fields": [
{
"display_name": "Customer Name",
"variable_name": "customer_name",
"value": "John Doe"
}
]
},
"channels": ["card", "bank"]
}
Response:
{
"status": true,
"message": "Authorization URL created",
"data": {
"authorization_url": "https://checkout.paystack.com/xyz",
"access_code": "access_code_123",
"reference": "unique_reference_123"
}
}
Our Mapping:
reference→providerPaymentIdauthorization_url→authorizationUrlaccess_code→ stored in metadata
Verify Transaction
Endpoint: GET /transaction/verify/{reference}
Request: No body, reference in URL
Response:
{
"status": true,
"message": "Verification successful",
"data": {
"id": 1234567890,
"domain": "test",
"status": "success",
"reference": "unique_reference_123",
"amount": 10000,
"currency": "NGN",
"customer": {
"id": 12345,
"email": "customer@example.com"
},
"authorization": {
"authorization_code": "AUTH_xxx",
"bin": "408408",
"last4": "4081",
"exp_month": "12",
"exp_year": "2025",
"card_type": "visa"
},
"paid_at": "2024-12-20T10:30:10.000Z"
}
}
Status Mapping:
success→completedfailed→failedpending→pendingabandoned→cancelled
Refund Transaction
Endpoint: POST /refund
Request:
{
"transaction": "unique_reference_123",
"amount": 5000
}
Response:
{
"status": true,
"message": "Refund processed",
"data": {
"transaction": {
"id": 1234567890,
"transaction_date": "2024-12-20T10:30:10.000Z",
"customer_note": null,
"merchant_note": "Refund for order #123"
},
"deducted_amount": 5000,
"status": "processed"
}
}
2.3 Webhook Handling
Webhook Endpoint
URL: POST /webhooks/paystack
Signature Header: x-paystack-signature
Signature Verification:
function verifyPaystackSignature(
payload: string,
signature: string,
secret: string,
): boolean {
const hash = crypto
.createHmac('sha512', secret)
.update(payload)
.digest('hex');
return hash === signature;
}
Important: Must use raw body (string) for signature verification, not parsed JSON.
Webhook Payload
{
"event": "charge.success",
"data": {
"id": 1234567890,
"domain": "test",
"status": "success",
"reference": "unique_reference_123",
"amount": 10000,
"currency": "NGN",
"customer": {
"id": 12345,
"email": "customer@example.com"
},
"authorization": {
"authorization_code": "AUTH_xxx",
"bin": "408408",
"last4": "4081"
},
"paid_at": "2024-12-20T10:30:10.000Z",
"created_at": "2024-12-20T10:30:00.000Z"
}
}
Event Types:
charge.success→payment.completedcharge.failed→payment.failedrefund.processed→refund.completed
Webhook Retry Policy
- Max Attempts: 10
- Schedule: Exponential backoff over 2 hours
- Timeout: 5 seconds per attempt
2.4 Error Handling
Common Errors:
| Paystack Error | Our Error Code | HTTP Status |
|---|---|---|
Insufficient funds | insufficient_funds | 400 |
Invalid card | card_declined | 400 |
Card expired | card_declined | 400 |
Invalid amount | invalid_amount | 400 |
Invalid currency | invalid_currency | 400 |
Invalid API key | provider_invalid_credentials | 401 |
Rate limit exceeded | provider_rate_limit | 429 |
Service unavailable | provider_unavailable | 503 |
2.5 Rate Limits
- Test Mode: 1,000 requests/hour
- Live Mode: 3,000 requests/hour
- Webhook Retries: 10 attempts over 2 hours
2.6 Provider-Specific Quirks
-
Test Mode Limits:
- Max transaction: ₦50,000
- Limited test card numbers
-
Bank Transfers:
- Can take 24h+ to confirm
- Requires webhook for final status
-
USSD Payments:
- Timeout after 5 minutes
- Customer must complete on phone
-
Reference Format:
- Must be unique per transaction
- Use our payment ID as reference
-
Webhook Timing:
- Webhooks may arrive before API response
- Always verify transaction status
3. Stripe Integration
3.1 Overview
Base URL:
- Test:
https://api.stripe.com/v1 - Live:
https://api.stripe.com/v1(same URL, different keys)
Authentication:
- Header:
Authorization: Bearer {secret_key} - Secret key format:
sk_test_xxxorsk_live_xxx
Supported Currencies:
- 135+ currencies including NGN, USD, EUR, GBP, etc.
Supported Countries:
- Global (with country-specific payment methods)
Supported Payment Methods:
- Card payments
- Bank transfers (ACH, SEPA)
- Digital wallets (Apple Pay, Google Pay)
3.2 API Endpoints
Create Payment Intent
Endpoint: POST /payment_intents
Request:
{
"amount": 10000,
"currency": "ngn",
"payment_method_types": ["card"],
"metadata": {
"order_id": "order_123",
"customer_email": "customer@example.com"
},
"description": "Order #12345"
}
Response:
{
"id": "pi_1234567890",
"object": "payment_intent",
"amount": 10000,
"currency": "ngn",
"status": "requires_payment_method",
"client_secret": "pi_1234567890_secret_xxx"
}
Our Mapping:
id→providerPaymentIdclient_secret→ stored for frontend SDKstatus→ mapped to our status
Retrieve Payment Intent
Endpoint: GET /payment_intents/{id}
Response:
{
"id": "pi_1234567890",
"object": "payment_intent",
"amount": 10000,
"currency": "ngn",
"status": "succeeded",
"payment_method": "pm_1234567890",
"charges": {
"data": [
{
"id": "ch_1234567890",
"status": "succeeded",
"paid": true
}
]
},
"created": 1703062800
}
Status Mapping:
requires_payment_method→pendingrequires_confirmation→requires_actionrequires_action→requires_actionprocessing→processingsucceeded→completedrequires_capture→processingcanceled→cancelled