Unable to Add Stripe Client in NestJS using (https://www.npmjs.com/package/@golevelup/nestjs-stripe)

I'm currently facing an issue while trying to integrate the GoLevelUp stripe package into my NestJs project. Although I can successfully import the package into my global app module, I'm struggling to inject a functional client into the designated controller.

(https://github.com/golevelup/nestjs/tree/master/packages/stripe) (https://www.npmjs.com/package/@golevelup/nestjs-stripe) (https://www.npmjs.com/package/@nestjs/core)

redacted.controller.ts:

import { InjectStripeClient } from '@golevelup/nestjs-stripe';
import Stripe from 'stripe';

@Controller('[REDACTED]')
export class MyAwesomeController {
  constructor(
    @InjectStripeClient() stripeClient: Stripe, //this line crashes
    private readonly myService: MyCoolService
  ) { }
}

app.module.ts:

import { StripeModule } from '@golevelup/nestjs-stripe';
import { OtherModules } from 'where/ever';

@Module({
  imports: [
    ModuleA,
    ModuleB,
    ...,

    StripeModule.forRoot(StripeModule,
      {
        apiKey: 'PC_LOAD_KEY',
        webhookConfig: {
          // stripeWebhookSecret: 'PC_LOAD_SECRET'

          //TODO -- same deal w/ config
          stripeWebhookSecret: 'SHHHH',
          
        },
        
      }),


    MoreModulues,
    ...,
  ],
  controllers: [AppController, ControllerB, ControllerC, ...],
  providers: [AppService, ServiceB, ServiceC, ...]
}

The given code snippet is unable to build, showing the following error message:

Nest can't resolve dependencies of the [REDACTED]Controller (?, [REDACTED]Service). Please make sure that the argument Symbol(STRIPE_CLIENT_TOKEN) at index [0] is available in the [REDACTED]Module context.

Potential solutions:
- If Symbol(STRIPE_CLIENT_TOKEN) is a provider, is it part of the current [REDACTED]Module?
- If Symbol(STRIPE_CLIENT_TOKEN) is exported from a separate @Module, is that module imported within [REDACTED]Module?
  @Module({
    imports: [ /* the Module containing Symbol(STRIPE_CLIENT_TOKEN) */ ]

It is essential for me to instantiate a working stripe client to interact with the stripe API. Without this functionality, the package is essentially unusable. I lack the expertise to properly configure this setup and prevent it from crashing.

I have delved into the golevelup package to pinpoint the "STRIPE_CLIENT_TOKEN" causing the issue.

Here are the relevant files within the package: https://github.com/golevelup/nestjs/tree/master/packages/stripe/src/stripe.constants.ts https://github.com/golevelup/nestjs/tree/master/packages/stripe/src/stripe.decorators.ts https://github.com/golevelup/nestjs/tree/master/packages/stripe/src/stripe.module.ts

I have also examined the official stripe package for insights on configuring the missing tokens. Currently, I find myself stuck and in need of guidance or a functional example. Otherwise, I may resort to implementing it myself using Stripe™ primitives.

Answer №1

It appears that in the structure of the StripeModule, the usage of StripeModule.forRoot() is necessary within the [REDACTED]Module. The StripeModule operates within the scope of the module that configured and imported it, making the stripe client accessible only to that specific module.

Answer №2

It appears that injecting Stripe directly into the controller may not be the best approach. Consider moving it to a service instead.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Determining the dimensions of taskbar icons

How can I determine the size of taskbar buttons (small or large) on Windows 7 or 10? I have come across a registry key that might be helpful: HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced\ ...

Tips for importing a file with a dynamic path in Angular 6

I'm facing an issue where I need to import a file from a path specified in a variable's value. For example, it looks like this: let test = require(configurationUrl); Here, configurationUrl represents a path such as '../../assets/app.conf.j ...

Ways to require semicolons in a Typescript interface

When declaring a TypeScript interface, both , (comma) and ; (semicolon) are considered valid syntax. For example, the following declarations are all valid: export interface IUser { name: string; email: string; id: number; } export interface IUser { ...

How can you utilize both defineProps with TypeScript and set default values in Vue 3 setup? (Typescript)

Is there a way to use TypeScript types and default values in the "defineProps" function? I'm having difficulty getting it to work. Code snippet: const props = defineProps<{ type?: string color?: 'color-primary' | 'color-danger&a ...

Testing a NestJS service with multiple constructor parameters can be done by utilizing various techniques such as dependency

Content When testing a service that needs one parameter in the constructor, it's essential to initialize the service as a provider using an object instead of directly passing the service through: auth.service.ts (example) @Injectable() export class ...

Implementing updates to a particular value in a sub-document in Cosmos DB using Azure Function and TypeScript

I am looking to update a specific value called statutProduit in a sub-document residing within a document collection in Azure Cosmos DB. This will be accomplished using an HttpTrigger Azure Function that requires two parameters: the document ID (id) and th ...

Ways to resolve the "localtunnel error: tunnel server offline - Request failed with status code 502" issue

As I work on setting up a microservice, everything functions perfectly on localhost. Wanting to extend its accessibility to other computers, I decided to utilize npm's localtunnel. Initially, it was successful for two consecutive days until I encounte ...

What sets apart yarn/npm5 lockfiles from precise package versions?

I'm curious why I can't specify exact versions in my package.json. How does this differ from using a lockfile? ...

What is the best way to access the original observed node using MutationObserver when the subtree option is set to

Is there a way to access the original target node when using MutationObserver with options set to childList: true and subtree: true? According to the documentation on MDN, the target node changes to the mutated node during callbacks, but I want to always ...

What causes the node_modules folder to become corrupted when publishing an AspNetCore2 project with Visual Studio?

During the development of my AspNetCore project using Kendo, Angular5, and AspNet Mvc, everything was running smoothly. However, when trying to publish the project, I encountered a strange issue where it breaks. https://i.sstatic.net/2xQ1Q.png I then cam ...

Increasing the value of a TypeScript variable using ngFor in an HTML template can enhance its usefulness

Can you dynamically increase a variable declared in your TypeScript file for each element generated by an ngFor loop in your HTML file? <tbody> <tr *ngFor="let item of invoiceItems"> <td>{{item.ItemName}}</td> <td>{ ...

I'm encountering an error while trying to build my Ag-Grid using npm run build, can someone help me figure out

Being relatively new to Next.js and web development in general, my background mainly consists of working with compiled languages. I recently embarked on a project to build a web app using Ag-Grid, drawing inspiration from an example I found on a public Git ...

Ignore verification of unused parameters

In my typescript project compilation process, I make use of the noImplicitAny option to ensure that I specify the types for variables and arguments. However, there are instances where I have unused arguments. For instance: jQuery.ajaxTransport("+*", func ...

Having trouble locating async function after installation

Today, I encountered a strange issue after installing async globally in Node.js - it reported that the module could not be found. Here is the workflow: Install async npm install -g async Verify async installation npm list -g async Output received: / ...

The angular-CLI does not support the use of content delivery networks (CDNs) within the .angular-cli.json

Is there a way to make angular-cli recognize when we add any deployed URLs for styles or scripts using CDN? Currently, adding them to index.html works but adding to .angular-cli.json has no effect. Any workaround available? ...

Currently, I'm attempting to execute npm run dev as I install the authentication user interface within Laravel

Error: Module 'F:\vite\bin\vite.js' Not Found at Function.Module._resolveFilename (node:internal/modules/cjs/loader:925:15) at Function.Module._load (node:internal/modules/cjs/loader:769:27) at Function.executeUserEntry ...

How to declare a variable using new String() and s = '' in Typescript/Javascript

What is the correct way to declare an array of characters or a string in JavaScript? Is there a distinction between an array of characters and a string? let operators = new String(); or let operators = ''; ...

The Priority-Web-SDK encounters an issue with the message "Buffer is not defined"

Currently, I am in the process of developing a React Native application using create-react-native-app. The app is successfully connecting to Priority via the API. However, when attempting to utilize the Web-SDK to retrieve options for a select field, an er ...

How can I display data both as a dropdown and an autocomplete in Angular using a textbox?

There is a textbox with autocomplete functionality. When the user clicks on the textbox, an API call is made with two parameters - Pubid and Date. The data is then displayed in a dropdown with autocomplete feature. Now I am attempting to have the data app ...

Executing npm commands within a complex folder hierarchy

I am facing an issue where I can only execute my npm scripts like npm run dev or npm run build when my folder is placed on the Desktop. However, when I try to move the folder into my directory structure, it throws the following error: npm run dev > &l ...