@unchainedshop/core-orders 3.0.0-alpha7 → 3.0.0-rc10

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 (141) hide show
  1. package/lib/db/OrderDeliveriesCollection.d.ts +21 -2
  2. package/lib/db/OrderDeliveriesCollection.d.ts.map +1 -1
  3. package/lib/db/OrderDeliveriesCollection.js +6 -0
  4. package/lib/db/OrderDeliveriesCollection.js.map +1 -1
  5. package/lib/db/OrderDiscountsCollection.d.ts +16 -2
  6. package/lib/db/OrderDiscountsCollection.d.ts.map +1 -1
  7. package/lib/db/OrderDiscountsCollection.js +5 -0
  8. package/lib/db/OrderDiscountsCollection.js.map +1 -1
  9. package/lib/db/OrderPaymentsCollection.d.ts +22 -2
  10. package/lib/db/OrderPaymentsCollection.d.ts.map +1 -1
  11. package/lib/db/OrderPaymentsCollection.js +6 -0
  12. package/lib/db/OrderPaymentsCollection.js.map +1 -1
  13. package/lib/db/OrderPositionsCollection.d.ts +22 -2
  14. package/lib/db/OrderPositionsCollection.d.ts.map +1 -1
  15. package/lib/db/OrderPositionsCollection.js.map +1 -1
  16. package/lib/db/OrdersCollection.d.ts +33 -2
  17. package/lib/db/OrdersCollection.d.ts.map +1 -1
  18. package/lib/db/OrdersCollection.js +8 -1
  19. package/lib/db/OrdersCollection.js.map +1 -1
  20. package/lib/module/buildFindSelector.d.ts +5 -0
  21. package/lib/module/buildFindSelector.d.ts.map +1 -0
  22. package/lib/module/buildFindSelector.js +18 -0
  23. package/lib/module/buildFindSelector.js.map +1 -0
  24. package/lib/module/configureOrderDeliveriesModule.d.ts +14 -27
  25. package/lib/module/configureOrderDeliveriesModule.d.ts.map +1 -1
  26. package/lib/module/configureOrderDeliveriesModule.js +8 -69
  27. package/lib/module/configureOrderDeliveriesModule.js.map +1 -1
  28. package/lib/module/configureOrderDiscountsModule.d.ts +17 -18
  29. package/lib/module/configureOrderDiscountsModule.d.ts.map +1 -1
  30. package/lib/module/configureOrderDiscountsModule.js +34 -143
  31. package/lib/module/configureOrderDiscountsModule.js.map +1 -1
  32. package/lib/module/configureOrderPaymentsModule.d.ts +17 -37
  33. package/lib/module/configureOrderPaymentsModule.d.ts.map +1 -1
  34. package/lib/module/configureOrderPaymentsModule.js +16 -124
  35. package/lib/module/configureOrderPaymentsModule.js.map +1 -1
  36. package/lib/module/configureOrderPositionsModule.d.ts +22 -41
  37. package/lib/module/configureOrderPositionsModule.d.ts.map +1 -1
  38. package/lib/module/configureOrderPositionsModule.js +22 -85
  39. package/lib/module/configureOrderPositionsModule.js.map +1 -1
  40. package/lib/module/configureOrdersModule-mutations.d.ts +5 -11
  41. package/lib/module/configureOrdersModule-mutations.d.ts.map +1 -1
  42. package/lib/module/configureOrdersModule-mutations.js +11 -50
  43. package/lib/module/configureOrdersModule-mutations.js.map +1 -1
  44. package/lib/module/configureOrdersModule-queries.d.ts +18 -6
  45. package/lib/module/configureOrdersModule-queries.d.ts.map +1 -1
  46. package/lib/module/configureOrdersModule-queries.js +35 -22
  47. package/lib/module/configureOrdersModule-queries.js.map +1 -1
  48. package/lib/module/configureOrdersModule.d.ts +11 -8
  49. package/lib/module/configureOrdersModule.d.ts.map +1 -1
  50. package/lib/module/configureOrdersModule.js +134 -154
  51. package/lib/module/configureOrdersModule.js.map +1 -1
  52. package/lib/orders-index.d.ts +11 -8
  53. package/lib/orders-index.d.ts.map +1 -1
  54. package/lib/orders-index.js +11 -8
  55. package/lib/orders-index.js.map +1 -1
  56. package/lib/orders-settings.d.ts +4 -8
  57. package/lib/orders-settings.d.ts.map +1 -1
  58. package/lib/orders-settings.js.map +1 -1
  59. package/package.json +13 -13
  60. package/src/db/OrderDeliveriesCollection.ts +25 -2
  61. package/src/db/OrderDiscountsCollection.ts +18 -2
  62. package/src/db/OrderPaymentsCollection.ts +26 -2
  63. package/src/db/OrderPositionsCollection.ts +21 -2
  64. package/src/db/OrdersCollection.ts +44 -2
  65. package/src/module/buildFindSelector.test.ts +8 -8
  66. package/src/module/buildFindSelector.ts +24 -0
  67. package/src/module/configureOrderDeliveriesModule.ts +29 -172
  68. package/src/module/configureOrderDiscountsModule.ts +46 -213
  69. package/src/module/configureOrderPaymentsModule.ts +58 -266
  70. package/src/module/configureOrderPositionsModule.ts +57 -208
  71. package/src/module/configureOrdersModule-mutations.ts +13 -85
  72. package/src/module/configureOrdersModule-queries.ts +61 -29
  73. package/src/module/configureOrdersModule.ts +181 -264
  74. package/src/orders-index.ts +11 -10
  75. package/src/orders-settings.ts +5 -7
  76. package/tsconfig.json +5 -7
  77. package/lib/db/OrderDiscountTrigger.d.ts +0 -5
  78. package/lib/db/OrderDiscountTrigger.d.ts.map +0 -1
  79. package/lib/db/OrderDiscountTrigger.js +0 -6
  80. package/lib/db/OrderDiscountTrigger.js.map +0 -1
  81. package/lib/director/OrderDiscountAdapter.d.ts +0 -4
  82. package/lib/director/OrderDiscountAdapter.d.ts.map +0 -1
  83. package/lib/director/OrderDiscountAdapter.js +0 -3
  84. package/lib/director/OrderDiscountAdapter.js.map +0 -1
  85. package/lib/director/OrderDiscountConfiguration.d.ts +0 -6
  86. package/lib/director/OrderDiscountConfiguration.d.ts.map +0 -1
  87. package/lib/director/OrderDiscountConfiguration.js +0 -2
  88. package/lib/director/OrderDiscountConfiguration.js.map +0 -1
  89. package/lib/director/OrderDiscountDirector.d.ts +0 -3
  90. package/lib/director/OrderDiscountDirector.d.ts.map +0 -1
  91. package/lib/director/OrderDiscountDirector.js +0 -3
  92. package/lib/director/OrderDiscountDirector.js.map +0 -1
  93. package/lib/director/OrderPricingAdapter.d.ts +0 -22
  94. package/lib/director/OrderPricingAdapter.d.ts.map +0 -1
  95. package/lib/director/OrderPricingAdapter.js +0 -25
  96. package/lib/director/OrderPricingAdapter.js.map +0 -1
  97. package/lib/director/OrderPricingDirector.d.ts +0 -18
  98. package/lib/director/OrderPricingDirector.d.ts.map +0 -1
  99. package/lib/director/OrderPricingDirector.js +0 -39
  100. package/lib/director/OrderPricingDirector.js.map +0 -1
  101. package/lib/director/OrderPricingSheet.d.ts +0 -36
  102. package/lib/director/OrderPricingSheet.d.ts.map +0 -1
  103. package/lib/director/OrderPricingSheet.js +0 -108
  104. package/lib/director/OrderPricingSheet.js.map +0 -1
  105. package/lib/module/configureOrdersModule-processing.d.ts +0 -32
  106. package/lib/module/configureOrdersModule-processing.d.ts.map +0 -1
  107. package/lib/module/configureOrdersModule-processing.js +0 -339
  108. package/lib/module/configureOrdersModule-processing.js.map +0 -1
  109. package/lib/module/configureOrdersModule-transformations.d.ts +0 -20
  110. package/lib/module/configureOrdersModule-transformations.d.ts.map +0 -1
  111. package/lib/module/configureOrdersModule-transformations.js +0 -111
  112. package/lib/module/configureOrdersModule-transformations.js.map +0 -1
  113. package/lib/service/migrateOrderCartService.d.ts +0 -10
  114. package/lib/service/migrateOrderCartService.d.ts.map +0 -1
  115. package/lib/service/migrateOrderCartService.js +0 -32
  116. package/lib/service/migrateOrderCartService.js.map +0 -1
  117. package/lib/service/nextUserCartService.d.ts +0 -11
  118. package/lib/service/nextUserCartService.d.ts.map +0 -1
  119. package/lib/service/nextUserCartService.js +0 -34
  120. package/lib/service/nextUserCartService.js.map +0 -1
  121. package/lib/service/orderServices.d.ts +0 -8
  122. package/lib/service/orderServices.d.ts.map +0 -1
  123. package/lib/service/orderServices.js +0 -7
  124. package/lib/service/orderServices.js.map +0 -1
  125. package/lib/types.d.ts +0 -116
  126. package/lib/types.d.ts.map +0 -1
  127. package/lib/types.js +0 -25
  128. package/lib/types.js.map +0 -1
  129. package/src/db/OrderDiscountTrigger.ts +0 -4
  130. package/src/director/OrderDiscountAdapter.ts +0 -8
  131. package/src/director/OrderDiscountConfiguration.ts +0 -5
  132. package/src/director/OrderDiscountDirector.ts +0 -5
  133. package/src/director/OrderPricingAdapter.ts +0 -61
  134. package/src/director/OrderPricingDirector.ts +0 -72
  135. package/src/director/OrderPricingSheet.ts +0 -146
  136. package/src/module/configureOrdersModule-processing.ts +0 -508
  137. package/src/module/configureOrdersModule-transformations.ts +0 -171
  138. package/src/service/migrateOrderCartService.ts +0 -53
  139. package/src/service/nextUserCartService.ts +0 -54
  140. package/src/service/orderServices.ts +0 -12
  141. package/src/types.ts +0 -129
