@saasicat/nest 1.0.0-rc.2 → 1.0.0-rc.21
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 +44 -8
- package/dist/.build-stamp +1 -1
- package/dist/_entries.cjs +10214 -4796
- package/dist/admin/index.d.cts +5 -4
- package/dist/admin/index.d.ts +5 -4
- package/dist/admin/index.js +13 -9
- package/dist/{admin-resources.module-CpvzcfCc.d.cts → admin-resources.module-B4XNvdH-.d.cts} +1 -2
- package/dist/{admin-resources.module-DF5_Q7RD.d.ts → admin-resources.module-CWqdI9BV.d.ts} +1 -2
- package/dist/{admin-stats.service-TYiSUwIR.d.ts → admin-stats.service-CsLNt19Z.d.ts} +11 -7
- package/dist/{admin-stats.service-DfKupywR.d.cts → admin-stats.service-DrZrU8IJ.d.cts} +11 -7
- package/dist/{aggregation-B3CD0v_d.d.cts → aggregation-ChpZDh0g.d.ts} +39 -6
- package/dist/{aggregation-BFzW07DE.d.ts → aggregation-OpnhwzF5.d.cts} +39 -6
- package/dist/billing/index.d.cts +448 -108
- package/dist/billing/index.d.ts +448 -108
- package/dist/billing/index.js +108 -41
- package/dist/catalog/index.d.cts +74 -45
- package/dist/catalog/index.d.ts +74 -45
- package/dist/catalog/index.js +21 -13
- package/dist/catalog.module-C9O7BxRq.d.ts +180 -0
- package/dist/catalog.module-T-I5Ricz.d.cts +180 -0
- package/dist/checkout-offer/index.d.cts +17 -22
- package/dist/checkout-offer/index.d.ts +17 -22
- package/dist/checkout-offer/index.js +21 -7
- package/dist/checkout-offer.module-DFhGy6JO.d.cts +58 -0
- package/dist/checkout-offer.module-x7SP_dX4.d.ts +58 -0
- package/dist/checkout-offer.service-BeHgYikI.d.ts +242 -0
- package/dist/checkout-offer.service-CCVxG9b2.d.cts +242 -0
- package/dist/chunk-34XVPR6P.js +222 -0
- package/dist/{chunk-AOQJEYOL.js → chunk-3QVGA6JX.js} +3 -1
- package/dist/chunk-3RLWML2S.js +896 -0
- package/dist/{chunk-TXC3LHHB.js → chunk-4SDSYV4A.js} +21 -13
- package/dist/chunk-55QEDAMX.js +946 -0
- package/dist/chunk-5CKC7O52.js +140 -0
- package/dist/chunk-6PJE7EWO.js +185 -0
- package/dist/chunk-7NJKVC5X.js +353 -0
- package/dist/{chunk-RUNZ3X4C.js → chunk-AOS2JPDD.js} +1263 -185
- package/dist/{chunk-WOVQPXV4.js → chunk-CQ2ZZMTD.js} +702 -725
- package/dist/{chunk-NA6O63B7.js → chunk-F5X66HF5.js} +5 -5
- package/dist/chunk-FEQZCWUL.js +174 -0
- package/dist/{chunk-VIJ5NJWC.js → chunk-G6EZWECL.js} +107 -31
- package/dist/chunk-G7RQO2XO.js +0 -0
- package/dist/{chunk-N3L3AICU.js → chunk-GPQWGA6B.js} +5 -6
- package/dist/chunk-GZTL64QK.js +7 -0
- package/dist/{chunk-SABTXESR.js → chunk-J7NJRK3K.js} +17 -1
- package/dist/{chunk-SEPN52AD.js → chunk-JBCC6C3M.js} +566 -307
- package/dist/{chunk-I7GTA3RX.js → chunk-JQRA724W.js} +1 -1
- package/dist/{chunk-WXYJHZCN.js → chunk-JVAEKTJ4.js} +2 -14
- package/dist/chunk-KPEMTBOP.js +26 -0
- package/dist/chunk-LF6J4YYN.js +301 -0
- package/dist/{chunk-LTT736P3.js → chunk-LLYVYRGJ.js} +228 -387
- package/dist/{chunk-6Z7JR4EW.js → chunk-M47BNEY2.js} +1897 -633
- package/dist/{chunk-KFT5AIIH.js → chunk-NDLC5GYK.js} +206 -24
- package/dist/{chunk-O2J2HDXA.js → chunk-OOTEXP47.js} +3 -8
- package/dist/chunk-QPVDCKYS.js +702 -0
- package/dist/{chunk-NHVDCYK5.js → chunk-R5YCJBHY.js} +71 -106
- package/dist/{chunk-XBYAFEOR.js → chunk-S33SO5XX.js} +1 -1
- package/dist/chunk-SZ7RFPXA.js +10 -0
- package/dist/chunk-TBBZWZQT.js +98 -0
- package/dist/chunk-TOEFN7DN.js +295 -0
- package/dist/{chunk-7ZEGFL42.js → chunk-WHJSYKNC.js} +6 -6
- package/dist/chunk-WOEJ6K7M.js +55 -0
- package/dist/{chunk-AU3OOREM.js → chunk-XSSWYPP5.js} +16 -3
- package/dist/contract-line-item-money-B0Z3Ogur.d.cts +43 -0
- package/dist/contract-line-item-money-B0Z3Ogur.d.ts +43 -0
- package/dist/discovery/index.d.cts +2 -2
- package/dist/discovery/index.d.ts +2 -2
- package/dist/discovery/index.js +6 -6
- package/dist/{discovery.scanner-9cMqF95o.d.cts → discovery.scanner-DXKc6JkV.d.cts} +1 -1
- package/dist/{discovery.scanner-9cMqF95o.d.ts → discovery.scanner-DXKc6JkV.d.ts} +1 -1
- package/dist/{enforce-quota.interceptor-Df0e3OWe.d.cts → enforce-quota.interceptor-BFyVdWe8.d.cts} +6 -6
- package/dist/{enforce-quota.interceptor-DW3etVyI.d.ts → enforce-quota.interceptor-GaBXboGx.d.ts} +6 -6
- package/dist/entitlement/index.d.cts +27 -4
- package/dist/entitlement/index.d.ts +27 -4
- package/dist/entitlement/index.js +13 -8
- package/dist/index.d.cts +209 -28
- package/dist/index.d.ts +209 -28
- package/dist/index.js +285 -163
- package/dist/issuer-identity.check-CBO0vcsq.d.cts +197 -0
- package/dist/issuer-identity.check-Cz9CEMkZ.d.ts +197 -0
- package/dist/{module-options-COSEb0VW.d.ts → module-options-DmQ3G4sZ.d.ts} +135 -41
- package/dist/{module-options-BG3MzQva.d.cts → module-options-qAOwinHR.d.cts} +135 -41
- package/dist/payment-callback.service-CR84Xw1Z.d.cts +125 -0
- package/dist/payment-callback.service-CR84Xw1Z.d.ts +125 -0
- package/dist/payments/index.cjs +4 -0
- package/dist/payments/index.d.cts +187 -0
- package/dist/payments/index.d.ts +187 -0
- package/dist/payments/index.js +141 -0
- package/dist/payments.module-BdUq9ot_.d.cts +57 -0
- package/dist/payments.module-CQGv_VG7.d.ts +57 -0
- package/dist/plan-catalog-source-DWe-BGY1.d.cts +21 -0
- package/dist/plan-catalog-source-DWe-BGY1.d.ts +21 -0
- package/dist/{plan-resolution-Cgo_TR1H.d.cts → plan-resolution-CwUy_OqC.d.cts} +14 -0
- package/dist/{plan-resolution-Cgo_TR1H.d.ts → plan-resolution-CwUy_OqC.d.ts} +14 -0
- package/dist/{plan-versions.service-DChhbK6h.d.ts → plan-versions.service-C0N-Em2W.d.ts} +38 -64
- package/dist/{plan-versions.service-TPEtbN0r.d.cts → plan-versions.service-DARLh-qI.d.cts} +38 -64
- package/dist/platform/index.d.cts +52 -23
- package/dist/platform/index.d.ts +52 -23
- package/dist/platform/index.js +57 -36
- package/dist/promo/index.d.cts +23 -8
- package/dist/promo/index.d.ts +23 -8
- package/dist/promo/index.js +15 -7
- package/dist/{promo.module-DtvIycpt.d.cts → promo.module-CKkECmU8.d.cts} +9 -3
- package/dist/{promo.module-Z8h1PNX-.d.ts → promo.module-DuIJdK3U.d.ts} +9 -3
- package/dist/promo.service-BYBu6dy3.d.cts +215 -0
- package/dist/promo.service-CFjfF0Xm.d.ts +215 -0
- package/dist/registration/index.d.cts +104 -47
- package/dist/registration/index.d.ts +104 -47
- package/dist/registration/index.js +15 -9
- package/dist/subscriber/index.cjs +4 -0
- package/dist/subscriber/index.d.cts +28 -0
- package/dist/subscriber/index.d.ts +28 -0
- package/dist/subscriber/index.js +16 -0
- package/dist/subscriber.service-5W6Gi-1B.d.cts +68 -0
- package/dist/subscriber.service-5W6Gi-1B.d.ts +68 -0
- package/dist/subscription-contract/index.d.cts +4 -2
- package/dist/subscription-contract/index.d.ts +4 -2
- package/dist/subscription-contract/index.js +13 -5
- package/dist/{subscription-contract.module-fDFdQ0jm.d.ts → subscription-contract.module-BfIRpc1o.d.ts} +8 -2
- package/dist/{subscription-contract.module-CEK8HS5-.d.cts → subscription-contract.module-DTMuUJYd.d.cts} +8 -2
- package/dist/{subscription-contract.service-hD87MKyg.d.cts → subscription-contract.service-CPZrTM9C.d.ts} +32 -3
- package/dist/{subscription-contract.service-hD87MKyg.d.ts → subscription-contract.service-CfNApLuP.d.cts} +32 -3
- package/dist/tenant-billing.controller-BLqbsONe.d.ts +812 -0
- package/dist/tenant-billing.controller-DKbAqTbM.d.cts +812 -0
- package/dist/tenant-billing.module-ClbjzocC.d.cts +364 -0
- package/dist/tenant-billing.module-DohgJJ2m.d.ts +364 -0
- package/dist/tenant-billing.tokens-G-1xOlMr.d.cts +129 -0
- package/dist/tenant-billing.tokens-G-1xOlMr.d.ts +129 -0
- package/dist/testing/index.d.cts +44 -17
- package/dist/testing/index.d.ts +44 -17
- package/dist/testing/index.js +189 -40
- package/package.json +24 -4
- package/dist/catalog.module-BDDO6iwq.d.cts +0 -103
- package/dist/catalog.module-BTnMsE6u.d.ts +0 -103
- package/dist/checkout-offer.module-CMtiQJTT.d.ts +0 -39
- package/dist/checkout-offer.module-CVpWrzbe.d.cts +0 -39
- package/dist/checkout-offer.service-BLOv2HOo.d.cts +0 -49
- package/dist/checkout-offer.service-BLOv2HOo.d.ts +0 -49
- package/dist/chunk-57V6ZTI6.js +0 -22
- package/dist/chunk-BSK6YBLI.js +0 -87
- package/dist/chunk-DQKCK7DX.js +0 -217
- package/dist/chunk-VXEYLNIB.js +0 -632
- package/dist/chunk-WUDYIPYH.js +0 -715
- package/dist/define-saasicat-DROBe-b1.d.ts +0 -69
- package/dist/define-saasicat-vGBCkFys.d.cts +0 -69
- package/dist/promo.service-BJbKAmw3.d.cts +0 -112
- package/dist/promo.service-BJbKAmw3.d.ts +0 -112
- package/dist/tenant-billing.controller-BQ67mlmI.d.ts +0 -438
- package/dist/tenant-billing.controller-DS8kB8a7.d.cts +0 -438
- package/dist/tenant-billing.module-BznC3XtW.d.cts +0 -299
- package/dist/tenant-billing.module-wUbsQSFG.d.ts +0 -299
- /package/dist/{chunk-2FR6ZL7R.js → chunk-BHZOH2DY.js} +0 -0
- /package/dist/{chunk-2SLTRKXC.js → chunk-DFOW3JVO.js} +0 -0
- /package/dist/{chunk-DBZGV3HC.js → chunk-DU56UKEH.js} +0 -0
- /package/dist/{chunk-OYNHOY45.js → chunk-GAUEVIAE.js} +0 -0
|
@@ -0,0 +1,702 @@
|
|
|
1
|
+
import {
|
|
2
|
+
PAYMENT_EVENT_LOG_TOKEN,
|
|
3
|
+
PAYMENT_GATEWAYS_TOKEN,
|
|
4
|
+
PAYMENT_TRANSACTION_RUNNER_TOKEN,
|
|
5
|
+
PaymentCallbackService,
|
|
6
|
+
PaymentGatewayRegistry,
|
|
7
|
+
SUBSCRIBER_PAYMENT_METHOD_REPOSITORY_TOKEN,
|
|
8
|
+
refuseForeignReturnUrls
|
|
9
|
+
} from "./chunk-7NJKVC5X.js";
|
|
10
|
+
import {
|
|
11
|
+
BillingPermissionGuard,
|
|
12
|
+
ComposedTenantAuthGuard
|
|
13
|
+
} from "./chunk-5CKC7O52.js";
|
|
14
|
+
import {
|
|
15
|
+
BILLING_PERMISSION_GUARDS_TOKEN,
|
|
16
|
+
TENANT_AUTH_GUARDS_TOKEN,
|
|
17
|
+
TENANT_ID_RESOLVER_TOKEN,
|
|
18
|
+
USER_EMAIL_RESOLVER_TOKEN
|
|
19
|
+
} from "./chunk-GPQWGA6B.js";
|
|
20
|
+
import {
|
|
21
|
+
RLS_BYPASS_PORT_TOKEN
|
|
22
|
+
} from "./chunk-SZ7RFPXA.js";
|
|
23
|
+
import {
|
|
24
|
+
subscriberProviders
|
|
25
|
+
} from "./chunk-WOEJ6K7M.js";
|
|
26
|
+
import {
|
|
27
|
+
SubscriberService
|
|
28
|
+
} from "./chunk-LF6J4YYN.js";
|
|
29
|
+
import {
|
|
30
|
+
SaaSiCatPublicRoute
|
|
31
|
+
} from "./chunk-YSC46BGM.js";
|
|
32
|
+
import {
|
|
33
|
+
asProvider,
|
|
34
|
+
codedError
|
|
35
|
+
} from "./chunk-J7NJRK3K.js";
|
|
36
|
+
import {
|
|
37
|
+
__name
|
|
38
|
+
} from "./chunk-SHUYVCID.js";
|
|
39
|
+
|
|
40
|
+
// src/payments/payment-webhook.controller.ts
|
|
41
|
+
import { BadRequestException, Controller, HttpCode, Param, Post, Req } from "@nestjs/common";
|
|
42
|
+
import { PAYMENT_ERROR_CODES } from "@saasicat/core";
|
|
43
|
+
function _ts_decorate(decorators, target, key, desc) {
|
|
44
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
45
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
46
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
47
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
48
|
+
}
|
|
49
|
+
__name(_ts_decorate, "_ts_decorate");
|
|
50
|
+
function _ts_metadata(k, v) {
|
|
51
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
52
|
+
}
|
|
53
|
+
__name(_ts_metadata, "_ts_metadata");
|
|
54
|
+
function _ts_param(paramIndex, decorator) {
|
|
55
|
+
return function(target, key) {
|
|
56
|
+
decorator(target, key, paramIndex);
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
__name(_ts_param, "_ts_param");
|
|
60
|
+
var PARSED_BODY_TYPES = [
|
|
61
|
+
"application/json",
|
|
62
|
+
"application/x-www-form-urlencoded"
|
|
63
|
+
];
|
|
64
|
+
function carriesAParsedBody(contentType) {
|
|
65
|
+
const header = Array.isArray(contentType) ? contentType[0] : contentType;
|
|
66
|
+
const mediaType = (header ?? "").split(";")[0].trim().toLowerCase();
|
|
67
|
+
return PARSED_BODY_TYPES.includes(mediaType);
|
|
68
|
+
}
|
|
69
|
+
__name(carriesAParsedBody, "carriesAParsedBody");
|
|
70
|
+
var PaymentWebhookController = class {
|
|
71
|
+
static {
|
|
72
|
+
__name(this, "PaymentWebhookController");
|
|
73
|
+
}
|
|
74
|
+
callbacks;
|
|
75
|
+
constructor(callbacks) {
|
|
76
|
+
this.callbacks = callbacks;
|
|
77
|
+
}
|
|
78
|
+
async receive(account, request) {
|
|
79
|
+
if (!request.rawBody) {
|
|
80
|
+
if (!carriesAParsedBody(request.headers["content-type"])) {
|
|
81
|
+
throw new BadRequestException(codedError(PAYMENT_ERROR_CODES.PAYMENT_CALLBACK_REJECTED));
|
|
82
|
+
}
|
|
83
|
+
throw new Error("A payment callback arrived without its raw body, and its signature cannot be verified against a body parsed and serialised again. Create the application with `NestFactory.create(AppModule, { rawBody: true })`.");
|
|
84
|
+
}
|
|
85
|
+
await this.callbacks.handle(account, {
|
|
86
|
+
body: request.rawBody,
|
|
87
|
+
headers: request.headers
|
|
88
|
+
});
|
|
89
|
+
return {
|
|
90
|
+
received: true
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
_ts_decorate([
|
|
95
|
+
Post(":account"),
|
|
96
|
+
HttpCode(200),
|
|
97
|
+
_ts_param(0, Param("account")),
|
|
98
|
+
_ts_param(1, Req()),
|
|
99
|
+
_ts_metadata("design:type", Function),
|
|
100
|
+
_ts_metadata("design:paramtypes", [
|
|
101
|
+
String,
|
|
102
|
+
typeof RawBodyRequest === "undefined" ? Object : RawBodyRequest
|
|
103
|
+
]),
|
|
104
|
+
_ts_metadata("design:returntype", Promise)
|
|
105
|
+
], PaymentWebhookController.prototype, "receive", null);
|
|
106
|
+
PaymentWebhookController = _ts_decorate([
|
|
107
|
+
Controller("webhooks/payment"),
|
|
108
|
+
SaaSiCatPublicRoute(),
|
|
109
|
+
_ts_metadata("design:type", Function),
|
|
110
|
+
_ts_metadata("design:paramtypes", [
|
|
111
|
+
typeof PaymentCallbackService === "undefined" ? Object : PaymentCallbackService
|
|
112
|
+
])
|
|
113
|
+
], PaymentWebhookController);
|
|
114
|
+
|
|
115
|
+
// src/payments/subscriber-payment-method.service.ts
|
|
116
|
+
import { ConflictException, Inject, Injectable, Logger } from "@nestjs/common";
|
|
117
|
+
import { PAYMENT_ERROR_CODES as PAYMENT_ERROR_CODES2 } from "@saasicat/core";
|
|
118
|
+
function _ts_decorate2(decorators, target, key, desc) {
|
|
119
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
120
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
121
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
122
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
123
|
+
}
|
|
124
|
+
__name(_ts_decorate2, "_ts_decorate");
|
|
125
|
+
function _ts_metadata2(k, v) {
|
|
126
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
127
|
+
}
|
|
128
|
+
__name(_ts_metadata2, "_ts_metadata");
|
|
129
|
+
function _ts_param2(paramIndex, decorator) {
|
|
130
|
+
return function(target, key) {
|
|
131
|
+
decorator(target, key, paramIndex);
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
__name(_ts_param2, "_ts_param");
|
|
135
|
+
var SubscriberPaymentMethodService = class _SubscriberPaymentMethodService {
|
|
136
|
+
static {
|
|
137
|
+
__name(this, "SubscriberPaymentMethodService");
|
|
138
|
+
}
|
|
139
|
+
methods;
|
|
140
|
+
subscribers;
|
|
141
|
+
registry;
|
|
142
|
+
callbacks;
|
|
143
|
+
logger = new Logger(_SubscriberPaymentMethodService.name);
|
|
144
|
+
constructor(methods, subscribers, registry, callbacks) {
|
|
145
|
+
this.methods = methods;
|
|
146
|
+
this.subscribers = subscribers;
|
|
147
|
+
this.registry = registry;
|
|
148
|
+
this.callbacks = callbacks;
|
|
149
|
+
}
|
|
150
|
+
onModuleInit() {
|
|
151
|
+
this.callbacks.handleSetupsOf("subscriber", {
|
|
152
|
+
confirmed: /* @__PURE__ */ __name((event, context) => this.recordConfirmed(event, context), "confirmed"),
|
|
153
|
+
// Nothing was recorded for the setup, so a failed one changes nothing:
|
|
154
|
+
// the payment method in use stays, and the claim keeps the event.
|
|
155
|
+
failed: /* @__PURE__ */ __name(async () => void 0, "failed")
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
/** The payment method in use for the tenant's subscriber, or `null` when it has none. */
|
|
159
|
+
async current(tenantId) {
|
|
160
|
+
const subscriber = await this.subscribers.requireForTenant(tenantId);
|
|
161
|
+
return this.methods.findActive(subscriber.id);
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Opens the gateway's form for a new payment method for the tenant's
|
|
165
|
+
* subscriber, and returns where to send the person.
|
|
166
|
+
*
|
|
167
|
+
* The customer the subscriber has at that account is reused, so the new
|
|
168
|
+
* payment method sits beside the ones the gateway already holds for it.
|
|
169
|
+
*/
|
|
170
|
+
async startChange(tenantId, input) {
|
|
171
|
+
refuseForeignReturnUrls(input, this.registry.returnUrlOrigins());
|
|
172
|
+
const subscriber = await this.subscribers.requireForTenant(tenantId);
|
|
173
|
+
const account = this.registry.forNewPaymentMethods();
|
|
174
|
+
if (!account) {
|
|
175
|
+
throw new ConflictException(codedError(PAYMENT_ERROR_CODES2.PAYMENTS_NOT_CONFIGURED));
|
|
176
|
+
}
|
|
177
|
+
const inUse = await this.methods.findActive(subscriber.id);
|
|
178
|
+
const session = await account.gateway.startPaymentMethodSetup({
|
|
179
|
+
subject: {
|
|
180
|
+
kind: "subscriber",
|
|
181
|
+
subscriberId: subscriber.id
|
|
182
|
+
},
|
|
183
|
+
holder: holderOf(subscriber, input.fallbackEmail, customerAt(inUse, account.name)),
|
|
184
|
+
methods: account.methods,
|
|
185
|
+
successUrl: input.successUrl,
|
|
186
|
+
cancelUrl: input.cancelUrl
|
|
187
|
+
});
|
|
188
|
+
await this.methods.recordSetup({
|
|
189
|
+
subscriberId: subscriber.id,
|
|
190
|
+
gatewayAccount: account.name,
|
|
191
|
+
sessionRef: session.sessionRef,
|
|
192
|
+
customerRef: session.customerRef,
|
|
193
|
+
startedAt: /* @__PURE__ */ new Date()
|
|
194
|
+
});
|
|
195
|
+
if (session.immediateCallback) {
|
|
196
|
+
await this.callbacks.handle(account.name, session.immediateCallback);
|
|
197
|
+
}
|
|
198
|
+
return {
|
|
199
|
+
redirectUrl: session.redirectUrl
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
async recordConfirmed(event, context) {
|
|
203
|
+
if (event.subject.kind !== "subscriber") return "nothing-to-do";
|
|
204
|
+
const completed = await this.methods.completeSetup({
|
|
205
|
+
gatewayAccount: context.gatewayAccount,
|
|
206
|
+
sessionRef: event.sessionRef,
|
|
207
|
+
subscriberId: event.subject.subscriberId
|
|
208
|
+
}, event.occurredAt, context.tx);
|
|
209
|
+
if (!completed) {
|
|
210
|
+
this.logger.error(`Payment event ${event.eventId} at '${context.gatewayAccount}' names subscriber ${event.subject.subscriberId} and session ${event.sessionRef}, which no open setup matches; nothing recorded.`);
|
|
211
|
+
return "nothing-to-do";
|
|
212
|
+
}
|
|
213
|
+
await this.methods.recordConfirmed({
|
|
214
|
+
...event.paymentMethod,
|
|
215
|
+
subscriberId: event.subject.subscriberId,
|
|
216
|
+
gatewayAccount: context.gatewayAccount,
|
|
217
|
+
provider: context.provider,
|
|
218
|
+
confirmedAt: event.occurredAt
|
|
219
|
+
}, context.tx);
|
|
220
|
+
return "took-effect";
|
|
221
|
+
}
|
|
222
|
+
};
|
|
223
|
+
SubscriberPaymentMethodService = _ts_decorate2([
|
|
224
|
+
Injectable(),
|
|
225
|
+
_ts_param2(0, Inject(SUBSCRIBER_PAYMENT_METHOD_REPOSITORY_TOKEN)),
|
|
226
|
+
_ts_metadata2("design:type", Function),
|
|
227
|
+
_ts_metadata2("design:paramtypes", [
|
|
228
|
+
typeof SubscriberPaymentMethodRepository === "undefined" ? Object : SubscriberPaymentMethodRepository,
|
|
229
|
+
typeof SubscriberService === "undefined" ? Object : SubscriberService,
|
|
230
|
+
typeof PaymentGatewayRegistry === "undefined" ? Object : PaymentGatewayRegistry,
|
|
231
|
+
typeof PaymentCallbackService === "undefined" ? Object : PaymentCallbackService
|
|
232
|
+
])
|
|
233
|
+
], SubscriberPaymentMethodService);
|
|
234
|
+
function customerAt(inUse, account) {
|
|
235
|
+
return inUse?.gatewayAccount === account ? inUse.customerRef : null;
|
|
236
|
+
}
|
|
237
|
+
__name(customerAt, "customerAt");
|
|
238
|
+
function holderOf(subscriber, fallbackEmail, customerRef) {
|
|
239
|
+
return {
|
|
240
|
+
name: subscriber.legalName,
|
|
241
|
+
email: subscriber.invoiceEmail ?? fallbackEmail,
|
|
242
|
+
address: {
|
|
243
|
+
addressLine1: subscriber.addressLine1,
|
|
244
|
+
addressLine2: subscriber.addressLine2,
|
|
245
|
+
postalCode: subscriber.postalCode,
|
|
246
|
+
city: subscriber.city,
|
|
247
|
+
country: subscriber.country
|
|
248
|
+
},
|
|
249
|
+
customerRef
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
__name(holderOf, "holderOf");
|
|
253
|
+
|
|
254
|
+
// src/payments/dto/change-billing-details.dto.ts
|
|
255
|
+
import { IsOptional, IsString, MaxLength, ValidateIf } from "class-validator";
|
|
256
|
+
function _ts_decorate3(decorators, target, key, desc) {
|
|
257
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
258
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
259
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
260
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
261
|
+
}
|
|
262
|
+
__name(_ts_decorate3, "_ts_decorate");
|
|
263
|
+
function _ts_metadata3(k, v) {
|
|
264
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
265
|
+
}
|
|
266
|
+
__name(_ts_metadata3, "_ts_metadata");
|
|
267
|
+
var present = /* @__PURE__ */ __name((_, value) => value !== null && value !== void 0, "present");
|
|
268
|
+
var ChangeBillingDetailsDto = class {
|
|
269
|
+
static {
|
|
270
|
+
__name(this, "ChangeBillingDetailsDto");
|
|
271
|
+
}
|
|
272
|
+
addressLine1;
|
|
273
|
+
addressLine2;
|
|
274
|
+
postalCode;
|
|
275
|
+
city;
|
|
276
|
+
/** ISO 3166-1 alpha-2, e.g. `DE`; its form is checked where every detail is settled. */
|
|
277
|
+
country;
|
|
278
|
+
invoiceEmail;
|
|
279
|
+
legalName;
|
|
280
|
+
vatId;
|
|
281
|
+
taxNumber;
|
|
282
|
+
};
|
|
283
|
+
_ts_decorate3([
|
|
284
|
+
ValidateIf(present),
|
|
285
|
+
IsString(),
|
|
286
|
+
MaxLength(200),
|
|
287
|
+
_ts_metadata3("design:type", Object)
|
|
288
|
+
], ChangeBillingDetailsDto.prototype, "addressLine1", void 0);
|
|
289
|
+
_ts_decorate3([
|
|
290
|
+
ValidateIf(present),
|
|
291
|
+
IsString(),
|
|
292
|
+
MaxLength(200),
|
|
293
|
+
_ts_metadata3("design:type", Object)
|
|
294
|
+
], ChangeBillingDetailsDto.prototype, "addressLine2", void 0);
|
|
295
|
+
_ts_decorate3([
|
|
296
|
+
ValidateIf(present),
|
|
297
|
+
IsString(),
|
|
298
|
+
MaxLength(20),
|
|
299
|
+
_ts_metadata3("design:type", Object)
|
|
300
|
+
], ChangeBillingDetailsDto.prototype, "postalCode", void 0);
|
|
301
|
+
_ts_decorate3([
|
|
302
|
+
ValidateIf(present),
|
|
303
|
+
IsString(),
|
|
304
|
+
MaxLength(100),
|
|
305
|
+
_ts_metadata3("design:type", Object)
|
|
306
|
+
], ChangeBillingDetailsDto.prototype, "city", void 0);
|
|
307
|
+
_ts_decorate3([
|
|
308
|
+
ValidateIf(present),
|
|
309
|
+
IsString(),
|
|
310
|
+
MaxLength(2),
|
|
311
|
+
_ts_metadata3("design:type", Object)
|
|
312
|
+
], ChangeBillingDetailsDto.prototype, "country", void 0);
|
|
313
|
+
_ts_decorate3([
|
|
314
|
+
ValidateIf(present),
|
|
315
|
+
IsString(),
|
|
316
|
+
MaxLength(254),
|
|
317
|
+
_ts_metadata3("design:type", Object)
|
|
318
|
+
], ChangeBillingDetailsDto.prototype, "invoiceEmail", void 0);
|
|
319
|
+
_ts_decorate3([
|
|
320
|
+
IsOptional(),
|
|
321
|
+
_ts_metadata3("design:type", Object)
|
|
322
|
+
], ChangeBillingDetailsDto.prototype, "legalName", void 0);
|
|
323
|
+
_ts_decorate3([
|
|
324
|
+
IsOptional(),
|
|
325
|
+
_ts_metadata3("design:type", Object)
|
|
326
|
+
], ChangeBillingDetailsDto.prototype, "vatId", void 0);
|
|
327
|
+
_ts_decorate3([
|
|
328
|
+
IsOptional(),
|
|
329
|
+
_ts_metadata3("design:type", Object)
|
|
330
|
+
], ChangeBillingDetailsDto.prototype, "taxNumber", void 0);
|
|
331
|
+
|
|
332
|
+
// src/payments/tenant-billing-details.controller.ts
|
|
333
|
+
import { Body, Controller as Controller2, Get, Inject as Inject2, NotFoundException, Patch, Req as Req2, UseGuards } from "@nestjs/common";
|
|
334
|
+
import { AUTH_ERROR_CODES } from "@saasicat/core";
|
|
335
|
+
function _ts_decorate4(decorators, target, key, desc) {
|
|
336
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
337
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
338
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
339
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
340
|
+
}
|
|
341
|
+
__name(_ts_decorate4, "_ts_decorate");
|
|
342
|
+
function _ts_metadata4(k, v) {
|
|
343
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
344
|
+
}
|
|
345
|
+
__name(_ts_metadata4, "_ts_metadata");
|
|
346
|
+
function _ts_param3(paramIndex, decorator) {
|
|
347
|
+
return function(target, key) {
|
|
348
|
+
decorator(target, key, paramIndex);
|
|
349
|
+
};
|
|
350
|
+
}
|
|
351
|
+
__name(_ts_param3, "_ts_param");
|
|
352
|
+
var TenantBillingDetailsController = class {
|
|
353
|
+
static {
|
|
354
|
+
__name(this, "TenantBillingDetailsController");
|
|
355
|
+
}
|
|
356
|
+
subscribers;
|
|
357
|
+
tenantIdResolver;
|
|
358
|
+
constructor(subscribers, tenantIdResolver) {
|
|
359
|
+
this.subscribers = subscribers;
|
|
360
|
+
this.tenantIdResolver = tenantIdResolver;
|
|
361
|
+
}
|
|
362
|
+
async current(request) {
|
|
363
|
+
const subscriber = await this.subscribers.requireForTenant(this.tenantOf(request));
|
|
364
|
+
return {
|
|
365
|
+
details: viewOf(subscriber)
|
|
366
|
+
};
|
|
367
|
+
}
|
|
368
|
+
async change(request, body) {
|
|
369
|
+
const subscriber = await this.subscribers.changeContactOfTenant(this.tenantOf(request), body);
|
|
370
|
+
return {
|
|
371
|
+
details: viewOf(subscriber)
|
|
372
|
+
};
|
|
373
|
+
}
|
|
374
|
+
tenantOf(request) {
|
|
375
|
+
const tenantId = this.tenantIdResolver(request);
|
|
376
|
+
if (!tenantId) throw new NotFoundException(codedError(AUTH_ERROR_CODES.TENANT_CONTEXT_MISSING));
|
|
377
|
+
return tenantId;
|
|
378
|
+
}
|
|
379
|
+
};
|
|
380
|
+
_ts_decorate4([
|
|
381
|
+
Get(),
|
|
382
|
+
_ts_param3(0, Req2()),
|
|
383
|
+
_ts_metadata4("design:type", Function),
|
|
384
|
+
_ts_metadata4("design:paramtypes", [
|
|
385
|
+
Object
|
|
386
|
+
]),
|
|
387
|
+
_ts_metadata4("design:returntype", Promise)
|
|
388
|
+
], TenantBillingDetailsController.prototype, "current", null);
|
|
389
|
+
_ts_decorate4([
|
|
390
|
+
Patch(),
|
|
391
|
+
_ts_param3(0, Req2()),
|
|
392
|
+
_ts_param3(1, Body()),
|
|
393
|
+
_ts_metadata4("design:type", Function),
|
|
394
|
+
_ts_metadata4("design:paramtypes", [
|
|
395
|
+
Object,
|
|
396
|
+
typeof ChangeBillingDetailsDto === "undefined" ? Object : ChangeBillingDetailsDto
|
|
397
|
+
]),
|
|
398
|
+
_ts_metadata4("design:returntype", Promise)
|
|
399
|
+
], TenantBillingDetailsController.prototype, "change", null);
|
|
400
|
+
TenantBillingDetailsController = _ts_decorate4([
|
|
401
|
+
Controller2("billing/details"),
|
|
402
|
+
UseGuards(ComposedTenantAuthGuard, BillingPermissionGuard),
|
|
403
|
+
_ts_param3(0, Inject2(SubscriberService)),
|
|
404
|
+
_ts_param3(1, Inject2(TENANT_ID_RESOLVER_TOKEN)),
|
|
405
|
+
_ts_metadata4("design:type", Function),
|
|
406
|
+
_ts_metadata4("design:paramtypes", [
|
|
407
|
+
typeof SubscriberService === "undefined" ? Object : SubscriberService,
|
|
408
|
+
typeof TenantIdResolver === "undefined" ? Object : TenantIdResolver
|
|
409
|
+
])
|
|
410
|
+
], TenantBillingDetailsController);
|
|
411
|
+
function viewOf(subscriber) {
|
|
412
|
+
return {
|
|
413
|
+
customerNumber: subscriber.customerNumber,
|
|
414
|
+
legalName: subscriber.legalName,
|
|
415
|
+
vatId: subscriber.vatId,
|
|
416
|
+
taxNumber: subscriber.taxNumber,
|
|
417
|
+
addressLine1: subscriber.addressLine1,
|
|
418
|
+
addressLine2: subscriber.addressLine2,
|
|
419
|
+
postalCode: subscriber.postalCode,
|
|
420
|
+
city: subscriber.city,
|
|
421
|
+
country: subscriber.country,
|
|
422
|
+
invoiceEmail: subscriber.invoiceEmail
|
|
423
|
+
};
|
|
424
|
+
}
|
|
425
|
+
__name(viewOf, "viewOf");
|
|
426
|
+
|
|
427
|
+
// src/payments/dto/start-payment-method-setup.dto.ts
|
|
428
|
+
import { IsUrl, MaxLength as MaxLength2 } from "class-validator";
|
|
429
|
+
function _ts_decorate5(decorators, target, key, desc) {
|
|
430
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
431
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
432
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
433
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
434
|
+
}
|
|
435
|
+
__name(_ts_decorate5, "_ts_decorate");
|
|
436
|
+
function _ts_metadata5(k, v) {
|
|
437
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
438
|
+
}
|
|
439
|
+
__name(_ts_metadata5, "_ts_metadata");
|
|
440
|
+
var StartPaymentMethodSetupDto = class {
|
|
441
|
+
static {
|
|
442
|
+
__name(this, "StartPaymentMethodSetupDto");
|
|
443
|
+
}
|
|
444
|
+
successUrl;
|
|
445
|
+
cancelUrl;
|
|
446
|
+
};
|
|
447
|
+
_ts_decorate5([
|
|
448
|
+
IsUrl({
|
|
449
|
+
require_tld: false,
|
|
450
|
+
require_protocol: true,
|
|
451
|
+
protocols: [
|
|
452
|
+
"https",
|
|
453
|
+
"http"
|
|
454
|
+
]
|
|
455
|
+
}),
|
|
456
|
+
MaxLength2(500),
|
|
457
|
+
_ts_metadata5("design:type", String)
|
|
458
|
+
], StartPaymentMethodSetupDto.prototype, "successUrl", void 0);
|
|
459
|
+
_ts_decorate5([
|
|
460
|
+
IsUrl({
|
|
461
|
+
require_tld: false,
|
|
462
|
+
require_protocol: true,
|
|
463
|
+
protocols: [
|
|
464
|
+
"https",
|
|
465
|
+
"http"
|
|
466
|
+
]
|
|
467
|
+
}),
|
|
468
|
+
MaxLength2(500),
|
|
469
|
+
_ts_metadata5("design:type", String)
|
|
470
|
+
], StartPaymentMethodSetupDto.prototype, "cancelUrl", void 0);
|
|
471
|
+
|
|
472
|
+
// src/payments/tenant-payment-method.controller.ts
|
|
473
|
+
import { Body as Body2, Controller as Controller3, Get as Get2, HttpCode as HttpCode2, Inject as Inject3, NotFoundException as NotFoundException2, Optional, Post as Post2, Req as Req3, UseGuards as UseGuards2 } from "@nestjs/common";
|
|
474
|
+
import { AUTH_ERROR_CODES as AUTH_ERROR_CODES2 } from "@saasicat/core";
|
|
475
|
+
function _ts_decorate6(decorators, target, key, desc) {
|
|
476
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
477
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
478
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
479
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
480
|
+
}
|
|
481
|
+
__name(_ts_decorate6, "_ts_decorate");
|
|
482
|
+
function _ts_metadata6(k, v) {
|
|
483
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
484
|
+
}
|
|
485
|
+
__name(_ts_metadata6, "_ts_metadata");
|
|
486
|
+
function _ts_param4(paramIndex, decorator) {
|
|
487
|
+
return function(target, key) {
|
|
488
|
+
decorator(target, key, paramIndex);
|
|
489
|
+
};
|
|
490
|
+
}
|
|
491
|
+
__name(_ts_param4, "_ts_param");
|
|
492
|
+
var TenantPaymentMethodController = class {
|
|
493
|
+
static {
|
|
494
|
+
__name(this, "TenantPaymentMethodController");
|
|
495
|
+
}
|
|
496
|
+
paymentMethods;
|
|
497
|
+
tenantIdResolver;
|
|
498
|
+
userEmailResolver;
|
|
499
|
+
constructor(paymentMethods, tenantIdResolver, userEmailResolver = null) {
|
|
500
|
+
this.paymentMethods = paymentMethods;
|
|
501
|
+
this.tenantIdResolver = tenantIdResolver;
|
|
502
|
+
this.userEmailResolver = userEmailResolver;
|
|
503
|
+
}
|
|
504
|
+
async current(request) {
|
|
505
|
+
const method = await this.paymentMethods.current(this.tenantOf(request));
|
|
506
|
+
return {
|
|
507
|
+
paymentMethod: method ? viewOf2(method) : null
|
|
508
|
+
};
|
|
509
|
+
}
|
|
510
|
+
startSetup(request, body) {
|
|
511
|
+
return this.paymentMethods.startChange(this.tenantOf(request), {
|
|
512
|
+
successUrl: body.successUrl,
|
|
513
|
+
cancelUrl: body.cancelUrl,
|
|
514
|
+
fallbackEmail: this.emailOf(request)
|
|
515
|
+
});
|
|
516
|
+
}
|
|
517
|
+
tenantOf(request) {
|
|
518
|
+
const tenantId = this.tenantIdResolver(request);
|
|
519
|
+
if (!tenantId) throw new NotFoundException2(codedError(AUTH_ERROR_CODES2.TENANT_CONTEXT_MISSING));
|
|
520
|
+
return tenantId;
|
|
521
|
+
}
|
|
522
|
+
emailOf(request) {
|
|
523
|
+
if (this.userEmailResolver) return this.userEmailResolver(request) ?? null;
|
|
524
|
+
return request.user?.email ?? null;
|
|
525
|
+
}
|
|
526
|
+
};
|
|
527
|
+
_ts_decorate6([
|
|
528
|
+
Get2(),
|
|
529
|
+
_ts_param4(0, Req3()),
|
|
530
|
+
_ts_metadata6("design:type", Function),
|
|
531
|
+
_ts_metadata6("design:paramtypes", [
|
|
532
|
+
Object
|
|
533
|
+
]),
|
|
534
|
+
_ts_metadata6("design:returntype", Promise)
|
|
535
|
+
], TenantPaymentMethodController.prototype, "current", null);
|
|
536
|
+
_ts_decorate6([
|
|
537
|
+
Post2("setup"),
|
|
538
|
+
HttpCode2(200),
|
|
539
|
+
_ts_param4(0, Req3()),
|
|
540
|
+
_ts_param4(1, Body2()),
|
|
541
|
+
_ts_metadata6("design:type", Function),
|
|
542
|
+
_ts_metadata6("design:paramtypes", [
|
|
543
|
+
Object,
|
|
544
|
+
typeof StartPaymentMethodSetupDto === "undefined" ? Object : StartPaymentMethodSetupDto
|
|
545
|
+
]),
|
|
546
|
+
_ts_metadata6("design:returntype", typeof Promise === "undefined" ? Object : Promise)
|
|
547
|
+
], TenantPaymentMethodController.prototype, "startSetup", null);
|
|
548
|
+
TenantPaymentMethodController = _ts_decorate6([
|
|
549
|
+
Controller3("billing/payment-method"),
|
|
550
|
+
UseGuards2(ComposedTenantAuthGuard, BillingPermissionGuard),
|
|
551
|
+
_ts_param4(1, Inject3(TENANT_ID_RESOLVER_TOKEN)),
|
|
552
|
+
_ts_param4(2, Optional()),
|
|
553
|
+
_ts_param4(2, Inject3(USER_EMAIL_RESOLVER_TOKEN)),
|
|
554
|
+
_ts_metadata6("design:type", Function),
|
|
555
|
+
_ts_metadata6("design:paramtypes", [
|
|
556
|
+
typeof SubscriberPaymentMethodService === "undefined" ? Object : SubscriberPaymentMethodService,
|
|
557
|
+
typeof TenantIdResolver === "undefined" ? Object : TenantIdResolver,
|
|
558
|
+
Object
|
|
559
|
+
])
|
|
560
|
+
], TenantPaymentMethodController);
|
|
561
|
+
function viewOf2(method) {
|
|
562
|
+
return {
|
|
563
|
+
type: method.type,
|
|
564
|
+
brand: method.brand,
|
|
565
|
+
last4: method.last4,
|
|
566
|
+
expiryMonth: method.expiryMonth,
|
|
567
|
+
expiryYear: method.expiryYear,
|
|
568
|
+
country: method.country,
|
|
569
|
+
mandateReference: method.mandateReference,
|
|
570
|
+
confirmedAt: method.confirmedAt.toISOString()
|
|
571
|
+
};
|
|
572
|
+
}
|
|
573
|
+
__name(viewOf2, "viewOf");
|
|
574
|
+
|
|
575
|
+
// src/payments/payments.module.ts
|
|
576
|
+
import { Module } from "@nestjs/common";
|
|
577
|
+
|
|
578
|
+
// src/payments/stored-references.check.ts
|
|
579
|
+
import { Inject as Inject4, Injectable as Injectable2, Optional as Optional2 } from "@nestjs/common";
|
|
580
|
+
function _ts_decorate7(decorators, target, key, desc) {
|
|
581
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
582
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
583
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
584
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
585
|
+
}
|
|
586
|
+
__name(_ts_decorate7, "_ts_decorate");
|
|
587
|
+
function _ts_metadata7(k, v) {
|
|
588
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
589
|
+
}
|
|
590
|
+
__name(_ts_metadata7, "_ts_metadata");
|
|
591
|
+
function _ts_param5(paramIndex, decorator) {
|
|
592
|
+
return function(target, key) {
|
|
593
|
+
decorator(target, key, paramIndex);
|
|
594
|
+
};
|
|
595
|
+
}
|
|
596
|
+
__name(_ts_param5, "_ts_param");
|
|
597
|
+
var StoredPaymentReferencesCheck = class {
|
|
598
|
+
static {
|
|
599
|
+
__name(this, "StoredPaymentReferencesCheck");
|
|
600
|
+
}
|
|
601
|
+
registry;
|
|
602
|
+
methods;
|
|
603
|
+
rlsBypass;
|
|
604
|
+
constructor(registry, methods, rlsBypass = null) {
|
|
605
|
+
this.registry = registry;
|
|
606
|
+
this.methods = methods;
|
|
607
|
+
this.rlsBypass = rlsBypass;
|
|
608
|
+
}
|
|
609
|
+
async onApplicationBootstrap() {
|
|
610
|
+
const read = /* @__PURE__ */ __name(() => this.methods.accountsInUse(), "read");
|
|
611
|
+
const inUse = await (this.rlsBypass ? this.rlsBypass.runWithBypass(read) : read());
|
|
612
|
+
const unconfigured = this.registry.unconfigured(inUse);
|
|
613
|
+
if (unconfigured.length === 0) return;
|
|
614
|
+
throw new Error(`Payment methods in use are held at ${unconfigured.map((name) => `'${name}'`).join(", ")}, which config/saas.yaml#payments.accounts no longer names. List each account again, with its gateway bound, until its subscribers have a payment method at another one.`);
|
|
615
|
+
}
|
|
616
|
+
};
|
|
617
|
+
StoredPaymentReferencesCheck = _ts_decorate7([
|
|
618
|
+
Injectable2(),
|
|
619
|
+
_ts_param5(1, Inject4(SUBSCRIBER_PAYMENT_METHOD_REPOSITORY_TOKEN)),
|
|
620
|
+
_ts_param5(2, Optional2()),
|
|
621
|
+
_ts_param5(2, Inject4(RLS_BYPASS_PORT_TOKEN)),
|
|
622
|
+
_ts_metadata7("design:type", Function),
|
|
623
|
+
_ts_metadata7("design:paramtypes", [
|
|
624
|
+
typeof PaymentGatewayRegistry === "undefined" ? Object : PaymentGatewayRegistry,
|
|
625
|
+
typeof SubscriberPaymentMethodRepository === "undefined" ? Object : SubscriberPaymentMethodRepository,
|
|
626
|
+
Object
|
|
627
|
+
])
|
|
628
|
+
], StoredPaymentReferencesCheck);
|
|
629
|
+
|
|
630
|
+
// src/payments/payments.module.ts
|
|
631
|
+
function _ts_decorate8(decorators, target, key, desc) {
|
|
632
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
633
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
634
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
635
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
636
|
+
}
|
|
637
|
+
__name(_ts_decorate8, "_ts_decorate");
|
|
638
|
+
var PaymentsModule = class _PaymentsModule {
|
|
639
|
+
static {
|
|
640
|
+
__name(this, "PaymentsModule");
|
|
641
|
+
}
|
|
642
|
+
static forRoot(options) {
|
|
643
|
+
const providers = [
|
|
644
|
+
asProvider(PAYMENT_GATEWAYS_TOKEN, options.gateways),
|
|
645
|
+
asProvider(PAYMENT_EVENT_LOG_TOKEN, options.paymentEventLog),
|
|
646
|
+
asProvider(SUBSCRIBER_PAYMENT_METHOD_REPOSITORY_TOKEN, options.subscriberPaymentMethodRepository),
|
|
647
|
+
asProvider(PAYMENT_TRANSACTION_RUNNER_TOKEN, options.transactionRunner),
|
|
648
|
+
...subscriberProviders(options.subscriberRepository),
|
|
649
|
+
PaymentGatewayRegistry,
|
|
650
|
+
PaymentCallbackService,
|
|
651
|
+
SubscriberPaymentMethodService,
|
|
652
|
+
StoredPaymentReferencesCheck,
|
|
653
|
+
...options.extraProviders ?? []
|
|
654
|
+
];
|
|
655
|
+
const controllers = [
|
|
656
|
+
PaymentWebhookController
|
|
657
|
+
];
|
|
658
|
+
const tenant = options.tenantRoutes;
|
|
659
|
+
if (tenant) {
|
|
660
|
+
providers.push(asProvider(TENANT_AUTH_GUARDS_TOKEN, tenant.authGuards), ComposedTenantAuthGuard, BillingPermissionGuard, {
|
|
661
|
+
provide: TENANT_ID_RESOLVER_TOKEN,
|
|
662
|
+
useValue: tenant.tenantIdResolver ?? ((req) => req.user?.tenantId ?? null)
|
|
663
|
+
});
|
|
664
|
+
if (tenant.billingPermissionGuards) {
|
|
665
|
+
providers.push(asProvider(BILLING_PERMISSION_GUARDS_TOKEN, tenant.billingPermissionGuards));
|
|
666
|
+
}
|
|
667
|
+
if (tenant.userEmailResolver) {
|
|
668
|
+
providers.push({
|
|
669
|
+
provide: USER_EMAIL_RESOLVER_TOKEN,
|
|
670
|
+
useValue: tenant.userEmailResolver
|
|
671
|
+
});
|
|
672
|
+
}
|
|
673
|
+
controllers.push(TenantPaymentMethodController, TenantBillingDetailsController);
|
|
674
|
+
}
|
|
675
|
+
return {
|
|
676
|
+
module: _PaymentsModule,
|
|
677
|
+
global: options.global ?? true,
|
|
678
|
+
imports: options.imports ?? [],
|
|
679
|
+
controllers,
|
|
680
|
+
providers,
|
|
681
|
+
exports: [
|
|
682
|
+
PaymentGatewayRegistry,
|
|
683
|
+
PaymentCallbackService,
|
|
684
|
+
SubscriberPaymentMethodService,
|
|
685
|
+
SUBSCRIBER_PAYMENT_METHOD_REPOSITORY_TOKEN
|
|
686
|
+
]
|
|
687
|
+
};
|
|
688
|
+
}
|
|
689
|
+
};
|
|
690
|
+
PaymentsModule = _ts_decorate8([
|
|
691
|
+
Module({})
|
|
692
|
+
], PaymentsModule);
|
|
693
|
+
|
|
694
|
+
export {
|
|
695
|
+
PaymentWebhookController,
|
|
696
|
+
SubscriberPaymentMethodService,
|
|
697
|
+
ChangeBillingDetailsDto,
|
|
698
|
+
TenantBillingDetailsController,
|
|
699
|
+
StartPaymentMethodSetupDto,
|
|
700
|
+
TenantPaymentMethodController,
|
|
701
|
+
PaymentsModule
|
|
702
|
+
};
|