JavaScript SDK for Payfake, African payment simulator
# payfake-js
Official JavaScript SDK for Payfake — a Paystack-compatible payment
simulator for African developers.
```bash
npm install payfake-js
```
---
## Quick Start
```js
import { createClient } from "payfake-js"
const client = createClient({
secretKey: "sk_test_xxx",
baseURL: "
api.payfake.co", // or "
localhost" for self-hosted
})
```
Change one env var to switch between Payfake and real Paystack:
```bash
# Development
PAYSTACK_BASE_URL=
api.payfake.co
PAYSTACK_SECRET_KEY=sk_test_xxx
# Production
PAYSTACK_BASE_URL=
api.paystack.co
PAYSTACK_SECRET_KEY=sk_live_xxx
```
---
## Full Card Flow
```js
// Initialize
const tx = await client.transaction.initialize({
email: "customer@example.com",
amount: 10000,
currency: "GHS",
})
// Charge — local Verve card
const step1 = await client.charge.card({
email: "customer@example.com",
accessCode: tx.access_code,
card: {
number: "5061000000000000",
cvv: "123",
expiryMonth: "12",
expiryYear: "2026",
},
})
// step1.status === "send_pin"
// Submit PIN
const step2 = await client.charge.submitPIN({ reference: tx.reference, pin: "1234" })
// step2.status === "send_otp"
// Get OTP from logs (no real phone needed)
const logs = await client.control.getOTPLogs(token, tx.reference)
const otp = logs[0]?.otp_code
// Submit OTP
const step3 = await client.charge.submitOTP({ reference: tx.reference, otp })
// step3.status === "success"
// Verify
const verified = await client.transaction.verify(tx.reference)
// verified.status === "success"
// verified.gateway_response === "Approved"
```
---
## Charge Flow Status Reference
| Status | Meaning | Next Call |
|--------|---------|-----------|
| `send_pin` | Enter card PIN | `charge.submitPIN` |
| `send_otp` | Enter OTP | `charge.submitOTP` |
| `send_birthday` | Enter date of birth | `charge.submitBirthday` |
| `send_address` | Enter billing address | `charge.submitAddress` |
| `open_url` | Complete 3DS — open `url` fiel …