@chevre/domain 25.2.0-alpha.5 → 25.2.0-alpha.51

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 (202) hide show
  1. package/lib/chevre/eventEmitter/task.d.ts +2 -1
  2. package/lib/chevre/factory/customerTelephone2COATelNum.d.ts +3 -0
  3. package/lib/chevre/factory/customerTelephone2COATelNum.js +22 -0
  4. package/lib/chevre/repo/action/acceptPay.d.ts +15 -0
  5. package/lib/chevre/repo/action/acceptPay.js +47 -19
  6. package/lib/chevre/repo/action/actionProcess.js +57 -57
  7. package/lib/chevre/repo/action.d.ts +16 -9
  8. package/lib/chevre/repo/action.js +99 -180
  9. package/lib/chevre/repo/aggregateOffer.d.ts +3 -14
  10. package/lib/chevre/repo/aggregateOffer.js +16 -125
  11. package/lib/chevre/repo/asyncAction.d.ts +69 -0
  12. package/lib/chevre/repo/asyncAction.js +237 -0
  13. package/lib/chevre/repo/concurrentLock.d.ts +3 -1
  14. package/lib/chevre/repo/creativeWork.d.ts +2 -3
  15. package/lib/chevre/repo/credentials.d.ts +2 -1
  16. package/lib/chevre/repo/customerType.d.ts +2 -3
  17. package/lib/chevre/repo/event.d.ts +10 -11
  18. package/lib/chevre/repo/eventOffer.d.ts +4 -5
  19. package/lib/chevre/repo/eventSellerMakesOffer.d.ts +2 -3
  20. package/lib/chevre/repo/eventSeries.d.ts +4 -5
  21. package/lib/chevre/repo/message.d.ts +1 -1
  22. package/lib/chevre/repo/message.js +1 -1
  23. package/lib/chevre/repo/mongoose/schemas/action.js +67 -66
  24. package/lib/chevre/repo/mongoose/schemas/asyncAction.d.ts +11 -0
  25. package/lib/chevre/repo/mongoose/schemas/asyncAction.js +89 -0
  26. package/lib/chevre/repo/mongoose/schemas/order.d.ts +4 -0
  27. package/lib/chevre/repo/mongoose/schemas/order.js +10 -0
  28. package/lib/chevre/repo/mongoose/schemas/setting.d.ts +4 -0
  29. package/lib/chevre/repo/mongoose/schemas/task.js +12 -12
  30. package/lib/chevre/repo/note.d.ts +3 -4
  31. package/lib/chevre/repo/noteAboutOrder.d.ts +2 -3
  32. package/lib/chevre/repo/offer/offerInCatalogReadOnly.d.ts +2 -2
  33. package/lib/chevre/repo/offer/unitPriceInCatalog.d.ts +2 -2
  34. package/lib/chevre/repo/offer/unitPriceInCatalog.js +59 -11
  35. package/lib/chevre/repo/offerCatalog.d.ts +2 -3
  36. package/lib/chevre/repo/offerCatalogItem.d.ts +2 -3
  37. package/lib/chevre/repo/order.d.ts +2 -0
  38. package/lib/chevre/repo/order.js +14 -14
  39. package/lib/chevre/repo/orderInTransaction.d.ts +68 -1
  40. package/lib/chevre/repo/orderInTransaction.js +181 -3
  41. package/lib/chevre/repo/passport.d.ts +2 -1
  42. package/lib/chevre/repo/person.d.ts +0 -15
  43. package/lib/chevre/repo/person.js +122 -108
  44. package/lib/chevre/repo/place/entranceGate.d.ts +4 -5
  45. package/lib/chevre/repo/place/movieTheater.d.ts +3 -4
  46. package/lib/chevre/repo/place/screeningRoom.d.ts +4 -5
  47. package/lib/chevre/repo/place/seat.d.ts +4 -5
  48. package/lib/chevre/repo/place/section.d.ts +3 -4
  49. package/lib/chevre/repo/priceSpecification.d.ts +4 -4
  50. package/lib/chevre/repo/product.d.ts +3 -4
  51. package/lib/chevre/repo/rateLimit/offer.d.ts +3 -1
  52. package/lib/chevre/repo/rateLimit/offer.js +0 -12
  53. package/lib/chevre/repo/reservation.d.ts +2 -3
  54. package/lib/chevre/repo/sellerMakesOffer.d.ts +3 -4
  55. package/lib/chevre/repo/stockHolder.d.ts +1 -1
  56. package/lib/chevre/repo/stockHolder.js +0 -146
  57. package/lib/chevre/repo/transaction/placeOrder.d.ts +2 -45
  58. package/lib/chevre/repo/transaction/placeOrder.js +43 -83
  59. package/lib/chevre/repo/transaction.d.ts +2 -2
  60. package/lib/chevre/repo/transactionNumberCounter.js +0 -34
  61. package/lib/chevre/repo/transactionProcess.d.ts +2 -1
  62. package/lib/chevre/repo/transactionProcess.js +0 -13
  63. package/lib/chevre/repository.d.ts +5 -0
  64. package/lib/chevre/repository.js +12 -1
  65. package/lib/chevre/service/assetTransaction/pay/publishPaymentUrl.js +1 -1
  66. package/lib/chevre/service/assetTransaction/pay/start/factory.d.ts +1 -1
  67. package/lib/chevre/service/assetTransaction/pay/start/factory.js +3 -4
  68. package/lib/chevre/service/assetTransaction/pay/start.d.ts +1 -1
  69. package/lib/chevre/service/asyncAction.d.ts +16 -0
  70. package/lib/chevre/service/asyncAction.js +36 -0
  71. package/lib/chevre/service/asyncActionHandler/onOperationFailed.d.ts +15 -0
  72. package/lib/chevre/service/asyncActionHandler/onOperationFailed.js +42 -0
  73. package/lib/chevre/service/asyncActionHandler.d.ts +13 -0
  74. package/lib/chevre/service/asyncActionHandler.js +89 -0
  75. package/lib/chevre/service/notification/factory.d.ts +2 -4
  76. package/lib/chevre/service/notification/factory.js +26 -24
  77. package/lib/chevre/service/notification/notifyAbortedTasksByEmail.d.ts +11 -5
  78. package/lib/chevre/service/notification/notifyAbortedTasksByEmail.js +11 -3
  79. package/lib/chevre/service/offer/event/authorize/factory.d.ts +3 -5
  80. package/lib/chevre/service/offer/event/authorize/factory.js +93 -75
  81. package/lib/chevre/service/offer/event/authorize.d.ts +0 -4
  82. package/lib/chevre/service/offer/event/authorize.js +2 -2
  83. package/lib/chevre/service/offer/eventServiceByCOA/authorize/factory.d.ts +6 -7
  84. package/lib/chevre/service/offer/eventServiceByCOA/authorize/factory.js +10 -10
  85. package/lib/chevre/service/offer/eventServiceByCOA/authorize/validateAcceptedOffers.js +2 -1
  86. package/lib/chevre/service/offer/eventServiceByCOA/authorize.d.ts +0 -5
  87. package/lib/chevre/service/offer/eventServiceByCOA/authorize.js +15 -12
  88. package/lib/chevre/service/offer/eventServiceByCOA/authorizeByAcceptAction.d.ts +0 -5
  89. package/lib/chevre/service/offer/eventServiceByCOA/authorizeByAcceptAction.js +2 -2
  90. package/lib/chevre/service/offer/eventServiceByCOA/findAcceptAction.d.ts +4 -0
  91. package/lib/chevre/service/offer/eventServiceByCOA/findAcceptAction.js +22 -9
  92. package/lib/chevre/service/order/deleteOrder.d.ts +5 -1
  93. package/lib/chevre/service/order/deleteOrder.js +8 -1
  94. package/lib/chevre/service/order/onAssetTransactionStatusChanged/onPayTransactionCanceled.js +19 -11
  95. package/lib/chevre/service/order/onAssetTransactionStatusChanged/onPayTransactionConfirmed.d.ts +2 -0
  96. package/lib/chevre/service/order/onAssetTransactionStatusChanged/paymentDue2Processing.d.ts +2 -2
  97. package/lib/chevre/service/order/onAssetTransactionStatusChanged/paymentDue2Processing.js +1 -7
  98. package/lib/chevre/service/order/onAssetTransactionStatusChanged.d.ts +2 -0
  99. package/lib/chevre/service/order/onAssetTransactionStatusChanged.js +2 -0
  100. package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing/createSendEmailMessageTaskIfNotExist.d.ts +5 -1
  101. package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing/createSendEmailMessageTaskIfNotExist.js +95 -33
  102. package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing.d.ts +2 -2
  103. package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing.js +4 -2
  104. package/lib/chevre/service/order/onOrderStatusChanged/onOrderReturned.js +2 -6
  105. package/lib/chevre/service/order/payOrder.d.ts +2 -0
  106. package/lib/chevre/service/order/placeOrder/createPlacingOrderFromExistingTransaction.d.ts +2 -1
  107. package/lib/chevre/service/order/placeOrder/createPlacingOrderFromExistingTransaction.js +13 -58
  108. package/lib/chevre/service/order/placeOrder/factory.js +3 -21
  109. package/lib/chevre/service/order/placeOrder.d.ts +4 -5
  110. package/lib/chevre/service/order/placeOrder.js +20 -31
  111. package/lib/chevre/service/payment/any/authorize/fixOrderAsNeeded.js +1 -2
  112. package/lib/chevre/service/payment/any/authorize/fixTransactionNumber.d.ts +3 -2
  113. package/lib/chevre/service/payment/any/authorize/handlePrePublishedPaymentMethodIdOnAuthorizing.d.ts +4 -3
  114. package/lib/chevre/service/payment/any/authorize/handlePrePublishedPaymentMethodIdOnAuthorizing.js +3 -31
  115. package/lib/chevre/service/payment/any/authorize.js +13 -37
  116. package/lib/chevre/service/payment/any/factory.d.ts +7 -7
  117. package/lib/chevre/service/payment/any/factory.js +19 -22
  118. package/lib/chevre/service/payment/any/findAcceptAction.d.ts +3 -1
  119. package/lib/chevre/service/payment/any/findAcceptAction.js +14 -6
  120. package/lib/chevre/service/payment/any/invalidatePaymentUrl.d.ts +2 -0
  121. package/lib/chevre/service/payment/any/invalidatePaymentUrl.js +4 -66
  122. package/lib/chevre/service/payment/any/publishPaymentUrl.d.ts +4 -0
  123. package/lib/chevre/service/payment/any/publishPaymentUrl.js +4 -18
  124. package/lib/chevre/service/payment/any/voidPayTransaction.d.ts +2 -0
  125. package/lib/chevre/service/payment/any/voidPayTransaction.js +1 -23
  126. package/lib/chevre/service/payment/creditCard/authorize/processAuthorizeCreditCard.d.ts +1 -1
  127. package/lib/chevre/service/payment/creditCard/authorize/processAuthorizeCreditCard.js +5 -9
  128. package/lib/chevre/service/reserve/adminFindReservations.d.ts +15 -0
  129. package/lib/chevre/service/reserve/adminFindReservations.js +35 -0
  130. package/lib/chevre/service/reserve/potentialActions/onReservationConfirmed.js +17 -8
  131. package/lib/chevre/service/reserve/searchByOrder.js +2 -6
  132. package/lib/chevre/service/reserve.d.ts +2 -2
  133. package/lib/chevre/service/reserve.js +3 -3
  134. package/lib/chevre/service/task/aggregateOffers.d.ts +2 -2
  135. package/lib/chevre/service/task/aggregateOffers.js +2 -1
  136. package/lib/chevre/service/task/aggregateScreeningEvent.d.ts +2 -2
  137. package/lib/chevre/service/task/aggregateScreeningEvent.js +2 -1
  138. package/lib/chevre/service/task/authorizePayment.js +3 -1
  139. package/lib/chevre/service/task/cancelReservation.d.ts +2 -2
  140. package/lib/chevre/service/task/cancelReservation.js +2 -1
  141. package/lib/chevre/service/task/confirmPayTransaction.js +0 -1
  142. package/lib/chevre/service/task/confirmReserveTransaction.js +2 -7
  143. package/lib/chevre/service/task/deleteTransaction.d.ts +2 -2
  144. package/lib/chevre/service/task/deleteTransaction.js +2 -1
  145. package/lib/chevre/service/task/onAssetTransactionStatusChanged.d.ts +2 -2
  146. package/lib/chevre/service/task/onAssetTransactionStatusChanged.js +4 -3
  147. package/lib/chevre/service/task/onEventChanged.d.ts +2 -2
  148. package/lib/chevre/service/task/onEventChanged.js +2 -1
  149. package/lib/chevre/service/task/onOrderPaymentCompleted.d.ts +2 -2
  150. package/lib/chevre/service/task/onOrderPaymentCompleted.js +4 -1
  151. package/lib/chevre/service/task/onResourceUpdated/onAggregateOfferUpdated.js +1 -1
  152. package/lib/chevre/service/task/onResourceUpdated.d.ts +2 -2
  153. package/lib/chevre/service/task/onResourceUpdated.js +2 -1
  154. package/lib/chevre/service/task/placeOrder.d.ts +2 -2
  155. package/lib/chevre/service/task/placeOrder.js +6 -3
  156. package/lib/chevre/service/task/publishPaymentUrl.js +7 -3
  157. package/lib/chevre/service/task/refund.d.ts +2 -2
  158. package/lib/chevre/service/task/refund.js +4 -10
  159. package/lib/chevre/service/task/reserve.d.ts +2 -2
  160. package/lib/chevre/service/task/reserve.js +2 -1
  161. package/lib/chevre/service/task/returnOrder.d.ts +2 -2
  162. package/lib/chevre/service/task/returnOrder.js +2 -1
  163. package/lib/chevre/service/task/sendOrder.d.ts +2 -2
  164. package/lib/chevre/service/task/sendOrder.js +2 -1
  165. package/lib/chevre/service/task/voidPayTransaction.js +3 -7
  166. package/lib/chevre/service/task/voidPayment.d.ts +2 -2
  167. package/lib/chevre/service/task/voidPayment.js +2 -1
  168. package/lib/chevre/service/taskHandler/onOperationFailed.js +1 -1
  169. package/lib/chevre/service/taskHandler.d.ts +2 -2
  170. package/lib/chevre/service/taskHandler.js +36 -37
  171. package/lib/chevre/service/transaction/deleteTransaction/deletePayTransactionsByPlaceOrder.d.ts +15 -0
  172. package/lib/chevre/service/transaction/deleteTransaction/deletePayTransactionsByPlaceOrder.js +51 -0
  173. package/lib/chevre/service/transaction/deleteTransaction/deleteReservationsByPlaceOrder.d.ts +23 -0
  174. package/lib/chevre/service/transaction/deleteTransaction/deleteReservationsByPlaceOrder.js +64 -0
  175. package/lib/chevre/service/transaction/deleteTransaction.js +15 -152
  176. package/lib/chevre/service/transaction/placeOrder/confirm/potentialActions/sendEmailMessage.d.ts +28 -2
  177. package/lib/chevre/service/transaction/placeOrder/confirm/potentialActions/sendEmailMessage.js +11 -12
  178. package/lib/chevre/service/transaction/placeOrder/confirm/potentialActions.d.ts +4 -2
  179. package/lib/chevre/service/transaction/placeOrder/confirm/potentialActions.js +6 -7
  180. package/lib/chevre/service/transaction/placeOrder/confirm/prepareUnitPriceOfferConditions.d.ts +35 -2
  181. package/lib/chevre/service/transaction/placeOrder/confirm/prepareUnitPriceOfferConditions.js +15 -11
  182. package/lib/chevre/service/transaction/placeOrder/confirm/validation/factory.d.ts +5 -1
  183. package/lib/chevre/service/transaction/placeOrder/confirm/validation.d.ts +11 -2
  184. package/lib/chevre/service/transaction/placeOrder/confirm/validation.js +53 -32
  185. package/lib/chevre/service/transaction/placeOrder/confirm.d.ts +6 -5
  186. package/lib/chevre/service/transaction/placeOrder/confirm.js +33 -78
  187. package/lib/chevre/service/transaction/placeOrder/publishConfirmationNumberIfNotExist.d.ts +4 -7
  188. package/lib/chevre/service/transaction/placeOrder/publishConfirmationNumberIfNotExist.js +33 -15
  189. package/lib/chevre/service/transaction/placeOrder/start.d.ts +1 -1
  190. package/lib/chevre/service/transaction/placeOrder/updateAgent/fixCustomer.d.ts +20 -0
  191. package/lib/chevre/service/transaction/placeOrder/updateAgent/fixCustomer.js +63 -0
  192. package/lib/chevre/service/transaction/placeOrder/updateAgent.d.ts +0 -1
  193. package/lib/chevre/service/transaction/placeOrder/updateAgent.js +17 -86
  194. package/lib/chevre/service/transaction/returnOrder/preStart.js +1 -1
  195. package/lib/chevre/service.d.ts +4 -0
  196. package/lib/chevre/service.js +12 -1
  197. package/lib/chevre/taskSettings.d.ts +1 -3
  198. package/package.json +8 -11
  199. package/lib/chevre/service/order/findConfirmedPlaceOrder.d.ts +0 -13
  200. package/lib/chevre/service/order/findConfirmedPlaceOrder.js +0 -32
  201. package/lib/chevre/service/reserve/findReservations.d.ts +0 -33
  202. package/lib/chevre/service/reserve/findReservations.js +0 -61
