{"id":13598877,"url":"https://github.com/nestjsx/nestjs-braintree","last_synced_at":"2025-10-10T12:21:10.031Z","repository":{"id":33037936,"uuid":"146730181","full_name":"nestjsx/nestjs-braintree","owner":"nestjsx","description":"A module for braintree reoccurring payments and transactions :credit_card:","archived":false,"fork":false,"pushed_at":"2023-01-23T22:25:42.000Z","size":285,"stargazers_count":76,"open_issues_count":26,"forks_count":8,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-09-16T06:43:10.678Z","etag":null,"topics":["braintree","nestjs","node","payments","subscriptions","typescript","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/nestjsx.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":"2018-08-30T09:55:15.000Z","updated_at":"2024-03-02T09:46:28.000Z","dependencies_parsed_at":"2023-02-13T04:15:59.600Z","dependency_job_id":null,"html_url":"https://github.com/nestjsx/nestjs-braintree","commit_stats":null,"previous_names":["nestjs-community/nestjs-braintree"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/nestjsx/nestjs-braintree","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nestjsx%2Fnestjs-braintree","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nestjsx%2Fnestjs-braintree/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nestjsx%2Fnestjs-braintree/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nestjsx%2Fnestjs-braintree/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nestjsx","download_url":"https://codeload.github.com/nestjsx/nestjs-braintree/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nestjsx%2Fnestjs-braintree/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279003897,"owners_count":26083640,"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","status":"online","status_checked_at":"2025-10-10T02:00:06.843Z","response_time":62,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["braintree","nestjs","node","payments","subscriptions","typescript","webhooks"],"created_at":"2024-08-01T17:00:57.684Z","updated_at":"2025-10-10T12:21:09.997Z","avatar_url":"https://github.com/nestjsx.png","language":"TypeScript","funding_links":[],"categories":["Integrations","资源","TypeScript"],"sub_categories":["集成"],"readme":"\u003cp align=\"center\"\u003e\u003cimg src=\"https://avatars1.githubusercontent.com/u/43827489?s=400\u0026u=45ac0ac47d40b6d8f277c96bdf00244c10508aef\u0026v=4\"/\u003e\u003c/p\u003e\n\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://travis-ci.org/nestjsx/nestjs-braintree\"\u003e\u003cimg src=\"https://travis-ci.org/nestjsx/nestjs-braintree.svg?branch=master\"/\u003e\u003c/a\u003e\n    \u003ca href=\"https://www.npmjs.com/package/nestjs-braintree\"\u003e\u003cimg src=\"https://img.shields.io/npm/v/nestjs-braintree.svg\"/\u003e\u003c/a\u003e\n    \u003ca href=\"https://github.com/nestjsx/nestjs-braintree/blob/master/LICENSE\"\u003e\u003cimg src=\"https://img.shields.io/github/license/nestjsx/nestjs-braintree.svg\"/\u003e\u003c/a\u003e\n    \u003ca href='https://coveralls.io/github/nestjsx/nestjs-braintree?branch=master'\u003e\u003cimg src='https://coveralls.io/repos/github/nestjsx/nestjs-braintree/badge.svg?branch=master' alt='Coverage Status' /\u003e\u003c/a\u003e\n\u003c/p\u003e\n\u003ch1 align=\"center\"\u003eNestjs Braintree\u003c/h1\u003e\n\n\u003cp align=\"center\"\u003eA module for \u003ca href=\"https://www.braintreepayments.com/\"\u003eBraintree\u003c/a\u003e reoccurring payments and transactions built for the \u003ca href=\"https://github.com/nestjs/nest\"\u003eNestjs\u003c/a\u003e framework.\u003c/p\u003e\n\u003cbr/\u003e\n\u003cp\u003eUsing the \u003ca href=\"https://github.com/braintree/braintree_node\"\u003eBraintree node SDK\u003c/a\u003e.\u003c/p\u003e\n\n\u003e NOTE! Currently building\n\n## Install\n\n```bash\n$ yarn add nestjs-braintree\n```\n\n## Use\n\n### Basic use\n\n```typescript\nimport { Module } from '@nestjs/common';\nimport { BraintreeModule } from 'nestjs-braintree';\nimport * as braintree from 'braintree';\n\n@Module({\n  imports: [\n    BraintreeModule.forRoot({\n      environment: braintree.Environment.Sandbox,\n      merchantId: '',\n      publicKey: '',\n      privateKey: '',\n    }),\n  ],\n})\nexport default class AppModule {}\n```\n\n### In a subModule\n```typescript\nimport { Module } from '@nestjs/common';\nimport { BraintreeModule } from 'nestjs-braintree';\n\n@Module({\n  imports: [\n    BraintreeModule.forFeature(),\n  ],\n})\nexport default class SubModule {}\n```\n\n### Use with nestjs-config\n\n```typescript\nimport { Module } from '@nestjs/common';\nimport { BraintreeModule } from 'nestjs-braintree';\nimport { ConfigModule, ConfigService } from 'nestjs-config';\n\n@Module({\n  imports: [\n    ConfigModule.load('root/to/config/*/**.{ts,js}'),\n    BraintreeModule.forRootAsync({\n      useFactory: async (config: ConfigService) =\u003e config.get('braintree'),\n      inject: [ConfigService],\n    }),\n  ],\n})\nexport default class AppModule {}\n\n//config/braintree.ts\nimport * as braintree from 'braintree';\n\nexport default {\n  environment:\n    process.env.NODE_ENV == 'development'\n      ? braintree.Environment.Sandbox\n      : braintree.Environment.Live,\n  merchantId: process.env.BRAINTREE_MERCHANT_ID,\n  publicKey: process.env.BRAINTREE_PUBLIC_KEY,\n  privateKey: process.env.BRAINTREE_PRIVATE_KEY,\n};\n```\n\n## Transactions\n\nBraintree is capable of making one off transactions\n\n```typescript\nimport { Module } from '@nestjs/common';\nimport { BraintreeModule, InjectBraintreeProvider } from 'nestjs-braintree';\nimport { ConfigModule, ConfigService } from 'nestjs-config';\n\nclass TransactionProvider {\n  constructor(\n    @InjectBraintreeProvider()\n    private readonly braintreeProvider: BraintreeProvider,\n  ) {}\n\n  takePayment(amount: string, nonce: string) {\n    this.braintreeProvider.sale({\n      payment_method_nonce: nonce,\n      amount,\n    });\n  }\n}\n\n@Module({\n  imports: [\n    ConfigModule.load('root/to/config/*/**.{ts,js}'),\n    BraintreeModule.forRoot({\n      useFactory: async (config: ConfigService) =\u003e config.get('braintree'),\n      inject: [ConfigService],\n    }),\n  ],\n  providers: [TransactionProvider],\n})\nexport default class AppModule {}\n```\n\nAvailable methods relating to transactions are \n\n#### Sale \n`braintreeProvider.sale(transaction: BraintreeTransactionInterface): Promise\u003cBraintreeTransactionResultInterface\u003e`\n\n#### Refund\n`braintreeProvider.refund(transactionId: string, amount?: string, orderId?: string): Promise\u003cBraintreeTransactionResultInterface\u003e`\n\n#### Find\n`braintreeProvider.find(transactionId: string): Promise\u003cBraintreeTransactionResultInterface\u003e`\n\n\u003e The braintree SDK does offer additional methods. I will implement them soon hopefully \n\n## Webhooks\n\nWhen using subscriptions with braintree, braintree will issue webhooks to your\nendpoint which you can use the decorators to handle those actions.\n\n```typescript\nimport { Module } from '@nestjs/common';\nimport {\n  BraintreeModule,\n  BraintreeWebhookModule,\n  BraintreeSubscriptionCanceled,\n  BraintreeSubscriptionExpired,\n  BraintreeWebhookHandler,\n} from 'nestjs-braintree';\nimport { ConfigModule, ConfigService } from 'nestjs-config';\n\n@BraintreeWebhookHandler()\nclass SubscriptionProvider {\n  @BraintreeSubscriptionCanceled()\n  canceled() {\n    console.log('subscription canceled');\n  }\n\n  @BraintreeSubscriptionExpired()\n  expired() {\n    console.log('subscription expired');\n  }\n}\n\n@Module({\n  imports: [\n    ConfigModule.load('root/to/config/*/**.{ts,js}'),\n    BraintreeModule.forRootAsync({\n      useFactory: async (config: ConfigService) =\u003e config.get('braintree'),\n      inject: [ConfigService],\n    }),\n    BraintreeWebhookModule,\n  ],\n  providers: [SubscriptionProvider],\n})\nexport default class AppModule {}\n```\n\n### Use Example \nThe idea of the Braintree Webhook Module is to make implementation of actions a lot easier. For example we can build a provider like this one to cancel canceled subscriptions. \n\n```ts\n@BraintreeWebhookHandler()\nexport class SubscriptionProvider {\n  constructor(@InjectRepository(Subscription) private readonly subscriptionRepository: Repository\u003cSubscription\u003e) {}\n\n  async findByBraintreeId(braintreeId: string): Promise\u003cSubscription|null\u003e {\n    return await this.subscriptionRepository.find({\n      where: {\n        braintreeId,\n      },\n    });\n  }\n\n  async update(subscription: Subscription): Promise\u003cboolean\u003e {\n    return await this.subscriptionRepository.update(subscription);\n  }\n\n  @BraintreeSubscriptionCanceled()\n  async canceled(webhook: BraintreeWebhook) {\n    const subscription = await this.findByBraintreeId(webhook.subscription.id);\n    if (!subscription) {\n      return;\n    }\n    subscription.active = false;\n    await this.update(subscription);\n  }\n}\n```\n\n### Available webhooks \n\nShortname | Braintree webhook name/const/key | NestJS decorator\n--- | --- | ---\nSubscription Canceled | `subscription_canceled` | `@BraintreeSubscriptionCanceled()`\nSubscription Expired | `subscription_expired` | `@BraintreeSubscriptionExpired()`\nSubscription Charged Successfully | `subscription_charged_successfully` | `@BraintreeSubscriptionChargedSuccessfully()`\nSubscription Charged Unsuccessfully | `subscription_charged_unsuccessfully` | `@BraintreeSubscriptionChargedUnsuccessfully()`\nSubscription Went Active | `subscription_went_active` | `@BraintreeSubscriptionWentActive()`\nSubscription Went Past Due | `subscription_went_past_due` | `@BraintreeSubscriptionWentPastDue()`\nSubscription Trial Ended | `subscription_trial_ended` | `@BraintreeSubscriptionTrialEnded()`\n\nYou can find out more about the webhooks [here](https://developers.braintreepayments.com/reference/general/webhooks/overview). \n\n#### Custom routing for webhooks\nYou may want to divert from the default routing of `{your_domain}/braintree/webhook` for whatever reason. You can do so using the `forRoot` method on the `BraintreeWebhookModule` like so\n\n```ts\n@Module({\n  imports: [\n    ConfigModule.load('root/to/config/*/**.{ts,js}'),\n    BraintreeModule.forRootAsync({\n      useFactory: async (config: ConfigService) =\u003e config.get('braintree'),\n      inject: [ConfigService],\n    }),\n    BraintreeWebhookModule.forRoot({\n      root: 'replace-braintree',\n      handle: 'replace-webhook',\n    }),\n  ],\n  providers: [SubscriptionProvider],\n})\nexport default class AppModule {}\n```\n\nThe above will result in your route for your braintree webhooks being `{your_domain}/replace-braintree/replace-webhook`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnestjsx%2Fnestjs-braintree","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnestjsx%2Fnestjs-braintree","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnestjsx%2Fnestjs-braintree/lists"}