@medusajs/payment 3.0.0-snapshot-20250410112222 → 3.0.0-snapshot-20251104004624

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 (109) hide show
  1. package/dist/joiner-config.d.ts.map +1 -1
  2. package/dist/joiner-config.js +0 -13
  3. package/dist/joiner-config.js.map +1 -1
  4. package/dist/loaders/providers.d.ts +7 -0
  5. package/dist/loaders/providers.d.ts.map +1 -1
  6. package/dist/loaders/providers.js +37 -11
  7. package/dist/loaders/providers.js.map +1 -1
  8. package/dist/migrations/Migration20240225134525.d.ts +1 -1
  9. package/dist/migrations/Migration20240225134525.d.ts.map +1 -1
  10. package/dist/migrations/Migration20240225134525.js +1 -1
  11. package/dist/migrations/Migration20240225134525.js.map +1 -1
  12. package/dist/migrations/Migration20240806072619.d.ts +1 -1
  13. package/dist/migrations/Migration20240806072619.d.ts.map +1 -1
  14. package/dist/migrations/Migration20240806072619.js +1 -1
  15. package/dist/migrations/Migration20240806072619.js.map +1 -1
  16. package/dist/migrations/Migration20241211151053.d.ts +1 -1
  17. package/dist/migrations/Migration20241211151053.d.ts.map +1 -1
  18. package/dist/migrations/Migration20241211151053.js +1 -1
  19. package/dist/migrations/Migration20241211151053.js.map +1 -1
  20. package/dist/migrations/Migration20250115160517.d.ts +1 -1
  21. package/dist/migrations/Migration20250115160517.d.ts.map +1 -1
  22. package/dist/migrations/Migration20250115160517.js +1 -1
  23. package/dist/migrations/Migration20250115160517.js.map +1 -1
  24. package/dist/migrations/Migration20250120110552.d.ts +1 -1
  25. package/dist/migrations/Migration20250120110552.d.ts.map +1 -1
  26. package/dist/migrations/Migration20250120110552.js +1 -1
  27. package/dist/migrations/Migration20250120110552.js.map +1 -1
  28. package/dist/migrations/Migration20250123122334.d.ts +1 -1
  29. package/dist/migrations/Migration20250123122334.d.ts.map +1 -1
  30. package/dist/migrations/Migration20250123122334.js +1 -1
  31. package/dist/migrations/Migration20250123122334.js.map +1 -1
  32. package/dist/migrations/Migration20250206105639.d.ts +1 -1
  33. package/dist/migrations/Migration20250206105639.d.ts.map +1 -1
  34. package/dist/migrations/Migration20250206105639.js +1 -1
  35. package/dist/migrations/Migration20250206105639.js.map +1 -1
  36. package/dist/migrations/Migration20250207132723.d.ts +1 -1
  37. package/dist/migrations/Migration20250207132723.d.ts.map +1 -1
  38. package/dist/migrations/Migration20250207132723.js +1 -1
  39. package/dist/migrations/Migration20250207132723.js.map +1 -1
  40. package/dist/migrations/Migration20250625084134.d.ts +6 -0
  41. package/dist/migrations/Migration20250625084134.d.ts.map +1 -0
  42. package/dist/migrations/Migration20250625084134.js +16 -0
  43. package/dist/migrations/Migration20250625084134.js.map +1 -0
  44. package/dist/migrations/Migration20250924135437.d.ts +6 -0
  45. package/dist/migrations/Migration20250924135437.d.ts.map +1 -0
  46. package/dist/migrations/Migration20250924135437.js +37 -0
  47. package/dist/migrations/Migration20250924135437.js.map +1 -0
  48. package/dist/migrations/Migration20250929124701.d.ts +6 -0
  49. package/dist/migrations/Migration20250929124701.d.ts.map +1 -0
  50. package/dist/migrations/Migration20250929124701.js +23 -0
  51. package/dist/migrations/Migration20250929124701.js.map +1 -0
  52. package/dist/models/capture.d.ts +29 -10
  53. package/dist/models/capture.d.ts.map +1 -1
  54. package/dist/models/payment-collection.d.ts +37 -19
  55. package/dist/models/payment-collection.d.ts.map +1 -1
  56. package/dist/models/payment-provider.d.ts +37 -19
  57. package/dist/models/payment-provider.d.ts.map +1 -1
  58. package/dist/models/payment-session.d.ts +20 -16
  59. package/dist/models/payment-session.d.ts.map +1 -1
  60. package/dist/models/payment.d.ts +10 -8
  61. package/dist/models/payment.d.ts.map +1 -1
  62. package/dist/models/refund-reason.d.ts +27 -9
  63. package/dist/models/refund-reason.d.ts.map +1 -1
  64. package/dist/models/refund-reason.js +2 -1
  65. package/dist/models/refund-reason.js.map +1 -1
  66. package/dist/models/refund.d.ts +29 -10
  67. package/dist/models/refund.d.ts.map +1 -1
  68. package/dist/providers/index.d.ts +2 -1
  69. package/dist/providers/index.d.ts.map +1 -1
  70. package/dist/providers/index.js +4 -5
  71. package/dist/providers/index.js.map +1 -1
  72. package/dist/providers/payment-medusa/index.d.ts +2 -0
  73. package/dist/providers/payment-medusa/index.d.ts.map +1 -0
  74. package/dist/providers/payment-medusa/index.js +6 -0
  75. package/dist/providers/payment-medusa/index.js.map +1 -0
  76. package/dist/providers/payment-medusa/services/medusa-payments.d.ts +58 -0
  77. package/dist/providers/payment-medusa/services/medusa-payments.d.ts.map +1 -0
  78. package/dist/providers/payment-medusa/services/medusa-payments.js +526 -0
  79. package/dist/providers/payment-medusa/services/medusa-payments.js.map +1 -0
  80. package/dist/providers/payment-medusa/types/index.d.ts +23 -0
  81. package/dist/providers/payment-medusa/types/index.d.ts.map +1 -0
  82. package/dist/providers/payment-medusa/types/index.js +3 -0
  83. package/dist/providers/payment-medusa/types/index.js.map +1 -0
  84. package/dist/providers/payment-medusa/types/medusa-payments.d.ts +25 -0
  85. package/dist/providers/payment-medusa/types/medusa-payments.d.ts.map +1 -0
  86. package/dist/providers/payment-medusa/types/medusa-payments.js +3 -0
  87. package/dist/providers/payment-medusa/types/medusa-payments.js.map +1 -0
  88. package/dist/providers/payment-medusa/utils/get-smallest-unit.d.ts +17 -0
  89. package/dist/providers/payment-medusa/utils/get-smallest-unit.d.ts.map +1 -0
  90. package/dist/providers/payment-medusa/utils/get-smallest-unit.js +68 -0
  91. package/dist/providers/payment-medusa/utils/get-smallest-unit.js.map +1 -0
  92. package/dist/providers/system.d.ts +6 -3
  93. package/dist/providers/system.d.ts.map +1 -1
  94. package/dist/providers/system.js +14 -5
  95. package/dist/providers/system.js.map +1 -1
  96. package/dist/services/payment-module.d.ts +296 -7
  97. package/dist/services/payment-module.d.ts.map +1 -1
  98. package/dist/services/payment-module.js +68 -31
  99. package/dist/services/payment-module.js.map +1 -1
  100. package/dist/services/payment-provider.d.ts +7 -2
  101. package/dist/services/payment-provider.d.ts.map +1 -1
  102. package/dist/services/payment-provider.js +10 -0
  103. package/dist/services/payment-provider.js.map +1 -1
  104. package/dist/tsconfig.tsbuildinfo +1 -1
  105. package/package.json +17 -28
  106. package/dist/schema/index.d.ts +0 -3
  107. package/dist/schema/index.d.ts.map +0 -1
  108. package/dist/schema/index.js +0 -114
  109. package/dist/schema/index.js.map +0 -1