@@ -1,98 +1,11 @@
1
- import { UnchainedCore } from '@unchainedshop/core';
2
1
  import { emit, registerEvents } from '@unchainedshop/events';
3
2
  import { generateDbFilterById, generateDbObjectId, mongodb } from '@unchainedshop/mongodb';
4
- import { Order, OrderDiscount, OrderPayment, OrderPaymentStatus } from '../types.js';
5
- import { IPaymentPricingSheet } from '@unchainedshop/core-payment';
6
- import { OrderPricingDiscount } from '../director/OrderPricingDirector.js';
7
-
8
- export type OrderPaymentsModule = {
9
- // Queries
10
- findOrderPayment: (
11
- params: {
12
- orderPaymentId: string;
13
- },
14
- options?: mongodb.FindOptions,
15
- ) => Promise<OrderPayment>;
16
-
17
- findOrderPaymentByContextData: (
18
- params: {
19
- context: any;
20
- },
21
- options?: mongodb.FindOptions,
22
- ) => Promise<OrderPayment>;
23
-
24
- countOrderPaymentsByContextData: (
25
- params: {
26
- context: any;
27
- },
28
- options?: mongodb.FindOptions,
29
- ) => Promise<number>;
30
-
31
- // Transformations
32
- discounts: (
33
- orderPayment: OrderPayment,
34
- params: { order: Order; orderDiscount: OrderDiscount },
35
- unchainedAPI: UnchainedCore,
36
- ) => Array<OrderPricingDiscount>;
37
- isBlockingOrderConfirmation: (
38
- orderPayment: OrderPayment,
39
- unchainedAPI: UnchainedCore,
40
- ) => Promise<boolean>;
41
- isBlockingOrderFullfillment: (orderPayment: OrderPayment) => boolean;
42
- normalizedStatus: (orderPayment: OrderPayment) => string;
43
- pricingSheet: (
44
- orderPayment: OrderPayment,
45
- currency: string,
46
- unchainedAPI: UnchainedCore,
47
- ) => IPaymentPricingSheet;
48
-
49
- // Mutations
50
- create: (doc: OrderPayment) => Promise<OrderPayment>;
51
-
52
- cancel: (
53
- orderPayment: OrderPayment,
54
- paymentContext: {
55
- transactionContext: any;
56
- userId: string;
57
- },
58
- unchainedAPI: UnchainedCore,
59
- ) => Promise<OrderPayment>;
60
-
61
- confirm: (
62
- orderPayment: OrderPayment,
63
- paymentContext: {
64
- transactionContext: any;
65
- userId: string;
66
- },
67
- unchainedAPI: UnchainedCore,
68
- ) => Promise<OrderPayment>;
69
-
70
- charge: (
71
- orderPayment: OrderPayment,
72
- paymentContext: {
73
- transactionContext: any;
74
- userId: string;
75
- },
76
- unchainedAPI: UnchainedCore,
77
- ) => Promise<OrderPayment>;
78
-
79
- logEvent: (orderPaymentId: string, event: any) => Promise<boolean>;
80
-
81
- markAsPaid: (payment: OrderPayment, meta: any) => Promise<void>;
82
-
83
- updateContext: (orderPaymentId: string, context: any) => Promise<OrderPayment | null>;
84
-
85
- updateStatus: (
86
- orderPaymentId: string,
87
- params: { transactionId?: string; status: OrderPaymentStatus; info?: string },
88
- ) => Promise<OrderPayment>;
89
-
90
- updateCalculation: (orderPayment: OrderPayment, unchainedAPI: UnchainedCore) => Promise<OrderPayment>;
91
- };
3
+ import { PricingCalculation } from '@unchainedshop/utils';
4
+ import { OrderPayment, OrderPaymentStatus } from '../db/OrderPaymentsCollection.js';
92
5
 