@@ -17,14 +17,12 @@ const factory_1 = require("../../../../factory");
17
17
  const validateInvoiceReferencesOrder_1 = require("./validation/validateInvoiceReferencesOrder");
18
18
  const validateMovieTicket_1 = require("./validation/validateMovieTicket");
19
19
  const validatePrice_1 = require("./validation/validatePrice");
20
- const debug = (0, debug_1.default)('chevre-domain:service:transaction');
20
+ const debug = (0, debug_1.default)('chevre-domain:service:transaction:placeOrder:confirm:validation');
21
21
  /**
22
22
  * 取引が確定可能な状態かどうかをチェックする
23
23
  */
24
- function validateTransaction(transaction, acceptPayActions, authorizePaymentActions, authorizeEventServiceOfferActions,
25
- // authorizeProductOfferActions: Pick<IAuthorizeProductOffer, 'id' | 'result'>[],
26
- eventReservationAcceptedOffers, payTransactions, customer) {
27
- // validateProfile(transaction);
24
+ function validateTransaction(transaction, acceptPayActions, authorizePaymentActions, authorizeEventServiceOfferActions, eventReservationAcceptedOffers, payTransactions, customer, options) {
25
+ const { paymentMethodIdByTransaction } = options;
28
26
  validateProfile({ customer });
29
27
  (0, validatePrice_1.validatePrice)(authorizePaymentActions, authorizeEventServiceOfferActions);
30
28
  // 請求のreferencesOrder検証(2025-11-23~)
@@ -33,7 +31,6 @@ eventReservationAcceptedOffers, payTransactions, customer) {
33
31
  // validateMonetaryAmount(authorizePaymentActions, authorizeEventServiceOfferActions); // discontinue(2026-07-06~)
34
32
  // 利用可能なMovieTicketIF決済方法タイプに対して動的にコーディング
35
33
  const movieTicketPaymentMethodTypes = findMovieTicketPaymentMethodTypesFromTransaction(authorizePaymentActions, eventReservationAcceptedOffers);
36
- debug('processing validateMovieTicket... movieTicketPaymentMethodTypes:', movieTicketPaymentMethodTypes);
37
34
  if (Array.isArray(movieTicketPaymentMethodTypes) && movieTicketPaymentMethodTypes.length > 0) {
38
35
  movieTicketPaymentMethodTypes.forEach((paymentMethodType) => {
39
36
  const authorizeMovieTicketActions = authorizePaymentActions.filter((a) => {
@@ -59,13 +56,12 @@ eventReservationAcceptedOffers, payTransactions, customer) {
59
56
  authorizedMovieTickets.push(...object.paymentMethod.movieTickets);
60
57
  }
61
58
  });
62
- debug(authorizedMovieTickets.length, 'movie tickets authorized', 'transaction:', transaction.id);
63
59
  // validateMovieTicket(paymentMethodType, { id: transaction.id }, authorizePaymentActions, eventReservationAcceptedOffers);
64
60
  (0, validateMovieTicket_1.validateMovieTicket)(paymentMethodType, { id: transaction.id }, authorizedMovieTickets, eventReservationAcceptedOffers);
65
61
  });
66
62
  }
67
63
  // 決済URLが発行されている場合、検証
68
- validatePaymentUrl(transaction, acceptPayActions, authorizePaymentActions);
64
+ validatePaymentUrl({ paymentMethodIdByTransaction, acceptPayActions, authorizePaymentActions });
69
65
  }
