Overview
This guide walks you through creating a complete payment flow: initializing a transaction, redirecting the customer to pay, and verifying the payment.This guide uses test mode. Remember to switch to live keys when you’re ready to accept real payments.
Prerequisites
Before starting, make sure you have:- Installed the SDK (see Installation)
- Your Paystack test secret key from your dashboard
Step 1: Initialize the SDK
First, import and initialize the Paystack SDK with your secret key:index.ts
Step 2: Initialize a Transaction
To accept a payment, first initialize a transaction. This creates a payment session and returns an authorization URL:initialize.ts
Understanding the Response
The initialize method returns:authorization_url- Redirect your customer here to complete paymentaccess_code- Alternative payment access codereference- Unique transaction reference (auto-generated if not provided)
Custom Transaction Options
You can customize the transaction with additional parameters:advanced-initialize.ts
Step 3: Verify the Transaction
After the customer completes payment, verify the transaction using the reference:verify.ts
Always verify transactions on your server, not in client-side code. Never trust payment status from the client.
Complete Example
Here’s a complete example combining initialization and verification:Expected Output
When you initialize a transaction, you’ll get a response like:Error Handling
The SDK provides structured error handling:error-handling.ts
Testing Your Integration
1
Use test credentials
Always use test keys (
sk_test_...) during development.2
Test with Paystack test cards
Paystack provides test card numbers:
- Success:
4084 0840 8408 4081(CVV: any 3 digits) - Insufficient funds:
5060 6666 6666 6666
3
Verify on your server
Never rely on client-side verification alone.
4
Test error scenarios
Test failed payments, abandoned transactions, and network errors.
Next Steps
Now that you’ve completed your first integration, explore more features:Transactions API
Learn about all transaction operations
Webhooks
Handle real-time payment notifications
Transfers
Send money to customers and vendors
Virtual Accounts
Create dedicated virtual accounts
Common Patterns
Generating Custom References
Handling Webhook Verification
Retry Logic for Verification
Getting Help
API Reference
Detailed documentation for all methods
GitHub Issues
Report bugs or request features
Examples
Browse example projects
Paystack Docs
Official Paystack API documentation

