@ambushsoftworks/nestjs-payments-graphql 0.1.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 (217) hide show
  1. package/dist/constants.d.ts +17 -0
  2. package/dist/constants.js +21 -0
  3. package/dist/constants.js.map +1 -0
  4. package/dist/dto/create-installment.input.d.ts +5 -0
  5. package/dist/dto/create-installment.input.js +39 -0
  6. package/dist/dto/create-installment.input.js.map +1 -0
  7. package/dist/dto/create-invoice.input.d.ts +13 -0
  8. package/dist/dto/create-invoice.input.js +95 -0
  9. package/dist/dto/create-invoice.input.js.map +1 -0
  10. package/dist/dto/create-line-item.input.d.ts +10 -0
  11. package/dist/dto/create-line-item.input.js +77 -0
  12. package/dist/dto/create-line-item.input.js.map +1 -0
  13. package/dist/dto/create-payment-plan.input.d.ts +11 -0
  14. package/dist/dto/create-payment-plan.input.js +76 -0
  15. package/dist/dto/create-payment-plan.input.js.map +1 -0
  16. package/dist/dto/create-recurring-invoice.input.d.ts +18 -0
  17. package/dist/dto/create-recurring-invoice.input.js +117 -0
  18. package/dist/dto/create-recurring-invoice.input.js.map +1 -0
  19. package/dist/dto/create-recurring-line-item.input.d.ts +10 -0
  20. package/dist/dto/create-recurring-line-item.input.js +77 -0
  21. package/dist/dto/create-recurring-line-item.input.js.map +1 -0
  22. package/dist/dto/create-refund.input.d.ts +5 -0
  23. package/dist/dto/create-refund.input.js +43 -0
  24. package/dist/dto/create-refund.input.js.map +1 -0
  25. package/dist/dto/index.d.ts +8 -0
  26. package/dist/dto/index.js +20 -0
  27. package/dist/dto/index.js.map +1 -0
  28. package/dist/dto/invoice-filter.input.d.ts +10 -0
  29. package/dist/dto/invoice-filter.input.js +64 -0
  30. package/dist/dto/invoice-filter.input.js.map +1 -0
  31. package/dist/dto/payment-plan-filter.input.d.ts +7 -0
  32. package/dist/dto/payment-plan-filter.input.js +46 -0
  33. package/dist/dto/payment-plan-filter.input.js.map +1 -0
  34. package/dist/dto/record-manual-payment.input.d.ts +9 -0
  35. package/dist/dto/record-manual-payment.input.js +58 -0
  36. package/dist/dto/record-manual-payment.input.js.map +1 -0
  37. package/dist/dto/recurring-invoice-filter.input.d.ts +7 -0
  38. package/dist/dto/recurring-invoice-filter.input.js +46 -0
  39. package/dist/dto/recurring-invoice-filter.input.js.map +1 -0
  40. package/dist/dto/update-invoice-metadata.input.d.ts +3 -0
  41. package/dist/dto/update-invoice-metadata.input.js +30 -0
  42. package/dist/dto/update-invoice-metadata.input.js.map +1 -0
  43. package/dist/dto/update-payment-config.input.d.ts +8 -0
  44. package/dist/dto/update-payment-config.input.js +61 -0
  45. package/dist/dto/update-payment-config.input.js.map +1 -0
  46. package/dist/dto/update-recurring-template.input.d.ts +12 -0
  47. package/dist/dto/update-recurring-template.input.js +89 -0
  48. package/dist/dto/update-recurring-template.input.js.map +1 -0
  49. package/dist/dto/upsert-payment-provider.input.d.ts +5 -0
  50. package/dist/dto/upsert-payment-provider.input.js +43 -0
  51. package/dist/dto/upsert-payment-provider.input.js.map +1 -0
  52. package/dist/dto/validators/is-metadata.d.ts +1 -0
  53. package/dist/dto/validators/is-metadata.js +41 -0
  54. package/dist/dto/validators/is-metadata.js.map +1 -0
  55. package/dist/exceptions/index.d.ts +34 -0
  56. package/dist/exceptions/index.js +73 -0
  57. package/dist/exceptions/index.js.map +1 -0
  58. package/dist/gateways/gateway-registry.service.d.ts +10 -0
  59. package/dist/gateways/gateway-registry.service.js +45 -0
  60. package/dist/gateways/gateway-registry.service.js.map +1 -0
  61. package/dist/gateways/payment-gateway.interface.d.ts +50 -0
  62. package/dist/gateways/payment-gateway.interface.js +3 -0
  63. package/dist/gateways/payment-gateway.interface.js.map +1 -0
  64. package/dist/gateways/recurring-payment-gateway.interface.d.ts +32 -0
  65. package/dist/gateways/recurring-payment-gateway.interface.js +3 -0
  66. package/dist/gateways/recurring-payment-gateway.interface.js.map +1 -0
  67. package/dist/gateways/stripe/stripe-webhook.controller.d.ts +24 -0
  68. package/dist/gateways/stripe/stripe-webhook.controller.js +150 -0
  69. package/dist/gateways/stripe/stripe-webhook.controller.js.map +1 -0
  70. package/dist/gateways/stripe/stripe.gateway.d.ts +84 -0
  71. package/dist/gateways/stripe/stripe.gateway.js +424 -0
  72. package/dist/gateways/stripe/stripe.gateway.js.map +1 -0
  73. package/dist/index.d.ts +70 -0
  74. package/dist/index.js +147 -0
  75. package/dist/index.js.map +1 -0
  76. package/dist/interfaces/invoice-repository.interface.d.ts +23 -0
  77. package/dist/interfaces/invoice-repository.interface.js +3 -0
  78. package/dist/interfaces/invoice-repository.interface.js.map +1 -0
  79. package/dist/interfaces/payment-config-repository.interface.d.ts +11 -0
  80. package/dist/interfaces/payment-config-repository.interface.js +3 -0
  81. package/dist/interfaces/payment-config-repository.interface.js.map +1 -0
  82. package/dist/interfaces/payment-customer-repository.interface.d.ts +6 -0
  83. package/dist/interfaces/payment-customer-repository.interface.js +3 -0
  84. package/dist/interfaces/payment-customer-repository.interface.js.map +1 -0
  85. package/dist/interfaces/payment-email.interfaces.d.ts +74 -0
  86. package/dist/interfaces/payment-email.interfaces.js +3 -0
  87. package/dist/interfaces/payment-email.interfaces.js.map +1 -0
  88. package/dist/interfaces/payment-event-listener.interface.d.ts +61 -0
  89. package/dist/interfaces/payment-event-listener.interface.js +3 -0
  90. package/dist/interfaces/payment-event-listener.interface.js.map +1 -0
  91. package/dist/interfaces/payment-plan-repository.interface.d.ts +16 -0
  92. package/dist/interfaces/payment-plan-repository.interface.js +3 -0
  93. package/dist/interfaces/payment-plan-repository.interface.js.map +1 -0
  94. package/dist/interfaces/payment-repository.interface.d.ts +13 -0
  95. package/dist/interfaces/payment-repository.interface.js +3 -0
  96. package/dist/interfaces/payment-repository.interface.js.map +1 -0
  97. package/dist/interfaces/recurring-invoice-repository.interface.d.ts +16 -0
  98. package/dist/interfaces/recurring-invoice-repository.interface.js +3 -0
  99. package/dist/interfaces/recurring-invoice-repository.interface.js.map +1 -0
  100. package/dist/interfaces/refund-repository.interface.d.ts +8 -0
  101. package/dist/interfaces/refund-repository.interface.js +3 -0
  102. package/dist/interfaces/refund-repository.interface.js.map +1 -0
  103. package/dist/interfaces/transaction-manager.interface.d.ts +19 -0
  104. package/dist/interfaces/transaction-manager.interface.js +3 -0
  105. package/dist/interfaces/transaction-manager.interface.js.map +1 -0
  106. package/dist/interfaces/webhook-idempotency-repository.interface.d.ts +5 -0
  107. package/dist/interfaces/webhook-idempotency-repository.interface.js +3 -0
  108. package/dist/interfaces/webhook-idempotency-repository.interface.js.map +1 -0
  109. package/dist/models/e-transfer-instructions.model.d.ts +11 -0
  110. package/dist/models/e-transfer-instructions.model.js +56 -0
  111. package/dist/models/e-transfer-instructions.model.js.map +1 -0
  112. package/dist/models/index.d.ts +13 -0
  113. package/dist/models/index.js +36 -0
  114. package/dist/models/index.js.map +1 -0
  115. package/dist/models/invoice-client.model.d.ts +5 -0
  116. package/dist/models/invoice-client.model.js +32 -0
  117. package/dist/models/invoice-client.model.js.map +1 -0
  118. package/dist/models/invoice-line-item.model.d.ts +14 -0
  119. package/dist/models/invoice-line-item.model.js +72 -0
  120. package/dist/models/invoice-line-item.model.js.map +1 -0
  121. package/dist/models/invoice.model.d.ts +86 -0
  122. package/dist/models/invoice.model.js +210 -0
  123. package/dist/models/invoice.model.js.map +1 -0
  124. package/dist/models/online-payment-session.model.d.ts +6 -0
  125. package/dist/models/online-payment-session.model.js +40 -0
  126. package/dist/models/online-payment-session.model.js.map +1 -0
  127. package/dist/models/paginated-invoices.model.d.ts +5 -0
  128. package/dist/models/paginated-invoices.model.js +19 -0
  129. package/dist/models/paginated-invoices.model.js.map +1 -0
  130. package/dist/models/paginated-payment-plans.model.d.ts +5 -0
  131. package/dist/models/paginated-payment-plans.model.js +19 -0
  132. package/dist/models/paginated-payment-plans.model.js.map +1 -0
  133. package/dist/models/paginated-recurring-invoices.model.d.ts +5 -0
  134. package/dist/models/paginated-recurring-invoices.model.js +19 -0
  135. package/dist/models/paginated-recurring-invoices.model.js.map +1 -0
  136. package/dist/models/paginated.model.d.ts +6 -0
  137. package/dist/models/paginated.model.js +30 -0
  138. package/dist/models/paginated.model.js.map +1 -0
  139. package/dist/models/payment-config.model.d.ts +21 -0
  140. package/dist/models/payment-config.model.js +98 -0
  141. package/dist/models/payment-config.model.js.map +1 -0
  142. package/dist/models/payment-method-setup.model.d.ts +4 -0
  143. package/dist/models/payment-method-setup.model.js +32 -0
  144. package/dist/models/payment-method-setup.model.js.map +1 -0
  145. package/dist/models/payment-plan-installment.model.d.ts +12 -0
  146. package/dist/models/payment-plan-installment.model.js +57 -0
  147. package/dist/models/payment-plan-installment.model.js.map +1 -0
  148. package/dist/models/payment-plan.model.d.ts +25 -0
  149. package/dist/models/payment-plan.model.js +105 -0
  150. package/dist/models/payment-plan.model.js.map +1 -0
  151. package/dist/models/payment.model.d.ts +23 -0
  152. package/dist/models/payment.model.js +102 -0
  153. package/dist/models/payment.model.js.map +1 -0
  154. package/dist/models/recurring-invoice-line-item.model.d.ts +14 -0
  155. package/dist/models/recurring-invoice-line-item.model.js +72 -0
  156. package/dist/models/recurring-invoice-line-item.model.js.map +1 -0
  157. package/dist/models/recurring-invoice.model.d.ts +43 -0
  158. package/dist/models/recurring-invoice.model.js +157 -0
  159. package/dist/models/recurring-invoice.model.js.map +1 -0
  160. package/dist/models/refund.model.d.ts +15 -0
  161. package/dist/models/refund.model.js +73 -0
  162. package/dist/models/refund.model.js.map +1 -0
  163. package/dist/payments.module.d.ts +54 -0
  164. package/dist/payments.module.js +211 -0
  165. package/dist/payments.module.js.map +1 -0
  166. package/dist/register-payment-enums.d.ts +1 -0
  167. package/dist/register-payment-enums.js +18 -0
  168. package/dist/register-payment-enums.js.map +1 -0
  169. package/dist/services/customer.service.d.ts +15 -0
  170. package/dist/services/customer.service.js +63 -0
  171. package/dist/services/customer.service.js.map +1 -0
  172. package/dist/services/default-payment-email-templates.d.ts +8 -0
  173. package/dist/services/default-payment-email-templates.js +249 -0
  174. package/dist/services/default-payment-email-templates.js.map +1 -0
  175. package/dist/services/e-transfer.service.d.ts +35 -0
  176. package/dist/services/e-transfer.service.js +93 -0
  177. package/dist/services/e-transfer.service.js.map +1 -0
  178. package/dist/services/invoice-number.service.d.ts +9 -0
  179. package/dist/services/invoice-number.service.js +56 -0
  180. package/dist/services/invoice-number.service.js.map +1 -0
  181. package/dist/services/invoice.service.d.ts +66 -0
  182. package/dist/services/invoice.service.js +293 -0
  183. package/dist/services/invoice.service.js.map +1 -0
  184. package/dist/services/payment-config.service.d.ts +26 -0
  185. package/dist/services/payment-config.service.js +90 -0
  186. package/dist/services/payment-config.service.js.map +1 -0
  187. package/dist/services/payment-email.service.d.ts +20 -0
  188. package/dist/services/payment-email.service.js +153 -0
  189. package/dist/services/payment-email.service.js.map +1 -0
  190. package/dist/services/payment-plan.service.d.ts +47 -0
  191. package/dist/services/payment-plan.service.js +264 -0
  192. package/dist/services/payment-plan.service.js.map +1 -0
  193. package/dist/services/payment.service.d.ts +65 -0
  194. package/dist/services/payment.service.js +532 -0
  195. package/dist/services/payment.service.js.map +1 -0
  196. package/dist/services/recurring-interval.util.d.ts +3 -0
  197. package/dist/services/recurring-interval.util.js +43 -0
  198. package/dist/services/recurring-interval.util.js.map +1 -0
  199. package/dist/services/recurring-invoice.service.d.ts +88 -0
  200. package/dist/services/recurring-invoice.service.js +450 -0
  201. package/dist/services/recurring-invoice.service.js.map +1 -0
  202. package/dist/services/refund.service.d.ts +44 -0
  203. package/dist/services/refund.service.js +373 -0
  204. package/dist/services/refund.service.js.map +1 -0
  205. package/dist/services/static-branding-resolver.d.ts +6 -0
  206. package/dist/services/static-branding-resolver.js +13 -0
  207. package/dist/services/static-branding-resolver.js.map +1 -0
  208. package/dist/types/index.d.ts +240 -0
  209. package/dist/types/index.js +19 -0
  210. package/dist/types/index.js.map +1 -0
  211. package/dist/types/payment-customer.types.d.ts +15 -0
  212. package/dist/types/payment-customer.types.js +3 -0
  213. package/dist/types/payment-customer.types.js.map +1 -0
  214. package/dist/types/recurring-invoice.types.d.ts +84 -0
  215. package/dist/types/recurring-invoice.types.js +3 -0
  216. package/dist/types/recurring-invoice.types.js.map +1 -0
  217. package/package.json +70 -0
