Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@isnolan/nestjs-subscription

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@isnolan/nestjs-subscription

`SubscriptionModule` is a comprehensive subscription handling module for NestJS applications, providing seamless integration with multiple subscription platforms such as Stripe, Google Pay, and Apple Pay. It facilitates the handling of subscription events

  • 1.0.12
  • unpublished
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

Subscription Module for NestJS

SubscriptionModule is a comprehensive subscription handling module for NestJS applications, providing seamless integration with multiple subscription platforms such as Stripe, Google Pay, and Apple Pay. It facilitates the handling of subscription events via webhooks, offering a unified approach to verify and process payment notifications securely.

version downloads license

Features

  • Easy integration with Stripe, Google Pay, and Apple Pay.
  • Secure validation and processing of payment webhooks.
  • Customizable event handlers for different payment events.
  • Supports both synchronous and asynchronous configurations.

Getting Started

Install

PNPM
  • Install the package along with the stripe peer dependency
`pnpm install --save @isnolan/nestjs-subscription`

Import

Asynchronous configuration

To use SubscriptionModule, import and add it to the imports array of your NestJS module, typically AppModule. Here's how you can do it:

Synchronous configuration
import { SubscriptionModule } from '@isnolan/nestjs-subscription';

@Module({
  imports: [
    SubscriptionModule.forRoot({
      stripe: {
        apiSecretKey: `${process.env.STRIPE_SECRET_KEY}`,
        webhookSecret: `${process.env.STRIPE_SECRET_WEBHOOK}`,
      },
      apple: {
        signingKey: `${process.env.APPLE_SIGNING_KEY}`,
        keyId: `${process.env.APPLE_KEY_ID}`,
        issuerId: `${process.env.APPLE_ISSUER_ID}`,
        bundleId: `${process.env.APPLE_BUNDLE_ID}`,
        environment: 'Sandbox',
      },
    }),
  ],
  providers: [AppService],
})
export class AppModule {}

Asynchronous configuration

SubscriptionModule also supports asynchronous configuration, which is useful when the configuration needs to be dynamically determined at runtime.


import { SubscriptionModule } from '@isnolan/nestjs-subscription';
import { ConfigService } from '@nestjs/config';

@Module({
  imports: [
    SubscriptionModule.forRootAsync({
      inject: [ConfigService],
      useFactory: async (config: ConfigService) => config.get('subscription'),
    }),
  ],
  providers: [AppService],
})
export class AppModule {}

Configure Webhooks

The webhooks url is

Appple

https://api.xxxx.com/v1/notify/apple

Google

https://api.xxxx.com/v1/notify/google

Stripe

https://api.xxxx.com/v1/notify/stripe

Follow the instructions from the Stripe Documentation 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.

Subscription lifetcycle

Event

事件生命周期Apple PayGoogle PayStripe
订阅创建subscription_createdSUBSCRIPTION_STATE_PENDINGcustomer.subscription.created
订阅付款subscription_renewedSUBSCRIPTION_RENEWEDcustomer.subscription.updated
订阅取消subscription_canceledSUBSCRIPTION_CANCELEDcustomer.subscription.deleted
订阅过期subscription_expiredSUBSCRIPTION_EXPIREDcustomer.subscription.expired
付款成功payment_successPAYMENT_SUCCESSinvoice.payment_succeeded
付款失败payment_failedPAYMENT_FAILEDinvoice.payment_failed

State

StateApple PayGoogle PayStripe
PENDINGINITIAL_BUYSUBSCRIPTION_STATE_PENDINGcustomer.subscription.created
Activesubscription_createdSUBSCRIPTION_STATE_ACTIVEcustomer.subscription.created
Pausedsubscription_createdSUBSCRIPTION_STATE_ON_HOLDcustomer.subscription.created
Canceledsubscription_createdSUBSCRIPTION_STATE_CANCELEDcustomer.subscription.created
Expiredsubscription_createdSUBSCRIPTION_STATE_EXPIREDcustomer.subscription.created

Contribute

Contributions welcome! Read the contribution guidelines first.

License

MIT License

FAQs

Package last updated on 25 Mar 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc