Skip to main content

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:

Step 1: Initialize the SDK

First, import and initialize the Paystack SDK with your secret key:
index.ts
The SDK automatically validates your secret key format. It must start with sk_test_ or sk_live_.

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
Amounts in Paystack are specified in the smallest currency unit (kobo for NGN, cents for USD). To charge ₦500.00, pass 50000.

Understanding the Response

The initialize method returns:
  • authorization_url - Redirect your customer here to complete payment
  • access_code - Alternative payment access code
  • reference - 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:
After verification, a successful payment returns:

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