@@ -0,0 +1,526 @@
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.MedusaPaymentsProvider = void 0;
7
+ const promises_1 = require("timers/promises");
8
+ const stripe_1 = __importDefault(require("stripe"));
9
+ const utils_1 = require("@medusajs/framework/utils");
10
+ const get_smallest_unit_1 = require("../utils/get-smallest-unit");
11
+ class CloudServiceError extends Error {
12
+ constructor(type, originalType, data, message) {
13
+ super(message);
14
+ this.type = type;
15
+ this.originalType = originalType;
16
+ this.data = data;
17
+ this.message = message;
18
+ }
19
+ }
20
+ class MedusaPaymentsProvider extends utils_1.AbstractPaymentProvider {
21
+ // The provider is loaded in a different a bit differently - it is not passed as a provider but the options are passed to the module's configuration.
22
+ // Due to that, the validation needs to happen in the constructor
23
+ static validateOptions(options) {
24
+ return validateOptions(options);
25
+ }
26
+ constructor(cradle, options) {
27
+ super(cradle, options);
28
+ validateOptions(options ?? {});
29
+ this.options_ = options;
30
+ this.stripeClient = new stripe_1.default(options.api_key);
31
+ }
32
+ request(url, options) {
33
+ const headers = {
34
+ "Content-Type": "application/json",
35
+ Authorization: `Basic ${this.options_.api_key}`,
36
+ };
37
+ if (this.options_.environment_handle) {
38
+ headers["x-medusa-environment-handle"] = this.options_.environment_handle;
39
+ }
40
+ if (this.options_.sandbox_handle) {
41
+ headers["x-medusa-sandbox-handle"] = this.options_.sandbox_handle;
42
+ }
43
+ return fetch(`${this.options_.endpoint}${url}`, {
44
+ ...options,
45
+ body: options.body ? JSON.stringify(options.body) : undefined,
46
+ headers: {
47
+ ...options.headers,
48
+ ...headers,
49
+ },
50
+ }).then(async (res) => {
51
+ const body = await res.json().catch(() => ({}));
52
+ if (!res.ok) {
53
+ throw new CloudServiceError(body.type, body.originalType, body.data, body.message);
54
+ }
55
+ return body;
56
+ });
57
+ }
58
+ normalizePaymentParameters(extra) {
59
+ const res = {
60
+ description: extra?.payment_description ?? "",
61
+ capture_method: extra?.capture_method,
62
+ setup_future_usage: extra?.setup_future_usage,
63
+ payment_method_types: extra?.payment_method_types,
64
+ payment_method_data: extra?.payment_method_data,
65
+ payment_method_options: extra?.payment_method_options,
66
+ automatic_payment_methods: extra?.automatic_payment_methods,
67
+ off_session: extra?.off_session,
68
+ confirm: extra?.confirm,
69
+ payment_method: extra?.payment_method,
70
+ return_url: extra?.return_url,
71
+ shared_payment_token: extra?.shared_payment_token,
72
+ };
73
+ return res;
74
+ }
75
+ handleStripeError(error) {
76
+ let medusaPayment;
77
+ switch (error.type) {
78
+ case "MedusaCardError":
79
+ // Medusa has created a payment but it failed
80
+ // Extract and return payment object to be stored in payment_session
81
+ // Allows for reference to the failed intent and potential webhook reconciliation
82
+ medusaPayment = error.data;
83
+ if (medusaPayment) {
84
+ return {
85
+ retry: false,
86
+ data: medusaPayment,
87
+ };
88
+ }
89
+ else {
90
+ throw error;
91
+ }
92
+ case "MedusaPaymentUnexpectedStateError":
93
+ medusaPayment = error.data;
94
+ if (medusaPayment) {
95
+ return {
96
+ retry: false,
97
+ data: medusaPayment,
98
+ };
99
+ }
100
+ else {
101
+ throw error;
102
+ }
103
+ case "MedusaConnectionError":
104
+ case "MedusaRateLimitError":
105
+ // Connection or rate limit errors indicate an uncertain result
106
+ // Retry the operation
107
+ return {
108
+ retry: true,
109
+ };
110
+ case "MedusaAPIError": {
111
+ // API errors should be treated as indeterminate per Stripe documentation
112
+ // Rely on webhooks rather than assuming failure
113
+ return {
114
+ retry: false,
115
+ data: {
116
+ indeterminate_due_to: "medusa_api_error",
117
+ },
118
+ };
119
+ }
120
+ default:
121
+ throw error;
122
+ }
123
+ }
124
+ async executeWithRetry(apiCall, maxRetries = 3, baseDelay = 1000, currentAttempt = 1) {
125
+ try {
126
+ return await apiCall();
127
+ }
128
+ catch (error) {
129
+ const handledError = this.handleStripeError(error);
130
+ if (!handledError.retry) {
131
+ // If retry is false, we know data exists per the type definition
132
+ return handledError.data;
133
+ }
134
+ if (handledError.retry && currentAttempt <= maxRetries) {
135
+ // Logic for retrying
136
+ const delay = baseDelay *
137
+ Math.pow(2, currentAttempt - 1) *
138
+ (0.5 + Math.random() * 0.5);
139
+ await (0, promises_1.setTimeout)(delay);
140
+ return this.executeWithRetry(apiCall, maxRetries, baseDelay, currentAttempt + 1);
141
+ }
142
+ // Retries are exhausted
143
+ throw error;
144
+ }
145
+ }
146
+ async getPaymentStatus(input) {
147
+ const id = input?.data?.id;
148
+ if (!id) {
149
+ throw new Error("No payment intent ID provided while getting payment status");
150
+ }
151
+ const payment = await this.retrievePayment({ data: { id } });
152
+ const statusResponse = this.getStatus(payment.data);
153
+ return statusResponse;
154
+ }
155
+ async initiatePayment({ currency_code, amount, data, context, }) {
156
+ const additionalParameters = this.normalizePaymentParameters(data);
157
+ const intentRequest = {
158
+ amount: (0, get_smallest_unit_1.getSmallestUnit)(amount, currency_code),
159
+ currency: currency_code,
160
+ metadata: {
161
+ session_id: data?.session_id,
162
+ },
163
+ account_holder_id: context?.account_holder?.data?.id,
164
+ idempotency_key: context?.idempotency_key,
165
+ ...additionalParameters,
166
+ };
167
+ const payment = (await this.executeWithRetry(() => {
168
+ return this.request("/payments", {
169
+ method: "POST",
170
+ body: intentRequest,
171
+ }).then((data) => data.payment);
172
+ }));
173
+ return {
174
+ id: payment.id,
175
+ ...this.getStatus(payment),
176
+ };
177
+ }
178
+ async authorizePayment(input) {
179
+ return this.getPaymentStatus(input);
180
+ }
181
+ async cancelPayment({ data, context, }) {
182
+ const id = data?.id;
183
+ if (!id) {
184
+ return { data: data };
185
+ }
186
+ const intent = (await this.executeWithRetry(() => {
187
+ return this.request(`/payments/${id}/cancel`, {
188
+ method: "POST",
189
+ body: {
190
+ idempotency_key: context?.idempotency_key,
191
+ },
192
+ }).then((data) => data.payment);
193
+ }));
194
+ const status = this.getStatus(intent);
195
+ if (status.status !== utils_1.PaymentSessionStatus.CANCELED) {
196
+ throw new Error(`Payment with id ${id} could not be canceled. Status: ${status.status}`);
197
+ }
198
+ return { data: intent };
199
+ }
200
+ async capturePayment({ data, context, }) {
201
+ const id = data?.id;
202
+ const intent = (await this.executeWithRetry(() => {
203
+ return this.request(`/payments/${id}/capture`, {
204
+ method: "POST",
205
+ body: {
206
+ idempotency_key: context?.idempotency_key,
207
+ },
208
+ }).then((data) => data.payment);
209
+ }));
210
+ const status = this.getStatus(intent);
211
+ if (status.status !== utils_1.PaymentSessionStatus.CAPTURED) {
212
+ throw new Error(`Payment with id ${id} could not be captured. Status: ${status.status}`);
213
+ }
214
+ return { data: intent };
215
+ }
216
+ async deletePayment(input) {
217
+ return await this.cancelPayment(input);
218
+ }
219
+ async refundPayment({ amount, data, context, }) {
220
+ const id = data?.id;
221
+ if (!id) {
222
+ throw new Error("No payment intent ID provided while refunding payment");
223
+ }
224
+ const currencyCode = data?.currency;
225
+ const response = (await this.executeWithRetry(() => {
226
+ return this.request(`/payments/${id}/refund`, {
227
+ method: "POST",
228
+ body: {
229
+ amount: (0, get_smallest_unit_1.getSmallestUnit)(amount, currencyCode),
230
+ idempotency_key: context?.idempotency_key,
231
+ },
232
+ }).then((data) => data.refund);
233
+ }));
234
+ return { data: response };
235
+ }
236
+ async retrievePayment({ data, }) {
237
+ const id = data?.id;
238
+ const intent = (await this.executeWithRetry(() => {
239
+ return this.request(`/payments/${id}`, {
240
+ method: "GET",
241
+ }).then((data) => data.payment);
242
+ }));
243
+ intent.amount = (0, get_smallest_unit_1.getAmountFromSmallestUnit)(intent.amount, intent.currency);
244
+ return { data: intent };
245
+ }
246
+ async updatePayment({ data, currency_code, amount, context, }) {
247
+ const amountNumeric = (0, get_smallest_unit_1.getSmallestUnit)(amount, currency_code);
248
+ if ((0, utils_1.isPresent)(amount) && data?.amount === amountNumeric) {
249
+ return this.getStatus(data);
250
+ }
251
+ const id = data?.id;
252
+ const sessionData = (await this.executeWithRetry(() => {
253
+ return this.request(`/payments/${id}`, {
254
+ method: "POST",
255
+ body: {
256
+ amount: amountNumeric,
257
+ idempotency_key: context?.idempotency_key,
258
+ },
259
+ }).then((data) => data.payment);
260
+ }));
261
+ return this.getStatus(sessionData);
262
+ }
263
+ async retrieveAccountHolder({ id, }) {
264
+ if (!id) {
265
+ throw new Error("No account holder ID provided while getting account holder");
266
+ }
267
+ const res = (await this.executeWithRetry(() => {
268
+ return this.request(`/account-holders/${id}`, {
269
+ method: "GET",
270
+ }).then((data) => data.account_holder);
271
+ }));
272
+ return {
273
+ id: res.id,
274
+ data: res,
275
+ };
276
+ }
277
+ async createAccountHolder({ context, }) {
278
+ const { account_holder, customer, idempotency_key } = context;
279
+ if (account_holder?.data?.id) {
280
+ return { id: account_holder.data.id };
281
+ }
282
+ if (!customer) {
283
+ throw new Error("No customer provided while creating account holder");
284
+ }
285
+ const shipping = customer.billing_address
286
+ ? {
287
+ address: {
288
+ city: customer.billing_address.city,
289
+ country: customer.billing_address.country_code,
290
+ line1: customer.billing_address.address_1,
291
+ line2: customer.billing_address.address_2,
292
+ postal_code: customer.billing_address.postal_code,
293
+ state: customer.billing_address.province,
294
+ },
295
+ }
296
+ : undefined;
297
+ const accountHolder = (await this.executeWithRetry(() => {
298
+ return this.request(`/account-holders`, {
299
+ method: "POST",
300
+ body: {
301
+ email: customer.email,
302
+ name: customer.company_name ||
303
+ `${customer.first_name ?? ""} ${customer.last_name ?? ""}`.trim() ||
304
+ undefined,
305
+ phone: customer.phone,
306
+ ...shipping,
307
+ idempotency_key: idempotency_key,
308
+ },
309
+ }).then((data) => data.account_holder);
310
+ }));
311
+ return {
312
+ id: accountHolder.id,
313
+ data: accountHolder,
314
+ };
315
+ }
316
+ async updateAccountHolder({ context, }) {
317
+ const { account_holder, customer, idempotency_key } = context;
318
+ if (!account_holder?.data?.id) {
319
+ throw new Error("No account holder in context while updating account holder");
320
+ }
321
+ // If no customer context was provided, we simply don't update anything within the provider
322
+ if (!customer) {
323
+ return {};
324
+ }
325
+ const accountHolderId = account_holder.data.id;
326
+ const shipping = customer.billing_address
327
+ ? {
328
+ address: {
329
+ city: customer.billing_address.city,
330
+ country: customer.billing_address.country_code,
331
+ line1: customer.billing_address.address_1,
332
+ line2: customer.billing_address.address_2,
333
+ postal_code: customer.billing_address.postal_code,
334
+ state: customer.billing_address.province,
335
+ },
336
+ }
337
+ : undefined;
338
+ const accountHolder = (await this.executeWithRetry(() => {
339
+ return this.request(`/account-holders/${accountHolderId}`, {
340
+ method: "POST",
341
+ body: {
342
+ email: customer.email,
343
+ name: customer.company_name ||
344
+ `${customer.first_name ?? ""} ${customer.last_name ?? ""}`.trim() ||
345
+ undefined,
346
+ phone: customer.phone,
347
+ ...shipping,
348
+ idempotency_key: idempotency_key,
349
+ },
350
+ }).then((data) => data.account_holder);
351
+ }));
352
+ return {
353
+ data: accountHolder,
354
+ };
355
+ }
356
+ async deleteAccountHolder({ context, }) {
357
+ const { account_holder } = context;
358
+ const accountHolderId = account_holder?.data?.id;
359
+ if (!accountHolderId) {
360
+ throw new Error("No account holder in context while deleting account holder");
361
+ }
362
+ await this.executeWithRetry(() => {
363
+ return this.request(`/account-holders/${accountHolderId}`, {
364
+ method: "DELETE",
365
+ });
366
+ });
367
+ return {};
368
+ }
369
+ async listPaymentMethods({ context, }) {
370
+ const accountHolderId = context?.account_holder?.data?.id;
371
+ if (!accountHolderId) {
372
+ return [];
373
+ }
374
+ const paymentMethods = (await this.executeWithRetry(() => {
375
+ return this.request(`/payment-methods?account_holder_id=${accountHolderId}`, {
376
+ method: "GET",
377
+ }).then((data) => data.payment_methods);
378
+ }));
379
+ return paymentMethods.map((method) => ({
380
+ id: method.id,
381
+ data: method,
382
+ }));
383
+ }
384
+ async savePaymentMethod({ context, data, }) {
385
+ const accountHolderId = context?.account_holder?.data?.id;
386
+ if (!accountHolderId) {
387
+ throw new Error("Account holder not set while saving a payment method");
388
+ }
389
+ const paymentMethodSession = (await this.executeWithRetry(() => {
390
+ return this.request(`/payment-methods`, {
391
+ method: "POST",
392
+ body: {
393
+ account_holder_id: accountHolderId,
394
+ ...data,
395
+ idempotency_key: context?.idempotency_key,
396
+ },
397
+ }).then((data) => data.payment_method_session);
398
+ }));
399
+ return {
400
+ id: paymentMethodSession.id,
401
+ data: paymentMethodSession,
402
+ };
403
+ }
404
+ getStatus(payment) {
405
+ const paymenAsRecord = payment;
406
+ switch (payment.status) {
407
+ case "requires_payment_method":
408
+ if (payment.last_payment_error) {
409
+ return { status: utils_1.PaymentSessionStatus.ERROR, data: paymenAsRecord };
410
+ }
411
+ return { status: utils_1.PaymentSessionStatus.PENDING, data: paymenAsRecord };
412
+ case "requires_confirmation":
413
+ case "processing":
414
+ return { status: utils_1.PaymentSessionStatus.PENDING, data: paymenAsRecord };
415
+ case "requires_action":
416
+ return {
417
+ status: utils_1.PaymentSessionStatus.REQUIRES_MORE,
418
+ data: paymenAsRecord,
419
+ };
420
+ case "canceled":
421
+ return { status: utils_1.PaymentSessionStatus.CANCELED, data: paymenAsRecord };
422
+ case "requires_capture":
423
+ return { status: utils_1.PaymentSessionStatus.AUTHORIZED, data: paymenAsRecord };
424
+ case "succeeded":
425
+ return { status: utils_1.PaymentSessionStatus.CAPTURED, data: paymenAsRecord };
426
+ default:
427
+ return { status: utils_1.PaymentSessionStatus.PENDING, data: paymenAsRecord };
428
+ }
429
+ }
430
+ async getWebhookActionAndData(webhookData) {
431
+ const event = this.constructWebhookEvent(webhookData);
432
+ const intent = event.data.object;
433
+ const { currency } = intent;
434
+ switch (event.type) {
435
+ case "payment_intent.created":
436
+ case "payment_intent.processing":
437
+ return {
438
+ action: utils_1.PaymentActions.PENDING,
439
+ data: {
440
+ session_id: intent.metadata.session_id,
441
+ amount: (0, get_smallest_unit_1.getAmountFromSmallestUnit)(intent.amount, currency),
442
+ },
443
+ };
444
+ case "payment_intent.canceled":
445
+ return {
446
+ action: utils_1.PaymentActions.CANCELED,
447
+ data: {
448
+ session_id: intent.metadata.session_id,
449
+ amount: (0, get_smallest_unit_1.getAmountFromSmallestUnit)(intent.amount, currency),
450
+ },
451
+ };
452
+ case "payment_intent.payment_failed":
453
+ return {
454
+ action: utils_1.PaymentActions.FAILED,
455
+ data: {
456
+ session_id: intent.metadata.session_id,
457
+ amount: (0, get_smallest_unit_1.getAmountFromSmallestUnit)(intent.amount, currency),
458
+ },
459
+ };
460
+ case "payment_intent.requires_action":
461
+ return {
462
+ action: utils_1.PaymentActions.REQUIRES_MORE,
463
+ data: {
464
+ session_id: intent.metadata.session_id,
465
+ amount: (0, get_smallest_unit_1.getAmountFromSmallestUnit)(intent.amount, currency),
466
+ },
467
+ };
468
+ case "payment_intent.amount_capturable_updated":
469
+ return {
470
+ action: utils_1.PaymentActions.AUTHORIZED,
471
+ data: {
472
+ session_id: intent.metadata.session_id,
473
+ amount: (0, get_smallest_unit_1.getAmountFromSmallestUnit)(intent.amount_capturable, currency),
474
+ },
475
+ };
476
+ case "payment_intent.partially_funded":
477
+ return {
478
+ action: utils_1.PaymentActions.REQUIRES_MORE,
479
+ data: {
480
+ session_id: intent.metadata.session_id,
481
+ amount: (0, get_smallest_unit_1.getAmountFromSmallestUnit)(intent.next_action?.display_bank_transfer_instructions
482
+ ?.amount_remaining ?? intent.amount, currency),
483
+ },
484
+ };
485
+ case "payment_intent.succeeded":
486
+ return {
487
+ action: utils_1.PaymentActions.SUCCESSFUL,
488
+ data: {
489
+ session_id: intent.metadata.session_id,
490
+ amount: (0, get_smallest_unit_1.getAmountFromSmallestUnit)(intent.amount_received, currency),
491
+ },
492
+ };
493
+ default:
494
+ return { action: utils_1.PaymentActions.NOT_SUPPORTED };
495
+ }
496
+ }
497
+ /**
498
+ * Constructs Medusa Payments Webhook event
499
+ * @param {object} data - the data of the webhook request: req.body
500
+ * ensures integrity of the webhook event
501
+ * @return {object} Medusa Payments Webhook event
502
+ */
503
+ constructWebhookEvent(data) {
504
+ const signature = data.headers["medusa-payments-signature"];
505
+ const stripeEvent = this.stripeClient.webhooks.constructEvent(data.rawData, signature, this.options_.webhook_secret);
506
+ return stripeEvent;
507
+ }
508
+ }
509
+ exports.MedusaPaymentsProvider = MedusaPaymentsProvider;
510
+ MedusaPaymentsProvider.identifier = "medusa-payments";
511
+ const validateOptions = (options) => {
512
+ if (!(0, utils_1.isDefined)(options.endpoint)) {
513
+ throw new Error("Required option `endpoint` is missing in Medusa payments plugin");
514
+ }
515
+ if (!(0, utils_1.isDefined)(options.webhook_secret)) {
516
+ throw new Error("Required option `webhook_secret` is missing in Medusa payments plugin");
517
+ }
518
+ if (!(0, utils_1.isDefined)(options.api_key)) {
519
+ throw new Error("Required option `api_key` is missing in Medusa payments plugin");
520
+ }
521
+ if (!(0, utils_1.isDefined)(options.environment_handle) &&
522
+ !(0, utils_1.isDefined)(options.sandbox_handle)) {
523
+ throw new Error("Required option `environment_handle` or `sandbox_handle` is missing in Medusa payments plugin");
524
+ }
525
+ };
526
+ //# sourceMappingURL=medusa-payments.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"medusa-payments.js","sourceRoot":"","sources":["../../../../src/providers/payment-medusa/services/medusa-payments.ts"],"names":[],"mappings":";;;;;;AAAA,8CAA4C;AAC5C,oDAA2B;AAmC3B,qDAMkC;AAElC,kEAGmC;AAcnC,MAAM,iBAAkB,SAAQ,KAAK;IAMnC,YAAY,IAAY,EAAE,YAAoB,EAAE,IAAS,EAAE,OAAe;QACxE,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QAChB,IAAI,CAAC,YAAY,GAAG,YAAY,CAAA;QAChC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QAChB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;IACxB,CAAC;C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iBAAS,EAAC,OAAO,CAAC,kBAAkB,CAAC;QACtC,CAAC,IAAA,iBAAS,EAAC,OAAO,CAAC,cAAc,CAAC,EAClC,CAAC;QACD,MAAM,IAAI,KAAK,CACb,+FAA+F,CAChG,CAAA;IACH,CAAC;AACH,CAAC,CAAA"}
@@ -0,0 +1,23 @@
1
+ export interface MedusaPaymentsOptions {
2
+ /**
3
+ * The API key for the Stripe account
4
+ */
5
+ api_key: string;
6
+ /**
7
+ * The webhook secret used to verify webhooks
8
+ */
9
+ webhook_secret: string;
10
+ /**
11
+ * The endpoint to use for the payments
12
+ */
13
+ endpoint: string;
14
+ /**
15
+ * The handle of the cloud environment
16
+ */
17
+ environment_handle: string;
18
+ /**
19
+ * The handle of the cloud sandbox
20
+ */
21
+ sandbox_handle: string;
22
+ }
23
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/providers/payment-medusa/types/index.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,qBAAqB;IACpC;;OAEG;IACH,OAAO,EAAE,MAAM,CAAA;IACf;;OAEG;IACH,cAAc,EAAE,MAAM,CAAA;IACtB;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAA;IAChB;;OAEG;IACH,kBAAkB,EAAE,MAAM,CAAA;IAC1B;;OAEG;IACH,cAAc,EAAE,MAAM,CAAA;CACvB"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/providers/payment-medusa/types/index.ts"],"names":[],"mappings":""}
@@ -0,0 +1,25 @@
1
+ import stripe from "stripe";
2
+ export interface CreatePaymentRequest extends stripe.PaymentIntentCreateParams {
3
+ account_holder_id?: string;
4
+ idempotency_key?: string;
5
+ }
6
+ export interface MedusaPayment extends stripe.PaymentIntent {
7
+ account_holder_id?: string;
8
+ }
9
+ export interface RefundPaymentRequest extends stripe.RefundCreateParams {
10
+ idempotency_key?: string;
11
+ }
12
+ export interface MedusaRefund extends stripe.Refund {
13
+ }
14
+ export interface CreateAccountHolderRequest extends stripe.CustomerCreateParams {
15
+ }
16
+ export interface UpdateAccountHolderRequest extends stripe.CustomerUpdateParams {
17
+ }
18
+ export interface MedusaAccountHolder extends stripe.Customer {
19
+ }
20
+ export interface MedusaPaymentMethod extends stripe.PaymentMethod {
21
+ account_holder_id?: string;
22
+ }
23
+ export interface MedusaPaymentMethodSession extends stripe.SetupIntent {
24
+ }
25
+ //# sourceMappingURL=medusa-payments.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"medusa-payments.d.ts","sourceRoot":"","sources":["../../../../src/providers/payment-medusa/types/medusa-payments.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAA;AAE3B,MAAM,WAAW,oBAAqB,SAAQ,MAAM,CAAC,yBAAyB;IAC5E,iBAAiB,CAAC,EAAE,MAAM,CAAA;IAC1B,eAAe,CAAC,EAAE,MAAM,CAAA;CACzB;AAED,MAAM,WAAW,aAAc,SAAQ,MAAM,CAAC,aAAa;IACzD,iBAAiB,CAAC,EAAE,MAAM,CAAA;CAC3B;AAED,MAAM,WAAW,oBAAqB,SAAQ,MAAM,CAAC,kBAAkB;IACrE,eAAe,CAAC,EAAE,MAAM,CAAA;CACzB;AAED,MAAM,WAAW,YAAa,SAAQ,MAAM,CAAC,MAAM;CAAG;AAEtD,MAAM,WAAW,0BACf,SAAQ,MAAM,CAAC,oBAAoB;CAAG;AAExC,MAAM,WAAW,0BACf,SAAQ,MAAM,CAAC,oBAAoB;CAAG;AAExC,MAAM,WAAW,mBAAoB,SAAQ,MAAM,CAAC,QAAQ;CAAG;AAE/D,MAAM,WAAW,mBAAoB,SAAQ,MAAM,CAAC,aAAa;IAC/D,iBAAiB,CAAC,EAAE,MAAM,CAAA;CAC3B;AAED,MAAM,WAAW,0BAA2B,SAAQ,MAAM,CAAC,WAAW;CAAG"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=medusa-payments.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"medusa-payments.js","sourceRoot":"","sources":["../../../../src/providers/payment-medusa/types/medusa-payments.ts"],"names":[],"mappings":""}
@@ -0,0 +1,17 @@
1
+ import { BigNumberInput } from "@medusajs/framework/types";
2
+ /**
3
+ * Converts an amount to the format required by Stripe based on currency.
4
+ * https://docs.stripe.com/currencies
5
+ * @param {BigNumberInput} amount - The amount to be converted.
6
+ * @param {string} currency - The currency code (e.g., 'USD', 'JOD').
7
+ * @returns {number} - The converted amount in the smallest currency unit.
8
+ */
9
+ export declare function getSmallestUnit(amount: BigNumberInput, currency: string): number;
10
+ /**
11
+ * Converts an amount from the smallest currency unit to the standard unit based on currency.
12
+ * @param {BigNumberInput} amount - The amount in the smallest currency unit.
13
+ * @param {string} currency - The currency code (e.g., 'USD', 'JOD').
14
+ * @returns {number} - The converted amount in the standard currency unit.
15
+ */
16
+ export declare function getAmountFromSmallestUnit(amount: BigNumberInput, currency: string): number;
17
+ //# sourceMappingURL=get-smallest-unit.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-smallest-unit.d.ts","sourceRoot":"","sources":["../../../../src/providers/payment-medusa/utils/get-smallest-unit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAA;AAqC1D;;;;;;GAMG;AACH,wBAAgB,eAAe,CAC7B,MAAM,EAAE,cAAc,EACtB,QAAQ,EAAE,MAAM,GACf,MAAM,CAgBR;AAED;;;;;GAKG;AACH,wBAAgB,yBAAyB,CACvC,MAAM,EAAE,cAAc,EACtB,QAAQ,EAAE,MAAM,GACf,MAAM,CAIR"}