@sarrafjs/nestjs
v0.2.1
Published
NestJS module for Sarraf: an injectable client, a verified webhook controller and @OnSarrafEvent() handlers.
Maintainers
Readme
@sarrafjs/nestjs
NestJS module for Sarraf.
📖 Docs: NestJS guide · All docs
npm i @sarrafjs/core @sarrafjs/nestjs// main.ts: signatures need the exact request bytes
const app = await NestFactory.create(AppModule, { rawBody: true });import { InjectSarraf, OnSarrafEvent, SarrafModule } from "@sarrafjs/nestjs";
@Module({ imports: [SarrafModule.forRoot({ client: { providers: { kashier: kashier({ ... }) } } })] })
export class AppModule {}
@Injectable()
export class OrdersService {
constructor(@InjectSarraf() private readonly pay: Sarraf) {}
@OnSarrafEvent("payment.succeeded")
async paid(event: PaymentEvent) {
// dedupe on event.id, then fulfil the order
}
}SarrafModule.forRoot({ client })orforRootAsync({ inject, useFactory })registers the client globally; inject it with@InjectSarraf().- The module serves
POST /webhooks/:provider: it verifies the signature and calls every@OnSarrafEvent()method that matches. It answers 404 for unknown providers, 400 for invalid signatures, and 500 when a handler throws, so the provider retries. webhooks: { path }changes the route,webhooks: { mode: "ack-first" }answers before running handlers, andwebhooks: falselets you callSarrafWebhooks.handle()from your own controller.
Requires Node.js 22+.
Not affiliated with any payment provider. Part of Sarraf. Apache-2.0.
