feat(payment): configure named gateway providers

This commit is contained in:
Clintchiz committed 2026-08-28 09:49:53 +05:30
1 parent c578bc0f92
commit 95c291db64
5 files changed
+162 -5

No files matched your search

+24
View File
@@ -5,3 +5,27 @@ Gateway-neutral, webhook-authoritative payments for WrNexus. Amounts are integer
Built-in adapters: offline `sandbox`, Stripe, Razorpay, and PayPal. Applications may add adapters with `defineGateway`. Capabilities are explicit, unsupported operations are refused, signed webhooks are mandatory in production, and package-owned migrations provision the append-only event ledger.
Webhook events are deduplicated by the provider's event ID and reduced in provider occurrence/sequence order. Captured and refund states are monotonic, so a delayed retry of an older event cannot regress a terminal payment.
Configure any number of named gateway accounts in `wrnexus.config.ts`; keep credentials in environment variables:
```ts
const payment = {
default: "razorpayIndia",
gateways: {
razorpayIndia: {
provider: "razorpay",
keyId: process.env.RAZORPAY_KEY_ID!,
keySecret: process.env.RAZORPAY_KEY_SECRET!,
webhookSecret: process.env.RAZORPAY_WEBHOOK_SECRET ?? "",
},
stripeGlobal: {
provider: "stripe",
secretKey: process.env.STRIPE_SECRET_KEY!,
publishableKey: process.env.STRIPE_PUBLISHABLE_KEY!,
webhookSecret: process.env.STRIPE_WEBHOOK_SECRET!,
},
},
} satisfies PaymentConfig;
```
At runtime, call `configurePaymentFromConfig(config.payment, databasePaymentStore())` once. Pass a configured gateway name to `initializePayment` to override the default for a specific checkout.