@owlmeans/server-payment 0.1.20-rc.1 → 0.2.0-alpha.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/README.md +52 -54
- package/agent-meta/manifest.json +2 -2
- package/agent-meta/skills/server-payment/SKILL.md +272 -330
- package/agent-meta/skills/server-payment/parts/reference.md +3 -3
- package/build/access/types.d.ts +7 -16
- package/build/access/types.d.ts.map +1 -1
- package/build/access.d.ts.map +1 -1
- package/build/access.js +6 -8
- package/build/access.js.map +1 -1
- package/build/actions/resync.d.ts +3 -3
- package/build/actions/resync.js +5 -5
- package/build/actions/resync.js.map +1 -1
- package/build/actions/webhook.d.ts +4 -1
- package/build/actions/webhook.d.ts.map +1 -1
- package/build/actions/webhook.js +8 -4
- package/build/actions/webhook.js.map +1 -1
- package/build/bootstrap/types.d.ts +13 -7
- package/build/bootstrap/types.d.ts.map +1 -1
- package/build/bootstrap.d.ts +4 -4
- package/build/bootstrap.d.ts.map +1 -1
- package/build/bootstrap.js +19 -10
- package/build/bootstrap.js.map +1 -1
- package/build/catalogue/types.d.ts +3 -3
- package/build/catalogue/types.d.ts.map +1 -1
- package/build/catalogue.d.ts.map +1 -1
- package/build/catalogue.js +4 -8
- package/build/catalogue.js.map +1 -1
- package/build/checkout/types.d.ts +21 -0
- package/build/checkout/types.d.ts.map +1 -0
- package/build/{plugins/stripe → checkout}/types.js.map +1 -1
- package/build/checkout.d.ts +6 -0
- package/build/checkout.d.ts.map +1 -0
- package/build/checkout.js +374 -0
- package/build/checkout.js.map +1 -0
- package/build/config.d.ts +10 -16
- package/build/config.d.ts.map +1 -1
- package/build/config.js +18 -59
- package/build/config.js.map +1 -1
- package/build/consts.d.ts +3 -49
- package/build/consts.d.ts.map +1 -1
- package/build/consts.js +3 -61
- package/build/consts.js.map +1 -1
- package/build/consumer/cancellation/types.d.ts +6 -4
- package/build/consumer/cancellation/types.d.ts.map +1 -1
- package/build/consumer/cancellation.d.ts.map +1 -1
- package/build/consumer/cancellation.js +11 -5
- package/build/consumer/cancellation.js.map +1 -1
- package/build/consumer/capture/types.d.ts +8 -12
- package/build/consumer/capture/types.d.ts.map +1 -1
- package/build/consumer/capture.d.ts.map +1 -1
- package/build/consumer/capture.js +48 -53
- package/build/consumer/capture.js.map +1 -1
- package/build/consumer/index.d.ts +4 -0
- package/build/consumer/index.d.ts.map +1 -1
- package/build/consumer/index.js +2 -0
- package/build/consumer/index.js.map +1 -1
- package/build/consumer/reconcile.d.ts.map +1 -1
- package/build/consumer/reconcile.js +82 -72
- package/build/consumer/reconcile.js.map +1 -1
- package/build/consumer/records/types.d.ts +4 -4
- package/build/consumer/records/types.d.ts.map +1 -1
- package/build/consumer/records.d.ts.map +1 -1
- package/build/consumer/records.js +16 -13
- package/build/consumer/records.js.map +1 -1
- package/build/consumer/service.d.ts +2 -2
- package/build/consumer/service.d.ts.map +1 -1
- package/build/consumer/service.js +28 -21
- package/build/consumer/service.js.map +1 -1
- package/build/consumer/types.d.ts +1 -4
- package/build/consumer/types.d.ts.map +1 -1
- package/build/consumer/types.local.d.ts +1 -9
- package/build/consumer/types.local.d.ts.map +1 -1
- package/build/consumer/withdrawal/types.d.ts +14 -12
- package/build/consumer/withdrawal/types.d.ts.map +1 -1
- package/build/consumer/withdrawal.d.ts.map +1 -1
- package/build/consumer/withdrawal.js +55 -71
- package/build/consumer/withdrawal.js.map +1 -1
- package/build/index.d.ts +12 -6
- package/build/index.d.ts.map +1 -1
- package/build/index.js +7 -4
- package/build/index.js.map +1 -1
- package/build/paygate/providers.d.ts +13 -0
- package/build/paygate/providers.d.ts.map +1 -0
- package/build/paygate/providers.js +38 -0
- package/build/paygate/providers.js.map +1 -0
- package/build/paygate/registry.d.ts +6 -0
- package/build/paygate/registry.d.ts.map +1 -0
- package/build/paygate/registry.js +37 -0
- package/build/paygate/registry.js.map +1 -0
- package/build/paygate/types.d.ts +577 -0
- package/build/paygate/types.d.ts.map +1 -0
- package/build/{plugins/session → paygate}/types.js.map +1 -1
- package/build/plan/types.d.ts +6 -1
- package/build/plan/types.d.ts.map +1 -1
- package/build/plan.d.ts.map +1 -1
- package/build/plan.js +16 -2
- package/build/plan.js.map +1 -1
- package/build/plugins/checkout-policy/types.d.ts +5 -3
- package/build/plugins/checkout-policy/types.d.ts.map +1 -1
- package/build/plugins/checkout-policy.d.ts.map +1 -1
- package/build/plugins/checkout-policy.js +5 -3
- package/build/plugins/checkout-policy.js.map +1 -1
- package/build/plugins/consts.local.d.ts +8 -10
- package/build/plugins/consts.local.d.ts.map +1 -1
- package/build/plugins/consts.local.js +2 -19
- package/build/plugins/consts.local.js.map +1 -1
- package/build/plugins/customer-lock/types.d.ts +2 -2
- package/build/plugins/customer-lock/types.d.ts.map +1 -1
- package/build/plugins/customer-lock.js +2 -2
- package/build/plugins/customer-lock.js.map +1 -1
- package/build/plugins/estimate/cache.js +1 -1
- package/build/plugins/estimate/cache.js.map +1 -1
- package/build/plugins/estimate/types.d.ts +10 -10
- package/build/plugins/estimate/types.d.ts.map +1 -1
- package/build/plugins/estimate.d.ts.map +1 -1
- package/build/plugins/estimate.js +48 -122
- package/build/plugins/estimate.js.map +1 -1
- package/build/plugins/events/types.d.ts +17 -10
- package/build/plugins/events/types.d.ts.map +1 -1
- package/build/plugins/events.d.ts +6 -5
- package/build/plugins/events.d.ts.map +1 -1
- package/build/plugins/events.js +162 -173
- package/build/plugins/events.js.map +1 -1
- package/build/plugins/fx/types.d.ts +10 -21
- package/build/plugins/fx/types.d.ts.map +1 -1
- package/build/plugins/fx.d.ts +1 -1
- package/build/plugins/fx.d.ts.map +1 -1
- package/build/plugins/fx.js +17 -54
- package/build/plugins/fx.js.map +1 -1
- package/build/plugins/portal/types.d.ts +8 -37
- package/build/plugins/portal/types.d.ts.map +1 -1
- package/build/plugins/portal.d.ts.map +1 -1
- package/build/plugins/portal.js +38 -208
- package/build/plugins/portal.js.map +1 -1
- package/build/plugins/refunds/types.d.ts +11 -11
- package/build/plugins/refunds/types.d.ts.map +1 -1
- package/build/plugins/refunds.d.ts.map +1 -1
- package/build/plugins/refunds.js +14 -39
- package/build/plugins/refunds.js.map +1 -1
- package/build/plugins/snapshot/types.d.ts +11 -0
- package/build/plugins/snapshot/types.d.ts.map +1 -0
- package/build/plugins/snapshot/types.js +2 -0
- package/build/plugins/snapshot/types.js.map +1 -0
- package/build/plugins/snapshot.d.ts +4 -0
- package/build/plugins/snapshot.d.ts.map +1 -0
- package/build/plugins/snapshot.js +19 -0
- package/build/plugins/snapshot.js.map +1 -0
- package/build/plugins/subscriptions/types.d.ts +17 -17
- package/build/plugins/subscriptions/types.d.ts.map +1 -1
- package/build/plugins/subscriptions.d.ts +4 -4
- package/build/plugins/subscriptions.d.ts.map +1 -1
- package/build/plugins/subscriptions.js +69 -77
- package/build/plugins/subscriptions.js.map +1 -1
- package/build/plugins/types.local.d.ts +9 -43
- package/build/plugins/types.local.d.ts.map +1 -1
- package/build/plugins/webhook-manager/types.d.ts +15 -43
- package/build/plugins/webhook-manager/types.d.ts.map +1 -1
- package/build/plugins/webhook-manager.d.ts +3 -3
- package/build/plugins/webhook-manager.d.ts.map +1 -1
- package/build/plugins/webhook-manager.js +21 -199
- package/build/plugins/webhook-manager.js.map +1 -1
- package/build/protocol.d.ts +1 -1
- package/build/protocol.d.ts.map +1 -1
- package/build/protocol.js +1 -1
- package/build/protocol.js.map +1 -1
- package/build/service.d.ts +11 -11
- package/build/service.d.ts.map +1 -1
- package/build/service.js +59 -23
- package/build/service.js.map +1 -1
- package/build/sync/types.d.ts +17 -13
- package/build/sync/types.d.ts.map +1 -1
- package/build/sync.d.ts.map +1 -1
- package/build/sync.js +22 -122
- package/build/sync.js.map +1 -1
- package/build/types.d.ts +46 -101
- package/build/types.d.ts.map +1 -1
- package/build/utils/types.d.ts +0 -8
- package/build/utils/types.d.ts.map +1 -1
- package/build/utils.d.ts +1 -4
- package/build/utils.d.ts.map +1 -1
- package/build/utils.js +1 -15
- package/build/utils.js.map +1 -1
- package/package.json +20 -22
- package/src/access/types.ts +7 -16
- package/src/access.ts +7 -15
- package/src/actions/resync.ts +5 -5
- package/src/actions/webhook.ts +8 -4
- package/src/bootstrap/types.ts +13 -7
- package/src/bootstrap.ts +23 -13
- package/src/catalogue/types.ts +3 -3
- package/src/catalogue.ts +4 -8
- package/src/checkout/types.ts +21 -0
- package/src/checkout.ts +414 -0
- package/src/config.ts +19 -66
- package/src/consts.ts +3 -69
- package/src/consumer/cancellation/types.ts +6 -4
- package/src/consumer/cancellation.ts +13 -7
- package/src/consumer/capture/types.ts +8 -12
- package/src/consumer/capture.ts +50 -59
- package/src/consumer/index.ts +4 -0
- package/src/consumer/reconcile.ts +69 -68
- package/src/consumer/records/types.ts +4 -4
- package/src/consumer/records.ts +19 -14
- package/src/consumer/service.ts +35 -22
- package/src/consumer/types.local.ts +1 -8
- package/src/consumer/types.ts +1 -4
- package/src/consumer/withdrawal/types.ts +14 -12
- package/src/consumer/withdrawal.ts +61 -77
- package/src/index.ts +12 -6
- package/src/paygate/providers.ts +48 -0
- package/src/paygate/registry.ts +53 -0
- package/src/paygate/types.ts +640 -0
- package/src/plan/types.ts +6 -1
- package/src/plan.ts +21 -3
- package/src/plugins/checkout-policy/types.ts +5 -3
- package/src/plugins/checkout-policy.ts +6 -5
- package/src/plugins/consts.local.ts +2 -26
- package/src/plugins/customer-lock/types.ts +2 -2
- package/src/plugins/customer-lock.ts +2 -2
- package/src/plugins/estimate/cache.ts +1 -1
- package/src/plugins/estimate/types.ts +10 -10
- package/src/plugins/estimate.ts +52 -128
- package/src/plugins/events/types.ts +17 -9
- package/src/plugins/events.ts +172 -190
- package/src/plugins/fx/types.ts +10 -23
- package/src/plugins/fx.ts +28 -64
- package/src/plugins/portal/types.ts +8 -38
- package/src/plugins/portal.ts +48 -229
- package/src/plugins/refunds/types.ts +11 -11
- package/src/plugins/refunds.ts +16 -40
- package/src/plugins/snapshot/types.ts +11 -0
- package/src/plugins/snapshot.ts +22 -0
- package/src/plugins/subscriptions/types.ts +17 -17
- package/src/plugins/subscriptions.ts +81 -81
- package/src/plugins/types.local.ts +9 -33
- package/src/plugins/webhook-manager/types.ts +15 -43
- package/src/plugins/webhook-manager.ts +24 -220
- package/src/protocol.ts +1 -1
- package/src/service.ts +66 -30
- package/src/sync/types.ts +17 -13
- package/src/sync.ts +25 -143
- package/src/types.ts +47 -97
- package/src/utils/types.ts +0 -9
- package/src/utils.ts +2 -20
- package/tests/capabilities.spec.ts +219 -0
- package/tests/entitlement.spec.ts +4 -4
- package/tests/gate-handlers.spec.ts +6 -6
- package/tests/gate.spec.ts +2 -2
- package/tests/grants.spec.ts +2 -2
- package/tests/internal-plan.spec.ts +2 -2
- package/tests/limit-gate.spec.ts +2 -2
- package/tests/paygates.spec.ts +132 -0
- package/tests/protocol.spec.ts +4 -5
- package/tests/usage.spec.ts +2 -2
- package/tests/webhook.spec.ts +137 -0
- package/build/plugins/session/types.d.ts +0 -34
- package/build/plugins/session/types.d.ts.map +0 -1
- package/build/plugins/session.d.ts +0 -4
- package/build/plugins/session.d.ts.map +0 -1
- package/build/plugins/session.js +0 -71
- package/build/plugins/session.js.map +0 -1
- package/build/plugins/status.d.ts +0 -8
- package/build/plugins/status.d.ts.map +0 -1
- package/build/plugins/status.js +0 -21
- package/build/plugins/status.js.map +0 -1
- package/build/plugins/stripe/types.d.ts +0 -20
- package/build/plugins/stripe/types.d.ts.map +0 -1
- package/build/plugins/stripe.d.ts +0 -6
- package/build/plugins/stripe.d.ts.map +0 -1
- package/build/plugins/stripe.js +0 -518
- package/build/plugins/stripe.js.map +0 -1
- package/src/plugins/session/types.ts +0 -30
- package/src/plugins/session.ts +0 -86
- package/src/plugins/status.ts +0 -22
- package/src/plugins/stripe/types.ts +0 -20
- package/src/plugins/stripe.ts +0 -571
- package/tests/checkout-consumer.spec.ts +0 -366
- package/tests/checkout-locks.spec.ts +0 -161
- package/tests/checkout-plugins.spec.ts +0 -164
- package/tests/checkout.spec.ts +0 -313
- package/tests/consumer-events.spec.ts +0 -215
- package/tests/consumer-fixtures.ts +0 -141
- package/tests/consumer-ops.spec.ts +0 -361
- package/tests/consumer-rights.integration.spec.ts +0 -147
- package/tests/consumer-rights.spec.ts +0 -606
- package/tests/context.ts +0 -110
- package/tests/estimate.spec.ts +0 -350
- package/tests/events.spec.ts +0 -367
- package/tests/fake-stripe.ts +0 -1004
- package/tests/gateway-options.spec.ts +0 -180
- package/tests/portal.spec.ts +0 -202
- package/tests/sync.spec.ts +0 -114
- package/tests/usage.integration.spec.ts +0 -165
- package/tests/webhook-manager.spec.ts +0 -149
- /package/build/{plugins/session → checkout}/types.js +0 -0
- /package/build/{plugins/stripe → paygate}/types.js +0 -0
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
import { createHash } from 'node:crypto';
|
|
2
1
|
import { makeSecurityHelper } from '@owlmeans/config';
|
|
3
2
|
import { normalizePath } from '@owlmeans/route';
|
|
4
|
-
import {
|
|
3
|
+
import { PaygateError, WebhookSetupError } from '@owlmeans/payment';
|
|
5
4
|
import { memoHelper } from '@owlmeans/context';
|
|
6
|
-
import { STRIPE_OWNER_KEY, STRIPE_OWNER_VALUE, STRIPE_PAYGATE_ALIAS, WEBHOOK_EVENTS, STRIPE_SIGNATURE, } from '../consts.js';
|
|
7
5
|
import { log } from '../log.js';
|
|
8
6
|
import { paymentAccessOf } from '../access.js';
|
|
9
|
-
import { paymentUtils } from '../utils.js';
|
|
10
7
|
import { paymentGate } from '../protocol.js';
|
|
11
|
-
import {
|
|
8
|
+
import { paymentEventsOf } from './events.js';
|
|
12
9
|
/** The path the webhook route answers for one paygate: `/<base>/webhook/<paygate>`. */
|
|
13
10
|
const webhookPathOf = (paygate) => '/' + normalizePath(normalizePath(paymentGate.base.route.route.path) + '/'
|
|
14
11
|
+ normalizePath(paymentGate.webhook.route.route.path).replace(':paygate', paygate));
|
|
@@ -25,9 +22,6 @@ const isDeliverableUrl = (url) => {
|
|
|
25
22
|
return parsed.protocol === 'https:' && host !== 'localhost' && host !== '127.0.0.1' && host !== '::1'
|
|
26
23
|
&& !host.endsWith('.local') && host.includes('.');
|
|
27
24
|
};
|
|
28
|
-
/** An operator's label on an endpoint this package created — never evidence of which deployment owns it. */
|
|
29
|
-
const ownerMetadata = (owner) => ({ [STRIPE_OWNER_KEY]: STRIPE_OWNER_VALUE, service: owner });
|
|
30
|
-
const hashOf = (url, apiVersion, events) => createHash('sha256').update(JSON.stringify({ url, apiVersion, events })).digest('hex');
|
|
31
25
|
export const makeWebhookHelper = (ctx) => {
|
|
32
26
|
const access = paymentAccessOf(ctx);
|
|
33
27
|
const webhookServiceOf = () => access.gatewayOf()?.webhookService ?? ctx.cfg.service;
|
|
@@ -39,207 +33,35 @@ export const makeWebhookHelper = (ctx) => {
|
|
|
39
33
|
}
|
|
40
34
|
return route;
|
|
41
35
|
};
|
|
42
|
-
const webhookUrlOf = (paygate
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
for (;;) {
|
|
47
|
-
const page = await stripe.webhookEndpoints.list({
|
|
48
|
-
limit: 100, ...(startingAfter != null ? { starting_after: startingAfter } : {}),
|
|
49
|
-
});
|
|
50
|
-
endpoints.push(...page.data);
|
|
51
|
-
if (!page.has_more || page.data.length === 0) {
|
|
52
|
-
return endpoints;
|
|
53
|
-
}
|
|
54
|
-
startingAfter = page.data[page.data.length - 1].id;
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
const dropEndpoint = async (stripe, id) => {
|
|
58
|
-
try {
|
|
59
|
-
await stripe.webhookEndpoints.del(id);
|
|
60
|
-
}
|
|
61
|
-
catch (error) {
|
|
62
|
-
if (!paymentUtils.isMissingObject(error)) {
|
|
63
|
-
throw error;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
|
-
/** Field-encrypt the secret where the database is configured for it; store it plain otherwise. */
|
|
68
|
-
const sealed = async (row) => {
|
|
69
|
-
const resource = access.paymentWebhooks();
|
|
70
|
-
if (typeof resource.lock !== 'function') {
|
|
71
|
-
return row;
|
|
72
|
-
}
|
|
73
|
-
try {
|
|
74
|
-
return await resource.lock(row, ['secret']);
|
|
75
|
-
}
|
|
76
|
-
catch {
|
|
77
|
-
return row;
|
|
78
|
-
}
|
|
79
|
-
};
|
|
80
|
-
const opened = async (row) => {
|
|
81
|
-
const resource = access.paymentWebhooks();
|
|
82
|
-
if (typeof resource.unlock !== 'function') {
|
|
83
|
-
return row.secret;
|
|
84
|
-
}
|
|
85
|
-
try {
|
|
86
|
-
return (await resource.unlock(row, ['secret'])).secret;
|
|
87
|
-
}
|
|
88
|
-
catch {
|
|
89
|
-
return row.secret;
|
|
90
|
-
}
|
|
91
|
-
};
|
|
92
|
-
/**
|
|
93
|
-
* Delete the endpoints this deployment created at URLs it has left: each `payment-webhook` row of
|
|
94
|
-
* this paygate and owner at another URL drops the endpoint it names (one already gone is fine),
|
|
95
|
-
* then the row itself. `live` — the endpoint just put in place — is never dropped.
|
|
96
|
-
*/
|
|
97
|
-
const pruneFormerUrls = async (stripe, owner, url, live) => {
|
|
98
|
-
const resource = access.paymentWebhooks();
|
|
99
|
-
const { items } = await resource.list({ paygate: STRIPE_PAYGATE_ALIAS, service: owner, url: { $ne: url } }, { size: 0 });
|
|
100
|
-
for (const row of items) {
|
|
101
|
-
if (row.externalId !== live) {
|
|
102
|
-
await dropEndpoint(stripe, row.externalId);
|
|
103
|
-
}
|
|
104
|
-
await resource.delete(row.id);
|
|
105
|
-
}
|
|
106
|
-
};
|
|
107
|
-
const ensureWebhookEndpoint = async (stripe, opts = {}) => {
|
|
108
|
-
const url = webhookUrlOf();
|
|
109
|
-
if (!isDeliverableUrl(url)) {
|
|
110
|
-
log.info('Webhook endpoint not managed: not a public https URL', { url }, { event: 'payment.webhook.unmanaged' });
|
|
36
|
+
const webhookUrlOf = (paygate) => makeSecurityHelper(ctx).makeUrl(webhookRouteOf(), webhookPathOf(paygate));
|
|
37
|
+
const deploymentOf = (paygate) => ({ owner: gatewayOwnerOf(), webhookUrl: webhookUrlOf(paygate) });
|
|
38
|
+
const ensureWebhookEndpoint = async (paygate, opts = {}) => {
|
|
39
|
+
if (paygate.webhook == null) {
|
|
111
40
|
return null;
|
|
112
41
|
}
|
|
113
|
-
const
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
const resource = access.paymentWebhooks();
|
|
118
|
-
const description = `owlmeans:${owner}`;
|
|
119
|
-
const metadata = ownerMetadata(owner);
|
|
120
|
-
const now = new Date();
|
|
121
|
-
let stored = await resource.load({ paygate: STRIPE_PAYGATE_ALIAS, service: owner, url });
|
|
122
|
-
if (stored != null && opts.force === true) {
|
|
123
|
-
try {
|
|
124
|
-
await stripe.webhookEndpoints.retrieve(stored.externalId);
|
|
125
|
-
}
|
|
126
|
-
catch (error) {
|
|
127
|
-
if (!paymentUtils.isMissingObject(error)) {
|
|
128
|
-
throw error;
|
|
129
|
-
}
|
|
130
|
-
await resource.delete(stored.id);
|
|
131
|
-
stored = null;
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
if (stored != null && stored.hash === hash && opts.force !== true) {
|
|
135
|
-
return stored;
|
|
136
|
-
}
|
|
137
|
-
let live = null;
|
|
138
|
-
if (stored != null && stored.apiVersion === apiVersion) {
|
|
139
|
-
try {
|
|
140
|
-
await stripe.webhookEndpoints.update(stored.externalId, {
|
|
141
|
-
url, enabled_events: events,
|
|
142
|
-
description, metadata, disabled: false,
|
|
143
|
-
});
|
|
144
|
-
live = await resource.update({ ...stored, events, hash, updatedAt: now });
|
|
145
|
-
}
|
|
146
|
-
catch (error) {
|
|
147
|
-
if (!paymentUtils.isMissingObject(error)) {
|
|
148
|
-
throw error;
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
if (live == null) {
|
|
153
|
-
if (stored != null) {
|
|
154
|
-
await dropEndpoint(stripe, stored.externalId);
|
|
155
|
-
}
|
|
156
|
-
for (const endpoint of await listEndpoints(stripe)) {
|
|
157
|
-
if (endpoint.url === url) {
|
|
158
|
-
await dropEndpoint(stripe, endpoint.id);
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
const created = await stripe.webhookEndpoints.create({
|
|
162
|
-
url, enabled_events: events,
|
|
163
|
-
api_version: apiVersion, description, metadata,
|
|
164
|
-
});
|
|
165
|
-
if (created.secret == null || created.secret === '') {
|
|
166
|
-
throw new WebhookSetupError('secret-missing');
|
|
167
|
-
}
|
|
168
|
-
const row = await sealed({
|
|
169
|
-
paygate: STRIPE_PAYGATE_ALIAS, service: owner, url, externalId: created.id, secret: created.secret,
|
|
170
|
-
apiVersion, events, hash, createdAt: stored?.createdAt ?? now, updatedAt: now,
|
|
171
|
-
});
|
|
172
|
-
try {
|
|
173
|
-
live = stored != null
|
|
174
|
-
? await resource.update({ ...row, id: stored.id })
|
|
175
|
-
: await resource.create(row);
|
|
176
|
-
}
|
|
177
|
-
catch (error) {
|
|
178
|
-
if (!paymentUtils.isDuplicateKey(error)) {
|
|
179
|
-
throw error;
|
|
180
|
-
}
|
|
181
|
-
// Another replica persisted its endpoint meanwhile; the one created last is the live one.
|
|
182
|
-
const winner = await resource.load({ paygate: STRIPE_PAYGATE_ALIAS, service: owner, url });
|
|
183
|
-
live = await resource.update({ ...row, id: winner?.id });
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
await pruneFormerUrls(stripe, owner, url, live.externalId);
|
|
187
|
-
return live;
|
|
188
|
-
};
|
|
189
|
-
const stripeWebhookSecrets = async () => {
|
|
190
|
-
const secrets = [];
|
|
191
|
-
const configured = await access.stripeConfig().then(config => config.webhook, () => undefined);
|
|
192
|
-
if (typeof configured === 'string' && configured.trim() !== '') {
|
|
193
|
-
secrets.push(configured.trim());
|
|
194
|
-
}
|
|
195
|
-
const stored = await access.paymentWebhooks().load({ paygate: STRIPE_PAYGATE_ALIAS, service: gatewayOwnerOf() }, { sort: [{ field: 'updatedAt', order: 'desc' }] });
|
|
196
|
-
if (stored != null) {
|
|
197
|
-
const secret = await opened(stored);
|
|
198
|
-
if (secret !== '' && !secrets.includes(secret)) {
|
|
199
|
-
secrets.push(secret);
|
|
200
|
-
}
|
|
42
|
+
const deployment = deploymentOf(paygate.id);
|
|
43
|
+
if (!isDeliverableUrl(deployment.webhookUrl)) {
|
|
44
|
+
log.info('Webhook endpoint not managed: not a public https URL', { url: deployment.webhookUrl, paygate: paygate.id }, { event: 'payment.webhook.unmanaged' });
|
|
45
|
+
return null;
|
|
201
46
|
}
|
|
202
|
-
return
|
|
47
|
+
return await paygate.webhook.ensureEndpoint(deployment, opts);
|
|
203
48
|
};
|
|
204
|
-
const
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
throw new WebhookSetupError('secret');
|
|
49
|
+
const handleDelivery = async (paygate, request) => {
|
|
50
|
+
if (paygate.webhook == null) {
|
|
51
|
+
throw new PaygateError('capability:webhook');
|
|
208
52
|
}
|
|
209
|
-
return secret;
|
|
210
|
-
};
|
|
211
|
-
const handleStripeWebhook = async (stripe, request) => {
|
|
212
53
|
const typed = request;
|
|
213
|
-
const
|
|
214
|
-
const
|
|
215
|
-
|
|
216
|
-
throw new PaygateSignatureError();
|
|
217
|
-
const secrets = await stripeWebhookSecrets();
|
|
218
|
-
if (secrets.length === 0) {
|
|
219
|
-
throw new WebhookSetupError('secret');
|
|
220
|
-
}
|
|
221
|
-
let event = null;
|
|
222
|
-
for (const secret of secrets) {
|
|
223
|
-
try {
|
|
224
|
-
event = await stripe.webhooks.constructEventAsync(rawBody, signature, secret);
|
|
225
|
-
break;
|
|
226
|
-
}
|
|
227
|
-
catch {
|
|
228
|
-
// Try the next secret; a signature none of them verifies is refused below.
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
if (event == null) {
|
|
232
|
-
throw new PaygateSignatureError();
|
|
54
|
+
const events = await paygate.webhook.verify({ rawBody: typed.original?.rawBody ?? typed.rawBody, headers: typed.headers ?? {} }, { owner: gatewayOwnerOf() });
|
|
55
|
+
for (const event of events) {
|
|
56
|
+
await paymentEventsOf(ctx).apply(paygate, event);
|
|
233
57
|
}
|
|
234
|
-
await createEventHandler(ctx, stripe).process(event);
|
|
235
58
|
};
|
|
236
59
|
return {
|
|
237
|
-
webhookServiceOf, gatewayOwnerOf, webhookRouteOf, webhookUrlOf, ensureWebhookEndpoint,
|
|
238
|
-
stripeWebhookSecret, handleStripeWebhook,
|
|
60
|
+
webhookServiceOf, gatewayOwnerOf, webhookRouteOf, webhookUrlOf, deploymentOf, ensureWebhookEndpoint, handleDelivery,
|
|
239
61
|
};
|
|
240
62
|
};
|
|
241
|
-
/** The
|
|
63
|
+
/** The paygate webhooks of a context — one per context. */
|
|
242
64
|
export const webhookOf = memoHelper.oncePer(makeWebhookHelper);
|
|
243
|
-
/** @deprecated compat:factory-refactor — use `webhookOf(ctx).webhookUrlOf(
|
|
244
|
-
export const webhookUrlOf = (ctx, paygate
|
|
65
|
+
/** @deprecated compat:factory-refactor — use `webhookOf(ctx).webhookUrlOf(paygate)` */
|
|
66
|
+
export const webhookUrlOf = (ctx, paygate) => webhookOf(ctx).webhookUrlOf(paygate);
|
|
245
67
|
//# sourceMappingURL=webhook-manager.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webhook-manager.js","sourceRoot":"","sources":["../../src/plugins/webhook-manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAExC,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAA;AACrD,OAAO,EAA2B,aAAa,EAAE,MAAM,iBAAiB,CAAA;AACxE,OAAO,EAAE,iBAAiB,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAA;AAE5E,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAC9C,OAAO,EACL,gBAAgB,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,cAAc,EAAE,gBAAgB,GAC7F,MAAM,cAAc,CAAA;AAErB,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAA;A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,EAAE,OAAO,EAAE,KAAK,CAAC,QAAQ,EAAE,OAAO,IAAI,KAAK,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,IAAI,EAAE,EAAE,EAAE,EAAE,KAAK,EAAE,cAAc,EAAE,EAAE,CACjH,CAAA;QACD,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;YAC3B,MAAM,eAAe,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,CAAA;QAClD,CAAC;IACH,CAAC,CAAA;IAED,OAAO;QACL,gBAAgB,EAAE,cAAc,EAAE,cAAc,EAAE,YAAY,EAAE,YAAY,EAAE,qBAAqB,EAAE,cAAc;KACpH,CAAA;AACH,CAAC,CAAA;AAED,2DAA2D;AAC3D,MAAM,CAAC,MAAM,SAAS,GAAG,UAAU,CAAC,OAAO,CAAC,iBAAiB,CAAC,CAAA;AAE9D,uFAAuF;AACvF,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,GAAe,EAAE,OAAe,EAAU,EAAE,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,YAAY,CAAC,OAAO,CAAC,CAAA"}
|
package/build/protocol.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/** Embedded gateway protocol tree; the alias strings are private adapter details. */
|
|
2
2
|
export declare const paymentGate: {
|
|
3
3
|
readonly base: import("@owlmeans/entrypoint").EntrypointProtocol<{}, undefined>;
|
|
4
|
-
/** Public:
|
|
4
|
+
/** Public: the paygate signs the raw body, so no application guard may sit in front of it. */
|
|
5
5
|
readonly webhook: import("@owlmeans/entrypoint").EntrypointProtocol<{
|
|
6
6
|
params: import("./types.js").PaygateParams;
|
|
7
7
|
}, undefined>;
|
package/build/protocol.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AAQA,qFAAqF;AACrF,eAAO,MAAM,WAAW;;IAEtB,
|
|
1
|
+
{"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AAQA,qFAAqF;AACrF,eAAO,MAAM,WAAW;;IAEtB,8FAA8F;;;;IAK9F,mFAAmF;;IAMnF,+EAA+E;;CAMvE,CAAA"}
|
package/build/protocol.js
CHANGED
|
@@ -7,7 +7,7 @@ const base = protocol(route(aliases.base, '/payment-gate', backend()), contract(
|
|
|
7
7
|
/** Embedded gateway protocol tree; the alias strings are private adapter details. */
|
|
8
8
|
export const paymentGate = {
|
|
9
9
|
base,
|
|
10
|
-
/** Public:
|
|
10
|
+
/** Public: the paygate signs the raw body, so no application guard may sit in front of it. */
|
|
11
11
|
webhook: protocol(route(aliases.webhook, '/webhook/:paygate', backend({ parent: base, method: RouteMethod.POST })), contract.request({ params: PaygateParamsSchema }, typed())),
|
|
12
12
|
/** Re-sync products, prices, the portal configuration and the webhook endpoint. */
|
|
13
13
|
resync: protocol(route(aliases.resync, '/resync', backend({ parent: base, method: RouteMethod.POST })), contract(ResyncResultSchema), { guards: GUARD_ED25519 }),
|
package/build/protocol.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"protocol.js","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAA;AAChE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAC7D,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAA;AACpD,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAA;AAC3C,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,+BAA+B,EAAE,MAAM,cAAc,CAAA;AAEvG,MAAM,IAAI,GAAG,QAAQ,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,EAAE,eAAe,EAAE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AE,MAAM,EAAE,aAAa,EAAE,CAC1B;IACD,+EAA+E;IAC/E,mBAAmB,EAAE,QAAQ,CAC3B,KAAK,CAAC,OAAO,CAAC,mBAAmB,EAAE,uBAAuB,EAAE,OAAO,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,WAAW,CAAC,IAAI,EAAE,CAAC,CAAC,EAChH,QAAQ,CAAC,+BAA+B,CAAC,EACzC,EAAE,MAAM,EAAE,aAAa,EAAE,CAC1B;CACO,CAAA"}
|
package/build/service.d.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import type { Context as ApiContext } from '@owlmeans/server-api';
|
|
3
|
-
import type { Config, Context, GatewayService, PaymentGatewayOptions, GatewayServiceOptions, StripeBootstrapOptions } from './types.js';
|
|
1
|
+
import type { Config, Context, GatewayService, PaymentGatewayOptions, GatewayServiceOptions } from './types.js';
|
|
4
2
|
/**
|
|
5
3
|
* Refuse contradictory gateway options: `bootstrap: true` on an unmanaged gateway
|
|
6
4
|
* (`PaygateError('bootstrap:unmanaged')`), an empty `owner` / `webhookService`
|
|
@@ -8,10 +6,12 @@ import type { Config, Context, GatewayService, PaymentGatewayOptions, GatewaySer
|
|
|
8
6
|
*/
|
|
9
7
|
export declare const assertGatewayOptions: (opts: GatewayServiceOptions) => void;
|
|
10
8
|
/**
|
|
11
|
-
* The gateway service. `manage`, `bootstrap`, `owner
|
|
12
|
-
* `PaymentGatewayOptions`; the options are checked here (`assertGatewayOptions`)
|
|
13
|
-
*
|
|
14
|
-
*
|
|
9
|
+
* The gateway service. `manage`, `bootstrap`, `owner` and `webhookService` are
|
|
10
|
+
* `PaymentGatewayOptions`; the options are checked here (`assertGatewayOptions`). At initialization a
|
|
11
|
+
* declared policy feature a registered paygate lacks fails the boot (`PaygateError('feature:…')`); a
|
|
12
|
+
* managed, bootstrapping gateway also refuses to initialize without any registered payment provider
|
|
13
|
+
* (`PaygateError('provider:none')`) or when its webhook service is not declared in `cfg.services`
|
|
14
|
+
* (`WebhookSetupError('service:<alias>')`); a managed one without a provider only warns.
|
|
15
15
|
*/
|
|
16
16
|
export declare const makeGatewayService: (alias?: string, opts?: GatewayServiceOptions) => GatewayService;
|
|
17
17
|
/**
|
|
@@ -20,10 +20,10 @@ export declare const makeGatewayService: (alias?: string, opts?: GatewayServiceO
|
|
|
20
20
|
* entitlement service and the consumer-rights records and service — each only when not registered yet.
|
|
21
21
|
*
|
|
22
22
|
* `manage: false` registers the same surface for a process that reads entitlements but never talks
|
|
23
|
-
* to
|
|
24
|
-
* and one `webhookService`; exactly one of them keeps `bootstrap` (the one receiving the
|
|
23
|
+
* to a paygate. Several managed processes of one deployment share the paygate rows through one
|
|
24
|
+
* `owner` and one `webhookService`; exactly one of them keeps `bootstrap` (the one receiving the
|
|
25
|
+
* webhook). The paygates themselves come from the payment providers registered with
|
|
26
|
+
* `ensurePaymentProviders(ctx).register(…)` (a provider package's `append…` helper), before or after.
|
|
25
27
|
*/
|
|
26
28
|
export declare const appendPaymentGatewayService: <C extends Config, T extends Context<C>>(ctx: T, opts?: PaymentGatewayOptions) => T;
|
|
27
|
-
/** @deprecated compat:factory-refactor — use `stripeBootstrapOf(ctx).bootstrapStripe(…)` */
|
|
28
|
-
export declare const bootstrapStripe: (ctx: ApiContext, stripe: Stripe, opts?: StripeBootstrapOptions) => Promise<void>;
|
|
29
29
|
//# sourceMappingURL=service.d.ts.map
|
package/build/service.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../src/service.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../src/service.ts"],"names":[],"mappings":"AAsBA,OAAO,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,cAAc,EAAE,qBAAqB,EAAe,qBAAqB,EAAE,MAAM,YAAY,CAAA;AAmD5H;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,SAAU,qBAAqB,KAAG,IASlE,CAAA;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,kBAAkB,WACtB,MAAM,SAA0B,qBAAqB,KAC3D,cAoEF,CAAA;AAED;;;;;;;;;;GAUG;AACH,eAAO,MAAM,2BAA2B,GAAI,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,OAAO,CAAC,CAAC,CAAC,OAC3E,CAAC,SAAS,qBAAqB,KACnC,CAiCF,CAAA"}
|
package/build/service.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { createService } from '@owlmeans/context';
|
|
2
|
-
import {
|
|
2
|
+
import { configHelper } from '@owlmeans/config';
|
|
3
|
+
import { appendPaymentService, CONSUMER_RIGHTS_RECORD_ID, DEFAULT_ALIAS as PAYMENT_SERVICE, DEFAULT_PRICING_POLICY, ENTITLEMENT_GATE, LIMIT_GATE, PaygateError, PRICING_POLICY_RECORD_ID, ProductError, } from '@owlmeans/payment';
|
|
3
4
|
import { ENTITLEMENT_SERVICE, GATEWAY_SERVICE, RES_PAYGATE_CUSTOMER, RES_PAYMENT_FINGERPRINT, RES_PAYMENT_FULFILLMENT, RES_PAYMENT_GRANT, RES_PAYMENT_SUBSCRIPTION, RES_PAYMENT_USAGE, RES_PAYMENT_USAGE_COUNTER, RES_PAYMENT_WEBHOOK, } from './consts.js';
|
|
4
5
|
import { registerConsumerRights } from './consumer/service.js';
|
|
5
6
|
import { makeEntitlementService } from './entitlement.js';
|
|
@@ -12,7 +13,7 @@ import { paymentAccessOf } from './access.js';
|
|
|
12
13
|
import { catalogueOf } from './catalogue.js';
|
|
13
14
|
import { makePlanDeclarationsModel } from './models/declarations.js';
|
|
14
15
|
import { subscriptionCommitOf } from './commit.js';
|
|
15
|
-
import {
|
|
16
|
+
import { paygateBootstrapOf } from './bootstrap.js';
|
|
16
17
|
import { productSyncOf } from './sync.js';
|
|
17
18
|
import { estimateOf } from './plugins/estimate.js';
|
|
18
19
|
import { makeEstimateCache } from './plugins/estimate/cache.js';
|
|
@@ -20,9 +21,38 @@ import { checkoutPluginsOf } from './plugins/checkout-plugins.js';
|
|
|
20
21
|
import { makeCheckoutPluginRegistry } from './plugins/checkout-registry.js';
|
|
21
22
|
import { portalOf } from './plugins/portal.js';
|
|
22
23
|
import { webhookOf } from './plugins/webhook-manager.js';
|
|
23
|
-
import {
|
|
24
|
-
import {
|
|
24
|
+
import { paygateSubscriptionsOf } from './plugins/subscriptions.js';
|
|
25
|
+
import { checkoutOf } from './checkout.js';
|
|
26
|
+
import { appendPaymentProviders } from './paygate/providers.js';
|
|
27
|
+
import { paygatesOf } from './paygate/registry.js';
|
|
25
28
|
const unmanaged = () => { throw new PaygateError('unmanaged'); };
|
|
29
|
+
/** A singleton policy record read straight from the configuration (the boot checks run before any resource). */
|
|
30
|
+
const recordOf = (cfg, id) => {
|
|
31
|
+
const record = (cfg.records ?? []).find(entry => entry.id === id);
|
|
32
|
+
return record != null ? configHelper.fromConfigRecord(record) : null;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* The policy features every registered paygate must offer: a declared pricing policy or consumer-rights
|
|
36
|
+
* mechanism a paygate cannot put on a checkout fails the boot.
|
|
37
|
+
*
|
|
38
|
+
* @throws PaygateError('feature:<flag>:<paygate>')
|
|
39
|
+
*/
|
|
40
|
+
const assertPaygateFeatures = (ctx) => {
|
|
41
|
+
const pricing = recordOf(ctx.cfg, PRICING_POLICY_RECORD_ID) ?? DEFAULT_PRICING_POLICY;
|
|
42
|
+
const rights = recordOf(ctx.cfg, CONSUMER_RIGHTS_RECORD_ID);
|
|
43
|
+
const required = [
|
|
44
|
+
...(pricing.tax?.automatic === true ? ['automaticTax'] : []),
|
|
45
|
+
...(pricing.tax?.collectTaxId === true ? ['taxIdCollection'] : []),
|
|
46
|
+
...(pricing.currency?.adaptive === true ? ['adaptiveCurrency'] : []),
|
|
47
|
+
...(rights?.mechanisms?.checkoutTerms === true ? ['termsConsent'] : []),
|
|
48
|
+
];
|
|
49
|
+
for (const paygate of paygatesOf(ctx).all()) {
|
|
50
|
+
const missing = required.find(flag => paygate.features[flag] !== true);
|
|
51
|
+
if (missing != null) {
|
|
52
|
+
throw new PaygateError(`feature:${missing}:${paygate.id}`);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
};
|
|
26
56
|
/**
|
|
27
57
|
* Refuse contradictory gateway options: `bootstrap: true` on an unmanaged gateway
|
|
28
58
|
* (`PaygateError('bootstrap:unmanaged')`), an empty `owner` / `webhookService`
|
|
@@ -39,17 +69,17 @@ export const assertGatewayOptions = (opts) => {
|
|
|
39
69
|
}
|
|
40
70
|
};
|
|
41
71
|
/**
|
|
42
|
-
* The gateway service. `manage`, `bootstrap`, `owner
|
|
43
|
-
* `PaymentGatewayOptions`; the options are checked here (`assertGatewayOptions`)
|
|
44
|
-
*
|
|
45
|
-
*
|
|
72
|
+
* The gateway service. `manage`, `bootstrap`, `owner` and `webhookService` are
|
|
73
|
+
* `PaymentGatewayOptions`; the options are checked here (`assertGatewayOptions`). At initialization a
|
|
74
|
+
* declared policy feature a registered paygate lacks fails the boot (`PaygateError('feature:…')`); a
|
|
75
|
+
* managed, bootstrapping gateway also refuses to initialize without any registered payment provider
|
|
76
|
+
* (`PaygateError('provider:none')`) or when its webhook service is not declared in `cfg.services`
|
|
77
|
+
* (`WebhookSetupError('service:<alias>')`); a managed one without a provider only warns.
|
|
46
78
|
*/
|
|
47
79
|
export const makeGatewayService = (alias = GATEWAY_SERVICE, opts = {}) => {
|
|
48
80
|
assertGatewayOptions(opts);
|
|
49
81
|
const managed = opts.manage !== false;
|
|
50
82
|
const bootstrap = opts.bootstrap ?? managed;
|
|
51
|
-
const stripeOf = opts.stripe
|
|
52
|
-
?? (async (ctx) => await paymentAccessOf(ctx).stripeClient());
|
|
53
83
|
// One estimate cache per gateway SERVICE instance, never module-level: several service
|
|
54
84
|
// instances (several tests, several deployments in one process) must never share hits.
|
|
55
85
|
const estimateCache = makeEstimateCache();
|
|
@@ -64,9 +94,8 @@ export const makeGatewayService = (alias = GATEWAY_SERVICE, opts = {}) => {
|
|
|
64
94
|
get owner() {
|
|
65
95
|
return opts.owner ?? service.assertCtx().cfg.service;
|
|
66
96
|
},
|
|
67
|
-
stripe: stripeOf,
|
|
68
97
|
createLink: async (ctx, params) => managed
|
|
69
|
-
? await
|
|
98
|
+
? await checkoutOf(ctx).createCheckoutLink(params, plugins.list()) : unmanaged(),
|
|
70
99
|
use: plugin => { plugins.use(plugin); },
|
|
71
100
|
checkoutPlugins: () => plugins.list(),
|
|
72
101
|
amountPolicy: async (ctx, entityId, productSku, planSku) => {
|
|
@@ -79,18 +108,25 @@ export const makeGatewayService = (alias = GATEWAY_SERVICE, opts = {}) => {
|
|
|
79
108
|
},
|
|
80
109
|
planPrices: async (ctx, productSku) => await productSyncOf(ctx).syncedPlanPrices(productSku),
|
|
81
110
|
portalLink: async (ctx, entityId, link) => managed
|
|
82
|
-
? await portalOf(ctx).createPortalLink(
|
|
111
|
+
? await portalOf(ctx).createPortalLink(entityId, link) : unmanaged(),
|
|
83
112
|
grantInternalPlan: async (ctx, entityId, planSku, grant) => await subscriptionCommitOf(ctx).grantInternalPlan(entityId, planSku, grant),
|
|
84
113
|
revokeInternalPlan: async (ctx, entityId, planSku) => await subscriptionCommitOf(ctx).revokeInternalPlan(entityId, planSku),
|
|
85
114
|
resyncSubscription: async (ctx, ref) => managed
|
|
86
|
-
? await
|
|
115
|
+
? await paygateSubscriptionsOf(ctx).resyncSubscription(ref) : unmanaged(),
|
|
87
116
|
resyncAll: async (ctx) => managed
|
|
88
|
-
? await
|
|
117
|
+
? await paygateSubscriptionsOf(ctx).resyncAll() : unmanaged(),
|
|
89
118
|
estimatePrice: async (ctx, params) => managed
|
|
90
|
-
? await estimateOf(ctx).
|
|
119
|
+
? await estimateOf(ctx).estimatePrice(params, estimateCache) : unmanaged(),
|
|
91
120
|
}, service => async () => {
|
|
92
121
|
const ctx = service.assertCtx();
|
|
93
122
|
makePlanDeclarationsModel(ctx.cfg).assertPlans();
|
|
123
|
+
assertPaygateFeatures(ctx);
|
|
124
|
+
if (managed && paygatesOf(ctx).all().length === 0) {
|
|
125
|
+
if (bootstrap) {
|
|
126
|
+
throw new PaygateError('provider:none');
|
|
127
|
+
}
|
|
128
|
+
log.warn('Payment gateway is managed but no payment provider is registered: checkout, the portal and the webhook refuse');
|
|
129
|
+
}
|
|
94
130
|
if (bootstrap) {
|
|
95
131
|
// Every boot bootstrap forms the webhook URL on this alias: an undeclared one fails the boot.
|
|
96
132
|
webhookOf(ctx).webhookRouteOf(opts.webhookService ?? ctx.cfg.service);
|
|
@@ -101,8 +137,8 @@ export const makeGatewayService = (alias = GATEWAY_SERVICE, opts = {}) => {
|
|
|
101
137
|
paymentAccessOf(ctx).consumerRightsOf();
|
|
102
138
|
if (bootstrap) {
|
|
103
139
|
void ctx.waitForInitialized().then(async () => {
|
|
104
|
-
await
|
|
105
|
-
}).catch(error => { log.error('
|
|
140
|
+
await paygateBootstrapOf(ctx).bootstrap();
|
|
141
|
+
}).catch(error => { log.error('Paygate bootstrap failed', error); });
|
|
106
142
|
}
|
|
107
143
|
});
|
|
108
144
|
return service;
|
|
@@ -113,8 +149,10 @@ export const makeGatewayService = (alias = GATEWAY_SERVICE, opts = {}) => {
|
|
|
113
149
|
* entitlement service and the consumer-rights records and service — each only when not registered yet.
|
|
114
150
|
*
|
|
115
151
|
* `manage: false` registers the same surface for a process that reads entitlements but never talks
|
|
116
|
-
* to
|
|
117
|
-
* and one `webhookService`; exactly one of them keeps `bootstrap` (the one receiving the
|
|
152
|
+
* to a paygate. Several managed processes of one deployment share the paygate rows through one
|
|
153
|
+
* `owner` and one `webhookService`; exactly one of them keeps `bootstrap` (the one receiving the
|
|
154
|
+
* webhook). The paygates themselves come from the payment providers registered with
|
|
155
|
+
* `ensurePaymentProviders(ctx).register(…)` (a provider package's `append…` helper), before or after.
|
|
118
156
|
*/
|
|
119
157
|
export const appendPaymentGatewayService = (ctx, opts) => {
|
|
120
158
|
const makers = [
|
|
@@ -134,11 +172,11 @@ export const appendPaymentGatewayService = (ctx, opts) => {
|
|
|
134
172
|
}
|
|
135
173
|
if (!ctx.hasService(PAYMENT_SERVICE))
|
|
136
174
|
appendPaymentService(ctx);
|
|
175
|
+
appendPaymentProviders(ctx);
|
|
137
176
|
appendCompletionObserver(ctx);
|
|
138
177
|
if (!ctx.hasService(GATEWAY_SERVICE)) {
|
|
139
178
|
ctx.registerService(makeGatewayService(GATEWAY_SERVICE, {
|
|
140
179
|
manage: opts?.manage, bootstrap: opts?.bootstrap, owner: opts?.owner, webhookService: opts?.webhookService,
|
|
141
|
-
stripe: opts?.stripe,
|
|
142
180
|
}));
|
|
143
181
|
}
|
|
144
182
|
if (!ctx.hasService(ENTITLEMENT_GATE))
|
|
@@ -153,6 +191,4 @@ export const appendPaymentGatewayService = (ctx, opts) => {
|
|
|
153
191
|
registerConsumerRights(ctx, { manage: opts?.manage, dbAlias: opts?.dbAlias, serviceAlias: opts?.serviceAlias }, 'gateway');
|
|
154
192
|
return ctx;
|
|
155
193
|
};
|
|
156
|
-
/** @deprecated compat:factory-refactor — use `stripeBootstrapOf(ctx).bootstrapStripe(…)` */
|
|
157
|
-
export const bootstrapStripe = async (ctx, stripe, opts = {}) => { await stripeBootstrapOf(ctx).bootstrapStripe(stripe, opts); };
|
|
158
194
|
//# sourceMappingURL=service.js.map
|
package/build/service.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"service.js","sourceRoot":"","sources":["../src/service.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"service.js","sourceRoot":"","sources":["../src/service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AACjD,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AAE/C,OAAO,EACL,oBAAoB,EAAE,yBAAyB,EAAE,aAAa,IAAI,eAAe,EAAE,sBAAsB,EACzG,gBAAgB,EAAE,UAAU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AAC,UAAU,CAAC,eAAe,CAAC;QAAE,oBAAoB,CAAC,GAAY,CAAC,CAAA;IACxE,sBAAsB,CAAC,GAAG,CAAC,CAAA;IAC3B,wBAAwB,CAAC,GAAG,CAAC,CAAA;IAC7B,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,eAAe,CAAC,EAAE,CAAC;QACrC,GAAG,CAAC,eAAe,CAAC,kBAAkB,CAAC,eAAe,EAAE;YACtD,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,cAAc,EAAE,IAAI,EAAE,cAAc;SAC3G,CAAC,CAAC,CAAA;IACL,CAAC;IACD,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,gBAAgB,CAAC;QAAE,GAAG,CAAC,eAAe,CAAC,kBAAkB,EAAE,CAAC,CAAA;IAChF,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,UAAU,CAAC;QAAE,GAAG,CAAC,eAAe,CAAC,aAAa,EAAE,CAAC,CAAA;IACrE,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,mBAAmB,CAAC;QAAE,GAAG,CAAC,eAAe,CAAC,sBAAsB,EAAE,CAAC,CAAA;IACvF,+FAA+F;IAC/F,2FAA2F;IAC3F,qDAAqD;IACrD,sBAAsB,CAAC,GAAG,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,YAAY,EAAE,IAAI,EAAE,YAAY,EAAE,EAAE,SAAS,CAAC,CAAA;IAE1H,OAAO,GAAG,CAAA;AACZ,CAAC,CAAA"}
|
package/build/sync/types.d.ts
CHANGED
|
@@ -1,25 +1,29 @@
|
|
|
1
|
-
import type Stripe from 'stripe';
|
|
2
1
|
import type { PlanPriceView } from '@owlmeans/payment';
|
|
3
|
-
|
|
2
|
+
import type { Paygate } from '../paygate/types.js';
|
|
3
|
+
/** The catalogue of a context as each paygate's products and reusable prices. */
|
|
4
4
|
export interface ProductSyncHelper {
|
|
5
5
|
/**
|
|
6
|
-
* Synchronize every product sold through
|
|
7
|
-
*
|
|
8
|
-
* and plans sold through
|
|
6
|
+
* Synchronize every product with a plan sold through the paygate, and those plans, to the
|
|
7
|
+
* paygate's catalogue (`paygate.catalogue.syncProduct`). A product whose declaration fingerprint is
|
|
8
|
+
* unchanged makes no paygate call; free plans and plans sold through other paygates are never
|
|
9
|
+
* synchronized; a paygate without `catalogue` is skipped. A recurring or quantity plan whose
|
|
10
|
+
* catalogue currency differs from the paygate's settlement currency is converted at its FX reference
|
|
11
|
+
* rate (rounded up).
|
|
9
12
|
*
|
|
10
|
-
* The declared `PricingPolicy.tax.behavior` (absent by default
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
13
|
+
* The declared `PricingPolicy.tax.behavior` (absent by default) is applied by the paygate to a
|
|
14
|
+
* matching price it can still change, and to a fresh one on creation; a price carrying the
|
|
15
|
+
* OPPOSITE behavior is replaced, same as any other mismatch. Each sync stores the product's
|
|
16
|
+
* `prices[]` on its fingerprint row — what `planPrices`, checkout currency forcing and the estimate
|
|
17
|
+
* read. The fingerprint row is keyed by the product sku: one paygate syncs a product's catalogue.
|
|
14
18
|
*/
|
|
15
|
-
|
|
19
|
+
syncProducts: (paygate: Paygate) => Promise<void>;
|
|
16
20
|
/**
|
|
17
21
|
* The prices a product's plans are charged at, per currency, as the last sync stored them — no
|
|
18
|
-
* paygate call, so it works in an unmanaged process. One entry for each
|
|
19
|
-
* (`default: true`) and one per currency
|
|
22
|
+
* paygate call, so it works in an unmanaged process. One entry for each price's default currency
|
|
23
|
+
* (`default: true`) and one per further currency.
|
|
20
24
|
*/
|
|
21
25
|
syncedPlanPrices: (productSku: string) => Promise<PlanPriceView[]>;
|
|
22
|
-
/** `
|
|
26
|
+
/** `syncProducts` for every registered paygate. */
|
|
23
27
|
syncPaymentProducts: () => Promise<void>;
|
|
24
28
|
}
|
|
25
29
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/sync/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/sync/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AACtD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAElD,iFAAiF;AACjF,MAAM,WAAW,iBAAiB;IAChC;;;;;;;;;;;;;OAaG;IACH,YAAY,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;IACjD;;;;OAIG;IACH,gBAAgB,EAAE,CAAC,UAAU,EAAE,MAAM,KAAK,OAAO,CAAC,aAAa,EAAE,CAAC,CAAA;IAClE,mDAAmD;IACnD,mBAAmB,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;CACzC"}
|