Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stripe webhooks can not be found by library #877

Open
yarman1 opened this issue Nov 8, 2024 · 3 comments
Open

Stripe webhooks can not be found by library #877

yarman1 opened this issue Nov 8, 2024 · 3 comments
Labels
bug Something isn't working stale stripe

Comments

@yarman1
Copy link

yarman1 commented Nov 8, 2024

I was trying to implement stripe payment in my application. At first, I had a raw body problem, which I fixed according to documentation. Secondly, I had a problem with stripe-cli not being able to send requests because of the auth guard. I fixed it with Public decorator. The current problem is that the library cannot find defined webhook handlers.

subscription.webhook.service.ts

import {
  Injectable,
  InternalServerErrorException,
  Logger,
} from '@nestjs/common';
import {
  InjectStripeClient,
  StripeWebhookHandler,
} from '@golevelup/nestjs-stripe';
import Stripe from 'stripe';
import { PrismaService } from '../prisma/prisma.service';
import { Status } from '@prisma/client';

@Injectable()
export class SubscriptionWebhookService {
  private readonly logger = new Logger(SubscriptionWebhookService.name);

  constructor(
    @InjectStripeClient() private readonly stripe: Stripe,
    private readonly prismaService: PrismaService,
  ) {}

  @StripeWebhookHandler('invoice.payment_succeeded')
  async handleInvoicePaymentSucceeded(
    evt: Stripe.InvoicePaymentSucceededEvent,
  ) {
    //business logic
 }

subscription.module.ts

import { Module, RawBody } from '@nestjs/common';
import { SubscriptionService } from './subscription.service';
import { SubscriptionController } from './subscription.controller';
import { StripeModule, StripeWebhookService } from '@golevelup/nestjs-stripe';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { Public } from '../auth/decorators';
import { PrismaModule } from '../prisma/prisma.module';
import { SubscriptionWebhookService } from './subscription.webhook.service';

@Module({
  imports: [
    StripeModule.forRootAsync(StripeModule, {
      imports: [ConfigModule],
      inject: [ConfigService],
      useFactory: (configService: ConfigService) => ({
        apiKey: configService.get<string>('STRIPE_SECRET_KEY'),
        webhookConfig: {
          stripeSecrets: {
            accountTest: configService.get<string>('STRIPE_WEBHOOK_KEY'),
          },
          loggingConfiguration: {
            logMatchingEventHandlers: true,
          },
          requestBodyProperty: 'rawBody',
          decorators: [Public()],
        },
      }),
    }),
    PrismaModule,
  ],
  controllers: [SubscriptionController],
  providers: [SubscriptionService, SubscriptionWebhookService],
})
export class SubscriptionModule {}

Stripe CLI shows expected results
image

Stripe event objects are logged. I think it's a default situation for the handlers' absence.
image

I've been stuck with this problem for a couple of hours, so I'm looking forward to the help. Thanks in advance!

@underfisk
Copy link
Contributor

@yarman1 What version of stripe are you at and Nestjs stripe module? I'll need that information as we've recently upgraded Stripe

@yarman1
Copy link
Author

yarman1 commented Nov 9, 2024

@underfisk "stripe": "^14.25.0", "@golevelup/nestjs-stripe": "^0.8.2"

@underfisk underfisk added bug Something isn't working and removed waiting for more info labels Nov 10, 2024
Copy link

This issue is stale because it has been open for 30 days with no activity.

@github-actions github-actions bot added the stale label Dec 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working stale stripe
Projects
None yet
Development

No branches or pull requests

2 participants