93
6
  const ORDER_PAYMENT_EVENTS: string[] = ['ORDER_UPDATE_PAYMENT', 'ORDER_SIGN_PAYMENT', 'ORDER_PAY'];
94
7
 
95
- export const buildFindByIdSelector = (orderPaymentId: string) =>
8
+ export const buildFindOrderPaymentByIdSelector = (orderPaymentId: string) =>
96
9
  generateDbFilterById(orderPaymentId) as mongodb.Filter<OrderPayment>;
97
10
 
98
11
  export const buildFindByContextDataSelector = (context: any): mongodb.Filter<OrderPayment> => {
@@ -117,32 +30,23 @@ export const configureOrderPaymentsModule = ({
117
30
  OrderPayments,
118
31
  }: {
119
32
  OrderPayments: mongodb.Collection<OrderPayment>;
120
- }): OrderPaymentsModule => {
33
+ }) => {
121
34
  registerEvents(ORDER_PAYMENT_EVENTS);
122
35
 
123
- const normalizedStatus: OrderPaymentsModule['normalizedStatus'] = (orderPayment) => {
36
+ const normalizedStatus = (orderPayment: OrderPayment) => {
124
37
  return orderPayment.status === null
125
38
  ? OrderPaymentStatus.OPEN
126
39
  : (orderPayment.status as OrderPaymentStatus);
127
40
  };
128
41
 
129
- const buildPaymentProviderActionsContext = (
130
- orderPayment: OrderPayment,
131
- { transactionContext, ...rest }: { transactionContext: any; userId: string },
132
- ) => ({
133
- ...rest,
134
- orderPayment,
135
- paymentProviderId: orderPayment.paymentProviderId,
136
- transactionContext: {
137
- ...(transactionContext || {}),
138
- ...(orderPayment.context || {}),
139
- },
140
- });
141
-
142
- const updateStatus: OrderPaymentsModule['updateStatus'] = async (
143
- orderPaymentId,
144
- { status, transactionId, info },
145
- ) => {
42
+ const updateStatus = async (
43
+ orderPaymentId: string,
44
+ {
45
+ transactionId,
46
+ status,
47
+ info,
48
+ }: { transactionId?: string; status: OrderPaymentStatus; info?: string },
49
+ ): Promise<OrderPayment> => {
146
50
  const date = new Date();
147
51
  const modifier: mongodb.UpdateFilter<OrderPayment> = {
148
52
  $set: { status, updated: new Date() },
@@ -165,67 +69,52 @@ export const configureOrderPaymentsModule = ({
165
69
  modifier.$set.paid = date;
166
70
  }
167
71
 
168
- const selector = buildFindByIdSelector(orderPaymentId);
72
+ const selector = buildFindOrderPaymentByIdSelector(orderPaymentId);
169
73
  return OrderPayments.findOneAndUpdate(selector, modifier, { returnDocument: 'after' });
170
74
  };
171
75
 
172
76
  return {
173
77
  // Queries
174
- findOrderPayment: async ({ orderPaymentId }, options) => {
175
- return OrderPayments.findOne(buildFindByIdSelector(orderPaymentId), options);
176
- },
177
- findOrderPaymentByContextData: async ({ context }, options) => {
78
+ findOrderPayment: async (
79
+ {
80
+ orderPaymentId,
81
+ }: {
82
+ orderPaymentId: string;
83
+ },
84
+ options?: mongodb.FindOptions,
85
+ ): Promise<OrderPayment> => {
86
+ return OrderPayments.findOne(buildFindOrderPaymentByIdSelector(orderPaymentId), options);
87
+ },
88
+ findOrderPaymentByContextData: async (
89
+ {
90
+ context,
91
+ }: {
92
+ context: any;
93
+ },
94
+ options?: mongodb.FindOptions,
95
+ ): Promise<OrderPayment> => {
178
96
  const selector = buildFindByContextDataSelector(context);
179
97
 
180
98
  return OrderPayments.findOne(selector, options);
181
99
  },
182
- countOrderPaymentsByContextData: async ({ context }, options) => {
100
+ countOrderPaymentsByContextData: async (
101
+ {
102
+ context,
103
+ }: {
104
+ context: any;
105
+ },
106
+ options?: mongodb.FindOptions,
107
+ ) => {
183
108
  const selector = buildFindByContextDataSelector(context);
184
109
 
185
110
  return OrderPayments.countDocuments(selector, options);
186
111
  },
187
- // Transformations
188
- discounts: (orderPayment, { order, orderDiscount }, context) => {
189
- const { modules } = context;
190
- if (!orderPayment) return [];
191
- const pricingSheet = modules.orders.payments.pricingSheet(orderPayment, order.currency, context);
192
- return pricingSheet.discountPrices(orderDiscount._id).map((discount) => ({
193
- payment: orderPayment,
194
- ...discount,
195
- }));
196
- },
197
-
198
- isBlockingOrderConfirmation: async (orderPayment, unchainedAPI) => {
199
- if (orderPayment.status === OrderPaymentStatus.PAID) return false;
200
-
201
- const provider = await unchainedAPI.modules.payment.paymentProviders.findProvider({
202
- paymentProviderId: orderPayment.paymentProviderId,
203
- });
204
-
205
- const isPayLaterAllowed = await unchainedAPI.modules.payment.paymentProviders.isPayLaterAllowed(
206
- provider,
207
- unchainedAPI,
208
- );
209
-
210
- return !isPayLaterAllowed;
211
- },
212
- isBlockingOrderFullfillment: (orderPayment) => {
213
- if (orderPayment.status === OrderPaymentStatus.PAID) return false;
214
- return true;
215
- },
216
112
 
217
113
  normalizedStatus,
218
114
 
219
- pricingSheet: (orderPayment, currency, { modules }) => {
220
- return modules.payment.paymentProviders.pricingSheet({
221
- calculation: orderPayment.calculation,
222
- currency,
223
- });
224
- },
225
-
226
115
  // Mutations
227
116
 
228
- create: async (doc) => {
117
+ create: async (doc: OrderPayment): Promise<OrderPayment> => {
229
118
  const { insertedId: orderPaymentId } = await OrderPayments.insertOne({
230
119
  _id: generateDbObjectId(),
231
120
  created: new Date(),
@@ -234,113 +123,14 @@ export const configureOrderPaymentsModule = ({
234
123
  context: doc.context || {},
235
124
  });
236
125
 
237
- const orderPayment = await OrderPayments.findOne(buildFindByIdSelector(orderPaymentId));
238
-
239
- return orderPayment;
240
- },
241
-
242
- confirm: async (orderPayment, paymentContext, unchainedAPI) => {
243
- const { modules } = unchainedAPI;
244
-
245
- if (normalizedStatus(orderPayment) !== OrderPaymentStatus.PAID) {
246
- return orderPayment;
247
- }
248
-
249
- const arbitraryResponseData = await modules.payment.paymentProviders.confirm(
250
- orderPayment.paymentProviderId,
251
- buildPaymentProviderActionsContext(orderPayment, paymentContext),
252
- unchainedAPI,
253
- );
254
-
255
- if (arbitraryResponseData) {
256
- return updateStatus(orderPayment._id, {
257
- status: OrderPaymentStatus.PAID,
258
- info: JSON.stringify(arbitraryResponseData),
259
- });
260
- }
261
-
262
- return orderPayment;
263
- },
264
-
265
- cancel: async (orderPayment, paymentContext, unchainedAPI) => {
266
- const { modules } = unchainedAPI;
267
-
268
- if (normalizedStatus(orderPayment) !== OrderPaymentStatus.PAID) {
269
- return orderPayment;
270
- }
271
-
272
- const arbitraryResponseData = await modules.payment.paymentProviders.cancel(
273
- orderPayment.paymentProviderId,
274
- buildPaymentProviderActionsContext(orderPayment, paymentContext),
275
- unchainedAPI,
276
- );
277
-
278
- if (arbitraryResponseData) {
279
- return updateStatus(orderPayment._id, {
280
- status: OrderPaymentStatus.REFUNDED,
281
- info: JSON.stringify(arbitraryResponseData),
282
- });
283
- }
284
-
285
- return orderPayment;
286
- },
287
-
288
- charge: async (orderPayment, context, unchainedAPI) => {
289
- const { modules } = unchainedAPI;
290
-
291
- if (normalizedStatus(orderPayment) !== OrderPaymentStatus.OPEN) {
292
- return orderPayment;
293
- }
294
-
295
- const paymentCredentials =
296
- context.transactionContext?.paymentCredentials ||
297
- (await modules.payment.paymentCredentials.findPaymentCredential({
298
- userId: context.userId,
299
- paymentProviderId: orderPayment.paymentProviderId,
300
- isPreferred: true,
301
- }));
302
-
303
- const paymentContext = buildPaymentProviderActionsContext(orderPayment, {
304
- ...context,
305
- transactionContext: {
306
- ...context.transactionContext,
307
- paymentCredentials,
308
- },
309
- });
310
-
311
- const result = await modules.payment.paymentProviders.charge(
312
- orderPayment.paymentProviderId,
313
- paymentContext,
314
- unchainedAPI,
126
+ const orderPayment = await OrderPayments.findOne(
127
+ buildFindOrderPaymentByIdSelector(orderPaymentId),
315
128
  );
316
129
 
317
- if (!result) return orderPayment;
318
-
319
- const { credentials, ...arbitraryResponseData } = result;
320
-
321
- if (credentials) {
322
- const { token, ...meta } = credentials;
323
- await modules.payment.paymentCredentials.upsertCredentials({
324
- userId: paymentContext.userId,
325
- paymentProviderId: orderPayment.paymentProviderId,
326
- token,
327
- ...meta,
328
- });
329
- }
330
-
331
- if (arbitraryResponseData) {
332
- const { transactionId, ...info } = arbitraryResponseData;
333
- return updateStatus(orderPayment._id, {
334
- transactionId,
335
- status: OrderPaymentStatus.PAID,
336
- info: JSON.stringify(info),
337
- });
338
- }
339
-
340
130
  return orderPayment;
341
131
  },
342
132
 
343
- logEvent: async (orderPaymentId, event) => {
133
+ logEvent: async (orderPaymentId: string, event: any): Promise<boolean> => {
344
134
  const date = new Date();
345
135
  const modifier = {
346
136
  $push: {
@@ -356,7 +146,7 @@ export const configureOrderPaymentsModule = ({
356
146
  return true;
357
147
  },
358
148
 
359
- markAsPaid: async (orderPayment, meta) => {
149
+ markAsPaid: async (orderPayment: OrderPayment, meta: any) => {
360
150
  if (normalizedStatus(orderPayment) !== OrderPaymentStatus.OPEN) return;
361
151
 
362
152
  await updateStatus(orderPayment._id, {
@@ -366,8 +156,8 @@ export const configureOrderPaymentsModule = ({
366
156
  await emit('ORDER_PAY', { orderPayment });
367
157
  },
368
158
 
369
- updateContext: async (orderPaymentId, context) => {
370
- const selector = buildFindByIdSelector(orderPaymentId);
159
+ updateContext: async (orderPaymentId: string, context: any): Promise<OrderPayment> => {
160
+ const selector = buildFindOrderPaymentByIdSelector(orderPaymentId);
371
161
  if (!context || Object.keys(context).length === 0) return OrderPayments.findOne(selector, {});
372
162
 
373
163
  const contextSetters = Object.fromEntries(
@@ -396,16 +186,12 @@ export const configureOrderPaymentsModule = ({
396
186
 
397
187
  updateStatus,
398
188
 
399
- updateCalculation: async (orderPayment, unchainedAPI) => {
400
- const calculation = await unchainedAPI.modules.payment.paymentProviders.calculate(
401
- {
402
- item: orderPayment,
403
- },
404
- unchainedAPI,
405
- );
406
-
189
+ updateCalculation: async <T extends PricingCalculation>(
190
+ orderPaymentId: string,
191
+ calculation: Array<T>,
192
+ ) => {
407
193
  return OrderPayments.findOneAndUpdate(
408
- buildFindByIdSelector(orderPayment._id),
194
+ buildFindOrderPaymentByIdSelector(orderPaymentId),
409
195
  {
410
196
  $set: {
411
197
  calculation,
@@ -417,5 +203,11 @@ export const configureOrderPaymentsModule = ({
417
203
  },
418
204
  );
419
205
  },
206
+ deleteOrderPayments: async (orderId: string) => {
207
+ const { deletedCount } = await OrderPayments.deleteMany({ orderId });
208
+ return deletedCount;
209
+ },
420
210
  };
421
211
  };
212
+
213
+ export type OrderPaymentsModule = ReturnType<typeof configureOrderPaymentsModule>;