{"id":25487195,"url":"https://github.com/orimdominic/paystack-nestjs","last_synced_at":"2025-10-30T15:49:54.838Z","repository":{"id":40477686,"uuid":"487855489","full_name":"orimdominic/paystack-nestjs","owner":"orimdominic","description":"Integrate Paystack APIs within your NestJs application and handle Paystack webhook events with ease","archived":false,"fork":false,"pushed_at":"2022-05-05T20:55:56.000Z","size":443,"stargazers_count":9,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-09T21:14:08.494Z","etag":null,"topics":["nestjs","paystack","webhooks"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/orimdominic.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-05-02T13:28:14.000Z","updated_at":"2025-02-25T19:01:31.000Z","dependencies_parsed_at":"2022-08-09T21:40:25.207Z","dependency_job_id":null,"html_url":"https://github.com/orimdominic/paystack-nestjs","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/orimdominic%2Fpaystack-nestjs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/orimdominic%2Fpaystack-nestjs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/orimdominic%2Fpaystack-nestjs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/orimdominic%2Fpaystack-nestjs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/orimdominic","download_url":"https://codeload.github.com/orimdominic/paystack-nestjs/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248111972,"owners_count":21049578,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["nestjs","paystack","webhooks"],"created_at":"2025-02-18T19:36:30.939Z","updated_at":"2025-10-30T15:49:49.817Z","avatar_url":"https://github.com/orimdominic.png","language":"TypeScript","readme":"# paystack-nestjs\n\nIntegrate Paystack APIs with your NestJS application. This library comes with support for handling Paystack webhook events with ease using decorators, for free 🤓\n\n## Features\n1. API client: An injectable Paystack client to interact with Paystack APIs.\n\n2. [Webhook event verification](https://paystack.com/docs/payments/webhooks/#verify-event-origin): Automatically verifies that calls to your webhook endpoint are from Paystack. Errors on calls from non-Paystack servers. It also returns a `200` by default for you.\n\n3. Handle specific events: Permits you to create providers that handle specific events using decorators. You can do away with implementing complex `switch` and `if...else` statements to determine what function/provider will handle an event.\n\n## Installation\n\n```bash\n# npm\nnpm install paystack-nestjs\n\n# yarn\nyarn add paystack-nestjs\n```\n\n## Usage\n\n### Paystack client\n\n1. Import the library into the module that handles Paystack payments (`PaymentModule` in this case)\n```ts\n// payment.module.ts\n\nimport { Module } from '@nestjs/common';\nimport { PaymentController } from './payment.controller';\nimport { PaystackModule } from 'paystack-nestjs';\n\n@Module({\n  imports: [\n    PaystackModule.forRoot(PaystackModule, {\n      secretKey: 'sk_4r3y0ur3a11ytry1n9t0f19ur3th1s0ut'\n    }),\n  ],\n  controllers: [PaymentController],\n})\nexport class PaymentModule {}\n```\nFor an asynchronous setup, use `PaystackModule.forRootAsync`\n\n2. Inject the client into a controller or provider via the constructor\n```ts\n// payment.controller.ts\n\nimport { Body, Controller } from '@nestjs/common';\nimport { InjectPaystackClient } from 'paystack-nestjs';\nimport { Paystack } from 'paystack-sdk';\n\n@Controller('paystack')\nexport class PaymentController {\n  constructor(\n    @InjectPaystackClient() private readonly paystackClient: Paystack,\n  ) {}\n\n  @Post('pay')\n  async pay(@Body() body) {\n    await this.paystackClient.charge.create({\n      email: body.email,\n      amount: '24000',\n      reference: body.trxref,\n    });\n  }\n}\n```\n\nThe full configuration of the second argument (`PaystackModuleConfig`) passed to `forRoot` method can be found in [interfaces.ts](/src/interfaces.ts)\n\n### Webhook\n\nTo enable webhook configuration, set the `enableWebhook` property in `PaystackModuleConfig` to true.\n\nThe module adds a `POST /paystack/webhook` route as the default webhook route. This means that if you have a controller method `m` that handles this route, and you have set up Paystack webhook on your developer console to forward events to `your.api/paystack/webhook`, method `m` will receive webhook events from Paystack.\n\nYou can modify this route using the `webhookConfig.controllerPrefix` option in `PaystackModuleConfig`.\n\n```ts\n// payment.controller.ts\n\nimport { Body, Controller } from '@nestjs/common';\n\n@Controller('paystack')\nexport class PaymentController {\n\n  @Post('webhook')\n  handlePaystackEvent(@Body() payload) {\n    console.log('verified payload from Paystack =\u003e', payload)\n  }\n}\n```\n\n### Handling Webhook Events with Decorated Methods\n\nThe module provides a `PaystackWebhookHandler` decorator that you can use to decorate methods that you want to use to handle specific events. You can set this up using the setup described below.\n\nLet's say you want to have a specific method of a provider handle the `charge.success` event. You inject the module into the co-ordinating module like so\n\n1. Configure and inject the module\n```ts\n// payment.module.ts\n\nimport { Module } from '@nestjs/common';\nimport { PaymentController } from './payment.controller';\nimport { PaystackModule, PaystackWebhookService } from 'paystack-nestjs';\nimport { ChargeSuccessService } from './charge-success.service';\n\n@Module({\n  imports: [\n    PaystackModule.forRoot(PaystackModule, {\n      secretKey: 'sk_4r3y0ur3a11ytry1n9t0f19ur3th1s0ut',\n      enableWebhook: true,\n    }),\n  ],\n  controllers: [PaymentController],\n  providers: [ChargeSuccessService, PaystackWebhookService],\n})\nexport class PaymentModule {}\n```\n\n2. Create the provider that holds the method that handles the `charge.success` event. Decorate the (`handleChargeSuccess`) with `PaystackWebhookHandler` and the name of the event that the method should handle (`charge.success`)\n\n```ts\n// charge-success.service.ts\n\nimport { Injectable } from '@nestjs/common';\nimport { PaystackWebhookHandler } from 'paystack-nestjs';\n\n@Injectable()\nexport class ChargeSuccessService {\n  @PaystackWebhookHandler('charge.success')\n  handleChargeSuccess(payload) {\n    console.log('from ChargeSuccessService');\n    console.log(`handling ${payload.event}`);\n  }\n}\n\n```\n\n3. Inject `PaystackWebhookService` into the controller and execute its `handleWebhookEvent`, passing the payload to it.\n\n```ts\n// payment.controller.ts\n\nimport { Body, Controller, Post } from '@nestjs/common';\nimport { PaystackWebhookService } from 'paystack-nestjs';\n\n@Controller('paystack')\nexport class PaymentController {\n  constructor(\n    private readonly webhookService: PaystackWebhookService,\n  ) {}\n\n  @Post('webhook')\n  handlePaystackEvent(@Body() payload) {\n    this.webhookService.handleWebhookEvent(payload)\n  }\n}\n```\n\nWhenever there is a `charge.success` event, it will be handled by the `handleChargeSuccess` method of `ChargeSuccessService`. You can have more than one method handling the same event.\n\n## Helpful links\n- [Paystack webhooks](https://paystack.com/docs/payments/webhooks)\n- [Testing webhooks locally with the Paystack CLI](https://paystack.com/blog/product/cli#how-to-get-started-with-the-paystack-cli)\n\n## Contributing\nSee a need, fill a need! PRs and issues are welcome!\n\n- Inpired by [@golevelup-nestjs/stripe](https://github.com/golevelup/packages/stripe)\n- Built on [@en1tan/paystack-node](https://github.com/en1tan/paystack-node)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Forimdominic%2Fpaystack-nestjs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Forimdominic%2Fpaystack-nestjs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Forimdominic%2Fpaystack-nestjs/lists"}