1.0.2 • Published 4 months ago

payload-paystack-plugin v1.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
4 months ago

Payload Paystack Plugin

This plugin allows you to listen for Paystack webhooks and sync your Paystack resources to your Payload resources.

Installation

pnpm add payload-paystack-plugin

Configuration

Add the following to your payload.config.ts file:

import { payloadPaystackPlugin } from 'payload-paystack-plugin'

export default payload({
  plugins: [
    payloadPaystackPlugin({
      paystackSecretKey: process.env.PAYSTACK_SECRET_KEY || '',
      paystackWebhooksEndpointSecret: process.env.PAYSTACK_WEBHOOKS_ENDPOINT_SECRET || '',
      webhooks: {
        'charge.success': ({ event, payload }) => {
          payload.logger.info(event)
        },
      },
    }),
  ],
})

Usage

Webhooks

The plugin will automatically listen for webhooks from Paystack and handle them accordingly. You can also define custom webhook handlers by passing an object to the webhooks option in the plugin configuration.

For example, if you want to handle the charge.success event, you can add the following to your payload.config.ts file:

import { payloadPaystackPlugin } from 'payload-paystack-plugin'

export default payload({
  plugins: [
    payloadPaystackPlugin({
      paystackSecretKey: process.env.PAYSTACK_SECRET_KEY || '',
      paystackWebhooksEndpointSecret: process.env.PAYSTACK_WEBHOOKS_ENDPOINT_SECRET || '',
      webhooks: {
        'charge.success': ({ event, payload }) => {
          payload.logger.info(event)
        },
      },
    }),
  ],
})

Syncing Paystack resources to Payload resources

Work In Progress. The plugin will automatically sync Paystack resources to Payload resources.