70
66
  function findMovieTicketPaymentMethodTypesFromTransaction(authorizePaymentActions, eventReservationAcceptedOffers) {
71
67
  const paymentMethodTypes = [];
@@ -95,18 +91,6 @@ function findMovieTicketPaymentMethodTypesFromTransaction(authorizePaymentAction
95
91
  // ];
96
92
  return [...new Set(paymentMethodTypes)];
97
93
  }
98
- // function validateProfile(transaction: Pick<factory.transaction.placeOrder.ITransaction, 'object'>) {
99
- // // object.customerで検証(2022-05-26~)
100
- // const profile = transaction.object.customer;
101
- // const profileSatisfied = typeof profile?.typeOf === 'string' && profile.typeOf.length > 0
102
- // && typeof profile.email === 'string' && profile.email.length > 0
103
- // && typeof profile.familyName === 'string' && profile.familyName.length > 0
104
- // && typeof profile.givenName === 'string' && profile.givenName.length > 0
105
- // && typeof profile.telephone === 'string' && profile.telephone.length > 0;
106
- // if (!profileSatisfied) {
107
- // throw new factory.errors.Argument('Transaction', 'Customer Profile Required');
108
- // }
109
- // }
110
94
  function validateProfile(params) {
111
95
  const profile = params.customer;
112
96
  const profileSatisfied = typeof profile?.typeOf === 'string' && profile.typeOf.length > 0
@@ -122,16 +106,19 @@ function validateProfile(params) {
122
106
  throw new factory_1.factory.errors.Argument('Transaction', 'customer name required');
123
107
  }
124
108
  }
125
- function validatePaymentUrl(transaction, acceptPayActions, authorizePaymentActions) {
109
+ function validatePaymentUrl(params) {
110
+ const { paymentMethodIdByTransaction, acceptPayActions, authorizePaymentActions } = params;
126
111
  // 決済URLが発行されている場合、検証
127
- const paymentMethodId = transaction.object.paymentMethods?.paymentMethodId;
112
+ const paymentMethodId = paymentMethodIdByTransaction;
113
+ debug('validatePaymentUrl: paymentMethodIdByTransaction:', paymentMethodIdByTransaction);
128
114
  if (typeof paymentMethodId === 'string' && paymentMethodId.length > 0) {
129
115
  // check existing accept action(2025-02-26~)
130
116
  const acceptActionExists = acceptPayActions.some(({ object, result }) => {
131
117
  return object.transactionNumber === paymentMethodId
132
- && result?.paymentMethodId === paymentMethodId
133
- && typeof result?.paymentUrl === 'string';
118
+ && result?.paymentMethodId === paymentMethodId;
119
+ // && typeof result?.paymentUrl === 'string'; // result.paymentUrlは廃止(2026-07-14~)
134
120
  });
121
+ debug('validatePaymentUrl: acceptActionExists:', acceptActionExists);
135
122
  if (!acceptActionExists) {
136
123
  throw new factory_1.factory.errors.NotFound(factory_1.factory.actionType.AcceptAction);
137
124
  }
@@ -143,6 +130,7 @@ function validatePaymentUrl(transaction, acceptPayActions, authorizePaymentActio
143
130
  : undefined;
144
131
  return resultAsInvoice?.paymentMethodId === paymentMethodId;
145
132
  });
133
+ debug('validatePaymentUrl: authorizePaymentAction4paymentUrlExists:', authorizePaymentAction4paymentUrlExists);
146
134
  if (!authorizePaymentAction4paymentUrlExists) {
147
135
  throw new factory_1.factory.errors.Argument('Transaction', 'Payment for published payment URL required');
148
136
  }
@@ -257,7 +245,6 @@ function validateAcceptedOffers(params) {
257
245
  });
258
246
  if (ticketIdentifiers.length > 0) {
259
247
  ticketIdentifiers = [...new Set(ticketIdentifiers)];
260
- debug('ticketIdentifiers unique?', ticketIdentifiers.join(' '), 'numAcceptedOffers:', numAcceptedOffers);
261
248
  // チケット識別子が注文内ユニークなので、注文オファー数に一致するはず
262
249
  if (ticketIdentifiers.length !== numAcceptedOffers) {
263
250
  throw new factory_1.factory.errors.Argument('Transaction', 'ticketIdentifiers must be unique');
@@ -274,7 +261,6 @@ function validateAcceptedOffers(params) {
274
261
  });
275
262
  if (ticketNumbers.length > 0) {
276
263
  ticketNumbers = [...new Set(ticketNumbers)];
277
- debug('ticketNumbers unique?', ticketNumbers.join(' '), 'numAcceptedOffers:', numAcceptedOffers);
278
264
  // チケット識別子が注文内ユニークなので、注文オファー数に一致するはず
279
265
  if (ticketNumbers.length !== numAcceptedOffers) {
280
266
  throw new factory_1.factory.errors.Argument('Transaction', 'ticketNumbers must be unique');
@@ -313,6 +299,44 @@ function validatePaymentMethods(params, options) {
313
299
  * 興行オファー適用条件確認
314
300
  */
315
301
  function validateEventOffers(params) {
302
+ const { unitPriceOfferConditions } = params;
303
+ /**
304
+ * 以下処理で検証に使用するアクション結果リスト
305
+ */
306
+ let validatingAuthorizeOfferActions;
307
+ // 承認アクションと比較する
308
+ if (Array.isArray(unitPriceOfferConditions)) {
309
+ const everyActionsMatched = unitPriceOfferConditions.length === params.authorizeOfferActions.length
310
+ && params.authorizeOfferActions.every((authorizeEventServiceOfferAction) => {
311
+ const conditionExpected = unitPriceOfferConditions.find(({ id }) => id === authorizeEventServiceOfferAction.id);
312
+ let resultMatched;
313
+ // 承認アクションのresultが最適化済の場合,price以外を比較しても意味がないので比較しない(2026-07-10~)
314
+ if (authorizeEventServiceOfferAction.result?.onlyPrice === true) {
315
+ resultMatched = typeof conditionExpected?.result?.price === 'number'
316
+ && conditionExpected?.result.price === authorizeEventServiceOfferAction.result.price;
317
+ }
318
+ else {
319
+ resultMatched = (0, util_1.isDeepStrictEqual)(conditionExpected?.result, authorizeEventServiceOfferAction.result);
320
+ }
321
+ debug('validateEventOffers: unitPriceOfferConditions: resultMatched?', resultMatched, params.project.id, authorizeEventServiceOfferAction.id);
322
+ if (!resultMatched) {
323
+ console.error('validateEventOffers: unitPriceOfferConditions not matched!', params.project.id, authorizeEventServiceOfferAction.id, conditionExpected?.result, authorizeEventServiceOfferAction.result);
324
+ }
325
+ return resultMatched;
326
+ });
327
+ // 全アクションについて結果が一致していればunitPriceOfferConditionsを採用する(2026-07-07~)
328
+ if (everyActionsMatched) {
329
+ validatingAuthorizeOfferActions = [...unitPriceOfferConditions];
330
+ }
331
+ else {
332
+ validatingAuthorizeOfferActions = [...params.authorizeOfferActions];
333
+ }
334
+ }
335
+ else {
336
+ // unitPriceOfferConditionsの準備は必須化(2026-07-13~)
337
+ throw new factory_1.factory.errors.NotImplemented('unitPriceOfferConditions must be an array');
338
+ // validatingAuthorizeOfferActions = [...params.authorizeOfferActions];
339
+ }
316
340
  const { paymentMethods } = params;
317
341
  const firstCreditCardPaymentMethodIdentifier = paymentMethods.find((referenceInvoice) => {
318
342
  return referenceInvoice.issuedThrough.typeOf === factory_1.factory.service.paymentService.PaymentServiceType.CreditCard
@@ -322,7 +346,7 @@ function validateEventOffers(params) {
322
346
  return referenceInvoice.issuedThrough.typeOf === factory_1.factory.service.paymentService.PaymentServiceType.CreditCard
323
347
  || referenceInvoice.issuedThrough.typeOf === factory_1.factory.service.paymentService.PaymentServiceType.FaceToFace;
324
348
  }).length;
325
- params.authorizeEventServiceOfferActions.forEach((a) => {
349
+ validatingAuthorizeOfferActions.forEach((a) => {
326
350
  // support result.offers(2024-06-18~)
327
351
  const acceptedOffersInResult = a.result?.offers;
328
352
  if (Array.isArray(acceptedOffersInResult) && acceptedOffersInResult.length > 0) {
@@ -348,20 +372,18 @@ function validateEventOffers(params) {
348
372
  // }
349
373
  // 適用数量検証(全興行オファー承認アクションについて)(2023-11-15~)
350
374
  // 適用数量要件を満たしていなければエラー
351
- const numAcceptedOffersByOfferId = params.authorizeEventServiceOfferActions.reduce((previousNumOffer, { result }) => {
375
+ const numAcceptedOffersByOfferId = validatingAuthorizeOfferActions.reduce((previousNumOffer, { result }) => {
352
376
  const numOfferOnCurrentAction = result?.offers?.find(({ id }) => id === offerId)?.includesObject.amountOfThisGood;
353
377
  return previousNumOffer + ((typeof numOfferOnCurrentAction === 'number') ? numOfferOnCurrentAction : 0);
354
378
  }, 0);
355
379
  const eligibleQuantityMaxValue = unitPriceSpec?.eligibleQuantity?.maxValue;
356
380
  if (typeof eligibleQuantityMaxValue === 'number') {
357
- debug('validateEventOffers: numAcceptedOffersByOfferId > eligibleQuantityMaxValue?', numAcceptedOffersByOfferId, eligibleQuantityMaxValue);
358
381
  if (numAcceptedOffersByOfferId > eligibleQuantityMaxValue) {
359
382
  throw new factory_1.factory.errors.Argument('Transaction', `Number of offer:${offerId} must be less than or equal to ${eligibleQuantityMaxValue}`);
360
383
  }
361
384
  }
362
385
  const eligibleQuantityMinValue = unitPriceSpec?.eligibleQuantity?.minValue;
363
386
  if (typeof eligibleQuantityMinValue === 'number') {
364
- debug('validateEventOffers: numAcceptedOffersByOfferId < eligibleQuantityMinValue?', numAcceptedOffersByOfferId, eligibleQuantityMinValue);
365
387
  if (numAcceptedOffersByOfferId < eligibleQuantityMinValue) {
366
388
  throw new factory_1.factory.errors.Argument('Transaction', `Number of offer:${offerId} must be more than or equal to ${eligibleQuantityMinValue}`);
367
389
  }
@@ -372,7 +394,6 @@ function validateEventOffers(params) {
372
394
  const satisfyAcceptedPaymentMethod = numCreditCardOrFaceToFacePaymentMethod === 1
373
395
  && typeof firstCreditCardPaymentMethodIdentifier === 'string'
374
396
  && acceptedPaymentMethodTypes.includes(firstCreditCardPaymentMethodIdentifier);
375
- debug('validateEventOffers: satisfyAcceptedPaymentMethod?', JSON.stringify(acceptedPaymentMethodTypes));
376
397
  if (!satisfyAcceptedPaymentMethod) {
377
398
  throw new factory_1.factory.errors.Argument('Transaction', `acceptedPaymentMethod requirement not satisfied`);
378
399
  }
@@ -381,7 +402,7 @@ function validateEventOffers(params) {
381
402
  }
382
403
  });
383
404
  // check programMembershipUsed(2024-08-15~)
384
- const programMembershipRequired = params.authorizeEventServiceOfferActions.reduce((a, b) => {
405
+ const programMembershipRequired = validatingAuthorizeOfferActions.reduce((a, b) => {
385
406
  const programMembershipUsedfromResult = b.result?.itemOffered?.serviceOutput.programMembershipUsed;
386
407
  if (Array.isArray(programMembershipUsedfromResult)) {
387
408
  a.push(...programMembershipUsedfromResult);
@@ -13,6 +13,7 @@ import type { PlaceOrderRepo } from '../../../repo/transaction/placeOrder';
13
13
  import { factory } from '../../../factory';
14
14
  import { PlaceOrderFactory } from '../../../factory/transaction';
15
15
  import { IOrderAsResult } from './confirm/factory/result';
16
+ import { IPotentialActionsParams } from './confirm/potentialActions';
16
17
  interface IConfirmOperationRepos {
17
18
  acceptPayAction: AcceptPayActionRepo;
18
19
  authorizePaymentMethodAction: AuthorizePaymentMethodActionRepo;
@@ -41,13 +42,13 @@ interface IConfirmOptions {
41
42
  * 注文における最大CreditCardIF決済方法数
42
43
  */
43
44
  maxNumCreditCardPaymentMethod: number;
45
+ }
46
+ type IConfirmParams = PlaceOrderFactory.IConfirmParams & {
44
47
  /**
45
- * 2026-07-06~
46
- * 実験的に
48
+ * 取引確定後アクション
47
49
  */
48
- usePrepareUnitPriceOfferConditions?: boolean;
49
- }
50
- type IConfirmParams = PlaceOrderFactory.IConfirmParams;
50
+ potentialActions?: IPotentialActionsParams;
51
+ };
51
52
  interface IConfirmResult {
52
53
  order: Pick<IOrderAsResult, 'confirmationNumber' | 'orderNumber'>;
53
54
  customer: factory.order.ICustomer;
@@ -58,9 +58,9 @@ function processTransactionNotInProgress(params) {
58
58
  function confirm(params, options) {
59
59
  return async (repos) => {
60
60
  // 確認番号を事前発行
61
- await (0, publishConfirmationNumberIfNotExist_1.publishConfirmationNumberIfNotExist)({
61
+ const confirmationNumber = await (0, publishConfirmationNumberIfNotExist_1.publishConfirmationNumberIfNotExist)({
62
62
  id: params.id,
63
- status: { $in: [factory_1.factory.transactionStatusType.Confirmed, factory_1.factory.transactionStatusType.InProgress] },
63
+ // status: { $in: [factory.transactionStatusType.Confirmed, factory.transactionStatusType.InProgress] },
64
64
  object: { orderDate: params.result.order.orderDate }
65
65
  })(repos);
66
66
  const transaction = await repos.placeOrder.findPlaceOrderById({ typeOf: factory_1.factory.transactionType.PlaceOrder, id: params.id }, ['typeOf', 'project', 'status', 'agent', 'seller', 'object', 'result']);
@@ -82,10 +82,12 @@ function confirm(params, options) {
82
82
  // if (typeof orderNumber !== 'string' || orderNumber === '') {
83
83
  // throw new factory.errors.Argument('transactionId', 'orderNumber not issued');
84
84
  // }
85
+ // 注文に決済方法IDが発行済か確認(2026-07-12)
86
+ const paymentMethodIdByTransaction = await repos.orderInTransaction.findPaymentMethodId({ id: params.id });
85
87
  // 取引に対する全ての承認アクションをマージ
86
88
  const completedAuthorizeActions = await searchAuthorizeActions(params)(repos);
87
89
  let acceptPayActions = [];
88
- if (typeof transaction.object.paymentMethods?.paymentMethodId === 'string') {
90
+ if (typeof paymentMethodIdByTransaction === 'string') {
89
91
  acceptPayActions = await searchAcceptPayActions(params)(repos);
90
92
  }
91
93
  // 必要あらば注文コード発行(2024-02-05~)
@@ -110,20 +112,16 @@ function confirm(params, options) {
110
112
  serialNumbers } = dissolveAuthorizeActions(completedAuthorizeActions);
111
113
  // orderInTransactionから検索する(2024-03-04~)
112
114
  const acceptedOffers = (await repos.orderInTransaction.findAcceptedOffersWithPriceByIdentifier({
113
- // orderNumber,
114
115
  identifier: transaction.id,
115
116
  project: { id: transaction.project.id }
116
- }))
117
+ }, { onlyPlaceOrder: true }))
117
118
  .filter(({ serialNumber }) => typeof serialNumber === 'string' && serialNumbers.includes(serialNumber));
118
119
  // 単価オファーの全適用条件を検証するために、単価オファーを参照(2026-07-06~)
119
- const { usePrepareUnitPriceOfferConditions } = options;
120
- if (usePrepareUnitPriceOfferConditions === true) {
121
- await (0, prepareUnitPriceOfferConditions_1.prepareUnitPriceOfferConditions)({
122
- project: { id: transaction.project.id, },
123
- acceptedOffers,
124
- authorizeEventServiceOfferActions
125
- })({ offer: repos.offer });
126
- }
120
+ const unitPriceOfferConditions = await (0, prepareUnitPriceOfferConditions_1.prepareUnitPriceOfferConditions)({
121
+ project: { id: transaction.project.id, },
122
+ acceptedOffers,
123
+ authorizeEventServiceOfferActions
124
+ })({ offer: repos.offer });
127
125
  // authorizePaymentActionsからpayTransactionsを参照(2024-06-20~)
128
126
  let payTransactions = [];
129
127
  // 決済承認アクションのinstrument依存をobject依存へ変更(2025-12-14~)
@@ -141,42 +139,28 @@ function confirm(params, options) {
141
139
  const seller = (0, factory_2.createSeller)({ transaction });
142
140
  const { paymentMethods, placingOrder, result, eventId, reservationIds } = createResult({
143
141
  ...params,
144
- orderNumber, transaction,
142
+ orderNumber,
143
+ confirmationNumber,
144
+ transaction,
145
145
  acceptPayActions,
146
146
  authorizePaymentActions, authorizeEventServiceOfferActions,
147
- // authorizeProductOfferActions,
148
147
  acceptedOffers, payTransactions, customer,
149
- ...(typeof code === 'string') ? { code } : undefined
148
+ unitPriceOfferConditions,
149
+ ...(typeof code === 'string') ? { code } : undefined,
150
+ paymentMethodIdByTransaction
150
151
  }, options);
151
- // discontinue emailMessageRepo
152
- // // デフォルトEメールメッセージを検索
153
- // let emailMessageOnOrderSent: factory.creativeWork.message.email.ICreativeWork | undefined;
154
- // if (repos.emailMessage !== undefined) {
155
- // const searchEmailMessagesResult = await repos.emailMessage.search({
156
- // limit: 1,
157
- // page: 1,
158
- // project: { id: { $eq: transaction.project.id } },
159
- // about: { identifier: { $eq: factory.creativeWork.message.email.AboutIdentifier.OnOrderSent } }
160
- // });
161
- // emailMessageOnOrderSent = searchEmailMessagesResult.shift();
162
- // }
163
152
  // ポストアクションを作成
164
153
  const setting = await repos.setting.findOne({ project: { id: { $eq: '*' } } }, ['defaultSenderEmail']);
165
154
  if (typeof setting?.defaultSenderEmail !== 'string') {
166
155
  throw new factory_1.factory.errors.NotFound('setting.defaultSenderEmail');
167
156
  }
168
- const { emailMessages, potentialActions } = await (0, potentialActions_1.createPotentialActions)({
157
+ const { emailMessages } = await (0, potentialActions_1.createPotentialActions)({
169
158
  order: placingOrder, // createEmailMessageでのorder.acceptedOffersへの依存性を排除したのでこちらでよいはず(2024-02-21~)
170
159
  customer,
171
160
  seller,
172
161
  paymentMethods,
173
- // order: orderWithAcceptedOffers, // 現時点でcreateEmailMessageでorder.acceptedOffersを使用している(2024-02-06~)
174
- // transaction: transaction,
175
162
  ...(params.potentialActions !== undefined) ? { potentialActions: params.potentialActions } : undefined,
176
- // ...(emailMessageOnOrderSent !== undefined) ? { emailMessage: emailMessageOnOrderSent } : undefined
177
- },
178
- // settings
179
- setting);
163
+ }, setting);
180
164
  // メッセージ保管(2024-04-28~)
181
165
  await saveMessagesIfNeeded({
182
166
  project: { id: transaction.project.id },
@@ -189,10 +173,11 @@ function confirm(params, options) {
189
173
  id: transaction.id,
190
174
  object: {
191
175
  orderDate: params.result.order.orderDate,
192
- orderNumber
176
+ orderNumber,
177
+ confirmationNumber: placingOrder.confirmationNumber
193
178
  },
194
179
  result: result,
195
- potentialActions: potentialActions
180
+ // ...((options.useTransactionPotentialActions) && { potentialActions }) // support undefined(2026-07-17~)
196
181
  });
197
182
  }
198
183
  catch (error) {
@@ -329,17 +314,20 @@ function createResult(params, options) {
329
314
  }
330
315
  });
331
316
  // 取引の確定条件が全て整っているかどうか確認
332
- (0, validation_1.validateTransaction)(transaction, params.acceptPayActions, params.authorizePaymentActions, params.authorizeEventServiceOfferActions,
333
- // params.authorizeProductOfferActions,
334
- eventReservationAcceptedOffers, params.payTransactions, params.customer);
317
+ const { paymentMethodIdByTransaction } = params;
318
+ (0, validation_1.validateTransaction)({ id: transaction.id }, params.acceptPayActions, params.authorizePaymentActions, params.authorizeEventServiceOfferActions, eventReservationAcceptedOffers, params.payTransactions, params.customer, {
319
+ ...((typeof paymentMethodIdByTransaction === 'string') && { paymentMethodIdByTransaction })
320
+ });
335
321
  const { paymentMethods, price } = (0, factory_2.createPaymentMethods)({ authorizePaymentActions: params.authorizePaymentActions });
336
322
  const orderedItem = (0, orderedItem_1.acceptedOffers2orderedItem)({
337
323
  eventReservationAcceptedOffers
338
324
  });
339
325
  (0, validation_1.validateEventOffers)({
326
+ project: { id: transaction.project.id },
340
327
  order: { price },
341
328
  paymentMethods,
342
- authorizeEventServiceOfferActions: params.authorizeEventServiceOfferActions
329
+ authorizeOfferActions: params.authorizeEventServiceOfferActions,
330
+ unitPriceOfferConditions: params.unitPriceOfferConditions
343
331
  });
344
332
  // 注文オファー検証
345
333
  (0, validation_1.validateAcceptedOffers)({
@@ -352,8 +340,10 @@ function createResult(params, options) {
352
340
  result: params.result
353
341
  });
354
342
  (0, validation_1.validatePaymentMethods)({ order: { paymentMethods } }, options);
355
- // 確認番号を発行
356
- const { confirmationNumber } = createConfirmationNumber({ transaction });
343
+ // 取引のobjectへの依存を排除する(2026-07-08~)
344
+ const { confirmationNumber } = params;
345
+ // // 確認番号を発行
346
+ // const { confirmationNumber } = createConfirmationNumber({ transaction });
357
347
  // 注文作成
358
348
  const orderAsResult = (0, result_1.createOrderAsResult)({
359
349
  orderNumber: params.orderNumber,
@@ -400,21 +390,6 @@ function createResult(params, options) {
400
390
  }
401
391
  function searchAcceptPayActions(params) {
402
392
  return async (repos) => {
403
- // let acceptPayActions = <IAcceptPayAction[]>await repos.action.search(
404
- // {
405
- // project: { id: { $eq: params.project.id } },
406
- // typeOf: { $eq: factory.actionType.AcceptAction },
407
- // actionStatus: { $in: [factory.actionStatusType.CompletedActionStatus] },
408
- // purpose: {
409
- // id: { $in: [params.id] },
410
- // typeOf: { $in: [factory.transactionType.PlaceOrder] }
411
- // },
412
- // object: {
413
- // typeOf: { $eq: factory.assetTransactionType.Pay }
414
- // }
415
- // },
416
- // ['object', 'endDate', 'result']
417
- // );
418
393
  let acceptPayActions = await repos.acceptPayAction.findAcceptActionsByPurpose({
419
394
  project: { id: params.project.id },
420
395
  actionStatus: factory_1.factory.actionStatusType.CompletedActionStatus,
@@ -433,15 +408,6 @@ function searchAcceptPayActions(params) {
433
408
  function searchAuthorizeActions(params) {
434
409
  return async (repos) => {
435
410
  // 取引に対する全ての承認アクションをマージ
436
- // let authorizeActions = <IAuthorizeOfferOrPaymentAction[]>await repos.action.searchByPurpose({
437
- // typeOf: factory.actionType.AuthorizeAction,
438
- // purpose: {
439
- // typeOf: factory.transactionType.PlaceOrder,
440
- // id: params.id
441
- // },
442
- // // Completedに絞る(2023-05-16~)
443
- // actionStatus: { $eq: factory.actionStatusType.CompletedActionStatus }
444
- // });
445
411
  let authorizeActions = [
446
412
  ...await repos.authorizePaymentMethodAction.findAuthorizePaymentMethodActionsByPurpose({
447
413
  purpose: {
@@ -468,14 +434,3 @@ function searchAuthorizeActions(params) {
468
434
  return authorizeActions;
469
435
  };
470
436
  }
471
- function createConfirmationNumber(params) {
472
- const confirmationNumber = params.transaction.object.confirmationNumber;
473
- // 取引に確認番号が保管されていなければ、確認番号を発行
474
- if (typeof confirmationNumber !== 'string') {
475
- // 事前に発行済なはずなので、ありえないフロー
476
- throw new factory_1.factory.errors.Internal('object.confirmationNumber undefined');
477
- }
478
- return {
479
- confirmationNumber,
480
- };
481
- }
@@ -1,22 +1,19 @@
1
1
  import type { ConfirmationNumberRepo } from '../../../repo/confirmationNumber';
2
- import type { PlaceOrderRepo } from '../../../repo/transaction/placeOrder';
3
- import { factory } from '../../../factory';
2
+ import type { OrderInTransactionRepo } from '../../../repo/orderInTransaction';
4
3
  /**
5
- * 未発行であれば、注文の確認番号を発行して取引に保管する
4
+ * 未発行であれば、確認番号を発行して注文ドキュメントに保管する
5
+ * reimplement using OrderInTransactionRepo(2026-07-09~)
6
6
  */
7
7
  declare function publishConfirmationNumberIfNotExist(params: {
8
8
  /**
9
9
  * 取引ID
10
10
  */
11
11
  id: string;
12
- status: {
13
- $in: factory.transactionStatusType[];
14
- };
15
12
  object: {
16
13
  orderDate: Date;
17
14
  };
18
15
  }): (repos: {
19
- placeOrder: PlaceOrderRepo;
20
16
  confirmationNumber: ConfirmationNumberRepo;
17
+ orderInTransaction: OrderInTransactionRepo;
21
18
  }) => Promise<string>;
22
19
  export { publishConfirmationNumberIfNotExist };
@@ -1,36 +1,54 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.publishConfirmationNumberIfNotExist = publishConfirmationNumberIfNotExist;
7
+ const debug_1 = __importDefault(require("debug"));
8
+ // import type { PlaceOrderRepo } from '../../../repo/transaction/placeOrder';
4
9
  const factory_1 = require("../../../factory");
10
+ const debug = (0, debug_1.default)('chevre-domain:service:transaction:placeOrder:publishConfirmationNumberIfNotExist');
5
11
  /**
6
- * 未発行であれば、注文の確認番号を発行して取引に保管する
12
+ * 未発行であれば、確認番号を発行して注文ドキュメントに保管する
13
+ * reimplement using OrderInTransactionRepo(2026-07-09~)
7
14
  */
8
15
  function publishConfirmationNumberIfNotExist(params) {
9
16
  return async (repos) => {
10
- let confirmationNumber = await repos.placeOrder.findInProgressConfirmationNumberById({
11
- id: params.id,
12
- status: { $in: params.status.$in }
13
- });
17
+ // let confirmationNumber = await repos.placeOrder.findInProgressConfirmationNumberById({
18
+ // id: params.id,
19
+ // status: { $in: params.status.$in }
20
+ // });
21
+ let confirmationNumber = await repos.orderInTransaction.findConfirmationNumberByIdentifier({ identifier: params.id });
22
+ debug('already exists?', confirmationNumber);
14
23
  // すでに発行済であれば何もしない
15
24
  if (typeof confirmationNumber === 'string') {
16
25
  return confirmationNumber;
17
26
  }
18
27
  // 確認番号を発行
19
28
  confirmationNumber = await repos.confirmationNumber.publish({ orderDate: params.object.orderDate });
20
- // 取引に存在しなければ保管
21
- await repos.placeOrder.saveConfirmationNumberIfNotExist({
22
- id: params.id,
23
- status: { $in: params.status.$in },
29
+ debug('saving new confirmationNumber...', confirmationNumber);
30
+ // // 取引に存在しなければ保管
31
+ // await repos.placeOrder.saveConfirmationNumberIfNotExist({
32
+ // id: params.id,
33
+ // status: { $in: params.status.$in },
34
+ // confirmationNumber
35
+ // });
36
+ // 注文ドキュメントにも保管(2026-07-08~)
37
+ const saveResult = await repos.orderInTransaction.saveConfirmationNumberIfNotExist({
38
+ identifier: params.id,
24
39
  confirmationNumber
25
- });
40
+ }, { onlyPlaceOrder: true });
41
+ debug('saveConfirmationNumberIfNotExist result:', JSON.stringify(saveResult));
26
42
  // 確認番号を取引から再取得
27
- confirmationNumber = await repos.placeOrder.findInProgressConfirmationNumberById({
28
- id: params.id,
29
- status: { $in: params.status.$in }
30
- });
43
+ // confirmationNumber = await repos.placeOrder.findInProgressConfirmationNumberById({
44
+ // id: params.id,
45
+ // status: { $in: params.status.$in }
46
+ // });
47
+ confirmationNumber = await repos.orderInTransaction.findConfirmationNumberByIdentifier({ identifier: params.id });
48
+ debug('confirmationNumber should exist:', confirmationNumber);
31
49
  // 万が一処理が想定通りでない場合confirmationNumberが存在しない
32
50
  if (typeof confirmationNumber !== 'string') {
33
- throw new factory_1.factory.errors.Internal('transaction.object.confirmationNumber not found');
51
+ throw new factory_1.factory.errors.Internal('orderInTransaction.confirmationNumber not found');
34
52
  }
35
53
  return confirmationNumber;
36
54
  };
@@ -9,7 +9,7 @@ import type { ProjectMakesOfferRepo } from '../../../repo/projectMakesOffer';
9
9
  import type { SellerRepo } from '../../../repo/seller';
10
10
  import type { IStartedPlaceOrder, PlaceOrderRepo } from '../../../repo/transaction/placeOrder';
11
11
  import { IStartPlaceOrderParams } from './start/factory';
12
- interface IStartOperationRepos {
12
+ export interface IStartOperationRepos {
13
13
  issuer: IssuerRepo;
14
14
  member: MemberRepo;
15
15
  memberProgram: MemberProgramRepo;
@@ -0,0 +1,20 @@
1
+ import { factory } from '../../../../factory';
2
+ import type { OrderInTransactionRepo } from '../../../../repo/orderInTransaction';
3
+ export interface IFixCustomerRepos {
4
+ orderInTransaction: OrderInTransactionRepo;
5
+ }
6
+ export type IProfileByRequest = Pick<factory.order.ICustomer, 'additionalProperty' | 'address' | 'age' | 'email' | 'familyName' | 'gender' | 'givenName' | 'name' | 'telephone' | 'url'> & {
7
+ telephoneRegion?: string;
8
+ };
9
+ /**
10
+ * 進行中取引からカスタマー属性を決定する
11
+ */
12
+ export declare function fixCustomer(params: {
13
+ /**
14
+ * 注文取引ID
15
+ */
16
+ id: string;
17
+ profileByRequest: IProfileByRequest;
18
+ }): (repos: IFixCustomerRepos) => Promise<{
19
+ customer: factory.order.ICustomer;
20
+ }>;
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.fixCustomer = fixCustomer;
4
+ const libphonenumber_js_1 = require("libphonenumber-js");
5
+ const factory_1 = require("../../../../factory");
6
+ /**
7
+ * 進行中取引からカスタマー属性を決定する
8
+ */
9
+ function fixCustomer(params) {
10
+ return async (repos) => {
11
+ const { profileByRequest } = params;
12
+ let formattedTelephone;
13
+ try {
14
+ const phoneNumber = (0, libphonenumber_js_1.parsePhoneNumberFromString)(String(profileByRequest.telephone), profileByRequest.telephoneRegion);
15
+ if (phoneNumber === undefined || !phoneNumber.isValid()) {
16
+ throw new factory_1.factory.errors.Argument('telephone', 'Invalid phone number');
17
+ }
18
+ formattedTelephone = phoneNumber.format('E.164');
19
+ // if (useLibphonenumber) {
20
+ // const phoneNumber = parsePhoneNumberFromString(String(params.agent.telephone), params.agent.telephoneRegion as CountryCode | undefined);
21
+ // if (phoneNumber === undefined || !phoneNumber.isValid()) {
22
+ // throw new factory.errors.Argument('telephone', 'Invalid phone number');
23
+ // }
24
+ // formattedTelephone = phoneNumber.format('E.164');
25
+ // } else {
26
+ // const phoneUtil = PhoneNumberUtil.getInstance();
27
+ // const phoneNumber = phoneUtil.parse(params.agent.telephone, params.agent.telephoneRegion);
28
+ // if (!phoneUtil.isValidNumber(phoneNumber)) {
29
+ // throw new factory.errors.Argument('telephone', 'Invalid phone number');
30
+ // }
31
+ // formattedTelephone = phoneUtil.format(phoneNumber, PhoneNumberFormat.E164);
32
+ // }
33
+ }
34
+ catch (error) {
35
+ throw new factory_1.factory.errors.Argument('telephone', (error instanceof Error) ? error.message : /* istanbul ignore next */ String(error));
36
+ }
37
+ // orderInTransaction.customer?.typeOfは取引開始時にセットされている前提で再実装(2026-06-24~)
38
+ const customerByTransaction = await repos.orderInTransaction.findCustomerByOrderIdentifier({ identifier: params.id });
39
+ const customerName = (typeof profileByRequest.name === 'string' && profileByRequest.name !== '')
40
+ ? profileByRequest.name
41
+ : /* istanbul ignore next */ (typeof profileByRequest.givenName === 'string' && typeof profileByRequest.familyName === 'string'
42
+ && profileByRequest.givenName !== '' && profileByRequest.familyName !== '')
43
+ ? `${profileByRequest.givenName} ${profileByRequest.familyName}`
44
+ : undefined;
45
+ const identifier = (Array.isArray(customerByTransaction.identifier)) ? customerByTransaction.identifier : /* istanbul ignore next */ [];
46
+ const customer = {
47
+ typeOf: customerByTransaction.typeOf, // 取引開始時で固定
48
+ id: customerByTransaction.id, // 取引開始時で固定
49
+ identifier, // 取引開始時で固定
50
+ ...((Array.isArray(profileByRequest.additionalProperty)) && { additionalProperty: profileByRequest.additionalProperty }),
51
+ ...((typeof profileByRequest.age === 'string') && { age: profileByRequest.age }),
52
+ ...((typeof profileByRequest.address === 'string') && { address: profileByRequest.address }),
53
+ ...((typeof profileByRequest.email === 'string') && { email: profileByRequest.email }),
54
+ ...((typeof profileByRequest.familyName === 'string') && { familyName: profileByRequest.familyName }),
55
+ ...((typeof profileByRequest.gender === 'string') && { gender: profileByRequest.gender }),
56
+ ...((typeof profileByRequest.givenName === 'string') && { givenName: profileByRequest.givenName }),
57
+ ...((typeof customerName === 'string') && { name: customerName }),
58
+ ...((typeof formattedTelephone === 'string') && { telephone: formattedTelephone }),
59
+ ...((typeof profileByRequest.url === 'string') && { url: profileByRequest.url })
60
+ };
61
+ return { customer };
62
+ };
63
+ }
@@ -5,7 +5,6 @@ import type { PlaceOrderRepo } from '../../../repo/transaction/placeOrder';
5
5
  * 取引人プロフィール更新
6
6
  */
7
7
  export declare function updateAgent(params: {
8
- typeOf: factory.transactionType.PlaceOrder;
9
8
  /**
10
9
  * 取引ID
11
10
  */