@darraghor/nest-backend-libs 5.7.5 → 6.0.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.
Files changed (134) hide show
  1. package/README.md +87 -36
  2. package/dist/exports/authorization.d.ts +14 -0
  3. package/dist/exports/authorization.js +12 -0
  4. package/dist/exports/authorization.js.map +1 -0
  5. package/dist/exports/core.d.ts +11 -0
  6. package/dist/exports/core.js +10 -0
  7. package/dist/exports/core.js.map +1 -0
  8. package/dist/exports/database.d.ts +5 -0
  9. package/dist/exports/database.js +6 -0
  10. package/dist/exports/database.js.map +1 -0
  11. package/dist/exports/email.d.ts +4 -0
  12. package/dist/exports/email.js +4 -0
  13. package/dist/exports/email.js.map +1 -0
  14. package/dist/exports/invitations.d.ts +6 -0
  15. package/dist/exports/invitations.js +6 -0
  16. package/dist/exports/invitations.js.map +1 -0
  17. package/dist/exports/organisations.d.ts +11 -0
  18. package/dist/exports/organisations.js +12 -0
  19. package/dist/exports/organisations.js.map +1 -0
  20. package/dist/exports/stripe-legacy.d.ts +6 -0
  21. package/dist/exports/stripe-legacy.js +7 -0
  22. package/dist/exports/stripe-legacy.js.map +1 -0
  23. package/dist/exports/stripe.d.ts +11 -0
  24. package/dist/exports/stripe.js +9 -0
  25. package/dist/exports/stripe.js.map +1 -0
  26. package/dist/exports/twitter.d.ts +5 -0
  27. package/dist/exports/twitter.js +5 -0
  28. package/dist/exports/twitter.js.map +1 -0
  29. package/dist/exports/users.d.ts +10 -0
  30. package/dist/exports/users.js +11 -0
  31. package/dist/exports/users.js.map +1 -0
  32. package/dist/index.d.ts +11 -0
  33. package/dist/index.js +11 -0
  34. package/dist/index.js.map +1 -1
  35. package/dist/organisation-subscriptions/entities/organisation-subscription.entity.js +2 -1
  36. package/dist/organisation-subscriptions/entities/organisation-subscription.entity.js.map +1 -1
  37. package/dist/stripe-client/StripeClientConfigurationService.js +1 -0
  38. package/dist/stripe-client/StripeClientConfigurationService.js.map +1 -1
  39. package/dist/stripe-client/controllers/stripe-checkout-controller.d.ts +1 -0
  40. package/dist/stripe-client/controllers/stripe-checkout-controller.js +1 -0
  41. package/dist/stripe-client/controllers/stripe-checkout-controller.js.map +1 -1
  42. package/dist/stripe-client/controllers/stripe-events-controller.js +1 -0
  43. package/dist/stripe-client/controllers/stripe-events-controller.js.map +1 -1
  44. package/dist/stripe-client/controllers/stripe-unauthenticated-checkout-controller.js +1 -0
  45. package/dist/stripe-client/controllers/stripe-unauthenticated-checkout-controller.js.map +1 -1
  46. package/dist/stripe-client/services/auth-stripe-checkout.service.js +1 -0
  47. package/dist/stripe-client/services/auth-stripe-checkout.service.js.map +1 -1
  48. package/dist/stripe-client/services/queued-payment-event.handler.d.ts +1 -0
  49. package/dist/stripe-client/services/queued-payment-event.handler.js +2 -0
  50. package/dist/stripe-client/services/queued-payment-event.handler.js.map +1 -1
  51. package/dist/stripe-client/services/stripe-checkout.service.d.ts +1 -0
  52. package/dist/stripe-client/services/stripe-checkout.service.js +2 -0
  53. package/dist/stripe-client/services/stripe-checkout.service.js.map +1 -1
  54. package/dist/stripe-client/stripe-account.module.d.ts +1 -0
  55. package/dist/stripe-client/stripe-account.module.js +2 -0
  56. package/dist/stripe-client/stripe-account.module.js.map +1 -1
  57. package/dist/stripe-client/stripe-account.options.d.ts +2 -0
  58. package/dist/stripe-client/stripe-account.options.js.map +1 -1
  59. package/dist/stripe-payments/controllers/secure-stripe-checkout.controller.d.ts +10 -0
  60. package/dist/stripe-payments/controllers/secure-stripe-checkout.controller.js +65 -0
  61. package/dist/stripe-payments/controllers/secure-stripe-checkout.controller.js.map +1 -0
  62. package/dist/stripe-payments/controllers/secure-stripe-events.controller.d.ts +9 -0
  63. package/dist/stripe-payments/controllers/secure-stripe-events.controller.js +65 -0
  64. package/dist/stripe-payments/controllers/secure-stripe-events.controller.js.map +1 -0
  65. package/dist/stripe-payments/controllers/secure-stripe-webhook.controller.d.ts +14 -0
  66. package/dist/stripe-payments/controllers/secure-stripe-webhook.controller.js +112 -0
  67. package/dist/stripe-payments/controllers/secure-stripe-webhook.controller.js.map +1 -0
  68. package/dist/stripe-payments/entities/stripe-checkout-attempt.entity.d.ts +15 -0
  69. package/dist/stripe-payments/entities/stripe-checkout-attempt.entity.js +88 -0
  70. package/dist/stripe-payments/entities/stripe-checkout-attempt.entity.js.map +1 -0
  71. package/dist/stripe-payments/entities/stripe-payment-event.entity.d.ts +16 -0
  72. package/dist/stripe-payments/entities/stripe-payment-event.entity.js +101 -0
  73. package/dist/stripe-payments/entities/stripe-payment-event.entity.js.map +1 -0
  74. package/dist/stripe-payments/entities/stripe-payment-state.entity.d.ts +9 -0
  75. package/dist/stripe-payments/entities/stripe-payment-state.entity.js +53 -0
  76. package/dist/stripe-payments/entities/stripe-payment-state.entity.js.map +1 -0
  77. package/dist/stripe-payments/models/secure-checkout.dto.d.ts +14 -0
  78. package/dist/stripe-payments/models/secure-checkout.dto.js +105 -0
  79. package/dist/stripe-payments/models/secure-checkout.dto.js.map +1 -0
  80. package/dist/stripe-payments/models/secure-payment-response.dto.d.ts +7 -0
  81. package/dist/stripe-payments/models/secure-payment-response.dto.js +30 -0
  82. package/dist/stripe-payments/models/secure-payment-response.dto.js.map +1 -0
  83. package/dist/stripe-payments/services/default-stripe-payments-entitlement-store.d.ts +12 -0
  84. package/dist/stripe-payments/services/default-stripe-payments-entitlement-store.js +49 -0
  85. package/dist/stripe-payments/services/default-stripe-payments-entitlement-store.js.map +1 -0
  86. package/dist/stripe-payments/services/secure-stripe-checkout.service.d.ts +24 -0
  87. package/dist/stripe-payments/services/secure-stripe-checkout.service.js +213 -0
  88. package/dist/stripe-payments/services/secure-stripe-checkout.service.js.map +1 -0
  89. package/dist/stripe-payments/services/secure-stripe-client.provider.d.ts +2 -0
  90. package/dist/stripe-payments/services/secure-stripe-client.provider.js +15 -0
  91. package/dist/stripe-payments/services/secure-stripe-client.provider.js.map +1 -0
  92. package/dist/stripe-payments/services/secure-stripe-product.service.d.ts +9 -0
  93. package/dist/stripe-payments/services/secure-stripe-product.service.js +54 -0
  94. package/dist/stripe-payments/services/secure-stripe-product.service.js.map +1 -0
  95. package/dist/stripe-payments/services/secure-stripe-webhook.service.d.ts +14 -0
  96. package/dist/stripe-payments/services/secure-stripe-webhook.service.js +58 -0
  97. package/dist/stripe-payments/services/secure-stripe-webhook.service.js.map +1 -0
  98. package/dist/stripe-payments/services/secure-subscription.service.d.ts +18 -0
  99. package/dist/stripe-payments/services/secure-subscription.service.js +217 -0
  100. package/dist/stripe-payments/services/secure-subscription.service.js.map +1 -0
  101. package/dist/stripe-payments/services/stripe-payment-event.processor.d.ts +15 -0
  102. package/dist/stripe-payments/services/stripe-payment-event.processor.js +78 -0
  103. package/dist/stripe-payments/services/stripe-payment-event.processor.js.map +1 -0
  104. package/dist/stripe-payments/services/stripe-payment-event.service.d.ts +20 -0
  105. package/dist/stripe-payments/services/stripe-payment-event.service.js +178 -0
  106. package/dist/stripe-payments/services/stripe-payment-event.service.js.map +1 -0
  107. package/dist/stripe-payments/services/stripe-payment-fulfillment.service.d.ts +31 -0
  108. package/dist/stripe-payments/services/stripe-payment-fulfillment.service.js +331 -0
  109. package/dist/stripe-payments/services/stripe-payment-fulfillment.service.js.map +1 -0
  110. package/dist/stripe-payments/services/stripe-payments-operations.service.d.ts +25 -0
  111. package/dist/stripe-payments/services/stripe-payments-operations.service.js +59 -0
  112. package/dist/stripe-payments/services/stripe-payments-operations.service.js.map +1 -0
  113. package/dist/stripe-payments/services/stripe-payments-telemetry.service.d.ts +7 -0
  114. package/dist/stripe-payments/services/stripe-payments-telemetry.service.js +40 -0
  115. package/dist/stripe-payments/services/stripe-payments-telemetry.service.js.map +1 -0
  116. package/dist/stripe-payments/stripe-payment.config.d.ts +19 -0
  117. package/dist/stripe-payments/stripe-payment.config.js +98 -0
  118. package/dist/stripe-payments/stripe-payment.config.js.map +1 -0
  119. package/dist/stripe-payments/stripe-payment.config.test.d.ts +1 -0
  120. package/dist/stripe-payments/stripe-payment.config.test.js +59 -0
  121. package/dist/stripe-payments/stripe-payment.config.test.js.map +1 -0
  122. package/dist/stripe-payments/stripe-payments.extensions.d.ts +69 -0
  123. package/dist/stripe-payments/stripe-payments.extensions.js +30 -0
  124. package/dist/stripe-payments/stripe-payments.extensions.js.map +1 -0
  125. package/dist/stripe-payments/stripe-payments.module.d.ts +12 -0
  126. package/dist/stripe-payments/stripe-payments.module.js +118 -0
  127. package/dist/stripe-payments/stripe-payments.module.js.map +1 -0
  128. package/dist/stripe-payments/stripe-payments.options.d.ts +21 -0
  129. package/dist/stripe-payments/stripe-payments.options.js +2 -0
  130. package/dist/stripe-payments/stripe-payments.options.js.map +1 -0
  131. package/dist/typeorm/entities.d.ts +15 -0
  132. package/dist/typeorm/entities.js +32 -0
  133. package/dist/typeorm/entities.js.map +1 -0
  134. package/package.json +41 -1
