我正在尝试使用 GoLevelUp stripe 包将 stripe 与我的 NestJs 项目集成。我可以将包导入到我的全局应用程序模块中,但我无法实际将工作客户端注入指定的控制器中。
(https://github.com/golevelup/nestjs/tree/master/packages/stripe)(https://www.npmjs.com/package/@golevelup/nestjs-stripe) (https://www.npmjs.com/package/@nestjs/core)
已编辑.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, ...]
}
上述代码无法构建,并出现以下错误:
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) */ ]
我需要能够实际实例化一个 stripe 客户端,以便我可以调用 stripe api。如果没有它,该包将无法使用。我不太了解如何配置它以免崩溃。
我尝试在 golevelup 包中寻找有问题的“STRIPE_CLIENT_TOKEN”。
它住在这儿: 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
我还查看了官方的 stripe 包,以获取有关如何配置丢失的令牌的线索。此时我正处于困境中,可以使用指针或工作示例来完成。否则,我将使用 Stripe™ 原语自己实现它。
看起来像 StripeModule 的编写方式,您需要在
StripeModule.forRoot()
中使用 [REDACTED]Module
。 StripeModule
不是全局的,因此它仅将 stripe 客户端(通过其装饰器)暴露给配置并导入该模块的模块。
我认为没有心思在控制器中注入
Stripe
,最好将其移至服务中。