@appweaver/payments 0.0.0-stage → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +212 -2
- package/config.d.ts +77 -0
- package/config.js +118 -0
- package/gateway/fake-gateway.d.ts +144 -0
- package/gateway/fake-gateway.js +805 -0
- package/gateway/gateway-registry.d.ts +99 -0
- package/gateway/gateway-registry.js +275 -0
- package/gateway/payment-gateway.d.ts +68 -0
- package/gateway/payment-gateway.js +82 -0
- package/index.d.ts +16 -0
- package/index.js +51 -0
- package/locales/en.json +47 -0
- package/maintenance/payment-maintenance-jobs.d.ts +5 -0
- package/maintenance/payment-maintenance-jobs.js +38 -0
- package/module.d.ts +8 -0
- package/module.js +85 -0
- package/package.json +67 -3
- package/resources/model-util.d.ts +40 -0
- package/resources/model-util.js +30 -0
- package/resources/payment/model.d.ts +2 -0
- package/resources/payment/model.js +106 -0
- package/resources/payment-customer/model.d.ts +2 -0
- package/resources/payment-customer/model.js +53 -0
- package/resources/payment-event/model.d.ts +2 -0
- package/resources/payment-event/model.js +31 -0
- package/resources/payment-invoice/model.d.ts +2 -0
- package/resources/payment-invoice/model.js +55 -0
- package/resources/payment-method/model.d.ts +2 -0
- package/resources/payment-method/model.js +37 -0
- package/resources/payment-plan/model.d.ts +2 -0
- package/resources/payment-plan/model.js +37 -0
- package/resources/payment-subscription/model.d.ts +2 -0
- package/resources/payment-subscription/model.js +82 -0
- package/resources/payment-transaction/model.d.ts +2 -0
- package/resources/payment-transaction/model.js +43 -0
- package/resources/payment-webhook-event/model.d.ts +2 -0
- package/resources/payment-webhook-event/model.js +32 -0
- package/resources/policies.d.ts +15 -0
- package/resources/policies.js +36 -0
- package/resources/services.d.ts +6 -0
- package/resources/services.js +19 -0
- package/resources/subscriptions.d.ts +9 -0
- package/resources/subscriptions.js +30 -0
- package/resources.d.ts +8 -0
- package/resources.js +34 -0
- package/service/payment-emails.d.ts +12 -0
- package/service/payment-emails.js +145 -0
- package/service/payment-events.d.ts +90 -0
- package/service/payment-events.js +472 -0
- package/service/payment-handlers.d.ts +26 -0
- package/service/payment-handlers.js +42 -0
- package/service/payment-store.d.ts +50 -0
- package/service/payment-store.js +95 -0
- package/service/payment-sync.d.ts +113 -0
- package/service/payment-sync.js +745 -0
- package/service/payments-service.d.ts +307 -0
- package/service/payments-service.js +747 -0
- package/service/subscriptions-service.d.ts +178 -0
- package/service/subscriptions-service.js +433 -0
- package/tasks/payments-replay.d.ts +10 -0
- package/tasks/payments-replay.js +36 -0
- package/tasks/payments-sync-plans.d.ts +10 -0
- package/tasks/payments-sync-plans.js +24 -0
- package/templates/emails/payment-action-required.html.hbs +28 -0
- package/templates/emails/payment-action-required.subject.hbs +1 -0
- package/templates/emails/payment-failed.html.hbs +37 -0
- package/templates/emails/payment-failed.subject.hbs +1 -0
- package/templates/emails/payment-receipt.html.hbs +45 -0
- package/templates/emails/payment-receipt.subject.hbs +1 -0
- package/templates/emails/payment-refunded.html.hbs +37 -0
- package/templates/emails/payment-refunded.subject.hbs +1 -0
- package/templates/emails/subscription-canceled.html.hbs +24 -0
- package/templates/emails/subscription-canceled.subject.hbs +1 -0
- package/templates/emails/subscription-trial-ending.html.hbs +25 -0
- package/templates/emails/subscription-trial-ending.subject.hbs +1 -0
- package/templates/layouts/email.html.hbs +36 -0
- package/templates/partials/email-button.html.hbs +15 -0
- package/tsconfig.build.tsbuildinfo +1 -0
- package/types.d.ts +488 -0
- package/types.js +2 -0
- package/utils/money-util.d.ts +61 -0
- package/utils/money-util.js +124 -0
- package/utils/status-util.d.ts +29 -0
- package/utils/status-util.js +93 -0
- package/utils/telemetry.d.ts +16 -0
- package/utils/telemetry.js +69 -0
- package/web/payment-routes.d.ts +7 -0
- package/web/payment-routes.js +410 -0
- package/web/payment-schemas.d.ts +70 -0
- package/web/payment-schemas.js +101 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Luka Matosevic
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,213 @@
|
|
|
1
|
-
|
|
1
|
+
<p align="center">
|
|
2
|
+
<a href="https://appweaver.co" target="_blank"><img src="https://raw.githubusercontent.com/lmatosevic/appweaver/refs/heads/main/resources/appweaver-logo.svg" width="460" alt="Appweaver Logo" /></a>
|
|
3
|
+
</p>
|
|
2
4
|
|
|
3
|
-
|
|
5
|
+
<p align="center">
|
|
6
|
+
The online payments of Appweaver, the AI-first <a href="https://nodejs.org" target="_blank">Node.js</a> framework for backends built with agents.
|
|
7
|
+
</p>
|
|
8
|
+
|
|
9
|
+
<p align="center">
|
|
10
|
+
<a href="https://www.npmjs.com/package/@appweaver/payments" target="_blank"><img src="https://img.shields.io/npm/v/@appweaver/payments.svg" alt="NPM Version" /></a>
|
|
11
|
+
<a href="https://github.com/lmatosevic/appweaver/blob/main/LICENSE" target="_blank"><img src="https://img.shields.io/npm/l/@appweaver/payments.svg" alt="Package License" /></a>
|
|
12
|
+
<a href="https://www.npmjs.com/package/@appweaver/payments" target="_blank"><img src="https://img.shields.io/npm/dw/@appweaver/payments.svg" alt="NPM Downloads" /></a>
|
|
13
|
+
<a href="https://github.com/lmatosevic/appweaver/actions/workflows/ci.yml?query=branch%3Amain" target="_blank"><img src="https://img.shields.io/github/actions/workflow/status/lmatosevic/appweaver/ci.yml?branch=main&label=CI" alt="CI Status" /></a>
|
|
14
|
+
<a href="https://codecov.io/gh/lmatosevic/appweaver" target="_blank"><img src="https://codecov.io/gh/lmatosevic/appweaver/graph/badge.svg" alt="Test Coverage" /></a>
|
|
15
|
+
<a href="https://nodejs.org" target="_blank"><img src="https://img.shields.io/node/v/@appweaver/payments.svg" alt="Node Version" /></a>
|
|
16
|
+
</p>
|
|
17
|
+
|
|
18
|
+
## Description
|
|
19
|
+
|
|
20
|
+
`@appweaver/payments` takes the online payments of an [Appweaver](https://github.com/lmatosevic/appweaver) application
|
|
21
|
+
through its payment gateways, a module enabled by installing it (it requires `@appweaver/data`):
|
|
22
|
+
|
|
23
|
+
- **one-time payments**, confirmed by the client with the library of the gateway (the card form and 3D Secure), paid
|
|
24
|
+
on a hosted checkout page, or charged to a saved payment method, with authorizations captured later, cancellations
|
|
25
|
+
and partial refunds
|
|
26
|
+
- **recurring payments**: the plans read from the recurring prices of the gateways, the subscriptions of the users to
|
|
27
|
+
them, their trials, renewals, invoices, plan changes and the customer portal
|
|
28
|
+
- the signed **webhooks** of the gateways, each event received once, read again from its gateway and applied in a
|
|
29
|
+
transaction, and a reconciliation job catching the ones never received
|
|
30
|
+
- the **events** of the payments, stored with the change they tell of and delivered at least once to the handlers of
|
|
31
|
+
`onPaymentEvent`
|
|
32
|
+
- the **emails** of the payments (receipt, failed payment, refund, confirmation asked by the bank, canceled
|
|
33
|
+
subscription, trial ending), with default templates and translations an application overrides
|
|
34
|
+
|
|
35
|
+
A card never reaches the application, the amounts are integers in the minor units of their currency (`1999` for
|
|
36
|
+
19.99 USD, stored in `BigInt` columns), and every write to a gateway carries an idempotency key. A gateway is an
|
|
37
|
+
account at a payment provider, reached by a driver: `stripe` of
|
|
38
|
+
[`@appweaver/stripe`](https://www.npmjs.com/package/@appweaver/stripe), or the built-in `fake` gateway of development
|
|
39
|
+
and tests. Several gateways run at once, i.e. one per legal entity, and each payment is routed by its country and
|
|
40
|
+
currency.
|
|
41
|
+
|
|
42
|
+
## Installation
|
|
43
|
+
|
|
44
|
+
```sh
|
|
45
|
+
npm install @appweaver/payments @appweaver/stripe
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
or `weaver module add payments` in a project created with `@appweaver/create`. Then generate the Prisma client and
|
|
49
|
+
migrate the database (`weaver generate`, `weaver migration new add_payments`, which the command prints as its
|
|
50
|
+
next steps) for the models of the module (`PaymentCustomer`, `PaymentMethod`, `Payment`, `PaymentTransaction`,
|
|
51
|
+
`PaymentPlan`, `PaymentSubscription`, `PaymentInvoice`, `PaymentEvent`, `PaymentWebhookEvent`).
|
|
52
|
+
|
|
53
|
+
## Configuration
|
|
54
|
+
|
|
55
|
+
The gateways are named in `payments.gateways`, each property also an environment variable
|
|
56
|
+
(`PAYMENTS_GATEWAYS_STRIPE_SECRET_KEY`). The name of a gateway is stored with its records and ends the URL of its
|
|
57
|
+
webhooks:
|
|
58
|
+
|
|
59
|
+
```json
|
|
60
|
+
{
|
|
61
|
+
"payments": {
|
|
62
|
+
"currency": "EUR",
|
|
63
|
+
"defaultGateway": "stripe",
|
|
64
|
+
"gateways": {
|
|
65
|
+
"stripe": {
|
|
66
|
+
"secretKey": "sk_live_...",
|
|
67
|
+
"publicKey": "pk_live_...",
|
|
68
|
+
"webhookSecret": "whsec_..."
|
|
69
|
+
},
|
|
70
|
+
"stripeUs": {
|
|
71
|
+
"driver": "stripe",
|
|
72
|
+
"secretKey": "sk_live_...",
|
|
73
|
+
"webhookSecret": "whsec_...",
|
|
74
|
+
"countries": ["US", "CA"]
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
| Key | Description |
|
|
82
|
+
| --------------- | ------------------------------------------------------------------------------------------ |
|
|
83
|
+
| `driver` | The driver of the gateway, the name of the gateway by default (`stripe`) |
|
|
84
|
+
| `secretKey` | The secret API key of the account |
|
|
85
|
+
| `publicKey` | The public key the clients confirm the payments with, returned with every `confirm` action |
|
|
86
|
+
| `webhookSecret` | The signing secret of the webhook endpoint of the gateway |
|
|
87
|
+
| `countries` | The countries (ISO 3166-1 alpha-2) whose payments the gateway takes |
|
|
88
|
+
| `currencies` | The currencies (ISO 4217) the gateway takes when no country selects one |
|
|
89
|
+
| `apiVersion` | The version of the provider API, the one the driver is built for by default |
|
|
90
|
+
| `apiUrl` | The base URL of the provider API, i.e. of a mock server |
|
|
91
|
+
| `timeout` | The timeout of a request, `payments.timeout` by default |
|
|
92
|
+
| `maxRetries` | The retries of a failed request, `payments.maxRetries` by default |
|
|
93
|
+
|
|
94
|
+
The gateway of a payment is the one it names, else the one `setPaymentGatewayResolver` returns, else the first whose
|
|
95
|
+
`countries` hold the country of the payment, else the first whose `currencies` hold its currency, else
|
|
96
|
+
`payments.defaultGateway`. The other sections are `payments.webhooks` (tolerance, body size, retention),
|
|
97
|
+
`payments.routes` (the REST routes, off by default), `payments.subscriptions` (grace period, proration) and
|
|
98
|
+
`payments.emails` (a switch per email).
|
|
99
|
+
|
|
100
|
+
An application taking one-time payments only sets `payments.subscriptions.enabled: false` before its first
|
|
101
|
+
`weaver generate`: the plan, subscription and invoice models then get no tables, the `SubscriptionsService` fails
|
|
102
|
+
with `PAYMENT_SUBSCRIPTIONS_DISABLED`, and the routes and webhook events of the subscriptions are left out.
|
|
103
|
+
|
|
104
|
+
Point the webhook endpoint of each account to `https://<host>/payments/webhooks/<gateway>`, i.e.
|
|
105
|
+
`/payments/webhooks/stripe` and `/payments/webhooks/stripeUs` above. The route is always registered, verifies the
|
|
106
|
+
signature against the `webhookSecret` of its gateway, and answers once the event is stored.
|
|
107
|
+
|
|
108
|
+
## Usage
|
|
109
|
+
|
|
110
|
+
```ts
|
|
111
|
+
import { inject } from '@appweaver/core';
|
|
112
|
+
import {
|
|
113
|
+
onPaymentEvent,
|
|
114
|
+
PaymentsService,
|
|
115
|
+
SubscriptionsService
|
|
116
|
+
} from '@appweaver/payments';
|
|
117
|
+
|
|
118
|
+
const payments = inject(PaymentsService);
|
|
119
|
+
|
|
120
|
+
// A payment the client confirms with the library of the gateway
|
|
121
|
+
const { payment, nextAction } = await payments.createPayment({
|
|
122
|
+
amount: 1999,
|
|
123
|
+
currency: 'EUR',
|
|
124
|
+
userId: user.id,
|
|
125
|
+
email: user.email,
|
|
126
|
+
country: 'DE',
|
|
127
|
+
reference: String(order.id),
|
|
128
|
+
referenceType: 'order',
|
|
129
|
+
idempotencyKey: `order-${order.id}`
|
|
130
|
+
});
|
|
131
|
+
// nextAction: { type: 'confirm', clientSecret, publicKey } | { type: 'redirect', url } | { type: 'none' }
|
|
132
|
+
|
|
133
|
+
// Or a hosted checkout page, the customer sent back to `payments.successUrl`
|
|
134
|
+
const checkout = await payments.createCheckout({
|
|
135
|
+
amount: 1999,
|
|
136
|
+
userId: user.id,
|
|
137
|
+
description: `Order ${order.id}`
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
await payments.refundPayment(payment.id, {
|
|
141
|
+
amount: 500,
|
|
142
|
+
reason: 'Damaged item'
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
// The order is paid when the gateway says so, never when the client does
|
|
146
|
+
onPaymentEvent('payment.succeeded', async ({ payment }) => {
|
|
147
|
+
await orders.markPaid(payment!.reference!);
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
const subscriptions = inject(SubscriptionsService);
|
|
151
|
+
await subscriptions.syncPlans(); // or `weaver run payments-sync-plans`
|
|
152
|
+
const { subscription } = await subscriptions.subscribe({
|
|
153
|
+
userId: user.id,
|
|
154
|
+
email: user.email,
|
|
155
|
+
plan: 'pro-monthly'
|
|
156
|
+
});
|
|
157
|
+
if (await subscriptions.isActive(user.id, 'pro-monthly')) {
|
|
158
|
+
// ...
|
|
159
|
+
}
|
|
160
|
+
await subscriptions.cancel(subscription.id); // at the end of the paid period
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
An amount is never taken from a request of a client: the application computes it and creates the payment. With
|
|
164
|
+
`payments.routes.enabled` the module registers the routes of the records of the signed-in user (payments, payment
|
|
165
|
+
methods, subscriptions, invoices, plans), of saving a card, subscribing to a plan and the customer portal, and the
|
|
166
|
+
refund, capture and cancel routes of `payments.routes.adminRoles`. The client generated by
|
|
167
|
+
[`@appweaver/client`](https://www.npmjs.com/package/@appweaver/client) calls them with `client.payments`:
|
|
168
|
+
|
|
169
|
+
```ts
|
|
170
|
+
const { subscription, nextAction } = await client.payments.subscribe({
|
|
171
|
+
plan: 'pro-monthly'
|
|
172
|
+
});
|
|
173
|
+
const { url } = await client.payments.portal();
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
### Emails
|
|
177
|
+
|
|
178
|
+
With a mailer, the customer receives an email for a paid, failed or refunded payment, a payment their bank asks them
|
|
179
|
+
to confirm, a canceled subscription and a trial about to end. The module ships the templates (`emails/payment-receipt`,
|
|
180
|
+
`emails/payment-failed`, `emails/payment-refunded`, `emails/payment-action-required`, `emails/subscription-canceled`,
|
|
181
|
+
`emails/subscription-trial-ending`) and the English translations (`emails.payments.*`); a template or a translation
|
|
182
|
+
key of the application with the same name replaces the one of the module, and each email has its switch in
|
|
183
|
+
`payments.emails`.
|
|
184
|
+
|
|
185
|
+
### The fake gateway
|
|
186
|
+
|
|
187
|
+
Without a configured gateway the payments go through the built-in `fake` gateway, which calls no provider and moves no
|
|
188
|
+
money, and is never available in production. A payment charged to a saved payment method is paid at once, any other
|
|
189
|
+
one waits for `confirmPayment`, standing for the customer:
|
|
190
|
+
|
|
191
|
+
```ts
|
|
192
|
+
import { FakePaymentGateway, PaymentsService } from '@appweaver/payments';
|
|
193
|
+
|
|
194
|
+
const gateway = (await inject(PaymentsService).gateway(
|
|
195
|
+
'fake'
|
|
196
|
+
)) as FakePaymentGateway;
|
|
197
|
+
const { payment } = await payments.createPayment({ amount: 1999, userId: 1 });
|
|
198
|
+
|
|
199
|
+
await gateway.confirmPayment(payment.providerPaymentId!); // or 'failed', 'requiresAction'
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
Its events are processed like the webhooks of a real gateway, and its checkout page is
|
|
203
|
+
`/payments/fake/checkout/<gateway>/<id>`. A driver of another provider extends `PaymentGateway` and is tested with
|
|
204
|
+
`testPaymentGatewayContract` of `@appweaver/testing`.
|
|
205
|
+
|
|
206
|
+
## Documentation
|
|
207
|
+
|
|
208
|
+
- [Appweaver README](https://github.com/lmatosevic/appweaver#readme) – getting started, configuration, and the overview of every package
|
|
209
|
+
- [Agent skill](https://github.com/lmatosevic/appweaver/blob/main/skill/SKILL.md) – the complete framework reference shipped to every scaffolded project
|
|
210
|
+
|
|
211
|
+
## License
|
|
212
|
+
|
|
213
|
+
Appweaver is [MIT licensed](LICENSE).
|
package/config.d.ts
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { Type } from 'typebox';
|
|
2
|
+
/** A gateway of the `payments.gateways` config: an account at a payment provider, reached by a driver. */
|
|
3
|
+
export declare const paymentGatewaySchema: Type.TObject<{
|
|
4
|
+
/** The driver talking to the provider, i.e. `stripe`. Default: the name of the gateway. */
|
|
5
|
+
driver: Type.TOptional<Type.TString>;
|
|
6
|
+
/** The secret API key of the account, i.e. `sk_live_...`. */
|
|
7
|
+
secretKey: Type.TOptional<Type.TString>;
|
|
8
|
+
/** The public key the clients confirm the payments with, i.e. `pk_live_...`. */
|
|
9
|
+
publicKey: Type.TOptional<Type.TString>;
|
|
10
|
+
/** The signing secret of the webhook endpoint, i.e. `whsec_...`. */
|
|
11
|
+
webhookSecret: Type.TOptional<Type.TString>;
|
|
12
|
+
/** The version of the provider API, i.e. `2026-11-18.endive`. Default: the one the driver is built for. */
|
|
13
|
+
apiVersion: Type.TOptional<Type.TString>;
|
|
14
|
+
/** The base URL of the provider API, i.e. of a mock server. Default: the one of the driver. */
|
|
15
|
+
apiUrl: Type.TOptional<Type.TString>;
|
|
16
|
+
/** The countries the gateway takes the payments of, ISO 3166-1 alpha-2 codes, i.e. `['US', 'CA']`. Default: none,
|
|
17
|
+
* so only the default gateway or a call naming it uses it. */
|
|
18
|
+
countries: Type.TOptional<Type.TArray<Type.TString>>;
|
|
19
|
+
/** The currencies the gateway takes the payments of when no country selects one, ISO 4217 codes. Default: none. */
|
|
20
|
+
currencies: Type.TOptional<Type.TArray<Type.TString>>;
|
|
21
|
+
/** The timeout of a request, milliseconds or a duration string. Default: `payments.timeout`. */
|
|
22
|
+
timeout: Type.TOptional<Type.TUnsafe<number>>;
|
|
23
|
+
/** The retries of a failed request. Default: `payments.maxRetries`. */
|
|
24
|
+
maxRetries: Type.TOptional<Type.TInteger>;
|
|
25
|
+
}>;
|
|
26
|
+
export declare const paymentsConfig: Readonly<{
|
|
27
|
+
DEFAULT_GATEWAY?: string | undefined;
|
|
28
|
+
SUCCESS_URL?: string | undefined;
|
|
29
|
+
CANCEL_URL?: string | undefined;
|
|
30
|
+
GATEWAYS: Record<string, {
|
|
31
|
+
driver?: string | undefined;
|
|
32
|
+
secretKey?: string | undefined;
|
|
33
|
+
publicKey?: string | undefined;
|
|
34
|
+
webhookSecret?: string | undefined;
|
|
35
|
+
apiVersion?: string | undefined;
|
|
36
|
+
apiUrl?: string | undefined;
|
|
37
|
+
countries?: string[] | undefined;
|
|
38
|
+
currencies?: string[] | undefined;
|
|
39
|
+
timeout?: number | undefined;
|
|
40
|
+
maxRetries?: number | undefined;
|
|
41
|
+
}>;
|
|
42
|
+
CURRENCY: string;
|
|
43
|
+
CURRENCIES: string[];
|
|
44
|
+
PENDING_TTL: number;
|
|
45
|
+
RECONCILE_AFTER: number;
|
|
46
|
+
EVENT_RETENTION: number;
|
|
47
|
+
EVENT_MAX_ATTEMPTS: number;
|
|
48
|
+
TIMEOUT: number;
|
|
49
|
+
MAX_RETRIES: number;
|
|
50
|
+
QUEUE_CONCURRENCY: number;
|
|
51
|
+
HEALTH_CHECK_GATEWAYS: string[];
|
|
52
|
+
}>;
|
|
53
|
+
export declare const paymentsWebhooksConfig: Readonly<{
|
|
54
|
+
TOLERANCE: number;
|
|
55
|
+
BODY_MAX_SIZE: number;
|
|
56
|
+
REFETCH: boolean;
|
|
57
|
+
MAX_ATTEMPTS: number;
|
|
58
|
+
RETENTION: number;
|
|
59
|
+
}>;
|
|
60
|
+
export declare const paymentsRoutesConfig: Readonly<{
|
|
61
|
+
ENABLED: boolean;
|
|
62
|
+
ADMIN_ROLES: string[];
|
|
63
|
+
}>;
|
|
64
|
+
export declare const paymentsSubscriptionsConfig: Readonly<{
|
|
65
|
+
ENABLED: boolean;
|
|
66
|
+
GRACE_PERIOD: number;
|
|
67
|
+
PRORATE: boolean;
|
|
68
|
+
}>;
|
|
69
|
+
export declare const paymentsEmailsConfig: Readonly<{
|
|
70
|
+
ENABLED: boolean;
|
|
71
|
+
RECEIPT: boolean;
|
|
72
|
+
FAILED: boolean;
|
|
73
|
+
REFUNDED: boolean;
|
|
74
|
+
ACTION_REQUIRED: boolean;
|
|
75
|
+
SUBSCRIPTION_CANCELED: boolean;
|
|
76
|
+
TRIAL_ENDING: boolean;
|
|
77
|
+
}>;
|
package/config.js
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.paymentsEmailsConfig = exports.paymentsSubscriptionsConfig = exports.paymentsRoutesConfig = exports.paymentsWebhooksConfig = exports.paymentsConfig = exports.paymentGatewaySchema = void 0;
|
|
4
|
+
const typebox_1 = require("typebox");
|
|
5
|
+
const common_1 = require("@appweaver/common");
|
|
6
|
+
/** A gateway of the `payments.gateways` config: an account at a payment provider, reached by a driver. */
|
|
7
|
+
exports.paymentGatewaySchema = typebox_1.Type.Object({
|
|
8
|
+
/** The driver talking to the provider, i.e. `stripe`. Default: the name of the gateway. */
|
|
9
|
+
driver: typebox_1.Type.Optional(typebox_1.Type.String()),
|
|
10
|
+
/** The secret API key of the account, i.e. `sk_live_...`. */
|
|
11
|
+
secretKey: typebox_1.Type.Optional(typebox_1.Type.String({ secret: true })),
|
|
12
|
+
/** The public key the clients confirm the payments with, i.e. `pk_live_...`. */
|
|
13
|
+
publicKey: typebox_1.Type.Optional(typebox_1.Type.String()),
|
|
14
|
+
/** The signing secret of the webhook endpoint, i.e. `whsec_...`. */
|
|
15
|
+
webhookSecret: typebox_1.Type.Optional(typebox_1.Type.String({ secret: true })),
|
|
16
|
+
/** The version of the provider API, i.e. `2026-11-18.endive`. Default: the one the driver is built for. */
|
|
17
|
+
apiVersion: typebox_1.Type.Optional(typebox_1.Type.String()),
|
|
18
|
+
/** The base URL of the provider API, i.e. of a mock server. Default: the one of the driver. */
|
|
19
|
+
apiUrl: typebox_1.Type.Optional(typebox_1.Type.String()),
|
|
20
|
+
/** The countries the gateway takes the payments of, ISO 3166-1 alpha-2 codes, i.e. `['US', 'CA']`. Default: none,
|
|
21
|
+
* so only the default gateway or a call naming it uses it. */
|
|
22
|
+
countries: typebox_1.Type.Optional(typebox_1.Type.Array(typebox_1.Type.String())),
|
|
23
|
+
/** The currencies the gateway takes the payments of when no country selects one, ISO 4217 codes. Default: none. */
|
|
24
|
+
currencies: typebox_1.Type.Optional(typebox_1.Type.Array(typebox_1.Type.String())),
|
|
25
|
+
/** The timeout of a request, milliseconds or a duration string. Default: `payments.timeout`. */
|
|
26
|
+
timeout: typebox_1.Type.Optional((0, common_1.Duration)()),
|
|
27
|
+
/** The retries of a failed request. Default: `payments.maxRetries`. */
|
|
28
|
+
maxRetries: typebox_1.Type.Optional(typebox_1.Type.Integer())
|
|
29
|
+
});
|
|
30
|
+
exports.paymentsConfig = (0, common_1.defineConfig)('payments', {
|
|
31
|
+
/** The gateways by name, i.e. `{ "stripe": { "secretKey": "sk_..." } }`, each property also a variable
|
|
32
|
+
* (`PAYMENTS_GATEWAYS_STRIPE_SECRET_KEY`). The name is stored with every record and ends the URL of the webhooks
|
|
33
|
+
* of the gateway. The `fake` gateway is built in, outside of production. Default: `{}`. */
|
|
34
|
+
GATEWAYS: typebox_1.Type.Record(typebox_1.Type.String(), exports.paymentGatewaySchema, { default: {} }),
|
|
35
|
+
/** The gateway of a call naming none whose country and currency select none. Default: the only configured gateway,
|
|
36
|
+
* otherwise `fake`. */
|
|
37
|
+
DEFAULT_GATEWAY: typebox_1.Type.Optional(typebox_1.Type.String()),
|
|
38
|
+
/** The currency of a payment setting none, an ISO 4217 code. Default: `'USD'`. */
|
|
39
|
+
CURRENCY: typebox_1.Type.String({ default: 'USD' }),
|
|
40
|
+
/** The currencies a payment may be created in, ISO 4217 codes, empty for any. Default: `[]`. */
|
|
41
|
+
CURRENCIES: typebox_1.Type.Array(typebox_1.Type.String(), { default: [] }),
|
|
42
|
+
/** The URL the user is sent to once a hosted checkout is paid, the ID and the status of the payment added to its
|
|
43
|
+
* query. Default: the `app.hostname` config. */
|
|
44
|
+
SUCCESS_URL: typebox_1.Type.Optional(typebox_1.Type.String()),
|
|
45
|
+
/** The URL the user is sent to when leaving a hosted checkout unpaid. Default: `payments.successUrl`. */
|
|
46
|
+
CANCEL_URL: typebox_1.Type.Optional(typebox_1.Type.String()),
|
|
47
|
+
/** How long a payment may stay unpaid before it is canceled, milliseconds or a duration string, `0` to keep it.
|
|
48
|
+
* Default: `'1d'`. */
|
|
49
|
+
PENDING_TTL: (0, common_1.Duration)({ default: '1d' }),
|
|
50
|
+
/** The age from which a payment or a subscription in a state that is not final is read from its gateway again,
|
|
51
|
+
* catching the webhooks never received, milliseconds or a duration string. Default: `'15m'`. */
|
|
52
|
+
RECONCILE_AFTER: (0, common_1.Duration)({ default: '15m' }),
|
|
53
|
+
/** How long the delivered events of the payments are kept, milliseconds or a duration string, `0` to keep them.
|
|
54
|
+
* Default: `'90d'`. */
|
|
55
|
+
EVENT_RETENTION: (0, common_1.Duration)({ default: '90d' }),
|
|
56
|
+
/** The attempts of delivering an event to its handlers, before it is marked as failed. Default: `5`. */
|
|
57
|
+
EVENT_MAX_ATTEMPTS: typebox_1.Type.Integer({ default: 5, minimum: 1 }),
|
|
58
|
+
/** The timeout of a request to a gateway, milliseconds or a duration string. Default: `30000`. */
|
|
59
|
+
TIMEOUT: (0, common_1.Duration)({ default: 30000 }),
|
|
60
|
+
/** The retries of a request failing on the network or with a server error. Default: `2`. */
|
|
61
|
+
MAX_RETRIES: typebox_1.Type.Integer({ default: 2, minimum: 0 }),
|
|
62
|
+
/** The jobs of the `payments` queue a worker runs at once. Default: `4`. */
|
|
63
|
+
QUEUE_CONCURRENCY: typebox_1.Type.Integer({ default: 4, minimum: 1 }),
|
|
64
|
+
/** The gateways the health check of the payment service checks. Default: `[]`. */
|
|
65
|
+
HEALTH_CHECK_GATEWAYS: typebox_1.Type.Array(typebox_1.Type.String(), { default: [] })
|
|
66
|
+
});
|
|
67
|
+
exports.paymentsWebhooksConfig = (0, common_1.defineConfig)('payments.webhooks', {
|
|
68
|
+
/** How old the signature of a webhook may be, against the replay of a captured one, milliseconds or a duration
|
|
69
|
+
* string. Default: `'5m'`. */
|
|
70
|
+
TOLERANCE: (0, common_1.Duration)({ default: '5m' }),
|
|
71
|
+
/** The maximum size of the body of a webhook, bytes or a size string. Default: `'1MB'`. */
|
|
72
|
+
BODY_MAX_SIZE: (0, common_1.Size)({ default: '1MB', minimum: 1 }),
|
|
73
|
+
/** Read the object of an event from its gateway before applying it, so the events delivered out of order cannot
|
|
74
|
+
* move a record back. Default: `true`. */
|
|
75
|
+
REFETCH: typebox_1.Type.Boolean({ default: true }),
|
|
76
|
+
/** The attempts of processing a received event, before it is marked as failed. Default: `5`. */
|
|
77
|
+
MAX_ATTEMPTS: typebox_1.Type.Integer({ default: 5, minimum: 1 }),
|
|
78
|
+
/** How long the processed events are kept, milliseconds or a duration string, `0` to keep them. The failed ones
|
|
79
|
+
* are kept. Default: `'30d'`. */
|
|
80
|
+
RETENTION: (0, common_1.Duration)({ default: '30d' })
|
|
81
|
+
});
|
|
82
|
+
exports.paymentsRoutesConfig = (0, common_1.defineConfig)('payments.routes', {
|
|
83
|
+
/** Register the routes of the payments: the records of the user (payments, payment methods, subscriptions,
|
|
84
|
+
* invoices, plans), saving a card, subscribing to a plan and the billing portal, and the refunds of the admin
|
|
85
|
+
* roles. The webhook and return routes are registered without it. Default: `false`. */
|
|
86
|
+
ENABLED: typebox_1.Type.Boolean({ default: false }),
|
|
87
|
+
/** The roles reading the records of every user, and capturing, canceling and refunding the payments. Default:
|
|
88
|
+
* `['Admin']`. */
|
|
89
|
+
ADMIN_ROLES: typebox_1.Type.Array(typebox_1.Type.String(), { default: ['Admin'] })
|
|
90
|
+
});
|
|
91
|
+
exports.paymentsSubscriptionsConfig = (0, common_1.defineConfig)('payments.subscriptions', {
|
|
92
|
+
/** Enable the recurring payments. Off, the `PaymentPlan`, `PaymentSubscription` and `PaymentInvoice` models get no
|
|
93
|
+
* tables, the `SubscriptionsService` fails with `PAYMENT_SUBSCRIPTIONS_DISABLED`, the routes of the subscriptions
|
|
94
|
+
* are not registered and the webhook events of the subscriptions and invoices are ignored. Default: `true`. */
|
|
95
|
+
ENABLED: typebox_1.Type.Boolean({ default: true }),
|
|
96
|
+
/** How long a subscription whose renewal failed still counts as active, while the gateway retries the payment,
|
|
97
|
+
* milliseconds or a duration string. Default: `'3d'`. */
|
|
98
|
+
GRACE_PERIOD: (0, common_1.Duration)({ default: '3d' }),
|
|
99
|
+
/** Charge or credit the difference of a plan change for the rest of the period. Default: `true`. */
|
|
100
|
+
PRORATE: typebox_1.Type.Boolean({ default: true })
|
|
101
|
+
});
|
|
102
|
+
exports.paymentsEmailsConfig = (0, common_1.defineConfig)('payments.emails', {
|
|
103
|
+
/** Send the emails of the payments to the customers, with a mailer and a template engine. Default: `true`. */
|
|
104
|
+
ENABLED: typebox_1.Type.Boolean({ default: true }),
|
|
105
|
+
/** Send the receipt of a paid payment (`emails/payment-receipt`). Default: `true`. */
|
|
106
|
+
RECEIPT: typebox_1.Type.Boolean({ default: true }),
|
|
107
|
+
/** Tell the customer a payment failed (`emails/payment-failed`). Default: `true`. */
|
|
108
|
+
FAILED: typebox_1.Type.Boolean({ default: true }),
|
|
109
|
+
/** Confirm a refund (`emails/payment-refunded`). Default: `true`. */
|
|
110
|
+
REFUNDED: typebox_1.Type.Boolean({ default: true }),
|
|
111
|
+
/** Ask the customer to confirm a payment their bank holds, i.e. a renewal needing 3D Secure
|
|
112
|
+
* (`emails/payment-action-required`). Default: `true`. */
|
|
113
|
+
ACTION_REQUIRED: typebox_1.Type.Boolean({ default: true }),
|
|
114
|
+
/** Confirm a canceled subscription (`emails/subscription-canceled`). Default: `true`. */
|
|
115
|
+
SUBSCRIPTION_CANCELED: typebox_1.Type.Boolean({ default: true }),
|
|
116
|
+
/** Tell the customer the trial of a subscription ends soon (`emails/subscription-trial-ending`). Default: `true`. */
|
|
117
|
+
TRIAL_ENDING: typebox_1.Type.Boolean({ default: true })
|
|
118
|
+
});
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { HealthCheckResult } from '@appweaver/common';
|
|
2
|
+
import { GatewayCheckout, GatewayCheckoutInput, GatewayCustomer, GatewayCustomerInput, GatewayEvent, GatewayInvoice, GatewayPayment, GatewayPaymentInput, GatewayPaymentMethod, GatewayPrice, GatewayRefund, GatewayRefundInput, GatewaySetup, GatewaySubscription, GatewaySubscriptionInput, GatewaySubscriptionUpdate, PaymentCapability, WebhookHeaders } from '../types';
|
|
3
|
+
import { PaymentGateway } from './payment-gateway';
|
|
4
|
+
/** A saved payment method of the fake gateway refused when charged. */
|
|
5
|
+
export declare const FAKE_DECLINED_METHOD = "pm_fake_declined";
|
|
6
|
+
/** A saved payment method of the fake gateway whose payments wait for the customer, like a card with 3D Secure. */
|
|
7
|
+
export declare const FAKE_ACTION_METHOD = "pm_fake_action";
|
|
8
|
+
/** How the customer of the fake gateway answers a payment waiting for them. */
|
|
9
|
+
export type FakeOutcome = 'succeeded' | 'failed' | 'requiresAction';
|
|
10
|
+
/** Receives the events of the fake gateway, standing for its webhook endpoint. */
|
|
11
|
+
export type FakeEventListener = (gateway: string, event: GatewayEvent) => unknown;
|
|
12
|
+
/**
|
|
13
|
+
* Sets the function receiving the events of the fake gateways, in place of a webhook request. The payment module
|
|
14
|
+
* sets its own, so the events of a fake gateway are processed like the webhooks of a real one.
|
|
15
|
+
*
|
|
16
|
+
* @param {FakeEventListener | undefined} listener - The function, or `undefined` to remove it.
|
|
17
|
+
*/
|
|
18
|
+
export declare function onFakePaymentEvent(listener: FakeEventListener | undefined): void;
|
|
19
|
+
/**
|
|
20
|
+
* Sets the base URL of the checkout pages of the fake gateways, the ID of a checkout appended to it.
|
|
21
|
+
*
|
|
22
|
+
* @param {string | undefined} url - The base URL, or `undefined` for the default one.
|
|
23
|
+
*/
|
|
24
|
+
export declare function setFakeCheckoutUrl(url: string | undefined): void;
|
|
25
|
+
/**
|
|
26
|
+
* The built-in `fake` gateway, calling no provider and moving no money, for the tests and the development without
|
|
27
|
+
* an account. A payment with a saved payment method is paid at once ({@link FAKE_DECLINED_METHOD} refuses it,
|
|
28
|
+
* {@link FAKE_ACTION_METHOD} holds it), any other one waits for `confirmPayment`, standing for the customer and the
|
|
29
|
+
* client library of a provider. Every change emits the event a provider would send to the webhook endpoint.
|
|
30
|
+
*/
|
|
31
|
+
export declare class FakePaymentGateway extends PaymentGateway {
|
|
32
|
+
readonly capabilities: readonly PaymentCapability[];
|
|
33
|
+
/** The events emitted so far, in their order. */
|
|
34
|
+
readonly events: GatewayEvent[];
|
|
35
|
+
createCustomer(input: GatewayCustomerInput): Promise<GatewayCustomer>;
|
|
36
|
+
updateCustomer(customerId: string, input: GatewayCustomerInput): Promise<GatewayCustomer>;
|
|
37
|
+
deleteCustomer(customerId: string): Promise<void>;
|
|
38
|
+
createPayment(input: GatewayPaymentInput): Promise<GatewayPayment>;
|
|
39
|
+
getPayment(paymentId: string): Promise<GatewayPayment>;
|
|
40
|
+
capturePayment(paymentId: string, amount?: number): Promise<GatewayPayment>;
|
|
41
|
+
cancelPayment(paymentId: string): Promise<GatewayPayment>;
|
|
42
|
+
refundPayment(input: GatewayRefundInput): Promise<GatewayRefund>;
|
|
43
|
+
createCheckout(input: GatewayCheckoutInput): Promise<GatewayCheckout>;
|
|
44
|
+
getCheckout(checkoutId: string): Promise<GatewayCheckout>;
|
|
45
|
+
expireCheckout(checkoutId: string): Promise<GatewayCheckout>;
|
|
46
|
+
createSetup(customerId: string): Promise<GatewaySetup>;
|
|
47
|
+
listPaymentMethods(customerId: string): Promise<GatewayPaymentMethod[]>;
|
|
48
|
+
detachPaymentMethod(paymentMethodId: string): Promise<void>;
|
|
49
|
+
setDefaultPaymentMethod(customerId: string, paymentMethodId: string): Promise<void>;
|
|
50
|
+
createSubscription(input: GatewaySubscriptionInput): Promise<GatewaySubscription>;
|
|
51
|
+
getSubscription(subscriptionId: string): Promise<GatewaySubscription>;
|
|
52
|
+
updateSubscription(subscriptionId: string, update: GatewaySubscriptionUpdate): Promise<GatewaySubscription>;
|
|
53
|
+
cancelSubscription(subscriptionId: string): Promise<GatewaySubscription>;
|
|
54
|
+
getInvoice(invoiceId: string): Promise<GatewayInvoice>;
|
|
55
|
+
listPrices(): Promise<GatewayPrice[]>;
|
|
56
|
+
createPortalSession(customerId: string, returnUrl: string): Promise<{
|
|
57
|
+
url: string;
|
|
58
|
+
}>;
|
|
59
|
+
verifyWebhook(body: Buffer, headers: WebhookHeaders, tolerance: number): Promise<GatewayEvent>;
|
|
60
|
+
checkHealth(): Promise<HealthCheckResult>;
|
|
61
|
+
/**
|
|
62
|
+
* Signs an event the way the fake gateway sends it, for a request to the webhook endpoint of the gateway.
|
|
63
|
+
*
|
|
64
|
+
* @param {GatewayEvent} event - The event.
|
|
65
|
+
* @param {number} [timestamp] - The time of the signature, now by default.
|
|
66
|
+
* @return The body and the headers of the request.
|
|
67
|
+
*/
|
|
68
|
+
signWebhook(event: GatewayEvent, timestamp?: number): {
|
|
69
|
+
body: Buffer;
|
|
70
|
+
headers: Record<string, string>;
|
|
71
|
+
};
|
|
72
|
+
/**
|
|
73
|
+
* Returns what a checkout was created with, i.e. for the page standing in for the one of a provider.
|
|
74
|
+
*
|
|
75
|
+
* @param {string} checkoutId - The ID of the checkout.
|
|
76
|
+
* @return {GatewayCheckoutInput} The input of the checkout.
|
|
77
|
+
*/
|
|
78
|
+
checkoutInput(checkoutId: string): GatewayCheckoutInput;
|
|
79
|
+
/**
|
|
80
|
+
* Adds a recurring price the subscriptions are created with.
|
|
81
|
+
*
|
|
82
|
+
* @param {Partial<GatewayPrice>} price - The price, a monthly one of 1000 `USD` minor units by default.
|
|
83
|
+
* @return {GatewayPrice} The price.
|
|
84
|
+
*/
|
|
85
|
+
addPrice(price?: Partial<GatewayPrice>): GatewayPrice;
|
|
86
|
+
/**
|
|
87
|
+
* Saves a card to a customer, as when the customer completes a setup.
|
|
88
|
+
*
|
|
89
|
+
* @param {string} customerId - The ID of the customer.
|
|
90
|
+
* @param {Partial<GatewayPaymentMethod>} [card] - The details of the card, a Visa ending with 4242 by default.
|
|
91
|
+
* @return {Promise<GatewayPaymentMethod>} The payment method, once its event is delivered.
|
|
92
|
+
*/
|
|
93
|
+
attachPaymentMethod(customerId: string, card?: Partial<GatewayPaymentMethod>): Promise<GatewayPaymentMethod>;
|
|
94
|
+
/**
|
|
95
|
+
* Answers a payment waiting for the customer, as the client library of a provider does with a card.
|
|
96
|
+
*
|
|
97
|
+
* @param {string} paymentId - The ID of the payment at the gateway.
|
|
98
|
+
* @param {FakeOutcome} [outcome='succeeded'] - Whether the payment is paid, refused or held by the bank.
|
|
99
|
+
* @return {Promise<GatewayPayment>} The payment, once its events are delivered.
|
|
100
|
+
*/
|
|
101
|
+
confirmPayment(paymentId: string, outcome?: FakeOutcome): Promise<GatewayPayment>;
|
|
102
|
+
/**
|
|
103
|
+
* Completes a setup, saving a card to its customer.
|
|
104
|
+
*
|
|
105
|
+
* @param {string} setupId - The ID of the setup.
|
|
106
|
+
* @return {Promise<GatewayPaymentMethod>} The saved payment method, once its event is delivered.
|
|
107
|
+
*/
|
|
108
|
+
confirmSetup(setupId: string): Promise<GatewayPaymentMethod>;
|
|
109
|
+
/**
|
|
110
|
+
* Completes a checkout as the customer paying on its page does, or leaves it unpaid.
|
|
111
|
+
*
|
|
112
|
+
* @param {string} checkoutId - The ID of the checkout.
|
|
113
|
+
* @param {'succeeded' | 'expired'} [outcome='succeeded'] - Whether the customer paid or the page expired.
|
|
114
|
+
* @return {Promise<GatewayCheckout>} The checkout, once its events are delivered.
|
|
115
|
+
*/
|
|
116
|
+
completeCheckout(checkoutId: string, outcome?: 'succeeded' | 'expired'): Promise<GatewayCheckout>;
|
|
117
|
+
/**
|
|
118
|
+
* Starts the next period of a subscription and collects its invoice, as a provider does when the period ends.
|
|
119
|
+
*
|
|
120
|
+
* @param {string} subscriptionId - The ID of the subscription at the gateway.
|
|
121
|
+
* @param {'succeeded' | 'failed'} [outcome='succeeded'] - Whether the renewal is paid.
|
|
122
|
+
* @return {Promise<GatewaySubscription>} The subscription, once its events are delivered.
|
|
123
|
+
*/
|
|
124
|
+
renewSubscription(subscriptionId: string, outcome?: 'succeeded' | 'failed'): Promise<GatewaySubscription>;
|
|
125
|
+
/**
|
|
126
|
+
* Announces the end of the trial of a subscription, as a provider does a few days before it.
|
|
127
|
+
*
|
|
128
|
+
* @param {string} subscriptionId - The ID of the subscription at the gateway.
|
|
129
|
+
*/
|
|
130
|
+
announceTrialEnd(subscriptionId: string): Promise<void>;
|
|
131
|
+
/**
|
|
132
|
+
* Opens a dispute of a paid payment, then closes it when an outcome is given.
|
|
133
|
+
*
|
|
134
|
+
* @param {string} paymentId - The ID of the payment at the gateway.
|
|
135
|
+
* @param {'won' | 'lost'} [outcome] - How the dispute ends, left open without it.
|
|
136
|
+
*/
|
|
137
|
+
disputePayment(paymentId: string, outcome?: 'won' | 'lost'): Promise<void>;
|
|
138
|
+
/**
|
|
139
|
+
* Waits until every event emitted so far is delivered to the listener.
|
|
140
|
+
*
|
|
141
|
+
* @return {Promise<void>} A promise resolved once the events are delivered.
|
|
142
|
+
*/
|
|
143
|
+
flush(): Promise<void>;
|
|
144
|
+
}
|