@owlmeans/server-payment 0.1.21 → 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
package/build/plugins/portal.js
CHANGED
|
@@ -1,213 +1,62 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { ENTITLING_STATUSES, PortalFlow, PortalUnavailable, ProductError, UnknownPlan } from '@owlmeans/payment';
|
|
1
|
+
import { ENTITLING_STATUSES, INTERNAL_PAYGATE, PortalFlow, PortalUnavailable, UnknownPlan } from '@owlmeans/payment';
|
|
3
2
|
import { memoHelper } from '@owlmeans/context';
|
|
4
|
-
import { FINGERPRINT_PORTAL, STRIPE_DEPLOYMENT_KEY, STRIPE_OWNER_KEY, STRIPE_OWNER_VALUE, STRIPE_PAYGATE_ALIAS, } from '../consts.js';
|
|
5
|
-
import { log } from '../log.js';
|
|
6
3
|
import { paymentAccessOf } from '../access.js';
|
|
7
|
-
import { paymentUtils } from '../utils.js';
|
|
8
4
|
import { catalogueOf } from '../catalogue.js';
|
|
9
5
|
import { planHelper } from '../plan.js';
|
|
6
|
+
import { paygatesOf } from '../paygate/registry.js';
|
|
10
7
|
import { webhookOf } from './webhook-manager.js';
|
|
11
|
-
|
|
12
|
-
const portalFingerprintSku = (owner) => `${FINGERPRINT_PORTAL}:${owner}`;
|
|
13
|
-
/**
|
|
14
|
-
* Whose a configuration is by its metadata: `ours` carries this owner AND this deployment's key;
|
|
15
|
-
* `foreign` is tagged for another deployment or another owner; `unclaimed` names no deployment.
|
|
16
|
-
*/
|
|
17
|
-
const claimOf = (metadata, owner, deployment) => {
|
|
18
|
-
const owned = metadata?.[STRIPE_OWNER_KEY] === STRIPE_OWNER_VALUE;
|
|
19
|
-
const tagged = metadata?.[STRIPE_DEPLOYMENT_KEY];
|
|
20
|
-
if (owned && metadata?.service === owner && tagged === deployment) {
|
|
21
|
-
return 'ours';
|
|
22
|
-
}
|
|
23
|
-
if ((owned && metadata?.service !== owner) || (tagged != null && tagged !== '')) {
|
|
24
|
-
return 'foreign';
|
|
25
|
-
}
|
|
26
|
-
return 'unclaimed';
|
|
27
|
-
};
|
|
8
|
+
import { ENTITLING_SORT } from './consts.local.js';
|
|
28
9
|
export const makePortalHelper = (ctx) => {
|
|
29
10
|
const access = paymentAccessOf(ctx);
|
|
30
|
-
/** The
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
const recurring = plans.filter(plan => plan.recurring != null);
|
|
39
|
-
if (recurring.length === 0) {
|
|
40
|
-
continue;
|
|
41
|
-
}
|
|
42
|
-
result.push({
|
|
43
|
-
product,
|
|
44
|
-
lookupKeys: recurring.map(plan => planHelper.planLookupKey(product, plan)),
|
|
45
|
-
hashable: recurring.map(plan => ({
|
|
46
|
-
sku: plan.sku, price: plan.price, currency: plan.currency ?? 'usd', interval: plan.recurring?.interval,
|
|
47
|
-
rank: planHelper.planRank(plan), behavior,
|
|
48
|
-
// A changed currency option replaces the Price — the portal's price list must follow it.
|
|
49
|
-
...(plan.currencyPrices != null ? { currencyPrices: plan.currencyPrices } : {}),
|
|
50
|
-
})).sort((a, b) => a.sku.localeCompare(b.sku)),
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
return result.sort((a, b) => a.product.sku.localeCompare(b.product.sku));
|
|
54
|
-
};
|
|
55
|
-
const activeRecurringPrices = async (stripe, productSku) => (await stripe.prices.list({ product: productSku, active: true, limit: 100 })).data
|
|
56
|
-
.filter(price => price.recurring != null);
|
|
57
|
-
const listActiveConfigurations = async (stripe) => {
|
|
58
|
-
const configurations = [];
|
|
59
|
-
let startingAfter;
|
|
60
|
-
for (;;) {
|
|
61
|
-
const page = await stripe.billingPortal.configurations.list({
|
|
62
|
-
active: true, limit: 100, ...(startingAfter != null ? { starting_after: startingAfter } : {}),
|
|
63
|
-
});
|
|
64
|
-
configurations.push(...page.data);
|
|
65
|
-
if (!page.has_more || page.data.length === 0) {
|
|
66
|
-
return configurations;
|
|
67
|
-
}
|
|
68
|
-
startingAfter = page.data[page.data.length - 1].id;
|
|
69
|
-
}
|
|
70
|
-
};
|
|
71
|
-
const ensurePortalConfiguration = async (stripe, opts = {}) => {
|
|
72
|
-
const owner = webhookOf(ctx).gatewayOwnerOf();
|
|
73
|
-
const deployment = webhookOf(ctx).webhookUrlOf();
|
|
74
|
-
const sku = portalFingerprintSku(owner);
|
|
75
|
-
const branding = await access.portalBrandingConfig();
|
|
76
|
-
const catalog = await recurringCatalog();
|
|
77
|
-
const rights = await access.payment().consumerRightsPolicy();
|
|
78
|
-
// A locked billing country is never edited in the portal: tax follows the saved address.
|
|
79
|
-
const stripeConfig = await access.stripePricingConfig();
|
|
80
|
-
const countryLock = rights?.mechanisms.countryLock === true;
|
|
81
|
-
// A pinned country and a locked customer e-mail are the application's: never edited in the portal.
|
|
82
|
-
const countryPin = stripeConfig?.lockCustomerCountry === true;
|
|
83
|
-
const emailLock = stripeConfig?.lockCustomerEmail === true;
|
|
84
|
-
const regionCurrencies = Object.values(rights?.currencies ?? {}).filter(code => code != null).sort();
|
|
85
|
-
const hash = createHash('sha256').update(JSON.stringify({
|
|
86
|
-
service: owner,
|
|
87
|
-
deployment,
|
|
88
|
-
...(countryLock ? { countryLock } : {}),
|
|
89
|
-
...(countryPin ? { countryPin } : {}),
|
|
90
|
-
...(emailLock ? { emailLock } : {}),
|
|
91
|
-
...(regionCurrencies.length > 0 ? { regionCurrencies } : {}),
|
|
92
|
-
branding: branding != null ? {
|
|
93
|
-
headline: branding.headline ?? null, privacyPolicyUrl: branding.privacyPolicyUrl ?? null,
|
|
94
|
-
termsOfServiceUrl: branding.termsOfServiceUrl ?? null, returnUrl: branding.returnUrl ?? null,
|
|
95
|
-
} : null,
|
|
96
|
-
products: catalog.map(entry => ({ product: entry.product.sku, plans: entry.hashable })),
|
|
97
|
-
})).digest('hex');
|
|
98
|
-
const stored = await access.fingerprints().bySku(sku);
|
|
99
|
-
if (stored != null && stored.hash === hash && stored.externalId != null && opts.force !== true) {
|
|
100
|
-
return stored.externalId;
|
|
101
|
-
}
|
|
102
|
-
const products = [];
|
|
103
|
-
for (const entry of catalog) {
|
|
104
|
-
const prices = (await activeRecurringPrices(stripe, entry.product.sku)).map(price => price.id);
|
|
105
|
-
if (prices.length > 0) {
|
|
106
|
-
products.push({ product: entry.product.sku, prices });
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
const cancelable = catalog.length > 0;
|
|
110
|
-
const switchable = products.length > 0;
|
|
111
|
-
const metadata = { [STRIPE_OWNER_KEY]: STRIPE_OWNER_VALUE, service: owner, [STRIPE_DEPLOYMENT_KEY]: deployment };
|
|
112
|
-
const allowedUpdates = [
|
|
113
|
-
...(emailLock ? [] : ['email']), ...(countryLock || countryPin ? [] : ['address']), 'tax_id',
|
|
114
|
-
];
|
|
115
|
-
const params = {
|
|
116
|
-
features: {
|
|
117
|
-
customer_update: { enabled: true, allowed_updates: allowedUpdates },
|
|
118
|
-
invoice_history: { enabled: true },
|
|
119
|
-
payment_method_update: { enabled: true },
|
|
120
|
-
subscription_cancel: cancelable
|
|
121
|
-
? { enabled: true, mode: 'at_period_end', proration_behavior: 'none' }
|
|
122
|
-
: { enabled: false },
|
|
123
|
-
subscription_update: switchable
|
|
124
|
-
? {
|
|
125
|
-
enabled: true, default_allowed_updates: ['price'], products,
|
|
126
|
-
proration_behavior: 'create_prorations',
|
|
127
|
-
}
|
|
128
|
-
: { enabled: false },
|
|
129
|
-
},
|
|
130
|
-
...(branding != null ? {
|
|
131
|
-
business_profile: {
|
|
132
|
-
...(branding.headline != null ? { headline: branding.headline } : {}),
|
|
133
|
-
...(branding.privacyPolicyUrl != null ? { privacy_policy_url: branding.privacyPolicyUrl } : {}),
|
|
134
|
-
...(branding.termsOfServiceUrl != null ? { terms_of_service_url: branding.termsOfServiceUrl } : {}),
|
|
135
|
-
},
|
|
136
|
-
default_return_url: branding.returnUrl,
|
|
137
|
-
} : {}),
|
|
138
|
-
metadata,
|
|
11
|
+
/** The entity's highest-ranked entitling subscription of a paygate (any paygate but the internal one), or `null`. */
|
|
12
|
+
const entitlingSubscription = async (entityId, paygate) => await access.subscriptions().load({ entityId, paygate: paygate ?? { $ne: INTERNAL_PAYGATE }, status: [...ENTITLING_STATUSES] }, { sort: [...ENTITLING_SORT] });
|
|
13
|
+
/** The paygate a portal opens on and the entity's live customer there. */
|
|
14
|
+
const customerOf = async (entityId, requested) => {
|
|
15
|
+
const paygates = paygatesOf(ctx);
|
|
16
|
+
const live = async (paygate) => {
|
|
17
|
+
const customer = await access.paygateCustomers().byEntity(entityId, paygate.id);
|
|
18
|
+
return customer != null && customer.deletedAt == null ? customer : null;
|
|
139
19
|
};
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
const current = await stripe.billingPortal.configurations.retrieve(stored.externalId);
|
|
144
|
-
if (claimOf(current.metadata, owner, deployment) !== 'foreign') {
|
|
145
|
-
await stripe.billingPortal.configurations.update(current.id, params);
|
|
146
|
-
configurationId = current.id;
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
catch (error) {
|
|
150
|
-
if (!paymentUtils.isMissingObject(error)) {
|
|
151
|
-
throw error;
|
|
152
|
-
}
|
|
153
|
-
}
|
|
20
|
+
if (requested != null) {
|
|
21
|
+
const paygate = paygates.find(requested);
|
|
22
|
+
return { paygate, customer: paygate != null ? await live(paygate) : null };
|
|
154
23
|
}
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
24
|
+
const subscribed = (await entitlingSubscription(entityId))?.paygate;
|
|
25
|
+
const preferred = subscribed != null ? paygates.find(subscribed) : null;
|
|
26
|
+
for (const paygate of preferred != null ? [preferred, ...paygates.all().filter(item => item !== preferred)] : paygates.all()) {
|
|
27
|
+
const customer = await live(paygate);
|
|
28
|
+
if (customer != null) {
|
|
29
|
+
return { paygate, customer };
|
|
161
30
|
}
|
|
162
|
-
else {
|
|
163
|
-
configurationId = (await stripe.billingPortal.configurations.create(params)).id;
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
const now = new Date();
|
|
167
|
-
if (stored != null) {
|
|
168
|
-
await access.fingerprints().update({ ...stored, hash, externalId: configurationId, updatedAt: now });
|
|
169
|
-
}
|
|
170
|
-
else {
|
|
171
|
-
await access.fingerprints().create({ sku, hash, externalId: configurationId, updatedAt: now });
|
|
172
31
|
}
|
|
173
|
-
return
|
|
32
|
+
return { paygate: preferred, customer: null };
|
|
174
33
|
};
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
const customer = await access.paygateCustomers().byEntity(entityId, STRIPE_PAYGATE_ALIAS);
|
|
179
|
-
if (customer == null || customer.deletedAt != null) {
|
|
34
|
+
const createPortalLink = async (entityId, opts) => {
|
|
35
|
+
const { paygate, customer } = await customerOf(entityId, opts.paygate);
|
|
36
|
+
if (paygate == null || customer == null) {
|
|
180
37
|
throw new PortalUnavailable('customer');
|
|
181
38
|
}
|
|
182
|
-
const
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
await ensurePortalConfiguration(stripe).catch(error => {
|
|
186
|
-
log.error('Portal configuration unavailable', error);
|
|
187
|
-
});
|
|
188
|
-
configuration = (await access.fingerprints().bySku(sku))?.externalId ?? null;
|
|
39
|
+
const portal = paygate.portal;
|
|
40
|
+
if (portal == null) {
|
|
41
|
+
throw new PortalUnavailable('paygate');
|
|
189
42
|
}
|
|
190
|
-
|
|
43
|
+
const input = {
|
|
44
|
+
customerId: customer.externalId, flow: opts.flow, returnUrl: opts.returnUrl,
|
|
45
|
+
owner: webhookOf(ctx).gatewayOwnerOf(), deployment: () => webhookOf(ctx).deploymentOf(paygate.id),
|
|
46
|
+
};
|
|
191
47
|
switch (opts.flow) {
|
|
192
48
|
case PortalFlow.Manage:
|
|
193
|
-
break;
|
|
194
49
|
case PortalFlow.PaymentMethod:
|
|
195
|
-
flowData = { type: 'payment_method_update' };
|
|
196
50
|
break;
|
|
197
51
|
case PortalFlow.Cancel:
|
|
198
52
|
case PortalFlow.Update:
|
|
199
53
|
case PortalFlow.Change: {
|
|
200
|
-
const subscription = await
|
|
54
|
+
const subscription = await entitlingSubscription(entityId, paygate.id);
|
|
201
55
|
if (subscription == null) {
|
|
202
56
|
throw new PortalUnavailable('subscription');
|
|
203
57
|
}
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
}
|
|
207
|
-
else if (opts.flow === PortalFlow.Update) {
|
|
208
|
-
flowData = { type: 'subscription_update', subscription_update: { subscription: subscription.externalId } };
|
|
209
|
-
}
|
|
210
|
-
else {
|
|
58
|
+
input.subscriptionId = subscription.externalId;
|
|
59
|
+
if (opts.flow === PortalFlow.Change) {
|
|
211
60
|
if (opts.planSku == null || opts.planSku === '') {
|
|
212
61
|
throw new PortalUnavailable('plan');
|
|
213
62
|
}
|
|
@@ -219,36 +68,17 @@ export const makePortalHelper = (ctx) => {
|
|
|
219
68
|
if (subscription.itemId == null) {
|
|
220
69
|
throw new PortalUnavailable('item');
|
|
221
70
|
}
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
if (price == null) {
|
|
225
|
-
throw new ProductError(`price:${lookupKey}`);
|
|
226
|
-
}
|
|
227
|
-
flowData = {
|
|
228
|
-
type: 'subscription_update_confirm',
|
|
229
|
-
subscription_update_confirm: {
|
|
230
|
-
subscription: subscription.externalId,
|
|
231
|
-
items: [{ id: subscription.itemId, price: price.id, quantity: 1 }],
|
|
232
|
-
},
|
|
233
|
-
};
|
|
71
|
+
input.itemId = subscription.itemId;
|
|
72
|
+
input.lookupKey = planHelper.planLookupKey(product, plan);
|
|
234
73
|
}
|
|
235
74
|
break;
|
|
236
75
|
}
|
|
237
76
|
default:
|
|
238
77
|
throw new PortalUnavailable(`flow:${String(opts.flow)}`);
|
|
239
78
|
}
|
|
240
|
-
|
|
241
|
-
flowData.after_completion = { type: 'redirect', redirect: { return_url: opts.returnUrl } };
|
|
242
|
-
}
|
|
243
|
-
const session = await stripe.billingPortal.sessions.create({
|
|
244
|
-
customer: customer.externalId,
|
|
245
|
-
return_url: opts.returnUrl,
|
|
246
|
-
...(configuration != null ? { configuration } : {}),
|
|
247
|
-
...(flowData != null ? { flow_data: flowData } : {}),
|
|
248
|
-
});
|
|
249
|
-
return session.url;
|
|
79
|
+
return await portal.createSession(input);
|
|
250
80
|
};
|
|
251
|
-
return {
|
|
81
|
+
return { createPortalLink };
|
|
252
82
|
};
|
|
253
83
|
/** The customer portal of a context — one per context. */
|
|
254
84
|
export const portalOf = memoHelper.oncePer(makePortalHelper);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"portal.js","sourceRoot":"","sources":["../../src/plugins/portal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAExC,OAAO,EAAE,kBAAkB,EAAE,UAAU,EAAE,iBAAiB,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAEhH,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAC9C,OAAO,EACL,kBAAkB,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,oBAAoB,GACtG,MAAM,cAAc,CAAA;AAErB,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAA;AAG/B,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAC9C,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAC1C,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,CAAC,IAAI,CAAA;oBACzF,IAAI,IAAI,IAAI,IAAI,IAAI,OAAO,IAAI,IAAI,EAAE,CAAC;wBACpC,MAAM,IAAI,WAAW,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;oBACrC,CAAC;oBACD,IAAI,YAAY,CAAC,MAAM,IAAI,IAAI,EAAE,CAAC;wBAChC,MAAM,IAAI,iBAAiB,CAAC,MAAM,CAAC,CAAA;oBACrC,CAAC;oBACD,KAAK,CAAC,MAAM,GAAG,YAAY,CAAC,MAAM,CAAA;oBAClC,KAAK,CAAC,SAAS,GAAG,UAAU,CAAC,aAAa,CAAC,OAAO,EAAE,IAAI,CAAC,CAAA;gBAC3D,CAAC;gBACD,MAAK;YACP,CAAC;YACD;gBACE,MAAM,IAAI,iBAAiB,CAAC,QAAQ,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;QAC5D,CAAC;QAED,OAAO,MAAM,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,CAAA;IAC1C,CAAC,CAAA;IAED,OAAO,EAAE,gBAAgB,EAAE,CAAA;AAC7B,CAAC,CAAA;AAED,0DAA0D;AAC1D,MAAM,CAAC,MAAM,QAAQ,GAAG,UAAU,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAAA"}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import type Stripe from 'stripe';
|
|
2
1
|
import type { PaymentFulfillmentRecord, PaymentSubscriptionRecord } from '../../types.js';
|
|
2
|
+
import type { Paygate, PaygateCharge } from '../../paygate/types.js';
|
|
3
3
|
/** What a refund or a dispute is about: a one-time fulfillment, or one invoice of a subscription. */
|
|
4
4
|
export type PaymentTarget = {
|
|
5
5
|
kind: 'fulfillment';
|
|
6
6
|
record: PaymentFulfillmentRecord;
|
|
7
|
-
charge:
|
|
7
|
+
charge: PaygateCharge | null;
|
|
8
8
|
paymentIntentId?: string;
|
|
9
9
|
} | {
|
|
10
10
|
kind: 'subscription';
|
|
11
11
|
record: PaymentSubscriptionRecord;
|
|
12
|
-
charge:
|
|
12
|
+
charge: PaygateCharge | null;
|
|
13
13
|
paymentIntentId?: string;
|
|
14
14
|
invoiceId: string;
|
|
15
15
|
};
|
|
@@ -18,18 +18,18 @@ export interface PaymentReference {
|
|
|
18
18
|
chargeId?: string;
|
|
19
19
|
invoiceId?: string;
|
|
20
20
|
/** The charge, when the event already carries it. */
|
|
21
|
-
charge?:
|
|
21
|
+
charge?: PaygateCharge | null;
|
|
22
22
|
}
|
|
23
23
|
/** What a refund or a dispute of a context is about. */
|
|
24
24
|
export interface PaymentTargetHelper {
|
|
25
|
-
/** A charge by id, or `null` when the paygate has none. */
|
|
26
|
-
retrieveCharge: (
|
|
25
|
+
/** A charge by id, or `null` when the paygate has none (or reads no payments). */
|
|
26
|
+
retrieveCharge: (paygate: Paygate, chargeId: string) => Promise<PaygateCharge | null>;
|
|
27
27
|
/**
|
|
28
|
-
* Resolve a refund or a dispute to the record it is about: by payment
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
28
|
+
* Resolve a refund or a dispute to the record it is about: by payment to a fulfillment; by charge
|
|
29
|
+
* to a fulfillment (stored charge, else the charge's payment — whose charge id is then remembered),
|
|
30
|
+
* else the charge's invoice; by invoice to the subscription whose latest invoice it is, else the
|
|
31
|
+
* invoice's subscription. `null` when nothing here paid for it.
|
|
32
32
|
*/
|
|
33
|
-
resolvePaymentTarget: (
|
|
33
|
+
resolvePaymentTarget: (paygate: Paygate, ref: PaymentReference) => Promise<PaymentTarget | null>;
|
|
34
34
|
}
|
|
35
35
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/plugins/refunds/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/plugins/refunds/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,yBAAyB,EAAE,MAAM,gBAAgB,CAAA;AACzF,OAAO,KAAK,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAA;AAEpE,qGAAqG;AACrG,MAAM,MAAM,aAAa,GACrB;IAAE,IAAI,EAAE,aAAa,CAAC;IAAC,MAAM,EAAE,wBAAwB,CAAC;IAAC,MAAM,EAAE,aAAa,GAAG,IAAI,CAAC;IAAC,eAAe,CAAC,EAAE,MAAM,CAAA;CAAE,GACjH;IACA,IAAI,EAAE,cAAc,CAAC;IAAC,MAAM,EAAE,yBAAyB,CAAC;IAAC,MAAM,EAAE,aAAa,GAAG,IAAI,CAAC;IACtF,eAAe,CAAC,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;CAC7C,CAAA;AAEH,MAAM,WAAW,gBAAgB;IAC/B,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,qDAAqD;IACrD,MAAM,CAAC,EAAE,aAAa,GAAG,IAAI,CAAA;CAC9B;AAED,wDAAwD;AACxD,MAAM,WAAW,mBAAmB;IAClC,kFAAkF;IAClF,cAAc,EAAE,CAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC,aAAa,GAAG,IAAI,CAAC,CAAA;IACrF;;;;;OAKG;IACH,oBAAoB,EAAE,CAAC,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,gBAAgB,KAAK,OAAO,CAAC,aAAa,GAAG,IAAI,CAAC,CAAA;CACjG"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"refunds.d.ts","sourceRoot":"","sources":["../../src/plugins/refunds.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"refunds.d.ts","sourceRoot":"","sources":["../../src/plugins/refunds.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,sBAAsB,CAAA;AAIjE,OAAO,KAAK,EAAmC,mBAAmB,EAAE,MAAM,oBAAoB,CAAA;AAG9F,eAAO,MAAM,uBAAuB,QAAS,UAAU,KAAG,mBA4DzD,CAAA;AAED,qEAAqE;AACrE,eAAO,MAAM,eAAe,oFAA8C,CAAA"}
|
package/build/plugins/refunds.js
CHANGED
|
@@ -1,73 +1,48 @@
|
|
|
1
1
|
import { memoHelper } from '@owlmeans/context';
|
|
2
|
-
import { STRIPE_PAYGATE_ALIAS } from '../consts.js';
|
|
3
2
|
import { paymentAccessOf } from '../access.js';
|
|
4
|
-
import { paymentUtils } from '../utils.js';
|
|
5
3
|
export const makePaymentTargetHelper = (ctx) => {
|
|
6
4
|
const access = paymentAccessOf(ctx);
|
|
7
|
-
const retrieveCharge = async (
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
11
|
-
catch (error) {
|
|
12
|
-
if (paymentUtils.isMissingObject(error)) {
|
|
13
|
-
return null;
|
|
14
|
-
}
|
|
15
|
-
throw error;
|
|
16
|
-
}
|
|
17
|
-
};
|
|
18
|
-
const subscriptionOfInvoice = async (stripe, invoiceId) => {
|
|
19
|
-
const latest = await access.subscriptions().load({ paygate: STRIPE_PAYGATE_ALIAS, latestInvoiceId: invoiceId });
|
|
5
|
+
const retrieveCharge = async (paygate, chargeId) => paygate.payments != null ? await paygate.payments.charge(chargeId) : null;
|
|
6
|
+
const subscriptionOfInvoice = async (paygate, invoiceId) => {
|
|
7
|
+
const latest = await access.subscriptions().load({ paygate: paygate.id, latestInvoiceId: invoiceId });
|
|
20
8
|
if (latest != null) {
|
|
21
9
|
return latest;
|
|
22
10
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
catch (error) {
|
|
28
|
-
if (paymentUtils.isMissingObject(error)) {
|
|
29
|
-
return null;
|
|
30
|
-
}
|
|
31
|
-
throw error;
|
|
32
|
-
}
|
|
33
|
-
// `invoice.subscription` is top-level on the API version the client is pinned to.
|
|
34
|
-
const subscriptionId = paymentUtils.idOf(invoice.subscription);
|
|
35
|
-
return subscriptionId != null
|
|
36
|
-
? await access.subscriptions().byExternalId(subscriptionId, STRIPE_PAYGATE_ALIAS)
|
|
37
|
-
: null;
|
|
11
|
+
const invoice = paygate.payments != null ? await paygate.payments.invoice(invoiceId) : null;
|
|
12
|
+
const subscriptionId = invoice?.subscriptionId;
|
|
13
|
+
return subscriptionId != null ? await access.subscriptions().byExternalId(subscriptionId, paygate.id) : null;
|
|
38
14
|
};
|
|
39
|
-
const resolvePaymentTarget = async (
|
|
15
|
+
const resolvePaymentTarget = async (paygate, ref) => {
|
|
40
16
|
const ledger = access.fulfillments();
|
|
41
17
|
let charge = ref.charge ?? null;
|
|
42
18
|
let paymentIntentId = ref.paymentIntentId;
|
|
43
19
|
const chargeId = ref.chargeId ?? charge?.id;
|
|
44
20
|
if (paymentIntentId != null) {
|
|
45
|
-
const record = await ledger.load({ paygate:
|
|
21
|
+
const record = await ledger.load({ paygate: paygate.id, paymentIntentId });
|
|
46
22
|
if (record != null) {
|
|
47
23
|
return { kind: 'fulfillment', record, charge, paymentIntentId };
|
|
48
24
|
}
|
|
49
25
|
}
|
|
50
26
|
let invoiceId = ref.invoiceId;
|
|
51
27
|
if (chargeId != null) {
|
|
52
|
-
const record = await ledger.load({ paygate:
|
|
28
|
+
const record = await ledger.load({ paygate: paygate.id, chargeId });
|
|
53
29
|
if (record != null) {
|
|
54
30
|
return { kind: 'fulfillment', record, charge, paymentIntentId: paymentIntentId ?? record.paymentIntentId };
|
|
55
31
|
}
|
|
56
|
-
charge = charge ?? await retrieveCharge(
|
|
57
|
-
const chargeIntent =
|
|
32
|
+
charge = charge ?? await retrieveCharge(paygate, chargeId);
|
|
33
|
+
const chargeIntent = charge?.paymentId;
|
|
58
34
|
if (chargeIntent != null && chargeIntent !== paymentIntentId) {
|
|
59
35
|
paymentIntentId = chargeIntent;
|
|
60
|
-
const byIntent = await ledger.load({ paygate:
|
|
36
|
+
const byIntent = await ledger.load({ paygate: paygate.id, paymentIntentId: chargeIntent });
|
|
61
37
|
if (byIntent != null) {
|
|
62
38
|
const record = byIntent.chargeId == null ? await ledger.update({ ...byIntent, chargeId }) : byIntent;
|
|
63
39
|
return { kind: 'fulfillment', record, charge, paymentIntentId: chargeIntent };
|
|
64
40
|
}
|
|
65
41
|
}
|
|
66
|
-
|
|
67
|
-
invoiceId = invoiceId ?? paymentUtils.idOf(charge?.invoice);
|
|
42
|
+
invoiceId = invoiceId ?? charge?.invoiceId;
|
|
68
43
|
}
|
|
69
44
|
if (invoiceId != null) {
|
|
70
|
-
const record = await subscriptionOfInvoice(
|
|
45
|
+
const record = await subscriptionOfInvoice(paygate, invoiceId);
|
|
71
46
|
if (record != null) {
|
|
72
47
|
return { kind: 'subscription', record, charge, paymentIntentId, invoiceId };
|
|
73
48
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"refunds.js","sourceRoot":"","sources":["../../src/plugins/refunds.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"refunds.js","sourceRoot":"","sources":["../../src/plugins/refunds.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAI9C,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAE9C,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,GAAe,EAAuB,EAAE;IAC9E,MAAM,MAAM,GAAG,eAAe,CAAC,GAAG,CAAC,CAAA;IAEnC,MAAM,cAAc,GAAG,KAAK,EAAE,OAAgB,EAAE,QAAgB,EAAiC,EAAE,CACjG,OAAO,CAAC,QAAQ,IAAI,IAAI,CAAC,CAAC,CAAC,MAAM,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,IAAI,CAAA;IAE3E,MAAM,qBAAqB,GAAG,KAAK,EAA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,IAAI,IAAI,EAAE,CAAC;YACtB,MAAM,MAAM,GAAG,MAAM,qBAAqB,CAAC,OAAO,EAAE,SAAS,CAAC,CAAA;YAC9D,IAAI,MAAM,IAAI,IAAI,EAAE,CAAC;gBACnB,OAAO,EAAE,IAAI,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,EAAE,eAAe,EAAE,SAAS,EAAE,CAAA;YAC7E,CAAC;QACH,CAAC;QAED,OAAO,IAAI,CAAA;IACb,CAAC,CAAA;IAED,OAAO,EAAE,cAAc,EAAE,oBAAoB,EAAE,CAAA;AACjD,CAAC,CAAA;AAED,qEAAqE;AACrE,MAAM,CAAC,MAAM,eAAe,GAAG,UAAU,CAAC,OAAO,CAAC,uBAAuB,CAAC,CAAA"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { CheckoutSnapshot } from '../../paygate/types.js';
|
|
2
|
+
/** What a completed checkout session alone decides — pure. */
|
|
3
|
+
export interface CheckoutSnapshotHelper {
|
|
4
|
+
/**
|
|
5
|
+
* Whether a one-time checkout is fulfilled: a paid payment (a zero total only outside amount mode),
|
|
6
|
+
* or a completed amount checkout fully covered by promotion codes — a positive subtotal discounted
|
|
7
|
+
* to a zero total with no tax, the codes enabled on the session.
|
|
8
|
+
*/
|
|
9
|
+
canFulfill: (session: CheckoutSnapshot) => boolean;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/plugins/snapshot/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAA;AAE9D,8DAA8D;AAC9D,MAAM,WAAW,sBAAsB;IACrC;;;;OAIG;IACH,UAAU,EAAE,CAAC,OAAO,EAAE,gBAAgB,KAAK,OAAO,CAAA;CACnD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/plugins/snapshot/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"snapshot.d.ts","sourceRoot":"","sources":["../../src/plugins/snapshot.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAA;AAEjE,eAAO,MAAM,4BAA4B,QAAO,sBAe/C,CAAA;AAED,eAAO,MAAM,sBAAsB,wBAAiC,CAAA"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { CheckoutPricingMode } from '@owlmeans/payment';
|
|
2
|
+
export const createCheckoutSnapshotHelper = () => {
|
|
3
|
+
const canFulfill = (session) => {
|
|
4
|
+
if (session.mode !== 'payment')
|
|
5
|
+
return false;
|
|
6
|
+
if (session.payment === 'paid'
|
|
7
|
+
&& (session.amountTotalMinor !== 0 || session.metadata.pricingMode !== CheckoutPricingMode.Amount))
|
|
8
|
+
return true;
|
|
9
|
+
return (session.payment === 'not-required' || session.payment === 'paid')
|
|
10
|
+
&& session.status === 'complete' && session.metadata.pricingMode === CheckoutPricingMode.Amount
|
|
11
|
+
&& session.promotionCodes && session.amountTotalMinor === 0
|
|
12
|
+
&& Number.isSafeInteger(session.amountSubtotalMinor) && (session.amountSubtotalMinor ?? 0) > 0
|
|
13
|
+
&& session.amountDiscountMinor === session.amountSubtotalMinor
|
|
14
|
+
&& session.amountTaxMinor === 0;
|
|
15
|
+
};
|
|
16
|
+
return { canFulfill };
|
|
17
|
+
};
|
|
18
|
+
export const checkoutSnapshotHelper = createCheckoutSnapshotHelper();
|
|
19
|
+
//# sourceMappingURL=snapshot.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"snapshot.js","sourceRoot":"","sources":["../../src/plugins/snapshot.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAA;AAIvD,MAAM,CAAC,MAAM,4BAA4B,GAAG,GAA2B,EAAE;IACvE,MAAM,UAAU,GAAG,CAAC,OAAyB,EAAW,EAAE;QACxD,IAAI,OAAO,CAAC,IAAI,KAAK,SAAS;YAAE,OAAO,KAAK,CAAA;QAC5C,IAAI,OAAO,CAAC,OAAO,KAAK,MAAM;eACzB,CAAC,OAAO,CAAC,gBAAgB,KAAK,CAAC,IAAI,OAAO,CAAC,QAAQ,CAAC,WAAW,KAAK,mBAAmB,CAAC,MAAM,CAAC;YAAE,OAAO,IAAI,CAAA;QAEjH,OAAO,CAAC,OAAO,CAAC,OAAO,KAAK,cAAc,IAAI,OAAO,CAAC,OAAO,KAAK,MAAM,CAAC;eACpE,OAAO,CAAC,MAAM,KAAK,UAAU,IAAI,OAAO,CAAC,QAAQ,CAAC,WAAW,KAAK,mBAAmB,CAAC,MAAM;eAC5F,OAAO,CAAC,cAAc,IAAI,OAAO,CAAC,gBAAgB,KAAK,CAAC;eACxD,MAAM,CAAC,aAAa,CAAC,OAAO,CAAC,mBAAmB,CAAC,IAAI,CAAC,OAAO,CAAC,mBAAmB,IAAI,CAAC,CAAC,GAAG,CAAC;eAC3F,OAAO,CAAC,mBAAmB,KAAK,OAAO,CAAC,mBAAmB;eAC3D,OAAO,CAAC,cAAc,KAAK,CAAC,CAAA;IACnC,CAAC,CAAA;IAED,OAAO,EAAE,UAAU,EAAE,CAAA;AACvB,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,sBAAsB,GAAG,4BAA4B,EAAE,CAAA"}
|
|
@@ -1,39 +1,39 @@
|
|
|
1
|
-
import type Stripe from 'stripe';
|
|
2
1
|
import type { SubscriptionStatus } from '@owlmeans/payment';
|
|
3
2
|
import type { CommitResult, SubscriptionRef } from '../../types.js';
|
|
3
|
+
import type { Paygate, PaygateSubscription } from '../../paygate/types.js';
|
|
4
4
|
export interface ApplyOptions {
|
|
5
5
|
source: 'webhook' | 'resync';
|
|
6
6
|
eventId?: string;
|
|
7
|
-
/**
|
|
8
|
-
eventCreated?:
|
|
7
|
+
/** When the paygate produced the event; an older payload than the stored state is skipped. */
|
|
8
|
+
eventCreated?: Date;
|
|
9
9
|
renewal?: boolean;
|
|
10
10
|
invoiceId?: string;
|
|
11
11
|
trialEnding?: boolean;
|
|
12
12
|
/** Store this status whatever the payload says (a deleted subscription is canceled). */
|
|
13
13
|
forced?: SubscriptionStatus;
|
|
14
|
-
/** The paygate client — lets the first commit read the first invoice for its purchase row. */
|
|
15
|
-
stripe?: Stripe;
|
|
16
14
|
}
|
|
17
|
-
/**
|
|
18
|
-
export interface
|
|
15
|
+
/** Paygate subscriptions applied to a context's subscription rows. */
|
|
16
|
+
export interface PaygateSubscriptionsHelper {
|
|
19
17
|
/**
|
|
20
|
-
* Apply one
|
|
21
|
-
* tell observers what changed. Shared by every webhook and by resync.
|
|
18
|
+
* Apply one paygate subscription — from a webhook payload or a fresh retrieval — to its row, and
|
|
19
|
+
* tell observers what changed. Shared by every webhook and by resync. The first commit of a
|
|
20
|
+
* subscription writes its purchase before the `created` observers hear it.
|
|
22
21
|
*/
|
|
23
|
-
applySubscription: (subscription:
|
|
24
|
-
/** A subscription by id, or `null` when
|
|
25
|
-
retrieveSubscription: (
|
|
22
|
+
applySubscription: (paygate: Paygate, subscription: PaygateSubscription, opts: ApplyOptions) => Promise<CommitResult>;
|
|
23
|
+
/** A subscription by id, or `null` when the paygate no longer has it (or keeps no subscriptions). */
|
|
24
|
+
retrieveSubscription: (paygate: Paygate, id: string) => Promise<PaygateSubscription | null>;
|
|
26
25
|
/** A row whose paygate subscription no longer exists is canceled (observers hear `canceled`). */
|
|
27
|
-
cancelMissing: (externalId: string) => Promise<CommitResult>;
|
|
26
|
+
cancelMissing: (paygate: Paygate, externalId: string) => Promise<CommitResult>;
|
|
28
27
|
/**
|
|
29
|
-
* Re-read paygate subscriptions — one by id, or every row of one entity — and apply each as
|
|
30
|
-
* webhook would. A subscription the paygate no longer has is canceled
|
|
28
|
+
* Re-read paygate subscriptions — one by id, or every paygate row of one entity — and apply each as
|
|
29
|
+
* a webhook would. A subscription the paygate no longer has is canceled; a row of a paygate that is
|
|
30
|
+
* not registered, or keeps no subscriptions, is skipped.
|
|
31
31
|
*
|
|
32
32
|
* @returns how many rows changed
|
|
33
33
|
*/
|
|
34
|
-
|
|
34
|
+
resyncSubscription: (ref: SubscriptionRef) => Promise<number>;
|
|
35
35
|
/** Resync every paygate subscription that is not already terminal. Errors per row are logged. */
|
|
36
|
-
|
|
36
|
+
resyncAll: () => Promise<{
|
|
37
37
|
scanned: number;
|
|
38
38
|
updated: number;
|
|
39
39
|
}>;
|