UNPKG

@vbusatta/adonis-stripe

Version:

Provider for AdonisJS 6. Simplifies Stripe integration with webhooks and services.

38 lines (37 loc) 1.31 kB
/** * Stripe Service for AdonisJS 6. * * This module provides a service for interacting with the Stripe API and handling * incoming webhook events. The service is designed to be used as a singleton and * can be registered with the AdonisJS IoC container. * * @see https://stripe.com/docs/api * @see https://stripe.com/docs/webhooks */ import type { LoggerService } from '@adonisjs/core/types'; import { Stripe as StripeSDK } from 'stripe'; import { EventHandlerFn, StripeConfig } from './types/main.js'; export default class StripeService { #private; constructor(logger: LoggerService, config: StripeConfig); /** * Provides direct access to the Stripe SDK instance. */ get api(): StripeSDK; /** * Processes an incoming webhook request by verifying the signature and handling the event. */ processWebhook(rawBody: Buffer, signature: string): Promise<void>; /** * Verifies the signature of a Stripe webhook request and extracts the event. */ private verifyWebhookSignature; /** * Processes a Stripe event by invoking the registered handler. */ private handleEvent; /** * Registers a handler for a specific Stripe event type. */ onEvent(eventType: StripeSDK.Event['type'], handler: EventHandlerFn): void; }