@@ -0,0 +1,424 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.StripeGateway = void 0;
7
+ const common_1 = require("@nestjs/common");
8
+ const stripe_1 = __importDefault(require("stripe"));
9
+ const exceptions_1 = require("../../exceptions");
10
+ class StripeGateway {
11
+ constructor(secretKey, webhookSecret = '') {
12
+ this.providerType = 'stripe';
13
+ this.logger = new common_1.Logger(StripeGateway.name);
14
+ this.webhookSecret = webhookSecret;
15
+ this.stripe = new stripe_1.default(secretKey, {
16
+ apiVersion: '2025-02-24.acacia',
17
+ typescript: true,
18
+ });
19
+ }
20
+ async createPaymentSession(params) {
21
+ try {
22
+ const session = await this.stripe.checkout.sessions.create({
23
+ mode: 'payment',
24
+ line_items: [
25
+ {
26
+ price_data: {
27
+ currency: params.currency.toLowerCase(),
28
+ unit_amount: params.amount,
29
+ product_data: {
30
+ name: params.description ?? `Invoice ${params.invoiceId}`,
31
+ },
32
+ },
33
+ quantity: 1,
34
+ },
35
+ ],
36
+ customer_email: params.customerEmail || undefined,
37
+ success_url: params.successUrl,
38
+ cancel_url: params.cancelUrl,
39
+ ...(params.expiresAt && {
40
+ expires_at: Math.floor(params.expiresAt.getTime() / 1000),
41
+ }),
42
+ metadata: {
43
+ ...params.metadata,
44
+ invoiceId: params.invoiceId,
45
+ },
46
+ });
47
+ if (!session.url) {
48
+ throw new exceptions_1.PaymentGatewayException('Stripe Checkout session created but no URL returned');
49
+ }
50
+ return {
51
+ checkoutUrl: session.url,
52
+ providerPaymentId: session.id,
53
+ metadata: { sessionId: session.id },
54
+ };
55
+ }
56
+ catch (error) {
57
+ if (error instanceof exceptions_1.PaymentGatewayException) {
58
+ throw error;
59
+ }
60
+ if (error instanceof stripe_1.default.errors.StripeError) {
61
+ this.logger.error(`Stripe createPaymentSession failed: ${error.message}`, error.stack);
62
+ throw new exceptions_1.PaymentGatewayException(`Stripe error: ${error.message}`);
63
+ }
64
+ throw error;
65
+ }
66
+ }
67
+ async createRefund(params) {
68
+ try {
69
+ const refund = await this.stripe.refunds.create({
70
+ payment_intent: params.providerPaymentId,
71
+ amount: params.amount,
72
+ reason: params.reason === 'duplicate'
73
+ ? 'duplicate'
74
+ : params.reason === 'fraudulent'
75
+ ? 'fraudulent'
76
+ : 'requested_by_customer',
77
+ });
78
+ return {
79
+ providerRefundId: refund.id,
80
+ status: this.mapRefundStatus(refund.status),
81
+ };
82
+ }
83
+ catch (error) {
84
+ if (error instanceof stripe_1.default.errors.StripeError) {
85
+ this.logger.error(`Stripe createRefund failed: ${error.message}`, error.stack);
86
+ throw new exceptions_1.PaymentGatewayException(`Stripe refund error: ${error.message}`);
87
+ }
88
+ throw error;
89
+ }
90
+ }
91
+ async getPaymentStatus(providerPaymentId) {
92
+ try {
93
+ if (providerPaymentId.startsWith('cs_')) {
94
+ return this.getCheckoutSessionStatus(providerPaymentId);
95
+ }
96
+ const intent = await this.stripe.paymentIntents.retrieve(providerPaymentId, { expand: ['latest_charge'] });
97
+ const charge = intent.latest_charge;
98
+ return {
99
+ status: this.mapPaymentIntentStatus(intent.status),
100
+ amount: intent.amount,
101
+ currency: intent.currency.toUpperCase(),
102
+ receiptUrl: charge?.receipt_url ?? undefined,
103
+ paymentIntentId: intent.id,
104
+ };
105
+ }
106
+ catch (error) {
107
+ if (error instanceof stripe_1.default.errors.StripeError) {
108
+ this.logger.error(`Stripe getPaymentStatus failed: ${error.message}`, error.stack);
109
+ throw new exceptions_1.PaymentGatewayException(`Stripe status check error: ${error.message}`);
110
+ }
111
+ throw error;
112
+ }
113
+ }
114
+ async getCheckoutSessionStatus(sessionId) {
115
+ const session = await this.stripe.checkout.sessions.retrieve(sessionId);
116
+ const paymentIntentId = session.payment_intent;
117
+ if (session.status === 'expired') {
118
+ return {
119
+ status: 'cancelled',
120
+ amount: session.amount_total ?? 0,
121
+ currency: (session.currency ?? 'usd').toUpperCase(),
122
+ paymentIntentId: paymentIntentId ?? undefined,
123
+ };
124
+ }
125
+ if (session.status === 'open') {
126
+ return {
127
+ status: 'pending',
128
+ amount: session.amount_total ?? 0,
129
+ currency: (session.currency ?? 'usd').toUpperCase(),
130
+ paymentIntentId: paymentIntentId ?? undefined,
131
+ };
132
+ }
133
+ if (paymentIntentId) {
134
+ const intent = await this.stripe.paymentIntents.retrieve(paymentIntentId, { expand: ['latest_charge'] });
135
+ const charge = intent.latest_charge;
136
+ return {
137
+ status: this.mapPaymentIntentStatus(intent.status),
138
+ amount: intent.amount,
139
+ currency: intent.currency.toUpperCase(),
140
+ receiptUrl: charge?.receipt_url ?? undefined,
141
+ paymentIntentId: intent.id,
142
+ };
143
+ }
144
+ return {
145
+ status: session.payment_status === 'paid' ? 'succeeded' : 'pending',
146
+ amount: session.amount_total ?? 0,
147
+ currency: (session.currency ?? 'usd').toUpperCase(),
148
+ };
149
+ }
150
+ async cancelPayment(providerPaymentId) {
151
+ try {
152
+ await this.stripe.paymentIntents.cancel(providerPaymentId);
153
+ return { success: true };
154
+ }
155
+ catch (error) {
156
+ if (error instanceof stripe_1.default.errors.StripeError) {
157
+ if (error.code === 'payment_intent_unexpected_state') {
158
+ this.logger.warn(`PaymentIntent ${providerPaymentId} already cancelled or in non-cancellable state`);
159
+ return { success: true };
160
+ }
161
+ this.logger.error(`Stripe cancelPayment failed: ${error.message}`, error.stack);
162
+ throw new exceptions_1.PaymentGatewayException(`Stripe cancel error: ${error.message}`);
163
+ }
164
+ throw error;
165
+ }
166
+ }
167
+ async handleWebhook(params) {
168
+ const sig = params.headers['stripe-signature'];
169
+ if (!sig) {
170
+ throw new exceptions_1.PaymentGatewayException('Missing stripe-signature header');
171
+ }
172
+ let event;
173
+ try {
174
+ event = this.stripe.webhooks.constructEvent(params.body, sig, this.webhookSecret);
175
+ }
176
+ catch (error) {
177
+ const message = error instanceof Error ? error.message : 'Unknown error';
178
+ throw new exceptions_1.PaymentGatewayException(`Stripe webhook signature verification failed: ${message}`);
179
+ }
180
+ return this.normalizeWebhookEvent(event);
181
+ }
182
+ async createOrRetrieveCustomer(params) {
183
+ try {
184
+ const existing = await this.stripe.customers.list({
185
+ email: params.email,
186
+ limit: 1,
187
+ });
188
+ if (existing.data.length > 0) {
189
+ return { providerCustomerId: existing.data[0].id };
190
+ }
191
+ const customer = await this.stripe.customers.create({
192
+ email: params.email,
193
+ name: params.name,
194
+ metadata: params.metadata,
195
+ });
196
+ this.logger.log(`Created Stripe customer: ${customer.id} for ${params.email}`);
197
+ return { providerCustomerId: customer.id };
198
+ }
199
+ catch (error) {
200
+ throw new exceptions_1.PaymentGatewayException(`Failed to create/retrieve Stripe customer: ${error instanceof Error ? error.message : String(error)}`);
201
+ }
202
+ }
203
+ async createOffSessionPayment(params) {
204
+ try {
205
+ const paymentIntent = await this.stripe.paymentIntents.create({
206
+ amount: params.amount,
207
+ currency: params.currency.toLowerCase(),
208
+ customer: params.providerCustomerId,
209
+ off_session: true,
210
+ confirm: true,
211
+ description: params.description,
212
+ metadata: params.metadata,
213
+ });
214
+ if (paymentIntent.status === 'succeeded') {
215
+ const charge = paymentIntent.latest_charge;
216
+ const receiptUrl = typeof charge === 'object' && charge?.receipt_url
217
+ ? charge.receipt_url
218
+ : undefined;
219
+ return {
220
+ providerPaymentId: paymentIntent.id,
221
+ status: 'succeeded',
222
+ receiptUrl: receiptUrl ?? undefined,
223
+ };
224
+ }
225
+ if (paymentIntent.status === 'requires_action') {
226
+ return {
227
+ providerPaymentId: paymentIntent.id,
228
+ status: 'requires_action',
229
+ failureReason: 'sca_required',
230
+ clientSecret: paymentIntent.client_secret ?? undefined,
231
+ };
232
+ }
233
+ return {
234
+ providerPaymentId: paymentIntent.id,
235
+ status: 'failed',
236
+ failureReason: paymentIntent.last_payment_error?.code ?? 'unknown',
237
+ };
238
+ }
239
+ catch (error) {
240
+ if (error instanceof stripe_1.default.errors.StripeCardError) {
241
+ return {
242
+ providerPaymentId: error.payment_intent?.id ?? 'unknown',
243
+ status: 'failed',
244
+ failureReason: error.code ?? 'card_declined',
245
+ };
246
+ }
247
+ throw new exceptions_1.PaymentGatewayException(`Off-session payment failed: ${error instanceof Error ? error.message : String(error)}`);
248
+ }
249
+ }
250
+ async createSetupSession(params) {
251
+ try {
252
+ const session = await this.stripe.checkout.sessions.create({
253
+ mode: 'setup',
254
+ customer: params.providerCustomerId,
255
+ success_url: params.successUrl,
256
+ cancel_url: params.cancelUrl,
257
+ metadata: params.metadata,
258
+ });
259
+ if (!session.url) {
260
+ throw new Error('Stripe did not return a session URL');
261
+ }
262
+ return {
263
+ setupUrl: session.url,
264
+ providerSetupId: session.setup_intent,
265
+ };
266
+ }
267
+ catch (error) {
268
+ if (error instanceof exceptions_1.PaymentGatewayException) {
269
+ throw error;
270
+ }
271
+ throw new exceptions_1.PaymentGatewayException(`Failed to create setup session: ${error instanceof Error ? error.message : String(error)}`);
272
+ }
273
+ }
274
+ async normalizeWebhookEvent(event) {
275
+ switch (event.type) {
276
+ case 'checkout.session.completed':
277
+ return this.handleCheckoutSessionCompleted(event);
278
+ case 'payment_intent.processing':
279
+ return this.handlePaymentIntentProcessing(event);
280
+ case 'payment_intent.payment_failed':
281
+ return this.handlePaymentIntentFailed(event);
282
+ case 'charge.refunded':
283
+ return this.handleChargeRefunded(event);
284
+ default:
285
+ this.logger.warn(`Unhandled Stripe event type: ${event.type}`);
286
+ throw new exceptions_1.PaymentGatewayException(`Unhandled Stripe webhook event type: ${event.type}`);
287
+ }
288
+ }
289
+ async handleCheckoutSessionCompleted(event) {
290
+ const session = event.data.object;
291
+ if (session.mode === 'setup') {
292
+ return this.handleSetupSessionCompleted(event, session);
293
+ }
294
+ const paymentIntentId = session.payment_intent;
295
+ let receiptUrl;
296
+ let amount = session.amount_total ?? 0;
297
+ let currency = (session.currency ?? 'usd').toUpperCase();
298
+ try {
299
+ const intent = await this.stripe.paymentIntents.retrieve(paymentIntentId, { expand: ['latest_charge'] });
300
+ const charge = intent.latest_charge;
301
+ receiptUrl = charge?.receipt_url ?? undefined;
302
+ amount = intent.amount;
303
+ currency = intent.currency.toUpperCase();
304
+ }
305
+ catch (error) {
306
+ this.logger.warn(`Failed to fetch PaymentIntent for receipt_url: ${error instanceof Error ? error.message : 'Unknown error'}`);
307
+ }
308
+ return {
309
+ type: 'payment.succeeded',
310
+ eventId: event.id,
311
+ providerPaymentId: session.id,
312
+ amount,
313
+ currency,
314
+ receiptUrl,
315
+ providerData: {
316
+ sessionId: session.id,
317
+ paymentIntentId,
318
+ invoiceId: session.metadata?.invoiceId,
319
+ customerEmail: session.customer_email,
320
+ paymentStatus: session.payment_status,
321
+ },
322
+ };
323
+ }
324
+ handleSetupSessionCompleted(event, session) {
325
+ const customerId = typeof session.customer === 'string'
326
+ ? session.customer
327
+ : (session.customer?.id ?? null);
328
+ this.logger.log(`Payment method setup completed for customer ${customerId} (session ${session.id})`);
329
+ return {
330
+ type: 'setup.succeeded',
331
+ eventId: event.id,
332
+ providerPaymentId: session.setup_intent ?? session.id,
333
+ amount: 0,
334
+ currency: (session.currency ?? 'usd').toUpperCase(),
335
+ providerData: {
336
+ sessionId: session.id,
337
+ customerId,
338
+ setupIntentId: session.setup_intent,
339
+ mode: 'setup',
340
+ },
341
+ };
342
+ }
343
+ handlePaymentIntentProcessing(event) {
344
+ const intent = event.data.object;
345
+ return {
346
+ type: 'payment.processing',
347
+ eventId: event.id,
348
+ providerPaymentId: intent.id,
349
+ amount: intent.amount,
350
+ currency: intent.currency.toUpperCase(),
351
+ providerData: {
352
+ invoiceId: intent.metadata?.invoiceId,
353
+ status: intent.status,
354
+ },
355
+ };
356
+ }
357
+ handlePaymentIntentFailed(event) {
358
+ const intent = event.data.object;
359
+ return {
360
+ type: 'payment.failed',
361
+ eventId: event.id,
362
+ providerPaymentId: intent.id,
363
+ amount: intent.amount,
364
+ currency: intent.currency.toUpperCase(),
365
+ providerData: {
366
+ invoiceId: intent.metadata?.invoiceId,
367
+ status: intent.status,
368
+ lastPaymentError: intent.last_payment_error?.message,
369
+ },
370
+ };
371
+ }
372
+ handleChargeRefunded(event) {
373
+ const charge = event.data.object;
374
+ const paymentIntentId = typeof charge.payment_intent === 'string'
375
+ ? charge.payment_intent
376
+ : (charge.payment_intent?.id ?? '');
377
+ const latestRefund = charge.refunds?.data?.[0];
378
+ return {
379
+ type: 'refund.succeeded',
380
+ eventId: event.id,
381
+ providerPaymentId: paymentIntentId,
382
+ providerRefundId: latestRefund?.id,
383
+ amount: charge.amount_refunded,
384
+ currency: charge.currency.toUpperCase(),
385
+ receiptUrl: charge.receipt_url ?? undefined,
386
+ providerData: {
387
+ chargeId: charge.id,
388
+ refundId: latestRefund?.id,
389
+ refundAmount: latestRefund?.amount,
390
+ invoiceId: charge.metadata?.invoiceId,
391
+ },
392
+ };
393
+ }
394
+ mapPaymentIntentStatus(status) {
395
+ switch (status) {
396
+ case 'requires_payment_method':
397
+ case 'requires_confirmation':
398
+ case 'requires_action':
399
+ return 'pending';
400
+ case 'processing':
401
+ return 'processing';
402
+ case 'succeeded':
403
+ return 'succeeded';
404
+ case 'canceled':
405
+ return 'cancelled';
406
+ default:
407
+ return 'failed';
408
+ }
409
+ }
410
+ mapRefundStatus(status) {
411
+ switch (status) {
412
+ case 'succeeded':
413
+ return 'SUCCEEDED';
414
+ case 'pending':
415
+ return 'PENDING';
416
+ case 'failed':
417
+ return 'FAILED';
418
+ default:
419
+ return 'PROCESSING';
420
+ }
421
+ }
422
+ }
423
+ exports.StripeGateway = StripeGateway;
424
+ //# sourceMappingURL=stripe.gateway.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stripe.gateway.js","sourceRoot":"","sources":["../../../src/gateways/stripe/stripe.gateway.ts"],"names":[],"mappings":";;;;;;AAAA,2CAAwC;AACxC,oDAA4B;AAO5B,iDAA2D;AA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AC;IACJ,CAAC;IAEO,sBAAsB,CAC5B,MAAmC;QAEnC,QAAQ,MAAM,EAAE,CAAC;YACf,KAAK,yBAAyB,CAAC;YAC/B,KAAK,uBAAuB,CAAC;YAC7B,KAAK,iBAAiB;gBACpB,OAAO,SAAS,CAAC;YACnB,KAAK,YAAY;gBACf,OAAO,YAAY,CAAC;YACtB,KAAK,WAAW;gBACd,OAAO,WAAW,CAAC;YACrB,KAAK,UAAU;gBACb,OAAO,WAAW,CAAC;YACrB;gBACE,OAAO,QAAQ,CAAC;QACpB,CAAC;IACH,CAAC;IAEO,eAAe,CACrB,MAAqB;QAErB,QAAQ,MAAM,EAAE,CAAC;YACf,KAAK,WAAW;gBACd,OAAO,WAAW,CAAC;YACrB,KAAK,SAAS;gBACZ,OAAO,SAAS,CAAC;YACnB,KAAK,QAAQ;gBACX,OAAO,QAAQ,CAAC;YAClB;gBACE,OAAO,YAAY,CAAC;QACxB,CAAC;IACH,CAAC;CACF;AAlnBD,sCAknBC"}
@@ -0,0 +1,70 @@
1
+ export { PaymentsModule } from './payments.module';
2
+ export type { PaymentsModuleOptions, PaymentsModuleAsyncOptions, } from './payments.module';
3
+ export { INVOICE_REPOSITORY, PAYMENT_REPOSITORY, REFUND_REPOSITORY, PAYMENT_PLAN_REPOSITORY, PAYMENT_CONFIG_REPOSITORY, WEBHOOK_IDEMPOTENCY_REPOSITORY, RECURRING_INVOICE_REPOSITORY, PAYMENT_CUSTOMER_REPOSITORY, TRANSACTION_MANAGER, PAYMENT_EVENT_LISTENER, PAYMENT_EMAIL_SENDER, PAYMENT_CLIENT_RESOLVER, PAYMENT_EMAIL_BRANDING_RESOLVER, PAYMENT_EMAIL_TEMPLATE_RENDERER, WEBHOOK_ERROR_REPORTER, DEFAULT_CURRENCY, E_TRANSFER_CODE_PREFIX, } from './constants';
4
+ export type { IInvoiceRepository } from './interfaces/invoice-repository.interface';
5
+ export type { IPaymentRepository } from './interfaces/payment-repository.interface';
6
+ export type { IRefundRepository } from './interfaces/refund-repository.interface';
7
+ export type { IPaymentPlanRepository } from './interfaces/payment-plan-repository.interface';
8
+ export type { IPaymentConfigRepository } from './interfaces/payment-config-repository.interface';
9
+ export type { IWebhookIdempotencyRepository } from './interfaces/webhook-idempotency-repository.interface';
10
+ export type { IRecurringInvoiceRepository } from './interfaces/recurring-invoice-repository.interface';
11
+ export type { IPaymentCustomerRepository } from './interfaces/payment-customer-repository.interface';
12
+ export type { ITransactionManager, TransactionRepositories, } from './interfaces/transaction-manager.interface';
13
+ export type { IPaymentEmailSender, IPaymentClientResolver, PaymentEmailBrandingConfig, IPaymentEmailBrandingResolver, RenderedPaymentEmail, IPaymentEmailTemplateRenderer, InvoiceEmailParams, ETransferEmailParams, PaymentConfirmationEmailParams, OverdueReminderEmailParams, RefundConfirmationEmailParams, } from './interfaces/payment-email.interfaces';
14
+ export type { IPaymentEventListener, InvoiceLineItemEvent, PaidInvoiceEvent, RefundedInvoiceEvent, RecurringInvoiceGeneratedEvent, RecurringPaymentFailedEvent, RecurringInvoicePausedEvent, } from './interfaces/payment-event-listener.interface';
15
+ export type { PaymentGateway, PaymentWebhookEventType, PaymentWebhookEvent, } from './gateways/payment-gateway.interface';
16
+ export type { RecurringPaymentGateway } from './gateways/recurring-payment-gateway.interface';
17
+ export { InvoiceService } from './services/invoice.service';
18
+ export { InvoiceNumberService } from './services/invoice-number.service';
19
+ export { PaymentService } from './services/payment.service';
20
+ export { RefundService } from './services/refund.service';
21
+ export { PaymentConfigService } from './services/payment-config.service';
22
+ export { PaymentPlanService } from './services/payment-plan.service';
23
+ export type { PaymentPlanWithComputed } from './services/payment-plan.service';
24
+ export { PaymentEmailService } from './services/payment-email.service';
25
+ export { RecurringInvoiceService } from './services/recurring-invoice.service';
26
+ export { CustomerService } from './services/customer.service';
27
+ export { ETransferService } from './services/e-transfer.service';
28
+ export { GatewayRegistryService } from './gateways/gateway-registry.service';
29
+ export type { DecimalLike, InvoiceStatus, PaymentMethod, PaymentStatus, RefundStatus, PaymentPlanStatus, InstallmentStatus, Invoice, InvoiceLineItem, InvoiceWithItems, Payment, Refund, PaymentPlan, PaymentPlanInstallment, PaymentConfig, PaymentProvider, CreateInvoiceData, CreateLineItemData, CreatePaymentData, CreateRefundData, CreatePaymentPlanData, CreateInstallmentData, CreatePaymentConfigData, InvoiceFilter, PaymentPlanFilter, RecurringIntervalUnit, RecurringInvoiceStatus, RecurringInvoice, RecurringInvoiceLineItem, RecurringInvoiceWithItems, CreateRecurringInvoiceData, CreateRecurringLineItemData, RecurringInvoiceFilter, PaymentCustomer, CreatePaymentCustomerData, } from './types';
30
+ export { PaymentException, InvalidInvoiceStateException, PaymentAmountExceededException, PaymentGatewayException, DuplicatePaymentException, InvoiceNotPayableException, InvoiceNumberExhaustedException, RefundNotAllowedException, InvalidPaymentStateException, InvalidRecurringInvoiceStateException, UniqueConstraintViolationException, } from './exceptions';
31
+ export { InvoiceModel, InvoiceStatusEnum, PaymentMethodEnum, PaymentStatusEnum, RefundStatusEnum, PaymentPlanStatusEnum, InstallmentStatusEnum, } from './models/invoice.model';
32
+ export { InvoiceLineItemModel } from './models/invoice-line-item.model';
33
+ export { InvoiceClientModel } from './models/invoice-client.model';
34
+ export { PaymentModel } from './models/payment.model';
35
+ export { RefundModel } from './models/refund.model';
36
+ export { ETransferInstructionsModel } from './models/e-transfer-instructions.model';
37
+ export { OnlinePaymentSessionModel } from './models/online-payment-session.model';
38
+ export { PaymentConfigModel, PaymentProviderModel, } from './models/payment-config.model';
39
+ export { PaymentPlanModel } from './models/payment-plan.model';
40
+ export { PaymentPlanInstallmentModel } from './models/payment-plan-installment.model';
41
+ export { PaymentMethodSetupModel } from './models/payment-method-setup.model';
42
+ export { PaginatedInvoices } from './models/paginated-invoices.model';
43
+ export { PaginatedPaymentPlans } from './models/paginated-payment-plans.model';
44
+ export { PaginatedRecurringInvoices } from './models/paginated-recurring-invoices.model';
45
+ export { RecurringInvoiceModel } from './models/recurring-invoice.model';
46
+ export { RecurringIntervalUnitEnum, RecurringInvoiceStatusEnum, } from './models/recurring-invoice.model';
47
+ export { RecurringInvoiceLineItemModel } from './models/recurring-invoice-line-item.model';
48
+ export { Paginated } from './models/paginated.model';
49
+ export type { IPaginatedType } from './models/paginated.model';
50
+ export { CreateInvoiceInput } from './dto/create-invoice.input';
51
+ export { CreateLineItemInput } from './dto/create-line-item.input';
52
+ export { CreateRefundInput } from './dto/create-refund.input';
53
+ export { CreateInstallmentInput } from './dto/create-installment.input';
54
+ export { CreatePaymentPlanInput } from './dto/create-payment-plan.input';
55
+ export { CreateRecurringInvoiceInput } from './dto/create-recurring-invoice.input';
56
+ export { CreateRecurringLineItemInput } from './dto/create-recurring-line-item.input';
57
+ export { RecordManualPaymentInput } from './dto/record-manual-payment.input';
58
+ export { UpdatePaymentConfigInput } from './dto/update-payment-config.input';
59
+ export { UpdateInvoiceMetadataInput } from './dto/update-invoice-metadata.input';
60
+ export { UpdateRecurringTemplateInput } from './dto/update-recurring-template.input';
61
+ export { UpsertPaymentProviderInput } from './dto/upsert-payment-provider.input';
62
+ export { InvoiceFilterInput } from './dto/invoice-filter.input';
63
+ export { PaymentPlanFilterInput } from './dto/payment-plan-filter.input';
64
+ export { RecurringInvoiceFilterInput } from './dto/recurring-invoice-filter.input';
65
+ export { IsMetadata } from './dto/validators/is-metadata';
66
+ export { StripeGateway } from './gateways/stripe/stripe.gateway';
67
+ export { PaymentsWebhook, PAYMENTS_WEBHOOK, } from './gateways/stripe/stripe-webhook.controller';
68
+ export { StaticBrandingResolver } from './services/static-branding-resolver';
69
+ export { computeNextInvoiceDate, computeCycleCount, } from './services/recurring-interval.util';
70
+ export { DefaultPaymentEmailTemplateRenderer } from './services/default-payment-email-templates';