@@ -0,0 +1,178 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ 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;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __metadata = (this && this.__metadata) || function (k, v) {
8
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
+ };
10
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
11
+ return function (target, key) { decorator(target, key, paramIndex); }
12
+ };
13
+ var StripePaymentEventService_1;
14
+ import { Injectable, Logger } from "@nestjs/common";
15
+ import { InjectRepository } from "@nestjs/typeorm";
16
+ import { Queue } from "bullmq";
17
+ import { InjectQueue } from "@nestjs/bullmq";
18
+ import { Repository } from "typeorm";
19
+ import { StripeCheckoutEvent } from "../entities/stripe-payment-event.entity.js";
20
+ import { StripePaymentsTelemetryService } from "./stripe-payments-telemetry.service.js";
21
+ function getObject(event) {
22
+ return event.data.object;
23
+ }
24
+ function getObjectId(event) {
25
+ const objectId = getObject(event).id;
26
+ return typeof objectId === "string" ? objectId : "unknown";
27
+ }
28
+ function getClientReferenceId(event) {
29
+ const clientReferenceId = getObject(event).client_reference_id;
30
+ return typeof clientReferenceId === "string"
31
+ ? clientReferenceId
32
+ : undefined;
33
+ }
34
+ let StripePaymentEventService = StripePaymentEventService_1 = class StripePaymentEventService {
35
+ eventRepository;
36
+ eventQueue;
37
+ telemetry;
38
+ logger = new Logger(StripePaymentEventService_1.name);
39
+ constructor(eventRepository, eventQueue, telemetry) {
40
+ this.eventRepository = eventRepository;
41
+ this.eventQueue = eventQueue;
42
+ this.telemetry = telemetry;
43
+ }
44
+ async receive(event) {
45
+ let paymentEvent = await this.eventRepository.findOne({
46
+ where: { stripeEventId: event.id },
47
+ });
48
+ if (!paymentEvent) {
49
+ paymentEvent = this.eventRepository.create({
50
+ stripeEventId: event.id,
51
+ stripeObjectId: getObjectId(event),
52
+ eventType: event.type,
53
+ clientReferenceId: getClientReferenceId(event),
54
+ stripeData: event,
55
+ status: "received",
56
+ processingAttempts: 0,
57
+ });
58
+ try {
59
+ paymentEvent = await this.eventRepository.save(paymentEvent);
60
+ }
61
+ catch (error) {
62
+ const code = error
63
+ .driverError?.code;
64
+ if (code !== "23505") {
65
+ throw error;
66
+ }
67
+ paymentEvent = await this.eventRepository.findOneOrFail({
68
+ where: { stripeEventId: event.id },
69
+ });
70
+ }
71
+ }
72
+ if (paymentEvent.status === "processed") {
73
+ return;
74
+ }
75
+ await this.telemetry.record({
76
+ name: "webhook.received",
77
+ stripeEventId: event.id,
78
+ eventType: event.type,
79
+ });
80
+ const existingJob = await this.eventQueue.getJob(this.getBaseJobId(event.id));
81
+ if (existingJob && !(await existingJob.isFailed())) {
82
+ return;
83
+ }
84
+ const jobId = existingJob
85
+ ? `${this.getBaseJobId(event.id)}:retry:${String(Date.now())}`
86
+ : this.getBaseJobId(event.id);
87
+ await this.eventQueue.add("stripe-event", event, {
88
+ jobId,
89
+ attempts: 8,
90
+ backoff: { type: "exponential", delay: 5_000 },
91
+ removeOnComplete: { age: 86_400, count: 10_000 },
92
+ removeOnFail: { age: 604_800, count: 10_000 },
93
+ });
94
+ }
95
+ async claim(eventId) {
96
+ const now = new Date();
97
+ const staleProcessingCutoff = new Date(now.getTime() - 5 * 60 * 1000);
98
+ const result = await this.eventRepository
99
+ .createQueryBuilder()
100
+ .update(StripeCheckoutEvent)
101
+ .set({
102
+ status: "processing",
103
+ processingStartedAt: now,
104
+ processingAttempts: () => '"processingAttempts" + 1',
105
+ })
106
+ .where('"stripeEventId" = :eventId', { eventId })
107
+ .andWhere('("status" IN (:...retryableStatuses) OR ("status" = :processingStatus AND "processingStartedAt" < :staleProcessingCutoff))', {
108
+ retryableStatuses: ["received", "failed"],
109
+ processingStatus: "processing",
110
+ staleProcessingCutoff,
111
+ })
112
+ .execute();
113
+ return (result.affected ?? 0) > 0;
114
+ }
115
+ async isProcessed(eventId) {
116
+ const paymentEvent = await this.eventRepository.findOne({
117
+ select: { status: true },
118
+ where: { stripeEventId: eventId },
119
+ });
120
+ return paymentEvent?.status === "processed";
121
+ }
122
+ async markProcessed(eventId) {
123
+ await this.eventRepository.update({ stripeEventId: eventId }, {
124
+ status: "processed",
125
+ processedAt: new Date(),
126
+ errorMessage: undefined,
127
+ });
128
+ }
129
+ async markFailed(eventId, error) {
130
+ const errorMessage = error instanceof Error ? error.message : String(error);
131
+ await this.eventRepository.update({ stripeEventId: eventId }, {
132
+ status: "failed",
133
+ errorMessage: errorMessage.slice(0, 2_000),
134
+ });
135
+ this.logger.error("Stripe payment event processing failed", {
136
+ eventId,
137
+ error: errorMessage,
138
+ });
139
+ }
140
+ async list(take, skip) {
141
+ return this.eventRepository.find({
142
+ take,
143
+ skip,
144
+ order: { createdDate: "DESC" },
145
+ });
146
+ }
147
+ async replay(eventId) {
148
+ const paymentEvent = await this.eventRepository.findOne({
149
+ where: { stripeEventId: eventId },
150
+ });
151
+ if (!paymentEvent) {
152
+ throw new Error("Stripe event not found");
153
+ }
154
+ paymentEvent.status = "received";
155
+ paymentEvent.errorMessage = undefined;
156
+ await this.eventRepository.save(paymentEvent);
157
+ await this.eventQueue.add("stripe-event", paymentEvent.stripeData, {
158
+ jobId: `${this.getBaseJobId(eventId)}:manual:${String(Date.now())}`,
159
+ attempts: 8,
160
+ backoff: { type: "exponential", delay: 5_000 },
161
+ removeOnComplete: { age: 86_400, count: 10_000 },
162
+ removeOnFail: { age: 604_800, count: 10_000 },
163
+ });
164
+ }
165
+ getBaseJobId(eventId) {
166
+ return `stripe-event:${eventId}`;
167
+ }
168
+ };
169
+ StripePaymentEventService = StripePaymentEventService_1 = __decorate([
170
+ Injectable(),
171
+ __param(0, InjectRepository(StripeCheckoutEvent)),
172
+ __param(1, InjectQueue("stripe-events")),
173
+ __metadata("design:paramtypes", [Repository,
174
+ Queue,
175
+ StripePaymentsTelemetryService])
176
+ ], StripePaymentEventService);
177
+ export { StripePaymentEventService };
178
+ //# sourceMappingURL=stripe-payment-event.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stripe-payment-event.service.js","sourceRoot":"","sources":["../../../src/stripe-payments/services/stripe-payment-event.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,OAAO,EAAC,UAAU,EAAE,MAAM,EAAC,MAAM,gBAAgB,CAAC;AAClD,OAAO,EAAC,gBAAgB,EAAC,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAC,KAAK,EAAC,MAAM,QAAQ,CAAC;AAC7B,OAAO,EAAC,WAAW,EAAC,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAC,UAAU,EAAC,MAAM,SAAS,CAAC;AAEnC,OAAO,EAAC,mBAAmB,EAAC,MAAM,4CAA4C,CAAC;AAC/E,OAAO,EAAC,8BAA8B,EAAC,MAAM,wCA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AAC;SAClC,CAAC,CAAC;QACH,IAAI,CAAC,YAAY,EAAE,CAAC;YAChB,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAC;QAC9C,CAAC;QACD,YAAY,CAAC,MAAM,GAAG,UAAU,CAAC;QACjC,YAAY,CAAC,YAAY,GAAG,SAAS,CAAC;QACtC,MAAM,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;QAC9C,MAAM,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,cAAc,EAAE,YAAY,CAAC,UAAU,EAAE;YAC/D,KAAK,EAAE,GAAG,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,WAAW,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,EAAE;YACnE,QAAQ,EAAE,CAAC;YACX,OAAO,EAAE,EAAC,IAAI,EAAE,aAAa,EAAE,KAAK,EAAE,KAAK,EAAC;YAC5C,gBAAgB,EAAE,EAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAC;YAC9C,YAAY,EAAE,EAAC,GAAG,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAC;SAC9C,CAAC,CAAC;IACP,CAAC;IAEO,YAAY,CAAC,OAAe;QAChC,OAAO,gBAAgB,OAAO,EAAE,CAAC;IACrC,CAAC;CACJ,CAAA;AA7JY,yBAAyB;IADrC,UAAU,EAAE;IAKJ,WAAA,gBAAgB,CAAC,mBAAmB,CAAC,CAAA;IAErC,WAAA,WAAW,CAAC,eAAe,CAAC,CAAA;qCADK,UAAU;QAEf,KAAK;QACN,8BAA8B;GARrD,yBAAyB,CA6JrC"}
@@ -0,0 +1,31 @@
1
+ import Stripe from "stripe";
2
+ import { Repository } from "typeorm";
3
+ import { StripeCheckoutAttempt } from "../entities/stripe-checkout-attempt.entity.js";
4
+ import { PaymentSessionService } from "../../payment-sessions/payment-session.service.js";
5
+ import { SecureStripeProductService } from "./secure-stripe-product.service.js";
6
+ import { StripePaymentsEntitlementStore } from "../stripe-payments.extensions.js";
7
+ export declare class StripePaymentFulfillmentService {
8
+ private readonly stripe;
9
+ private readonly attemptRepository;
10
+ private readonly paymentSessionService;
11
+ private readonly productService;
12
+ private readonly entitlementStore;
13
+ private readonly logger;
14
+ constructor(stripe: Stripe, attemptRepository: Repository<StripeCheckoutAttempt>, paymentSessionService: PaymentSessionService, productService: SecureStripeProductService, entitlementStore: StripePaymentsEntitlementStore);
15
+ process(event: Stripe.Event): Promise<void>;
16
+ private processCheckoutSession;
17
+ private markCheckoutAttemptFailed;
18
+ private processSubscriptionEvent;
19
+ private processInvoiceEvent;
20
+ private processRefundEvent;
21
+ private processDisputeEvent;
22
+ private revokeChargeEntitlement;
23
+ private saveSubscription;
24
+ private resolveOrganisationUuid;
25
+ private retrieveSubscription;
26
+ private getSubscriptionValidUntil;
27
+ private getSubscriptionId;
28
+ private getId;
29
+ private getClientReferenceId;
30
+ private eventCreatedAt;
31
+ }
@@ -0,0 +1,331 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ 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;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __metadata = (this && this.__metadata) || function (k, v) {
8
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
+ };
10
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
11
+ return function (target, key) { decorator(target, key, paramIndex); }
12
+ };
13
+ var StripePaymentFulfillmentService_1;
14
+ import { Inject, Injectable, Logger } from "@nestjs/common";
15
+ import Stripe from "stripe";
16
+ import { InjectRepository } from "@nestjs/typeorm";
17
+ import { Repository } from "typeorm";
18
+ import { StripeCheckoutAttempt } from "../entities/stripe-checkout-attempt.entity.js";
19
+ import { PaymentSessionService } from "../../payment-sessions/payment-session.service.js";
20
+ import { SecureStripeProductService } from "./secure-stripe-product.service.js";
21
+ import { STRIPE_PAYMENTS_ENTITLEMENT_STORE, } from "../stripe-payments.extensions.js";
22
+ function getMetadata(value) {
23
+ return value.metadata ?? {};
24
+ }
25
+ function getCustomer(customer) {
26
+ if (typeof customer === "string") {
27
+ return { id: customer, email: "unknown" };
28
+ }
29
+ if (!customer || "deleted" in customer) {
30
+ return { id: customer?.id ?? "unknown", email: "unknown" };
31
+ }
32
+ return {
33
+ id: customer.id,
34
+ email: customer.email ?? "unknown",
35
+ };
36
+ }
37
+ function addGracePeriod(date) {
38
+ return new Date(date.getTime() + 2 * 24 * 60 * 60 * 1000);
39
+ }
40
+ function getLifetimeDate() {
41
+ const lifetime = new Date();
42
+ lifetime.setFullYear(lifetime.getFullYear() + 500);
43
+ return lifetime;
44
+ }
45
+ let StripePaymentFulfillmentService = StripePaymentFulfillmentService_1 = class StripePaymentFulfillmentService {
46
+ stripe;
47
+ attemptRepository;
48
+ paymentSessionService;
49
+ productService;
50
+ entitlementStore;
51
+ logger = new Logger(StripePaymentFulfillmentService_1.name);
52
+ constructor(stripe, attemptRepository, paymentSessionService, productService, entitlementStore) {
53
+ this.stripe = stripe;
54
+ this.attemptRepository = attemptRepository;
55
+ this.paymentSessionService = paymentSessionService;
56
+ this.productService = productService;
57
+ this.entitlementStore = entitlementStore;
58
+ }
59
+ async process(event) {
60
+ switch (event.type) {
61
+ case "checkout.session.completed":
62
+ await this.processCheckoutSession(event, false);
63
+ return;
64
+ case "checkout.session.async_payment_succeeded":
65
+ await this.processCheckoutSession(event, true);
66
+ return;
67
+ case "checkout.session.async_payment_failed":
68
+ case "checkout.session.expired":
69
+ await this.markCheckoutAttemptFailed(event);
70
+ return;
71
+ case "customer.subscription.created":
72
+ case "customer.subscription.updated":
73
+ case "customer.subscription.deleted":
74
+ case "customer.subscription.paused":
75
+ case "customer.subscription.resumed":
76
+ await this.processSubscriptionEvent(event);
77
+ return;
78
+ case "invoice.paid":
79
+ case "invoice.payment_failed":
80
+ await this.processInvoiceEvent(event);
81
+ return;
82
+ case "charge.refunded":
83
+ await this.processRefundEvent(event);
84
+ return;
85
+ case "charge.dispute.created":
86
+ await this.processDisputeEvent(event);
87
+ return;
88
+ default:
89
+ return;
90
+ }
91
+ }
92
+ async processCheckoutSession(event, isAsyncPayment) {
93
+ const sessionEvent = event.data.object;
94
+ const session = await this.stripe.checkout.sessions.retrieve(sessionEvent.id, {
95
+ expand: [
96
+ "line_items.data.price.product",
97
+ "customer",
98
+ "subscription",
99
+ ],
100
+ });
101
+ if (!isAsyncPayment && session.payment_status !== "paid") {
102
+ return;
103
+ }
104
+ const lineItems = session.line_items?.data ?? [];
105
+ if (lineItems.length !== 1 || lineItems[0]?.quantity !== 1) {
106
+ throw new Error("Checkout session did not contain the expected product");
107
+ }
108
+ const lineItem = lineItems[0];
109
+ const price = lineItem.price;
110
+ if (!price || typeof price === "string") {
111
+ throw new Error("Checkout session price was not expanded");
112
+ }
113
+ const configuredProduct = this.productService.getByPriceId(price.id);
114
+ const metadata = getMetadata(session);
115
+ if (metadata.productKey &&
116
+ metadata.productKey !== configuredProduct.key) {
117
+ throw new Error("Checkout metadata did not match the configured product");
118
+ }
119
+ const organisationUuid = await this.resolveOrganisationUuid(session, metadata);
120
+ const customer = getCustomer(session.customer);
121
+ const subscriptionId = this.getSubscriptionId(session.subscription);
122
+ let validUntil = getLifetimeDate();
123
+ if (configuredProduct.mode === "subscription") {
124
+ if (!subscriptionId) {
125
+ throw new Error("Subscription checkout did not create a subscription");
126
+ }
127
+ const subscription = await this.retrieveSubscription(subscriptionId);
128
+ validUntil = this.getSubscriptionValidUntil(subscription);
129
+ }
130
+ const productObject = typeof price.product === "string" ? undefined : price.product;
131
+ const input = {
132
+ paymentSystemTransactionId: subscriptionId ?? session.id,
133
+ paymentSystemProductId: productObject?.id ?? price.id,
134
+ paymentSystemCustomerId: customer.id,
135
+ paymentSystemCustomerEmail: customer.email !== "unknown"
136
+ ? customer.email
137
+ : (session.customer_details?.email ?? "unknown"),
138
+ paymentSystemMode: configuredProduct.mode,
139
+ paymentSystemName: "stripe",
140
+ validUntil,
141
+ internalSku: configuredProduct.internalSku,
142
+ productDisplayName: productObject && !("deleted" in productObject)
143
+ ? productObject.name
144
+ : configuredProduct.displayName,
145
+ organisationUuid,
146
+ stripeEventId: event.id,
147
+ stripeEventCreatedAt: this.eventCreatedAt(event),
148
+ stripeStatus: configuredProduct.mode === "subscription" ? "active" : "paid",
149
+ };
150
+ await this.entitlementStore.save(input);
151
+ }
152
+ async markCheckoutAttemptFailed(event) {
153
+ const session = event.data.object;
154
+ await this.attemptRepository.update({ stripeSessionId: session.id }, {
155
+ status: "failed",
156
+ errorMessage: event.type === "checkout.session.expired"
157
+ ? "Checkout session expired"
158
+ : "Asynchronous payment failed",
159
+ });
160
+ this.logger.warn("Stripe Checkout attempt did not complete", {
161
+ eventId: event.id,
162
+ sessionId: session.id,
163
+ eventType: event.type,
164
+ });
165
+ }
166
+ async processSubscriptionEvent(event) {
167
+ const subscriptionEvent = event.data.object;
168
+ const subscription = await this.retrieveSubscription(subscriptionEvent.id);
169
+ await this.saveSubscription(subscription, event);
170
+ }
171
+ async processInvoiceEvent(event) {
172
+ const invoice = event.data.object;
173
+ const parent = invoice.parent;
174
+ const subscriptionId = parent?.type === "subscription_details"
175
+ ? this.getSubscriptionId(parent.subscription)
176
+ : undefined;
177
+ if (!subscriptionId) {
178
+ return;
179
+ }
180
+ const subscription = await this.retrieveSubscription(subscriptionId);
181
+ await this.saveSubscription(subscription, event);
182
+ }
183
+ async processRefundEvent(event) {
184
+ const charge = event.data.object;
185
+ await this.revokeChargeEntitlement(charge, event, "refunded");
186
+ }
187
+ async processDisputeEvent(event) {
188
+ const dispute = event.data.object;
189
+ const chargeId = this.getId(dispute.charge);
190
+ if (!chargeId) {
191
+ return;
192
+ }
193
+ const charge = await this.stripe.charges.retrieve(chargeId);
194
+ await this.revokeChargeEntitlement(charge, event, "disputed");
195
+ }
196
+ async revokeChargeEntitlement(charge, event, status) {
197
+ const input = {
198
+ stripeEventId: event.id,
199
+ stripeEventCreatedAt: this.eventCreatedAt(event),
200
+ stripeStatus: status,
201
+ };
202
+ const paymentIntentId = this.getId(charge.payment_intent);
203
+ if (paymentIntentId) {
204
+ const paymentIntent = await this.stripe.paymentIntents.retrieve(paymentIntentId);
205
+ const paymentIntentMetadata = paymentIntent.metadata;
206
+ const checkoutAttemptId = paymentIntentMetadata.checkoutAttemptId;
207
+ if (/^\d+$/.test(checkoutAttemptId ?? "")) {
208
+ const attempt = await this.attemptRepository.findOne({
209
+ where: { id: Number(checkoutAttemptId) },
210
+ });
211
+ if (attempt?.stripeSessionId) {
212
+ const revoked = await this.entitlementStore.revokePayment(attempt.stripeSessionId, input);
213
+ if (revoked) {
214
+ return;
215
+ }
216
+ }
217
+ }
218
+ }
219
+ const customerId = getCustomer(charge.customer).id;
220
+ if (customerId !== "unknown") {
221
+ await this.entitlementStore.revokeCustomerPayments(customerId, input);
222
+ }
223
+ }
224
+ async saveSubscription(subscription, event) {
225
+ if (subscription.items.data.length === 0) {
226
+ throw new Error("Subscription has no line items");
227
+ }
228
+ const firstItem = subscription.items.data[0];
229
+ const price = firstItem.price;
230
+ if (typeof price === "string") {
231
+ throw new Error("Subscription price was not expanded");
232
+ }
233
+ const configuredProduct = this.productService.getByPriceId(price.id);
234
+ const metadata = getMetadata(subscription);
235
+ const existing = await this.entitlementStore.findByTransactionId(subscription.id);
236
+ const organisationUuid = metadata.organisationUuid ?? existing?.organisationUuid;
237
+ if (!organisationUuid) {
238
+ throw new Error("Subscription event could not be matched to an organisation");
239
+ }
240
+ const customer = getCustomer(subscription.customer);
241
+ const productObject = typeof price.product === "string" ? undefined : price.product;
242
+ const status = event.type === "customer.subscription.deleted"
243
+ ? "canceled"
244
+ : subscription.status;
245
+ await this.entitlementStore.save({
246
+ paymentSystemTransactionId: subscription.id,
247
+ paymentSystemProductId: productObject?.id ?? price.id,
248
+ paymentSystemCustomerId: customer.id,
249
+ paymentSystemCustomerEmail: customer.email,
250
+ paymentSystemMode: "subscription",
251
+ paymentSystemName: "stripe",
252
+ validUntil: this.getSubscriptionValidUntil(subscription, status),
253
+ internalSku: configuredProduct.internalSku,
254
+ productDisplayName: productObject && !("deleted" in productObject)
255
+ ? productObject.name
256
+ : configuredProduct.displayName,
257
+ organisationUuid,
258
+ stripeEventId: event.id,
259
+ stripeEventCreatedAt: this.eventCreatedAt(event),
260
+ stripeStatus: status,
261
+ });
262
+ }
263
+ async resolveOrganisationUuid(session, metadata) {
264
+ if (metadata.organisationUuid) {
265
+ return metadata.organisationUuid;
266
+ }
267
+ const attempt = await this.attemptRepository.findOne({
268
+ where: { stripeSessionId: session.id },
269
+ });
270
+ if (attempt) {
271
+ return attempt.organisationUuid;
272
+ }
273
+ // Preserve compatibility with sessions created by the legacy shared
274
+ // Stripe module, which used a PaymentSessionReference UUID as the
275
+ // Checkout client_reference_id.
276
+ const referenceId = this.getClientReferenceId(session);
277
+ if (referenceId) {
278
+ const paymentReference = await this.paymentSessionService.findSessionByUuid(referenceId);
279
+ if (paymentReference?.organisationUuid) {
280
+ return paymentReference.organisationUuid;
281
+ }
282
+ }
283
+ throw new Error("Checkout session could not be matched to an organisation");
284
+ }
285
+ async retrieveSubscription(id) {
286
+ return this.stripe.subscriptions.retrieve(id, {
287
+ expand: ["items.data.price.product", "customer"],
288
+ });
289
+ }
290
+ getSubscriptionValidUntil(subscription, status = subscription.status) {
291
+ if (status === "canceled" ||
292
+ status === "unpaid" ||
293
+ status === "incomplete_expired" ||
294
+ status === "paused") {
295
+ return new Date();
296
+ }
297
+ const periodEnd = subscription.items.data[0]?.current_period_end;
298
+ if (!periodEnd) {
299
+ throw new Error("Stripe subscription has no current period end");
300
+ }
301
+ return addGracePeriod(new Date(periodEnd * 1000));
302
+ }
303
+ getSubscriptionId(subscription) {
304
+ return typeof subscription === "string"
305
+ ? subscription
306
+ : subscription?.id;
307
+ }
308
+ getId(value) {
309
+ return typeof value === "string" ? value : value?.id;
310
+ }
311
+ getClientReferenceId(session) {
312
+ return typeof session.client_reference_id === "string"
313
+ ? session.client_reference_id
314
+ : undefined;
315
+ }
316
+ eventCreatedAt(event) {
317
+ return new Date(event.created * 1000);
318
+ }
319
+ };
320
+ StripePaymentFulfillmentService = StripePaymentFulfillmentService_1 = __decorate([
321
+ Injectable(),
322
+ __param(0, Inject("SecureStripeClient")),
323
+ __param(1, InjectRepository(StripeCheckoutAttempt)),
324
+ __param(4, Inject(STRIPE_PAYMENTS_ENTITLEMENT_STORE)),
325
+ __metadata("design:paramtypes", [Stripe,
326
+ Repository,
327
+ PaymentSessionService,
328
+ SecureStripeProductService, Object])
329
+ ], StripePaymentFulfillmentService);
330
+ export { StripePaymentFulfillmentService };
331
+ //# sourceMappingURL=stripe-payment-fulfillment.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stripe-payment-fulfillment.service.js","sourceRoot":"","sources":["../../../src/stripe-payments/services/stripe-payment-fulfillment.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,OAAO,EAAC,MAAM,EAAE,UAAU,EAAE,MAAM,EAAC,MAAM,gBAAgB,CAAC;AAC1D,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAC,gBAAgB,EAAC,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAC,UAAU,EAAC,MAAM,SAAS,CAAC;AACnC,OAAO,EAAC,qBAAqB,EAAC,MAAM,+CAA+C,CAAC;AACpF,OAAO,EAAC,qBAAqB,EAAC,MAAM,mDAAmD,CAAC;AACxF,OAAO,EAAC,0BAA0B,EAAC,MAAM,oCAAoC,CAAC;AAC9E,OAAO,EACH,iCAAiC,GAGpC,MAAM,kCAAkC,CAAC;AAI1C,SAAS,WAAW,CAAC,KAEpB;IACG,OAAO,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,CAAC,CAAA;qCALjB,MAAM;QAEK,UAAU;QACN,qBAAqB;QAC5B,0BAA0B;GATtD,+BAA+B,CAqX3C"}
@@ -0,0 +1,25 @@
1
+ import { Queue } from "bullmq";
2
+ import { Repository } from "typeorm";
3
+ import { StripeCheckoutEvent } from "../entities/stripe-payment-event.entity.js";
4
+ export interface StripePaymentsOperationsSnapshot {
5
+ status: "up" | "degraded";
6
+ checkedAt: string;
7
+ events: {
8
+ received: number;
9
+ processing: number;
10
+ failed: number;
11
+ staleProcessing: number;
12
+ };
13
+ queue: {
14
+ waiting: number;
15
+ active: number;
16
+ delayed: number;
17
+ failed: number;
18
+ };
19
+ }
20
+ export declare class StripePaymentsOperationsService {
21
+ private readonly eventRepository;
22
+ private readonly eventQueue;
23
+ constructor(eventRepository: Repository<StripeCheckoutEvent>, eventQueue: Queue);
24
+ getSnapshot(): Promise<StripePaymentsOperationsSnapshot>;
25
+ }
@@ -0,0 +1,59 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ 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;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __metadata = (this && this.__metadata) || function (k, v) {
8
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
+ };
10
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
11
+ return function (target, key) { decorator(target, key, paramIndex); }
12
+ };
13
+ import { InjectQueue } from "@nestjs/bullmq";
14
+ import { Injectable } from "@nestjs/common";
15
+ import { InjectRepository } from "@nestjs/typeorm";
16
+ import { Queue } from "bullmq";
17
+ import { LessThan, Repository } from "typeorm";
18
+ import { StripeCheckoutEvent } from "../entities/stripe-payment-event.entity.js";
19
+ let StripePaymentsOperationsService = class StripePaymentsOperationsService {
20
+ eventRepository;
21
+ eventQueue;
22
+ constructor(eventRepository, eventQueue) {
23
+ this.eventRepository = eventRepository;
24
+ this.eventQueue = eventQueue;
25
+ }
26
+ async getSnapshot() {
27
+ const staleCutoff = new Date(Date.now() - 5 * 60 * 1000);
28
+ const [received, processing, failed, staleProcessing, queueCounts] = await Promise.all([
29
+ this.eventRepository.countBy({ status: "received" }),
30
+ this.eventRepository.countBy({ status: "processing" }),
31
+ this.eventRepository.countBy({ status: "failed" }),
32
+ this.eventRepository.countBy({
33
+ status: "processing",
34
+ processingStartedAt: LessThan(staleCutoff),
35
+ }),
36
+ this.eventQueue.getJobCounts("waiting", "active", "delayed", "failed"),
37
+ ]);
38
+ return {
39
+ status: failed > 0 || staleProcessing > 0 ? "degraded" : "up",
40
+ checkedAt: new Date().toISOString(),
41
+ events: { received, processing, failed, staleProcessing },
42
+ queue: {
43
+ waiting: queueCounts.waiting,
44
+ active: queueCounts.active,
45
+ delayed: queueCounts.delayed,
46
+ failed: queueCounts.failed,
47
+ },
48
+ };
49
+ }
50
+ };
51
+ StripePaymentsOperationsService = __decorate([
52
+ Injectable(),
53
+ __param(0, InjectRepository(StripeCheckoutEvent)),
54
+ __param(1, InjectQueue("stripe-events")),
55
+ __metadata("design:paramtypes", [Repository,
56
+ Queue])
57
+ ], StripePaymentsOperationsService);
58
+ export { StripePaymentsOperationsService };
59
+ //# sourceMappingURL=stripe-payments-operations.service.js.map