@adonis-agora/payments 0.6.0 → 0.7.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/CHANGELOG.md +85 -0
- package/dist/commands/main.d.ts +4 -3
- package/dist/commands/main.d.ts.map +1 -1
- package/dist/commands/main.js +3 -1
- package/dist/commands/main.js.map +1 -1
- package/dist/commands/payments_renew.d.ts +33 -0
- package/dist/commands/payments_renew.d.ts.map +1 -0
- package/dist/commands/payments_renew.js +77 -0
- package/dist/commands/payments_renew.js.map +1 -0
- package/dist/providers/payments_provider.d.ts.map +1 -1
- package/dist/providers/payments_provider.js +6 -1
- package/dist/providers/payments_provider.js.map +1 -1
- package/dist/src/billing/billing_store.d.ts +50 -1
- package/dist/src/billing/billing_store.d.ts.map +1 -1
- package/dist/src/billing/billing_store.js.map +1 -1
- package/dist/src/billing/lucid_billing_store.d.ts +5 -1
- package/dist/src/billing/lucid_billing_store.d.ts.map +1 -1
- package/dist/src/billing/lucid_billing_store.js +72 -0
- package/dist/src/billing/lucid_billing_store.js.map +1 -1
- package/dist/src/billing/managed_subscriptions.d.ts +91 -0
- package/dist/src/billing/managed_subscriptions.d.ts.map +1 -0
- package/dist/src/billing/managed_subscriptions.js +208 -0
- package/dist/src/billing/managed_subscriptions.js.map +1 -0
- package/dist/src/billing/mixins/with_subscription.d.ts +41 -2
- package/dist/src/billing/mixins/with_subscription.d.ts.map +1 -1
- package/dist/src/billing/mixins/with_subscription.js +33 -0
- package/dist/src/billing/mixins/with_subscription.js.map +1 -1
- package/dist/src/billing/schema.d.ts.map +1 -1
- package/dist/src/billing/schema.js +23 -0
- package/dist/src/billing/schema.js.map +1 -1
- package/dist/src/define_config.d.ts +12 -0
- package/dist/src/define_config.d.ts.map +1 -1
- package/dist/src/define_config.js.map +1 -1
- package/dist/src/driver.d.ts +40 -0
- package/dist/src/driver.d.ts.map +1 -1
- package/dist/src/drivers/woovi.d.ts +41 -5
- package/dist/src/drivers/woovi.d.ts.map +1 -1
- package/dist/src/drivers/woovi.js +137 -9
- package/dist/src/drivers/woovi.js.map +1 -1
- package/dist/src/index.d.ts +8 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +4 -0
- package/dist/src/index.js.map +1 -1
- package/dist/src/payments_manager.d.ts +31 -0
- package/dist/src/payments_manager.d.ts.map +1 -1
- package/dist/src/payments_manager.js +46 -0
- package/dist/src/payments_manager.js.map +1 -1
- package/dist/src/subscription_lifecycle.d.ts +21 -0
- package/dist/src/subscription_lifecycle.d.ts.map +1 -0
- package/dist/src/subscription_lifecycle.js +22 -0
- package/dist/src/subscription_lifecycle.js.map +1 -0
- package/dist/src/subscription_mode.d.ts +32 -0
- package/dist/src/subscription_mode.d.ts.map +1 -0
- package/dist/src/subscription_mode.js +13 -0
- package/dist/src/subscription_mode.js.map +1 -0
- package/dist/src/subscriptions_api.d.ts +93 -0
- package/dist/src/subscriptions_api.d.ts.map +1 -0
- package/dist/src/subscriptions_api.js +102 -0
- package/dist/src/subscriptions_api.js.map +1 -0
- package/dist/src/testing/in_memory_billing_store.d.ts +19 -2
- package/dist/src/testing/in_memory_billing_store.d.ts.map +1 -1
- package/dist/src/testing/in_memory_billing_store.js +77 -0
- package/dist/src/testing/in_memory_billing_store.js.map +1 -1
- package/package.json +1 -1
package/dist/src/index.d.ts
CHANGED
|
@@ -8,6 +8,8 @@ export { withBillable, withPayment, withSubscription, } from './billing/index.js
|
|
|
8
8
|
export { BILLING_LIST_DEFAULT_LIMIT, BILLING_LIST_MAX_LIMIT, } from './billing/list_query.js';
|
|
9
9
|
export type { BillingModels } from './billing/lucid_billing_store.js';
|
|
10
10
|
export { LucidBillingStore, lucidBillingStore } from './billing/lucid_billing_store.js';
|
|
11
|
+
export type { ManagedCycle, RenewalOutcome } from './billing/managed_subscriptions.js';
|
|
12
|
+
export { advancePeriod, cancelManagedSubscription, createManagedSubscription, cycleIdempotencyKey, renewDueManagedSubscriptions, updateManagedSubscription, } from './billing/managed_subscriptions.js';
|
|
11
13
|
export type { MeteredBill, MeteredBillLine, MeterRate } from './billing/metered_bill.js';
|
|
12
14
|
export { meteredBill, meteredBillForSubscription } from './billing/metered_bill.js';
|
|
13
15
|
export { BillingAuditEvent } from './billing/mixins/with_audit_event.js';
|
|
@@ -51,6 +53,12 @@ export { InvoiceManager, resolveInvoiceProviders } from './invoice/invoice_manag
|
|
|
51
53
|
export type { InvoiceEmitInput, InvoiceProvider } from './invoice/invoice_provider.js';
|
|
52
54
|
export { currencyExponent, formatDecimal, fromDecimal, toDecimal } from './money.js';
|
|
53
55
|
export { PaymentsManager, resolveDrivers } from './payments_manager.js';
|
|
56
|
+
export type { ResolvedSubscriptionLifecycle, SubscriptionOperation, } from './subscription_lifecycle.js';
|
|
57
|
+
export { gatewayPerforms, gatewaySubscriptionLifecycle, } from './subscription_lifecycle.js';
|
|
58
|
+
export type { SubscriptionMode, SubscriptionsConfig } from './subscription_mode.js';
|
|
59
|
+
export { resolveSubscriptionMode } from './subscription_mode.js';
|
|
60
|
+
export type { CreateSubscriptionRequest, SubscriptionHandle } from './subscriptions_api.js';
|
|
61
|
+
export { SubscriptionsApi } from './subscriptions_api.js';
|
|
54
62
|
export type { BillingStatus, CheckoutSession, Currency, Customer, Dispute, DisputeDocument, DisputeDocumentKind, DisputeEvidence, DisputeStatus, Invoice, InvoiceOptions, Money, MoneyAmount, Payment, PaymentMethodName, PaymentMethodType, PriorUndisputedPayment, Refund, Subscription, SubscriptionStatus, TokenizedCard, WebhookEvent, } from './types.js';
|
|
55
63
|
export type { DiscoveredWebhookHandler, TypedWebhookHandler, WebhookEventDataFor, WebhookEventDataMap, WebhookEventFor, WebhookHandlerDefinition, WebhookHandlerModule, WebhookHandlerRegistration, WebhookHandlerService, WebhookHandlersBarrel, } from './webhook_handlers.js';
|
|
56
64
|
export { assertWebhookHandlerTypes, defineWebhookHandler, discoverWebhookHandlers, isWebhookHandlerService, loadWebhookHandlersFromBarrel, normalizeWebhookHandlerModule, pickModuleExt, resolveWebhookHandler, } from './webhook_handlers.js';
|
package/dist/src/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,aAAa,EACb,kBAAkB,EAClB,oBAAoB,GACrB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC5D,YAAY,EAAE,eAAe,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AAC5F,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAChE,YAAY,EACV,oBAAoB,EACpB,kBAAkB,EAClB,eAAe,EACf,iBAAiB,EACjB,gBAAgB,EAChB,YAAY,EACZ,gBAAgB,EAChB,iBAAiB,EACjB,oBAAoB,EACpB,eAAe,EACf,gBAAgB,EAChB,eAAe,EACf,gBAAgB,EAChB,oBAAoB,EACpB,yBAAyB,EACzB,oBAAoB,EACpB,qBAAqB,GACtB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,aAAa,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAClF,OAAO,EACL,YAAY,EACZ,WAAW,EACX,gBAAgB,GACjB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,0BAA0B,EAC1B,sBAAsB,GACvB,MAAM,yBAAyB,CAAC;AACjC,YAAY,EAAE,aAAa,EAAE,MAAM,kCAAkC,CAAC;AACtE,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AACxF,YAAY,EAAE,WAAW,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AACzF,OAAO,EAAE,WAAW,EAAE,0BAA0B,EAAE,MAAM,2BAA2B,CAAC;AACpF,OAAO,EAAE,iBAAiB,EAAE,MAAM,sCAAsC,CAAC;AACzE,OAAO,EAAE,eAAe,EAAE,MAAM,mCAA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EAAE,MAAM,8BAA8B,CAAC;AACvF,YAAY,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AACvF,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACrF,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACxE,YAAY,EACV,aAAa,EACb,eAAe,EACf,QAAQ,EACR,QAAQ,EACR,OAAO,EACP,eAAe,EACf,mBAAmB,EACnB,eAAe,EACf,aAAa,EACb,OAAO,EACP,cAAc,EACd,KAAK,EACL,WAAW,EACX,OAAO,EACP,iBAAiB,EACjB,iBAAiB,EACjB,sBAAsB,EACtB,MAAM,EACN,YAAY,EACZ,kBAAkB,EAClB,aAAa,EACb,YAAY,GACb,MAAM,YAAY,CAAC;AACpB,YAAY,EACV,wBAAwB,EACxB,mBAAmB,EACnB,mBAAmB,EACnB,mBAAmB,EACnB,eAAe,EACf,wBAAwB,EACxB,oBAAoB,EACpB,0BAA0B,EAC1B,qBAAqB,EACrB,qBAAqB,GACtB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,yBAAyB,EACzB,oBAAoB,EACpB,uBAAuB,EACvB,uBAAuB,EACvB,6BAA6B,EAC7B,6BAA6B,EAC7B,aAAa,EACb,qBAAqB,GACtB,MAAM,uBAAuB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,aAAa,EACb,kBAAkB,EAClB,oBAAoB,GACrB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC5D,YAAY,EAAE,eAAe,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AAC5F,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAChE,YAAY,EACV,oBAAoB,EACpB,kBAAkB,EACl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AA6B,EAC7B,qBAAqB,GACtB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EACL,eAAe,EACf,4BAA4B,GAC7B,MAAM,6BAA6B,CAAC;AACrC,YAAY,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AACpF,OAAO,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAC;AACjE,YAAY,EAAE,yBAAyB,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAC5F,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,YAAY,EACV,aAAa,EACb,eAAe,EACf,QAAQ,EACR,QAAQ,EACR,OAAO,EACP,eAAe,EACf,mBAAmB,EACnB,eAAe,EACf,aAAa,EACb,OAAO,EACP,cAAc,EACd,KAAK,EACL,WAAW,EACX,OAAO,EACP,iBAAiB,EACjB,iBAAiB,EACjB,sBAAsB,EACtB,MAAM,EACN,YAAY,EACZ,kBAAkB,EAClB,aAAa,EACb,YAAY,GACb,MAAM,YAAY,CAAC;AACpB,YAAY,EACV,wBAAwB,EACxB,mBAAmB,EACnB,mBAAmB,EACnB,mBAAmB,EACnB,eAAe,EACf,wBAAwB,EACxB,oBAAoB,EACpB,0BAA0B,EAC1B,qBAAqB,EACrB,qBAAqB,GACtB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,yBAAyB,EACzB,oBAAoB,EACpB,uBAAuB,EACvB,uBAAuB,EACvB,6BAA6B,EAC7B,6BAA6B,EAC7B,aAAa,EACb,qBAAqB,GACtB,MAAM,uBAAuB,CAAC"}
|
package/dist/src/index.js
CHANGED
|
@@ -4,6 +4,7 @@ export { AUDIT_ACTIONS, OPEN_DISPUTE_STATUSES } from './billing/billing_store.js
|
|
|
4
4
|
export { withBillable, withPayment, withSubscription, } from './billing/index.js';
|
|
5
5
|
export { BILLING_LIST_DEFAULT_LIMIT, BILLING_LIST_MAX_LIMIT, } from './billing/list_query.js';
|
|
6
6
|
export { LucidBillingStore, lucidBillingStore } from './billing/lucid_billing_store.js';
|
|
7
|
+
export { advancePeriod, cancelManagedSubscription, createManagedSubscription, cycleIdempotencyKey, renewDueManagedSubscriptions, updateManagedSubscription, } from './billing/managed_subscriptions.js';
|
|
7
8
|
export { meteredBill, meteredBillForSubscription } from './billing/metered_bill.js';
|
|
8
9
|
export { BillingAuditEvent } from './billing/mixins/with_audit_event.js';
|
|
9
10
|
export { BillingCustomer } from './billing/mixins/with_customer.js';
|
|
@@ -28,5 +29,8 @@ export { emitInvoice, emitInvoiceIfRequested } from './invoice/emit_invoice.js';
|
|
|
28
29
|
export { InvoiceManager, resolveInvoiceProviders } from './invoice/invoice_manager.js';
|
|
29
30
|
export { currencyExponent, formatDecimal, fromDecimal, toDecimal } from './money.js';
|
|
30
31
|
export { PaymentsManager, resolveDrivers } from './payments_manager.js';
|
|
32
|
+
export { gatewayPerforms, gatewaySubscriptionLifecycle, } from './subscription_lifecycle.js';
|
|
33
|
+
export { resolveSubscriptionMode } from './subscription_mode.js';
|
|
34
|
+
export { SubscriptionsApi } from './subscriptions_api.js';
|
|
31
35
|
export { assertWebhookHandlerTypes, defineWebhookHandler, discoverWebhookHandlers, isWebhookHandlerService, loadWebhookHandlersFromBarrel, normalizeWebhookHandlerModule, pickModuleExt, resolveWebhookHandler, } from './webhook_handlers.js';
|
|
32
36
|
//# sourceMappingURL=index.js.map
|
package/dist/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAE5D,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAoBhE,OAAO,EAAE,aAAa,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAClF,OAAO,EACL,YAAY,EACZ,WAAW,EACX,gBAAgB,GACjB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL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BAA6B,CAAC;AAErC,OAAO,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAC;AAEjE,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAqC1D,OAAO,EACL,yBAAyB,EACzB,oBAAoB,EACpB,uBAAuB,EACvB,uBAAuB,EACvB,6BAA6B,EAC7B,6BAA6B,EAC7B,aAAa,EACb,qBAAqB,GACtB,MAAM,uBAAuB,CAAC"}
|
|
@@ -1,18 +1,38 @@
|
|
|
1
|
+
import type { BillingStore } from './billing/billing_store.js';
|
|
1
2
|
import type { PaymentsConfig } from './define_config.js';
|
|
2
3
|
import type { PaymentsDriver } from './driver.js';
|
|
3
4
|
import type { InvoiceManager } from './invoice/invoice_manager.js';
|
|
5
|
+
import { type SubscriptionOperation } from './subscription_lifecycle.js';
|
|
6
|
+
import { type SubscriptionsConfig } from './subscription_mode.js';
|
|
7
|
+
import { SubscriptionsApi } from './subscriptions_api.js';
|
|
4
8
|
import type { PaymentMethodName } from './types.js';
|
|
5
9
|
export interface PaymentsManagerOptions {
|
|
6
10
|
drivers: Map<string, PaymentsDriver>;
|
|
7
11
|
invoices?: InvoiceManager;
|
|
8
12
|
/** Method → provider name routing (`config.methods`). */
|
|
9
13
|
methods?: Partial<Record<PaymentMethodName, string>>;
|
|
14
|
+
/** Who owns the recurrence, globally and per provider (`config.subscriptions`). */
|
|
15
|
+
subscriptions?: SubscriptionsConfig;
|
|
16
|
+
/**
|
|
17
|
+
* The billing store, resolved LAZILY.
|
|
18
|
+
*
|
|
19
|
+
* A getter and not the store itself because the manager is built before the billing layer
|
|
20
|
+
* — the provider constructs it inside a container singleton, and the store needs a booted
|
|
21
|
+
* database. Managed subscriptions are the only thing that reads it, so a gateway-only app
|
|
22
|
+
* never calls this and never needs a store at all.
|
|
23
|
+
*/
|
|
24
|
+
store?: () => BillingStore;
|
|
10
25
|
/** Explicit default provider name (`config.default`). */
|
|
11
26
|
defaultName?: string;
|
|
12
27
|
}
|
|
13
28
|
export declare class PaymentsManager {
|
|
14
29
|
#private;
|
|
15
30
|
constructor(options: PaymentsManagerOptions);
|
|
31
|
+
/**
|
|
32
|
+
* Create, cancel and re-price subscriptions without the caller branching on who owns the
|
|
33
|
+
* recurrence. See {@link SubscriptionsApi}.
|
|
34
|
+
*/
|
|
35
|
+
subscriptions(): SubscriptionsApi;
|
|
16
36
|
/**
|
|
17
37
|
* Every configured driver, by the name it was configured under.
|
|
18
38
|
*
|
|
@@ -41,6 +61,17 @@ export declare class PaymentsManager {
|
|
|
41
61
|
* early (e.g. Woovi/OpenPix has no refunds) instead of at the gateway.
|
|
42
62
|
*/
|
|
43
63
|
assertCapability(driver: PaymentsDriver, capability: 'refunds' | 'invoices' | 'subscriptions' | 'disputes' | 'cardTokenization'): void;
|
|
64
|
+
/**
|
|
65
|
+
* Refuse a subscription operation the GATEWAY does not perform, naming the alternative.
|
|
66
|
+
*
|
|
67
|
+
* Separate from {@link assertCapability} because the answer is not a single boolean: a
|
|
68
|
+
* gateway can create subscriptions and be unable to cancel them (Woovi/OpenPix), so
|
|
69
|
+
* `subscriptions` alone cannot decide this call. And unlike a missing refund API, this
|
|
70
|
+
* limitation has a way out that costs nothing at the gateway — `subscriptions.mode:
|
|
71
|
+
* 'managed'`, where the library owns the recurrence — so the error says so rather than
|
|
72
|
+
* leaving the reader to conclude the feature is impossible.
|
|
73
|
+
*/
|
|
74
|
+
assertGatewaySubscriptionOperation(driver: PaymentsDriver, operation: SubscriptionOperation): void;
|
|
44
75
|
}
|
|
45
76
|
/** Build the driver map from config, resolving every configured factory. */
|
|
46
77
|
export declare function resolveDrivers(config: PaymentsConfig, invoices?: InvoiceManager): Promise<Map<string, PaymentsDriver>>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"payments_manager.d.ts","sourceRoot":"","sources":["../../src/payments_manager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,KAAK,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AmF;IACnF,aAAa,CAAC,EAAE,mBAAmB,CAAC;IACpC;;;;;;;OAOG;IACH,KAAK,CAAC,EAAE,MAAM,YAAY,CAAC;IAC3B,yDAAyD;IACzD,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,qBAAa,eAAe;;IAgB1B,YAAY,OAAO,EAAE,sBAAsB,EAW1C;IAED;;;OAGG;IACH,aAAa,IAAI,gBAAgB,CAoBhC;IAED;;;;;OAKG;IACH,IAAI,OAAO,IAAI,WAAW,CAAC,MAAM,EAAE,cAAc,CAAC,CAEjD;IAED;;;;;;;;;OASG;IACH,MAAM,CAAC,YAAY,CAAC,EAAE,iBAAiB,GAAG,MAAM,GAAG,cAAc,CAoChE;IAuGD;;;OAGG;IACH,OAAO,CAAC,IAAI,CAAC,EAAE,MAAM,gDAOpB;IAED;;;OAGG;IACH,gBAAgB,CACd,MAAM,EAAE,cAAc,EACtB,UAAU,EAAE,SAAS,GAAG,UAAU,GAAG,eAAe,GAAG,UAAU,GAAG,kBAAkB,GACrF,IAAI,CAgBN;IAED;;;;;;;;;OASG;IACH,kCAAkC,CAChC,MAAM,EAAE,cAAc,EACtB,SAAS,EAAE,qBAAqB,GAC/B,IAAI,CAON;CAsDF;AAED,4EAA4E;AAC5E,wBAAsB,cAAc,CAClC,MAAM,EAAE,cAAc,EACtB,QAAQ,CAAC,EAAE,cAAc,GACxB,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC,CAatC"}
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { gatewayPerforms } from './subscription_lifecycle.js';
|
|
2
|
+
import { resolveSubscriptionMode } from './subscription_mode.js';
|
|
3
|
+
import { SubscriptionsApi } from './subscriptions_api.js';
|
|
1
4
|
import { PAYMENT_METHOD_NAMES } from './types.js';
|
|
2
5
|
export class PaymentsManager {
|
|
3
6
|
#drivers;
|
|
@@ -11,6 +14,9 @@ export class PaymentsManager {
|
|
|
11
14
|
* one's identity.
|
|
12
15
|
*/
|
|
13
16
|
#boundDrivers = new Map();
|
|
17
|
+
#subscriptionsConfig;
|
|
18
|
+
#store;
|
|
19
|
+
#subscriptionsApi;
|
|
14
20
|
constructor(options) {
|
|
15
21
|
this.#drivers = options.drivers;
|
|
16
22
|
this.#invoices = options.invoices;
|
|
@@ -20,6 +26,29 @@ export class PaymentsManager {
|
|
|
20
26
|
throw new Error('[payments] No drivers configured. Add a provider to config/payments.ts.');
|
|
21
27
|
}
|
|
22
28
|
this.#defaultName = options.defaultName ?? names[0];
|
|
29
|
+
this.#subscriptionsConfig = options.subscriptions;
|
|
30
|
+
this.#store = options.store;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Create, cancel and re-price subscriptions without the caller branching on who owns the
|
|
34
|
+
* recurrence. See {@link SubscriptionsApi}.
|
|
35
|
+
*/
|
|
36
|
+
subscriptions() {
|
|
37
|
+
if (this.#subscriptionsApi === undefined) {
|
|
38
|
+
this.#subscriptionsApi = new SubscriptionsApi({
|
|
39
|
+
resolveDriver: (via) => this.driver(via),
|
|
40
|
+
store: () => {
|
|
41
|
+
const store = this.#store?.();
|
|
42
|
+
if (store === undefined) {
|
|
43
|
+
throw new Error("[payments] Managed subscriptions need the billing store, and none is configured. Enable `billing` in config/payments.ts, or use `subscriptions.mode: 'gateway'`.");
|
|
44
|
+
}
|
|
45
|
+
return store;
|
|
46
|
+
},
|
|
47
|
+
mode: (provider, managedOnCall) => resolveSubscriptionMode(this.#subscriptionsConfig, provider, managedOnCall),
|
|
48
|
+
assertGatewayCan: (driver, operation) => this.assertGatewaySubscriptionOperation(driver, operation),
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
return this.#subscriptionsApi;
|
|
23
52
|
}
|
|
24
53
|
/**
|
|
25
54
|
* Every configured driver, by the name it was configured under.
|
|
@@ -193,6 +222,23 @@ export class PaymentsManager {
|
|
|
193
222
|
`Supported capabilities: ${supported.join(', ') || '(none)'}.`);
|
|
194
223
|
}
|
|
195
224
|
}
|
|
225
|
+
/**
|
|
226
|
+
* Refuse a subscription operation the GATEWAY does not perform, naming the alternative.
|
|
227
|
+
*
|
|
228
|
+
* Separate from {@link assertCapability} because the answer is not a single boolean: a
|
|
229
|
+
* gateway can create subscriptions and be unable to cancel them (Woovi/OpenPix), so
|
|
230
|
+
* `subscriptions` alone cannot decide this call. And unlike a missing refund API, this
|
|
231
|
+
* limitation has a way out that costs nothing at the gateway — `subscriptions.mode:
|
|
232
|
+
* 'managed'`, where the library owns the recurrence — so the error says so rather than
|
|
233
|
+
* leaving the reader to conclude the feature is impossible.
|
|
234
|
+
*/
|
|
235
|
+
assertGatewaySubscriptionOperation(driver, operation) {
|
|
236
|
+
if (gatewayPerforms(driver, operation))
|
|
237
|
+
return;
|
|
238
|
+
throw new Error(`[payments] Gateway "${driver.provider}" cannot ${operation} a subscription through its API. ` +
|
|
239
|
+
`Set \`subscriptions.mode: 'managed'\` (globally, per provider, or \`managed: true\` on the ` +
|
|
240
|
+
`call) to have the library own the recurrence and make this a local operation.`);
|
|
241
|
+
}
|
|
196
242
|
#resolveName(methodOrName) {
|
|
197
243
|
if (methodOrName === undefined) {
|
|
198
244
|
const candidates = this.#methodsRoutedTo(this.#defaultName);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"payments_manager.js","sourceRoot":"","sources":["../../src/payments_manager.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"payments_manager.js","sourceRoot":"","sources":["../../src/payments_manager.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,eAAe,EAA8B,MAAM,6BAA6B,CAAC;AAC1F,OAAO,EAAE,uBAAuB,EAA4B,MAAM,wBAAwB,CAAC;AAC3F,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAE1D,OAAO,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAsBlD,MAAM,OAAO,eAAe;IAC1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AC5E,MAAM,CAAC,KAAK,UAAU,cAAc,CAClC,MAAsB,EACtB,QAAyB;IAEzB,MAAM,SAAS,GAAG,MAAM,CAAC,SAAS,IAAI,EAAE,CAAC;IACzC,MAAM,GAAG,GAAG;QACV,MAAM,EAAE,GAAG,EAAE,CAAC,MAAM;QACpB,qFAAqF;QACrF,sFAAsF;QACtF,GAAG,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,IAAa,EAAE,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KAC3F,CAAC;IACF,MAAM,GAAG,GAAG,IAAI,GAAG,EAA0B,CAAC;IAC9C,KAAK,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,CAAC;QACxD,GAAG,CAAC,GAAG,CAAC,IAAI,EAAE,MAAM,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC;IACpC,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { PaymentsDriver } from './driver.js';
|
|
2
|
+
/** The three lifecycle operations a gateway either performs or does not. */
|
|
3
|
+
export type SubscriptionOperation = 'create' | 'update' | 'cancel';
|
|
4
|
+
/** What a gateway does itself, once defaults are applied. */
|
|
5
|
+
export interface ResolvedSubscriptionLifecycle {
|
|
6
|
+
create: boolean;
|
|
7
|
+
update: boolean;
|
|
8
|
+
cancel: boolean;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* What a driver's GATEWAY actually performs, reading `capabilities.subscriptionLifecycle`
|
|
12
|
+
* and falling back to the coarse `capabilities.subscriptions`.
|
|
13
|
+
*
|
|
14
|
+
* The fallback is what keeps this additive: a driver written before the finer flag existed
|
|
15
|
+
* said `subscriptions: true` and meant all three, so that is what it keeps meaning. Only a
|
|
16
|
+
* driver that spells out the exception gets a different answer.
|
|
17
|
+
*/
|
|
18
|
+
export declare function gatewaySubscriptionLifecycle(driver: PaymentsDriver): ResolvedSubscriptionLifecycle;
|
|
19
|
+
/** Whether the gateway behind `driver` performs `operation` itself. */
|
|
20
|
+
export declare function gatewayPerforms(driver: PaymentsDriver, operation: SubscriptionOperation): boolean;
|
|
21
|
+
//# sourceMappingURL=subscription_lifecycle.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"subscription_lifecycle.d.ts","sourceRoot":"","sources":["../../src/subscription_lifecycle.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAElD,4EAA4E;AAC5E,MAAM,MAAM,qBAAqB,GAAG,QAAQ,GAAG,QAAQ,GAAG,QAAQ,CAAC;AAEnE,6DAA6D;AAC7D,MAAM,WAAW,6BAA6B;IAC5C,MAAM,EAAE,OAAO,CAAC;IAChB,MAAM,EAAE,OAAO,CAAC;IAChB,MAAM,EAAE,OAAO,CAAC;CACjB;AAED;;;;;;;GAOG;AACH,wBAAgB,4BAA4B,CAC1C,MAAM,EAAE,cAAc,GACrB,6BAA6B,CAQ/B;AAED,uEAAuE;AACvE,wBAAgB,eAAe,CAAC,MAAM,EAAE,cAAc,EAAE,SAAS,EAAE,qBAAqB,GAAG,OAAO,CAEjG"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a driver's GATEWAY actually performs, reading `capabilities.subscriptionLifecycle`
|
|
3
|
+
* and falling back to the coarse `capabilities.subscriptions`.
|
|
4
|
+
*
|
|
5
|
+
* The fallback is what keeps this additive: a driver written before the finer flag existed
|
|
6
|
+
* said `subscriptions: true` and meant all three, so that is what it keeps meaning. Only a
|
|
7
|
+
* driver that spells out the exception gets a different answer.
|
|
8
|
+
*/
|
|
9
|
+
export function gatewaySubscriptionLifecycle(driver) {
|
|
10
|
+
const coarse = driver.capabilities?.subscriptions === true;
|
|
11
|
+
const fine = driver.capabilities?.subscriptionLifecycle;
|
|
12
|
+
return {
|
|
13
|
+
create: fine?.create ?? coarse,
|
|
14
|
+
update: fine?.update ?? coarse,
|
|
15
|
+
cancel: fine?.cancel ?? coarse,
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
/** Whether the gateway behind `driver` performs `operation` itself. */
|
|
19
|
+
export function gatewayPerforms(driver, operation) {
|
|
20
|
+
return gatewaySubscriptionLifecycle(driver)[operation];
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=subscription_lifecycle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"subscription_lifecycle.js","sourceRoot":"","sources":["../../src/subscription_lifecycle.ts"],"names":[],"mappings":"AAYA;;;;;;;GAOG;AACH,MAAM,UAAU,4BAA4B,CAC1C,MAAsB;IAEtB,MAAM,MAAM,GAAG,MAAM,CAAC,YAAY,EAAE,aAAa,KAAK,IAAI,CAAC;IAC3D,MAAM,IAAI,GAAG,MAAM,CAAC,YAAY,EAAE,qBAAqB,CAAC;IACxD,OAAO;QACL,MAAM,EAAE,IAAI,EAAE,MAAM,IAAI,MAAM;QAC9B,MAAM,EAAE,IAAI,EAAE,MAAM,IAAI,MAAM;QAC9B,MAAM,EAAE,IAAI,EAAE,MAAM,IAAI,MAAM;KAC/B,CAAC;AACJ,CAAC;AAED,uEAAuE;AACvE,MAAM,UAAU,eAAe,CAAC,MAAsB,EAAE,SAAgC;IACtF,OAAO,4BAA4B,CAAC,MAAM,CAAC,CAAC,SAAS,CAAC,CAAC;AACzD,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/** Who owns the recurrence: the gateway, or this library. */
|
|
2
|
+
export type SubscriptionMode = 'gateway' | 'managed';
|
|
3
|
+
/**
|
|
4
|
+
* Where subscriptions are driven from.
|
|
5
|
+
*
|
|
6
|
+
* Three levels because the honest answer differs per application AND per gateway inside one
|
|
7
|
+
* application. Plenty of teams want the gateway to own everything — the Stripe dashboard is
|
|
8
|
+
* the product, and nobody wants to rebuild dunning. Others want the plan, the price and the
|
|
9
|
+
* cancel button to live in their own app, and a gateway that only knows how to take money.
|
|
10
|
+
* Forcing either choice on the other is what makes a billing library something people rip
|
|
11
|
+
* out.
|
|
12
|
+
*
|
|
13
|
+
* It also stops being a preference the moment a gateway cannot do the job: Woovi/OpenPix
|
|
14
|
+
* cannot cancel or update a subscription at all, so `'managed'` is the only way to offer a
|
|
15
|
+
* cancel button — while the same app's card subscriptions can stay on Asaas, which does it
|
|
16
|
+
* fine. That is why the per-provider level exists and is not redundant with the global one.
|
|
17
|
+
*/
|
|
18
|
+
export interface SubscriptionsConfig {
|
|
19
|
+
/** Default for every provider. Defaults to `'gateway'` — today's behaviour. */
|
|
20
|
+
mode?: SubscriptionMode;
|
|
21
|
+
/** Per-provider override, keyed by the name used in `providers`. */
|
|
22
|
+
providers?: Record<string, SubscriptionMode>;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* The mode for one call: `managed` on the call, else the provider's setting, else the global
|
|
26
|
+
* default, else `'gateway'`.
|
|
27
|
+
*
|
|
28
|
+
* Narrowest wins, and the default is the old behaviour so upgrading changes nothing until
|
|
29
|
+
* someone asks it to.
|
|
30
|
+
*/
|
|
31
|
+
export declare function resolveSubscriptionMode(config: SubscriptionsConfig | undefined, provider: string, managedOnCall?: boolean): SubscriptionMode;
|
|
32
|
+
//# sourceMappingURL=subscription_mode.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"subscription_mode.d.ts","sourceRoot":"","sources":["../../src/subscription_mode.ts"],"names":[],"mappings":"AAAA,6DAA6D;AAC7D,MAAM,MAAM,gBAAgB,GAAG,SAAS,GAAG,SAAS,CAAC;AAErD;;;;;;;;;;;;;;GAcG;AACH,MAAM,WAAW,mBAAmB;IAClC,+EAA+E;IAC/E,IAAI,CAAC,EAAE,gBAAgB,CAAC;IACxB,oEAAoE;IACpE,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;CAC9C;AAED;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CACrC,MAAM,EAAE,mBAAmB,GAAG,SAAS,EACvC,QAAQ,EAAE,MAAM,EAChB,aAAa,CAAC,EAAE,OAAO,GACtB,gBAAgB,CAGlB"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The mode for one call: `managed` on the call, else the provider's setting, else the global
|
|
3
|
+
* default, else `'gateway'`.
|
|
4
|
+
*
|
|
5
|
+
* Narrowest wins, and the default is the old behaviour so upgrading changes nothing until
|
|
6
|
+
* someone asks it to.
|
|
7
|
+
*/
|
|
8
|
+
export function resolveSubscriptionMode(config, provider, managedOnCall) {
|
|
9
|
+
if (managedOnCall !== undefined)
|
|
10
|
+
return managedOnCall ? 'managed' : 'gateway';
|
|
11
|
+
return config?.providers?.[provider] ?? config?.mode ?? 'gateway';
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=subscription_mode.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"subscription_mode.js","sourceRoot":"","sources":["../../src/subscription_mode.ts"],"names":[],"mappings":"AAyBA;;;;;;GAMG;AACH,MAAM,UAAU,uBAAuB,CACrC,MAAuC,EACvC,QAAgB,EAChB,aAAuB;IAEvB,IAAI,aAAa,KAAK,SAAS;QAAE,OAAO,aAAa,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC;IAC9E,OAAO,MAAM,EAAE,SAAS,EAAE,CAAC,QAAQ,CAAC,IAAI,MAAM,EAAE,IAAI,IAAI,SAAS,CAAC;AACpE,CAAC"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import type { BillingStore } from './billing/billing_store.js';
|
|
2
|
+
import { type RenewalOutcome } from './billing/managed_subscriptions.js';
|
|
3
|
+
import type { CreateSubscriptionInput, PaymentsDriver } from './driver.js';
|
|
4
|
+
import { resolveSubscriptionMode, type SubscriptionMode } from './subscription_mode.js';
|
|
5
|
+
import type { Payment } from './types.js';
|
|
6
|
+
/** Creating a subscription, either way. */
|
|
7
|
+
export interface CreateSubscriptionRequest extends CreateSubscriptionInput {
|
|
8
|
+
/** Payment method or provider name, resolved exactly like `payments.driver(...)`. */
|
|
9
|
+
via?: string;
|
|
10
|
+
/**
|
|
11
|
+
* Force the mode for this one call, overriding config. `true` means the library owns the
|
|
12
|
+
* recurrence; `false` means the gateway does.
|
|
13
|
+
*/
|
|
14
|
+
managed?: boolean;
|
|
15
|
+
currency?: string;
|
|
16
|
+
}
|
|
17
|
+
/** What a caller gets back, whichever side owns the recurrence. */
|
|
18
|
+
export interface SubscriptionHandle {
|
|
19
|
+
/** The id to cancel/update with. The local row in managed mode, the gateway id otherwise. */
|
|
20
|
+
id: string;
|
|
21
|
+
mode: SubscriptionMode;
|
|
22
|
+
provider: string;
|
|
23
|
+
status: string;
|
|
24
|
+
/** `null` in managed mode — no gateway subscription exists. */
|
|
25
|
+
gatewayId: string | null;
|
|
26
|
+
currentPeriodStart?: Date;
|
|
27
|
+
currentPeriodEnd?: Date;
|
|
28
|
+
/** Managed mode only: the first cycle's charge, so a Pix QR code is available at once. */
|
|
29
|
+
charge?: Payment;
|
|
30
|
+
}
|
|
31
|
+
export interface SubscriptionsApiDeps {
|
|
32
|
+
resolveDriver: (via?: string) => PaymentsDriver;
|
|
33
|
+
/** Lazy: the store exists only after the provider has booted the billing layer. */
|
|
34
|
+
store: () => BillingStore;
|
|
35
|
+
mode: (provider: string, managedOnCall?: boolean) => SubscriptionMode;
|
|
36
|
+
assertGatewayCan: (driver: PaymentsDriver, op: 'create' | 'update' | 'cancel') => void;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* One place to create, cancel and re-price a subscription, whoever owns the recurrence.
|
|
40
|
+
*
|
|
41
|
+
* The two modes are genuinely different products — one is a gateway object you administer in
|
|
42
|
+
* the gateway's dashboard, the other is rows in your database and a charge per cycle — and
|
|
43
|
+
* teams legitimately want either. What they should not have to write is the branch between
|
|
44
|
+
* them at every call site, because that branch is where "Woovi cannot cancel" ends up
|
|
45
|
+
* hard-coded into an application that should never have heard of Woovi.
|
|
46
|
+
*/
|
|
47
|
+
export declare class SubscriptionsApi {
|
|
48
|
+
#private;
|
|
49
|
+
constructor(deps: SubscriptionsApiDeps);
|
|
50
|
+
create(request: CreateSubscriptionRequest): Promise<SubscriptionHandle>;
|
|
51
|
+
/**
|
|
52
|
+
* Cancel by the id `create` returned.
|
|
53
|
+
*
|
|
54
|
+
* In managed mode this never reaches the gateway, which is the entire reason the mode
|
|
55
|
+
* exists: it works on gateways that cannot cancel a subscription at all.
|
|
56
|
+
*/
|
|
57
|
+
cancel(id: string, options?: {
|
|
58
|
+
via?: string;
|
|
59
|
+
managed?: boolean;
|
|
60
|
+
atPeriodEnd?: boolean;
|
|
61
|
+
}): Promise<void>;
|
|
62
|
+
/** Re-price or re-describe. In managed mode it takes effect on the next cycle. */
|
|
63
|
+
update(id: string, patch: {
|
|
64
|
+
amount?: number;
|
|
65
|
+
description?: string | null;
|
|
66
|
+
cycle?: string;
|
|
67
|
+
}, options?: {
|
|
68
|
+
via?: string;
|
|
69
|
+
managed?: boolean;
|
|
70
|
+
}): Promise<void>;
|
|
71
|
+
/**
|
|
72
|
+
* Managed subscriptions due at or before `now`, WITHOUT charging anything.
|
|
73
|
+
*
|
|
74
|
+
* What `payments:renew --dry-run` reads. It runs the same store query the real pass does,
|
|
75
|
+
* so the preview cannot disagree with what would actually happen.
|
|
76
|
+
*/
|
|
77
|
+
due(options?: {
|
|
78
|
+
now?: Date;
|
|
79
|
+
limit?: number;
|
|
80
|
+
}): Promise<{
|
|
81
|
+
id: string;
|
|
82
|
+
}[]>;
|
|
83
|
+
/**
|
|
84
|
+
* Charge every managed subscription whose cycle is due. Drive it from `payments:renew`
|
|
85
|
+
* (a cron, a durable schedule) — nothing renews on its own.
|
|
86
|
+
*/
|
|
87
|
+
renewDue(options?: {
|
|
88
|
+
now?: Date;
|
|
89
|
+
limit?: number;
|
|
90
|
+
}): Promise<RenewalOutcome[]>;
|
|
91
|
+
}
|
|
92
|
+
export { resolveSubscriptionMode };
|
|
93
|
+
//# sourceMappingURL=subscriptions_api.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"subscriptions_api.d.ts","sourceRoot":"","sources":["../../src/subscriptions_api.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC/D,OAAO,EAGL,KAAK,cAAc,EAGpB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,KAAK,EAAE,uBAAuB,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC3E,OAAO,EAAE,uBAAuB,EAAE,KAAK,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AACxF,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAE1C,2CAA2C;AAC3C,MAAM,WAAW,yBAA0B,SAAQ,uBAAuB;IACxE,qFAAqF;IACrF,GAAG,CAAC,EAAE,MAAM,CAAC;IACb;;;OAGG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,mEAAmE;AACnE,MAAM,WAAW,kBAAkB;IACjC,6FAA6F;IAC7F,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,gBAAgB,CAAC;IACvB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,+DAA+D;IAC/D,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,kBAAkB,CAAC,EAAE,IAAI,CAAC;IAC1B,gBAAgB,CAAC,EAAE,IAAI,CAAC;IACxB,0FAA0F;IAC1F,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED,MAAM,WAAW,oBAAoB;IACnC,aAAa,EAAE,CAAC,GAAG,CAAC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AAE;QAAE,GAAG,CAAC,EAAE,IAAI,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAO,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC,CAMtF;CACF;AAED,OAAO,EAAE,uBAAuB,EAAE,CAAC"}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { cancelManagedSubscription, createManagedSubscription, renewDueManagedSubscriptions, updateManagedSubscription, } from './billing/managed_subscriptions.js';
|
|
2
|
+
import { resolveSubscriptionMode } from './subscription_mode.js';
|
|
3
|
+
/**
|
|
4
|
+
* One place to create, cancel and re-price a subscription, whoever owns the recurrence.
|
|
5
|
+
*
|
|
6
|
+
* The two modes are genuinely different products — one is a gateway object you administer in
|
|
7
|
+
* the gateway's dashboard, the other is rows in your database and a charge per cycle — and
|
|
8
|
+
* teams legitimately want either. What they should not have to write is the branch between
|
|
9
|
+
* them at every call site, because that branch is where "Woovi cannot cancel" ends up
|
|
10
|
+
* hard-coded into an application that should never have heard of Woovi.
|
|
11
|
+
*/
|
|
12
|
+
export class SubscriptionsApi {
|
|
13
|
+
#deps;
|
|
14
|
+
constructor(deps) {
|
|
15
|
+
this.#deps = deps;
|
|
16
|
+
}
|
|
17
|
+
async create(request) {
|
|
18
|
+
const { via, managed, currency, ...input } = request;
|
|
19
|
+
const driver = this.#deps.resolveDriver(via);
|
|
20
|
+
const mode = this.#deps.mode(driver.provider, managed);
|
|
21
|
+
if (mode === 'gateway') {
|
|
22
|
+
this.#deps.assertGatewayCan(driver, 'create');
|
|
23
|
+
const subscription = await driver.createSubscription(input);
|
|
24
|
+
return {
|
|
25
|
+
id: subscription.gatewayId,
|
|
26
|
+
mode,
|
|
27
|
+
provider: driver.provider,
|
|
28
|
+
status: subscription.status,
|
|
29
|
+
gatewayId: subscription.gatewayId,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
const result = await createManagedSubscription(driver, this.#deps.store(), {
|
|
33
|
+
...input,
|
|
34
|
+
...(currency !== undefined ? { currency } : {}),
|
|
35
|
+
});
|
|
36
|
+
return {
|
|
37
|
+
id: result.id,
|
|
38
|
+
mode,
|
|
39
|
+
provider: driver.provider,
|
|
40
|
+
status: result.status,
|
|
41
|
+
gatewayId: null,
|
|
42
|
+
currentPeriodStart: result.currentPeriodStart,
|
|
43
|
+
currentPeriodEnd: result.currentPeriodEnd,
|
|
44
|
+
charge: result.charge,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Cancel by the id `create` returned.
|
|
49
|
+
*
|
|
50
|
+
* In managed mode this never reaches the gateway, which is the entire reason the mode
|
|
51
|
+
* exists: it works on gateways that cannot cancel a subscription at all.
|
|
52
|
+
*/
|
|
53
|
+
async cancel(id, options = {}) {
|
|
54
|
+
const driver = this.#deps.resolveDriver(options.via);
|
|
55
|
+
const mode = this.#deps.mode(driver.provider, options.managed);
|
|
56
|
+
if (mode === 'gateway') {
|
|
57
|
+
this.#deps.assertGatewayCan(driver, 'cancel');
|
|
58
|
+
await driver.cancelSubscription(id, {
|
|
59
|
+
...(options.atPeriodEnd !== undefined ? { atPeriodEnd: options.atPeriodEnd } : {}),
|
|
60
|
+
});
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
await cancelManagedSubscription(this.#deps.store(), id, {
|
|
64
|
+
...(options.atPeriodEnd !== undefined ? { atPeriodEnd: options.atPeriodEnd } : {}),
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
/** Re-price or re-describe. In managed mode it takes effect on the next cycle. */
|
|
68
|
+
async update(id, patch, options = {}) {
|
|
69
|
+
const driver = this.#deps.resolveDriver(options.via);
|
|
70
|
+
const mode = this.#deps.mode(driver.provider, options.managed);
|
|
71
|
+
if (mode === 'gateway') {
|
|
72
|
+
this.#deps.assertGatewayCan(driver, 'update');
|
|
73
|
+
await driver.updateSubscription(id, {
|
|
74
|
+
...(patch.amount !== undefined ? { amount: patch.amount } : {}),
|
|
75
|
+
...(patch.description != null ? { description: patch.description } : {}),
|
|
76
|
+
});
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
await updateManagedSubscription(this.#deps.store(), id, patch);
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Managed subscriptions due at or before `now`, WITHOUT charging anything.
|
|
83
|
+
*
|
|
84
|
+
* What `payments:renew --dry-run` reads. It runs the same store query the real pass does,
|
|
85
|
+
* so the preview cannot disagree with what would actually happen.
|
|
86
|
+
*/
|
|
87
|
+
async due(options = {}) {
|
|
88
|
+
const rows = await this.#deps
|
|
89
|
+
.store()
|
|
90
|
+
.listDueManagedSubscriptions(options.now ?? new Date(), options.limit ?? 100);
|
|
91
|
+
return rows.map((row) => ({ id: row.id }));
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Charge every managed subscription whose cycle is due. Drive it from `payments:renew`
|
|
95
|
+
* (a cron, a durable schedule) — nothing renews on its own.
|
|
96
|
+
*/
|
|
97
|
+
async renewDue(options = {}) {
|
|
98
|
+
return renewDueManagedSubscriptions((provider) => this.#deps.resolveDriver(provider), this.#deps.store(), options);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
export { resolveSubscriptionMode };
|
|
102
|
+
//# sourceMappingURL=subscriptions_api.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"subscriptions_api.js","sourceRoot":"","sources":["../../src/subscriptions_api.ts"],"names":[],"mappings":"AACA,OAAO,EACL,yBAAyB,EACzB,yBAAyB,EAEzB,4BAA4B,EAC5B,yBAAyB,GAC1B,MAAM,oCAAoC,CAAC;AAE5C,OAAO,EAAE,uBAAuB,EAAyB,MAAM,wBAAwB,CAAC;AAsCxF;;;;;;;;GAQG;AACH,MAAM,OAAO,gBAAgB;IAC3B,KAAK,CAAuB;IAE5B,YAAY,IAA0B;QACpC,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;IACpB,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,OAAkC;QAC7C,MAAM,EA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type AuditEventListItem, type AuditEventQuery, type BillingCountQuery, type BillingListQuery, type BillingStore, type CustomerListItem, type CustomerListQuery, type DisputeDeadlineQuery, type DisputeListItem, type OpenDisputeQuery, type PaymentListItem, type PaymentListQuery, type SubscriptionListItem, type WebhookEventBreakdownLine, type WebhookEventListItem, type WebhookEventListQuery } from '../billing/billing_store.js';
|
|
1
|
+
import { type AuditEventCountQuery, type AuditEventListItem, type AuditEventQuery, type BillingCountQuery, type BillingListQuery, type BillingStore, type CustomerListItem, type CustomerListQuery, type DisputeDeadlineQuery, type DisputeListItem, type ManagedSubscriptionInput, type ManagedSubscriptionPatch, type OpenDisputeQuery, type PaymentListItem, type PaymentListQuery, type SubscriptionListItem, type WebhookEventBreakdownLine, type WebhookEventListItem, type WebhookEventListQuery } from '../billing/billing_store.js';
|
|
2
2
|
/** A plain in-memory customer-mapping row (mirrors the Lucid model's columns). */
|
|
3
3
|
export interface InMemoryCustomerRow {
|
|
4
4
|
id: string;
|
|
@@ -16,7 +16,8 @@ export interface InMemoryCustomerRow {
|
|
|
16
16
|
/** A minimal in-memory row shape (mirrors the Lucid models' columns). */
|
|
17
17
|
export interface InMemorySubscriptionRow {
|
|
18
18
|
id: string;
|
|
19
|
-
|
|
19
|
+
/** `null` on a managed subscription — nothing was created at the gateway. */
|
|
20
|
+
gatewayId: string | null;
|
|
20
21
|
provider: string;
|
|
21
22
|
customerId: string;
|
|
22
23
|
status: string;
|
|
@@ -26,6 +27,17 @@ export interface InMemorySubscriptionRow {
|
|
|
26
27
|
payload: Record<string, unknown>;
|
|
27
28
|
/** Insertion timestamp — the Lucid row has one, and the list query orders by it. */
|
|
28
29
|
createdAt: Date;
|
|
30
|
+
managed?: boolean | null;
|
|
31
|
+
amount?: number | null;
|
|
32
|
+
currency?: string | null;
|
|
33
|
+
cycle?: string | null;
|
|
34
|
+
method?: string | null;
|
|
35
|
+
description?: string | null;
|
|
36
|
+
externalReference?: string | null;
|
|
37
|
+
currentPeriodStart?: Date | null;
|
|
38
|
+
currentPeriodEnd?: Date | null;
|
|
39
|
+
nextChargeAt?: Date | null;
|
|
40
|
+
cancelAtPeriodEnd?: boolean | null;
|
|
29
41
|
}
|
|
30
42
|
export interface InMemoryPaymentRow {
|
|
31
43
|
id: string;
|
|
@@ -148,6 +160,11 @@ export declare class InMemoryBillingStore implements BillingStore<InMemorySubscr
|
|
|
148
160
|
listSubscriptions(query: BillingListQuery): Promise<SubscriptionListItem[]>;
|
|
149
161
|
countSubscriptions(query: BillingCountQuery): Promise<number>;
|
|
150
162
|
findSubscriptionByGatewayId(gatewayId: string): Promise<InMemorySubscriptionRow | null>;
|
|
163
|
+
managedSubscriptions: Map<string, InMemorySubscriptionRow>;
|
|
164
|
+
createManagedSubscription(sub: ManagedSubscriptionInput): Promise<InMemorySubscriptionRow>;
|
|
165
|
+
findSubscriptionById(id: string): Promise<InMemorySubscriptionRow | null>;
|
|
166
|
+
updateManagedSubscription(id: string, patch: ManagedSubscriptionPatch): Promise<InMemorySubscriptionRow | null>;
|
|
167
|
+
listDueManagedSubscriptions(now: Date, limit: number): Promise<InMemorySubscriptionRow[]>;
|
|
151
168
|
savePayment(payment: {
|
|
152
169
|
gatewayId: string;
|
|
153
170
|
provider: string;
|