{"_id":"@asanovr/nestjs-stripe","name":"@asanovr/nestjs-stripe","dist-tags":{"latest":"0.7.0"},"versions":{"0.7.0":{"name":"@asanovr/nestjs-stripe","version":"0.7.0","description":"Badass utilities for integrating stripe and NestJS","author":{"name":"Jesse Carter","email":"jesse.r.carter@gmail.com"},"homepage":"https://github.com/golevelup/nestjs#readme","license":"MIT","keywords":["NestJS","typescript","webhook","stripe"],"main":"lib/index.js","typings":"lib/index.d.ts","directories":{"lib":"lib","test":"__tests__"},"repository":{"type":"git","url":"git+https://github.com/asanovr/nestjs.git"},"scripts":{"build":"tsc --build tsconfig.build.json","build:watch":"tsc --build tsconfig.build.json --watch","test":"jest"},"bugs":{"url":"https://github.com/golevelup/nestjs/issues"},"publishConfig":{"access":"public"},"dependencies":{"@golevelup/nestjs-common":"^2.0.1","@golevelup/nestjs-discovery":"^4.0.1","@golevelup/nestjs-modules":"^0.7.1"},"devDependencies":{"stripe":"^11.2.0"},"peerDependencies":{"stripe":"^11.12.0"},"jest":{"moduleFileExtensions":["js","json","ts"],"rootDir":"src","testRegex":".spec.ts$","transform":{"^.+\\.ts$":"ts-jest"},"coverageDirectory":"../coverage","testEnvironment":"node"},"gitHead":"83abc8861cf5f8df94b8cd39964f41ce728aff6d","_id":"@asanovr/nestjs-stripe@0.7.0","_nodeVersion":"16.15.1","_npmVersion":"lerna/3.22.1/node@v16.15.1+arm64 (darwin)","dist":{"integrity":"sha512-K76GjFiMg06fh9gZyWE3ABQjo2gALLCFfIL/sW9TlaW+j9m8ftUYIrZsr6GeVuxjOSOFz4FS2V7s2EZj4Tl8PQ==","shasum":"deec4253ce1d1590e6b3f4c67ecc888f5b193753","tarball":"https://registry.npmjs.org/@asanovr/nestjs-stripe/-/nestjs-stripe-0.7.0.tgz","fileCount":36,"unpackedSize":53661,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIE8NcR+kL1HNudQnzDI6yfUESUrqzC9WLbLzwRA2GmfvAiEAzINMbFNGZ1brxIozjkt6WdCrFggwKdMariD6JqiGqyc="}]},"_npmUser":{"name":"asanovr","email":"bioforge91@gmail.com"},"maintainers":[{"name":"asanovr","email":"bioforge91@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/nestjs-stripe_0.7.0_1693545916507_0.2988291034970396"},"_hasShrinkwrap":false}},"time":{"created":"2023-09-01T05:25:16.398Z","0.7.0":"2023-09-01T05:25:16.700Z","modified":"2023-09-01T05:25:16.996Z"},"maintainers":[{"name":"asanovr","email":"bioforge91@gmail.com"}],"description":"Badass utilities for integrating stripe and NestJS","homepage":"https://github.com/golevelup/nestjs#readme","keywords":["NestJS","typescript","webhook","stripe"],"repository":{"type":"git","url":"git+https://github.com/asanovr/nestjs.git"},"author":{"name":"Jesse Carter","email":"jesse.r.carter@gmail.com"},"bugs":{"url":"https://github.com/golevelup/nestjs/issues"},"license":"MIT","readme":"# @golevelup/nestjs-stripe\n\nInteracting with the Stripe API or consuming Stripe webhooks in your NestJS applications is now easy as pie 🥧\n\n<p align=\"center\">\n<a href=\"https://www.npmjs.com/package/@golevelup/nestjs-stripe\"><img src=\"https://img.shields.io/npm/v/@golevelup/nestjs-stripe.svg?style=flat\" alt=\"version\" /></a>\n<a href=\"https://www.npmjs.com/package/@golevelup/nestjs-stripe\"><img alt=\"downloads\" src=\"https://img.shields.io/npm/dt/@golevelup/nestjs-stripe.svg?style=flat\"></a>\n<img alt=\"license\" src=\"https://img.shields.io/npm/l/@golevelup/nestjs-stripe.svg\">\n</p>\n\n## Features\n\n- 💉 Injectable Stripe client for interacting with the Stripe API in Controllers and Providers\n\n- 🎉 Optionally exposes an API endpoint from your NestJS application at to be used for webhook event processing from Stripe. Defaults to `/stripe/webhook/` but can be easily configured\n\n- 🔒 Automatically validates that the event payload was actually sent from Stripe using the configured webhook signing secret\n\n- 🕵️ Discovers providers from your application decorated with `StripeWebhookHandler` and routes incoming events to them\n\n- 🧭 Route events to logical services easily simply by providing the Stripe webhook event type\n\n## Getting Started\n\n### Install\n\n#### NPM\n\n- Install the package along with the stripe peer dependency\n\n  `npm install --save @golevelup/nestjs-stripe stripe`\n\n#### YARN\n\n- Install the package using yarn with the stripe peer dependency\n\n  `yarn add @golevelup/nestjs-stripe stripe`\n\n### Import\n\nImport and add `StripeModule` to the `imports` section of the consuming module (most likely `AppModule`). Your Stripe API key is required, and you can optionally include a webhook configuration if you plan on consuming Stripe webhook events inside your app.  \nStripe secrets you can get from your Dashboard’s [Webhooks settings](https://dashboard.stripe.com/webhooks). Select an endpoint that you want to obtain the secret for, then click the Click to reveal button.\n\n`account` - The webhook secret registered in the Stripe Dashboard for events on your accounts  \n`connect` - The webhook secret registered in the Stripe Dashboard for events on Connected accounts\n\n```typescript\nimport { StripeModule } from '@golevelup/nestjs-stripe';\n\n@Module({\n  imports: [\n    StripeModule.forRoot(StripeModule, {\n      apiKey: '123',\n      webhookConfig: {\n        stripeSecrets: {\n          account: 'abc',\n          connect: 'cba',\n        },\n      },\n    }),\n  ],\n})\nexport class AppModule {\n  // ...\n}\n```\n\n### Configuration\n\nThe Stripe Module supports both the `forRoot` and `forRootAsync` patterns for configuration, so you can easily retrieve the necessary config values from a `ConfigService` or other provider.\n\n### Injectable Providers\n\nThe module exposes two injectable providers with accompanying decorators for your convenience. These can be provided to the constructors of controllers and other providers:\n\n```typescript\n // injects the instantiated Stripe client which can be used to make API calls\n@InjectStripeClient() stripeClient: Stripe\n```\n\n```typescript\n// injects the module configuration\n@InjectStripeModuleConfig() config: StripeModuleConfig\n```\n\n## Consuming Webhooks\n\n### Included API Endpoint\n\nThis module will automatically add a new API endpoint to your NestJS application for processing webhooks. By default, the route for this endpoint will be `stripe/webhook` but you can modify this to use a different prefix using the `controllerPrefix` property of the `webhookConfig` when importing the module.\n\n### ⚠️ Configure Raw Request Body Handling\n\nIf you would like your NestJS application to be able to process incoming webhooks, it is essential that Stripe has access to the raw request payload.\n\nBy default, NestJS is configured to use JSON body parsing middleware which will transform the request before it can be validated by the Stripe library.\n\nYou can choose to [pass the raw request body](https://docs.nestjs.com/faq/raw-body#use-with-express) into the context of each Request,\nwhich will not cause side effects to any of your existing project's architectural design and other APIs.\n\n```typescript\n// main.ts\nconst app = await NestFactory.create<NestExpressApplication>(AppModule, {\n  rawBody: true,\n});\n```\n\nYou can then manually set up `bodyProperty` to use rawBody:\n\n```typescript\nStripeModule.forRoot(StripeModule, {\n  apiKey: '',\n  webhookConfig: {\n    stripeWebhookSecret: '',\n    requestBodyProperty: 'rawBody', // <-- Set to 'rawBody'\n  },\n});\n```\n\n### Decorate Methods For Processing Webhook Events\n\nExposing provider/service methods to be used for processing Stripe events is easy! Simply use the provided decorator and indicate the event type that the handler should receive.\n\n[Review the Stripe documentation](https://stripe.com/docs/api/events/types) for more information about the types of events available.\n\n```typescript\n@Injectable()\nclass PaymentCreatedService {\n  @StripeWebhookHandler('payment_intent.created')\n  handlePaymentIntentCreated(evt: StripeEvent) {\n    // execute your custom business logic\n  }\n}\n```\n\n### Webhook Controller Decorators\n\nYou can also pass any class decorator to the `decorators` property of the `webhookConfig` object as a part of the module configuration. This could be used in situations like when using the `@nestjs/throttler` package and needing to apply the `@SkipThrottle()` decorator, or when you have a global guard but need to skip routes with certain metadata.\n\n```typescript\nStripeModule.forRoot(StripeModule, {\n  apiKey: '123',\n  webhookConfig: {\n    stripeWebhookSecret: 'super-secret',\n    decorators: [SkipThrottle()],\n  },\n}),\n```\n\n### Usage with Interceptors, Guards and Filters\n\nThis library is built using an underlying NestJS concept called `External Contexts` which allows for methods to be included in the NestJS lifecycle. This means that Guards, Interceptors and Filters (collectively known as \"enhancers\") can be used in conjunction with Stripe webhook handlers. However, this can have unwanted/unintended consequences if you are using _Global_ enhancers in your application as these will also apply to all Stripe webhook handlers. If you were previously expecting all contexts to be regular HTTP contexts, you may need to add conditional logic to prevent your enhancers from applying to Stripe webhook handlers.\n\nYou can identify Stripe webhook contexts by their context type, `'stripe_webhook'`:\n\n```typescript\n@Injectable()\nclass ExampleInterceptor implements NestInterceptor {\n  intercept(context: ExecutionContext, next: CallHandler<any>) {\n    const contextType = context.getType<'http' | 'stripe_webhook'>();\n\n    // Do nothing if this is a Stripe webhook event\n    if (contextType === 'stripe_webhook') {\n      return next.handle();\n    }\n\n    // Execute custom interceptor logic for HTTP request/response\n    return next.handle();\n  }\n}\n```\n\n### Configure Webhooks in the Stripe Dashboard\n\nFollow the instructions from the [Stripe Documentation](https://stripe.com/docs/webhooks) for remaining integration steps such as testing your integration with the CLI before you go live and properly configuring the endpoint from the Stripe dashboard so that the correct events are sent to your NestJS app.\n\n## Contribute\n\nContributions welcome! Read the [contribution guidelines](../../CONTRIBUTING.md) first.\n\n## License\n\n[MIT License](../../LICENSE)\n","readmeFilename":"README.md"}