Skip to content

Introduction

Kaizen Payments is a NestJS library for charging with different payment gateways behind a single contract. You install it in your API as a dependency and use it as a black box: you don't clone its code or run it separately, you just consume it.

You keep your business logic (orders, users…); it talks to each gateway, verifies webhooks and stores the state of every payment in its own space in the DB.

What it gives you

  • One single way to charge, independent of the gateway. It currently supports Stripe, Redsys and PayPal.
  • You don't manage its database — see Configuration.
  • You don't manage webhook security — see Webhooks & events.
  • You react with your own domain events.

The surface it exposes in your API

When you register the module, your app gains two HTTP routes:

MethodRouteWho calls it
POST/payments/chargeYou call it to start a charge.
POST/webhooks/:gatewayThe gateway calls it to notify you.

The gateway is not an endpoint, it's data

To charge you always call the same endpoint, POST /payments/charge. The gateway travels as a body field (gateway: "stripe" | "redsys" | "paypal"), not in the URL: you pass it to the service along with the amount and it routes to the right gateway.

The lifecycle of a payment

  1. You charge. POST /payments/charge with { gateway, amount, currency, reference, redirect }. The response tells you how to take the user to pay (depending on the gateway).
  2. The gateway notifies. When the payment settles, it calls POST /webhooks/:gateway (that URL is the one you give the gateway when configuring it). The library verifies the signature and matches the notification to the payment.
  3. You react. You listen to payment.captured / payment.failed with your own listener and do your thing: mark the order as paid, send an email…

Requirements

  • NestJS 11+ and TypeORM 0.3+ (they go as peerDependencies, must be your app's).
  • PostgreSQL (you provide the driver, e.g. pg).
  • autoLoadEntities: true and rawBody: true — see Configuration.

Continue with Installation.