Back to Plugins

Paystack Payment Plugin v2

Robust Paystack payment integration for Medusa v2 with multi-currency support, webhook verification, and complete payment lifecycle management


Overview

The @alexasomba/medusa-paystack-plugin-v2 is a robust payment integration plugin for Medusa v2 that enables seamless payment processing using Paystack’s infrastructure. This plugin provides complete payment flow management with support for the new payment session lifecycle in Medusa v2.8.6+.

Key Features

System Requirements

Before installing the plugin, ensure your system meets the following requirements:

Installation

Step 1: Install Package

# Using npm
npm install @alexasomba/medusa-paystack-plugin-v2

Step 2: Environment Configuration

Add to your .env file:

PAYSTACK_SECRET_KEY=sk_test_your_secret_key_here
PAYSTACK_PUBLIC_KEY=pk_test_your_public_key_here
PAYSTACK_WEBHOOK_SECRET=your_webhook_secret_here

Step 3: Medusa Configuration

Update medusa-config.ts:

modules: [
  {
    resolve: "@medusajs/payment",
    options: {
      providers: [
        {
          resolve: "@alexasomba/medusa-paystack-plugin-v2",
          id: "paystack",
          options: {
            secret_key: process.env.PAYSTACK_SECRET_KEY,
            public_key: process.env.PAYSTACK_PUBLIC_KEY,
            webhook_secret: process.env.PAYSTACK_WEBHOOK_SECRET,
          },
        },
      ],
    },
  },
]

Step 4: Build and Start

npm run build
npm run dev

Configuration Details

VariableDescriptionRequiredExample
PAYSTACK_SECRET_KEYPaystack secret keyYessk_test_...
PAYSTACK_PUBLIC_KEYPaystack public keyYespk_test_...
PAYSTACK_WEBHOOK_SECRETWebhook verification secretRecommendedwhsec_...

Frontend Integration

Required Dependencies

Install Paystack’s inline JavaScript library:

npm install @paystack/inline-js

Payment Component

The plugin works with Paystack’s popup interface. Implement payment handling in your checkout flow by:

  1. Finding the Paystack session in the cart’s payment collection
  2. Using a session hook to monitor readiness
  3. Calling the PaystackPayment component when ready
  4. Completing the cart upon successful payment

Session Hook

Create a custom usePaystackSession hook to manage payment session state, including:

Integration Pattern

// Example integration in checkout
const session = cart.payment_collection?.payment_sessions?.find(
  (s) => s.provider_id === "paystack"
)

// Use session hook
const { isReady, updateSession } = usePaystackSession(session)

// Render payment component when ready
{isReady && (
  <PaystackPayment
    session={session}
    onSuccess={handleSuccess}
    onFailure={handleFailure}
  />
)}

Supported Currencies

Core Dependencies

Payment Operations

Initialize Payment

Creates a payment session with Paystack and generates a payment reference.

Authorize Payment

Verifies customer payment through Paystack’s secure popup.

Capture Payment

Captures authorized funds to complete the transaction.

Refund Payment

Processes refunds for completed transactions.

Webhook Integration

Configure webhooks in your Paystack dashboard to receive real-time payment status updates. The webhook secret ensures secure verification of webhook events.


Explore More Medusa Plugins

Find more powerful plugins and integrations to enhance your Medusa store. Browse our collection of community-driven solutions.

Free & Open Source
Community Driven
Easy Integration