@chevre/domain 21.35.0-alpha.8 → 21.35.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (98) hide show
  1. package/example/src/chevre/checkReserveTransactionSizes.ts +46 -0
  2. package/example/src/chevre/findCustomerByOrderNumber.ts +19 -0
  3. package/example/src/chevre/investigateMovieTicketIdentifier.ts +78 -0
  4. package/example/src/chevre/migrateAuthorizeEventServiceOfferCOA.ts +84 -0
  5. package/example/src/chevre/migrateAuthorizeEventServiceOfferChevre.ts +84 -0
  6. package/example/src/chevre/migrateAuthorizeEventServiceOfferInstrument.ts +128 -0
  7. package/example/src/chevre/migrateAuthorizeEventServiceOfferResult.ts +163 -0
  8. package/example/src/chevre/unsetUnnecessaryFieldsInAction.ts +55 -0
  9. package/example/src/chevre/{unsetUnnecessaryFields.ts → unsetUnnecessaryFieldsInTransaction.ts} +15 -6
  10. package/lib/chevre/factory/taskIdentifier.d.ts +29 -0
  11. package/lib/chevre/factory/taskIdentifier.js +10 -0
  12. package/lib/chevre/repo/action.d.ts +5 -5
  13. package/lib/chevre/repo/action.js +30 -29
  14. package/lib/chevre/repo/assetTransaction.js +10 -8
  15. package/lib/chevre/repo/mongoose/schemas/accountTransaction.js +0 -25
  16. package/lib/chevre/repo/mongoose/schemas/assetTransaction.js +2 -2
  17. package/lib/chevre/repo/mongoose/schemas/order.js +2 -4
  18. package/lib/chevre/repo/mongoose/schemas/transaction.js +2 -2
  19. package/lib/chevre/repo/orderInTransaction.d.ts +12 -1
  20. package/lib/chevre/repo/orderInTransaction.js +38 -0
  21. package/lib/chevre/repo/project.d.ts +1 -1
  22. package/lib/chevre/repo/project.js +11 -8
  23. package/lib/chevre/repo/seller.d.ts +9 -4
  24. package/lib/chevre/repo/seller.js +21 -15
  25. package/lib/chevre/repo/task.d.ts +12 -0
  26. package/lib/chevre/repo/task.js +17 -0
  27. package/lib/chevre/repo/transaction.d.ts +1 -1
  28. package/lib/chevre/repo/transaction.js +13 -17
  29. package/lib/chevre/service/assetTransaction/cancelReservation.js +1 -1
  30. package/lib/chevre/service/assetTransaction/pay.d.ts +6 -0
  31. package/lib/chevre/service/assetTransaction/pay.js +4 -4
  32. package/lib/chevre/service/notification.d.ts +5 -1
  33. package/lib/chevre/service/notification.js +6 -2
  34. package/lib/chevre/service/offer/event/authorize.js +2 -2
  35. package/lib/chevre/service/offer/event/factory.d.ts +6 -2
  36. package/lib/chevre/service/offer/event/factory.js +45 -47
  37. package/lib/chevre/service/offer/event/voidTransaction/processVoidTransaction4chevre.js +2 -2
  38. package/lib/chevre/service/offer/eventServiceByCOA/acceptOffer.js +2 -2
  39. package/lib/chevre/service/offer/eventServiceByCOA/authorize.js +2 -1
  40. package/lib/chevre/service/offer/eventServiceByCOA/changeOffers.js +34 -16
  41. package/lib/chevre/service/offer/eventServiceByCOA/factory.js +16 -15
  42. package/lib/chevre/service/order/onAssetTransactionStatusChanged.js +1 -1
  43. package/lib/chevre/service/order/onOrderStatusChanged/onOrderDelivered/factory.d.ts +1 -4
  44. package/lib/chevre/service/order/onOrderStatusChanged/onOrderDelivered/factory.js +1 -63
  45. package/lib/chevre/service/order/onOrderStatusChanged/onOrderDelivered.js +11 -11
  46. package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing/createSendEmailMessageTaskIfNotExist.d.ts +3 -1
  47. package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing/createSendEmailMessageTaskIfNotExist.js +2 -9
  48. package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing/factory.js +1 -1
  49. package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing.js +6 -8
  50. package/lib/chevre/service/order/onOrderStatusChanged/onOrderReturned/factory.d.ts +1 -0
  51. package/lib/chevre/service/order/onOrderStatusChanged/onOrderReturned/factory.js +18 -2
  52. package/lib/chevre/service/order/onOrderStatusChanged/onOrderReturned.js +5 -5
  53. package/lib/chevre/service/order/placeOrder/createPlacingOrderFromExistingTransaction.d.ts +21 -0
  54. package/lib/chevre/service/order/placeOrder/createPlacingOrderFromExistingTransaction.js +97 -0
  55. package/lib/chevre/service/order/placeOrder/factory.d.ts +3 -1
  56. package/lib/chevre/service/order/placeOrder/factory.js +34 -5
  57. package/lib/chevre/service/order/placeOrder/voidAcceptedOfferIfNecessary.d.ts +10 -0
  58. package/lib/chevre/service/order/placeOrder/voidAcceptedOfferIfNecessary.js +34 -0
  59. package/lib/chevre/service/order/placeOrder.d.ts +1 -17
  60. package/lib/chevre/service/order/placeOrder.js +10 -178
  61. package/lib/chevre/service/order/placeOrderWithoutTransaction.d.ts +22 -0
  62. package/lib/chevre/service/order/placeOrderWithoutTransaction.js +60 -0
  63. package/lib/chevre/service/order/sendOrder.js +1 -1
  64. package/lib/chevre/service/order.d.ts +2 -1
  65. package/lib/chevre/service/order.js +2 -1
  66. package/lib/chevre/service/payment/any/factory.d.ts +2 -2
  67. package/lib/chevre/service/payment/any.js +13 -4
  68. package/lib/chevre/service/payment/movieTicket/authorize.d.ts +6 -0
  69. package/lib/chevre/service/payment/movieTicket/authorize.js +1 -1
  70. package/lib/chevre/service/payment/movieTicket/checkMovieTicket.js +3 -3
  71. package/lib/chevre/service/payment/movieTicket/validation.d.ts +9 -2
  72. package/lib/chevre/service/payment/movieTicket/validation.js +32 -11
  73. package/lib/chevre/service/task/confirmReserveTransaction.js +3 -3
  74. package/lib/chevre/service/task/returnPayTransaction.d.ts +2 -2
  75. package/lib/chevre/service/task/returnPayTransaction.js +77 -23
  76. package/lib/chevre/service/task/sendEmailMessage.d.ts +2 -2
  77. package/lib/chevre/service/task/sendEmailMessage.js +3 -2
  78. package/lib/chevre/service/task.js +2 -0
  79. package/lib/chevre/service/transaction/deleteTransaction.js +3 -3
  80. package/lib/chevre/service/transaction/placeOrderInProgress/confirm.d.ts +8 -5
  81. package/lib/chevre/service/transaction/placeOrderInProgress/confirm.js +43 -41
  82. package/lib/chevre/service/transaction/placeOrderInProgress/potentialActions/sendEmailMessage.d.ts +1 -1
  83. package/lib/chevre/service/transaction/placeOrderInProgress/result.d.ts +1 -4
  84. package/lib/chevre/service/transaction/placeOrderInProgress/result.js +50 -30
  85. package/lib/chevre/service/transaction/placeOrderInProgress/validation.d.ts +5 -2
  86. package/lib/chevre/service/transaction/placeOrderInProgress/validation.js +57 -31
  87. package/lib/chevre/service/transaction/returnOrder/potentialActions/returnPaymentMethod.js +62 -58
  88. package/lib/chevre/service/transaction/returnOrder/potentialActions/sendEmailMessage.d.ts +3 -1
  89. package/lib/chevre/service/transaction/returnOrder/potentialActions/sendEmailMessage.js +14 -27
  90. package/lib/chevre/service/transaction/returnOrder/preStart.js +17 -19
  91. package/lib/chevre/service/transaction.d.ts +13 -2
  92. package/lib/chevre/service/transaction.js +42 -13
  93. package/lib/chevre/service.d.ts +2 -0
  94. package/lib/chevre/service.js +2 -0
  95. package/lib/chevre/settings.d.ts +0 -1
  96. package/lib/chevre/settings.js +1 -2
  97. package/package.json +3 -3
  98. package/example/src/chevre/investigateCheckMovieTicketActions.ts +0 -60
@@ -13,8 +13,9 @@ const debug = createDebug('chevre-domain:service:transaction');
13
13
  /**
14
14
  * 取引が確定可能な状態かどうかをチェックする
15
15
  */
16
- function validateTransaction(transaction, authorizePaymentActions, authorizeEventServiceOfferActions, authorizeMoneyTansferActions, authorizeProductOfferActions, eventReservationAcceptedOffers) {
17
- validateProfile(transaction);
16
+ function validateTransaction(transaction, authorizePaymentActions, authorizeEventServiceOfferActions, authorizeMoneyTansferActions, authorizeProductOfferActions, eventReservationAcceptedOffers, payTransactions, customer) {
17
+ // validateProfile(transaction);
18
+ validateProfile({ customer });
18
19
  validatePrice(authorizePaymentActions, authorizeEventServiceOfferActions, authorizeProductOfferActions, authorizeMoneyTansferActions);
19
20
  // 利用可能な通貨単位に対して取引検証
20
21
  validateMonetaryAmount(authorizePaymentActions, authorizeEventServiceOfferActions);
@@ -33,9 +34,17 @@ function validateTransaction(transaction, authorizePaymentActions, authorizeEven
33
34
  // 決済方法区分は必ず存在するはず(2023-08-15~)
34
35
  && ((_a = resultAsInvoice.paymentMethodAsObject) === null || _a === void 0 ? void 0 : _a.typeOf) === paymentMethodType;
35
36
  });
37
+ // 決済承認アクションobject.movieTicketsではなく、payTransaction.object参照で再実装(2024-06-20~)
36
38
  const authorizedMovieTickets = [];
37
- authorizeMovieTicketActions.forEach((a) => {
38
- authorizedMovieTickets.push(...(Array.isArray(a.object.movieTickets)) ? a.object.movieTickets : []);
39
+ // authorizeMovieTicketActions.forEach((a) => {
40
+ // authorizedMovieTickets.push(...(Array.isArray(a.object.movieTickets)) ? a.object.movieTickets : []);
41
+ // });
42
+ const payTransactionNumbers = authorizeMovieTicketActions.map(({ instrument }) => instrument.transactionNumber);
43
+ payTransactions.filter(({ object }) => payTransactionNumbers.includes(object.paymentMethodId))
44
+ .forEach(({ object }) => {
45
+ if (Array.isArray(object.paymentMethod.movieTickets)) {
46
+ authorizedMovieTickets.push(...object.paymentMethod.movieTickets);
47
+ }
39
48
  });
40
49
  debug(authorizedMovieTickets.length, 'movie tickets authorized', 'transaction:', transaction.id);
41
50
  // validateMovieTicket(paymentMethodType, { id: transaction.id }, authorizePaymentActions, eventReservationAcceptedOffers);
@@ -81,9 +90,20 @@ function findMovieTicketPaymentMethodTypesFromTransaction(authorizePaymentAction
81
90
  // ];
82
91
  return [...new Set(paymentMethodTypes)];
83
92
  }
84
- function validateProfile(transaction) {
85
- // object.customerで検証(2022-05-26~)
86
- const profile = transaction.object.customer;
93
+ // function validateProfile(transaction: Pick<factory.transaction.placeOrder.ITransaction, 'object'>) {
94
+ // // object.customerで検証(2022-05-26~)
95
+ // const profile = transaction.object.customer;
96
+ // const profileSatisfied = typeof profile?.typeOf === 'string' && profile.typeOf.length > 0
97
+ // && typeof profile.email === 'string' && profile.email.length > 0
98
+ // && typeof profile.familyName === 'string' && profile.familyName.length > 0
99
+ // && typeof profile.givenName === 'string' && profile.givenName.length > 0
100
+ // && typeof profile.telephone === 'string' && profile.telephone.length > 0;
101
+ // if (!profileSatisfied) {
102
+ // throw new factory.errors.Argument('Transaction', 'Customer Profile Required');
103
+ // }
104
+ // }
105
+ function validateProfile(params) {
106
+ const profile = params.customer;
87
107
  const profileSatisfied = typeof (profile === null || profile === void 0 ? void 0 : profile.typeOf) === 'string' && profile.typeOf.length > 0
88
108
  && typeof profile.email === 'string' && profile.email.length > 0
89
109
  && typeof profile.familyName === 'string' && profile.familyName.length > 0
@@ -92,6 +112,10 @@ function validateProfile(transaction) {
92
112
  if (!profileSatisfied) {
93
113
  throw new factory.errors.Argument('Transaction', 'Customer Profile Required');
94
114
  }
115
+ // customer.nameが必ず存在するように
116
+ if (typeof profile.name !== 'string' && profile.name === '') {
117
+ throw new factory.errors.Argument('Transaction', 'customer name required');
118
+ }
95
119
  }
96
120
  function validatePrice(authorizePaymentActions, authorizeEventServiceOfferActions, authorizeProductOfferActions, authorizeMoneyTansferActions) {
97
121
  let priceByAgent = 0;
@@ -186,14 +210,16 @@ function validateMonetaryAmount(authorizePaymentActions, authorizeEventServiceOf
186
210
  const requiredMonetaryAmount = requiredMonetaryAmountByCurrencyType
187
211
  .filter((m) => m.currency === currencyType)
188
212
  .reduce((a, b) => a + b.value, 0);
189
- const authorizedMonetaryAmount = authorizeMonetaryAmountActions.filter(({ result }) => {
213
+ let authorizedMonetaryAmount = 0;
214
+ authorizeMonetaryAmountActions.forEach(({ result }) => {
190
215
  var _a;
191
216
  const resultAsInvoice = (Array.isArray(result))
192
217
  ? result.find(({ typeOf }) => typeOf === factory.action.authorize.paymentMethod.any.ResultType.Payment)
193
218
  : undefined;
194
- return ((_a = resultAsInvoice === null || resultAsInvoice === void 0 ? void 0 : resultAsInvoice.totalPaymentDue) === null || _a === void 0 ? void 0 : _a.currency) === currencyType;
195
- })
196
- .reduce((a, b) => a + b.object.amount, 0);
219
+ if (((_a = resultAsInvoice === null || resultAsInvoice === void 0 ? void 0 : resultAsInvoice.totalPaymentDue) === null || _a === void 0 ? void 0 : _a.currency) === currencyType) {
220
+ authorizedMonetaryAmount += resultAsInvoice.totalPaymentDue.value;
221
+ }
222
+ });
197
223
  return requiredMonetaryAmount === authorizedMonetaryAmount;
198
224
  });
199
225
  if (!requireMonetaryAmountSatisfied) {
@@ -325,21 +351,16 @@ function validateEventOffers(params) {
325
351
  return referenceInvoice.issuedThrough.typeOf === factory.service.paymentService.PaymentServiceType.CreditCard
326
352
  || referenceInvoice.issuedThrough.typeOf === factory.service.paymentService.PaymentServiceType.FaceToFace;
327
353
  }).length;
354
+ // tslint:disable-next-line:max-func-body-length
328
355
  params.authorizeEventServiceOfferActions.forEach((a) => {
329
- // オファーIDごとにオファー適用条件を確認
330
- const offerIds = [...new Set(a.object.acceptedOffer.map((o) => o.id))];
331
- offerIds.forEach((offerId) => {
332
- var _a, _b, _c, _d;
333
- let unitPriceSpec;
334
- if (a.instrument.identifier === factory.service.webAPI.Identifier.Chevre) {
335
- const acceptedOffer = a.object.acceptedOffer.find((o) => o.id === offerId);
336
- if (acceptedOffer === undefined) {
337
- throw new factory.errors.ServiceUnavailable(`authorizeEventServiceOfferAction.object.acceptedOffer not found. [id:${offerId}]`);
338
- }
339
- // Chevre予約の場合、priceSpecificationに複合価格仕様が含まれるので、そこから単価仕様を取り出す
340
- unitPriceSpec = acceptedOffer.priceSpecification.priceComponent.find((spec) => spec.typeOf === factory.priceSpecificationType.UnitPriceSpecification
341
- && (!Array.isArray(spec.appliesToAddOn)) // アドオン単価ではない
342
- );
356
+ var _a;
357
+ // support result.offers(2024-06-18~)
358
+ const acceptedOffersInResult = (_a = a.result) === null || _a === void 0 ? void 0 : _a.offers;
359
+ if (Array.isArray(acceptedOffersInResult) && acceptedOffersInResult.length > 0) {
360
+ acceptedOffersInResult.forEach((acceptedOfferInResult) => {
361
+ var _a, _b, _c, _d;
362
+ const offerId = acceptedOfferInResult.id;
363
+ const unitPriceSpec = acceptedOfferInResult.priceSpecification;
343
364
  // 適用金額要件を満たしていなければエラー
344
365
  const eligibleTransactionVolumePrice = (_a = unitPriceSpec === null || unitPriceSpec === void 0 ? void 0 : unitPriceSpec.eligibleTransactionVolume) === null || _a === void 0 ? void 0 : _a.price;
345
366
  const eligibleTransactionVolumePriceCurrency = (_b = unitPriceSpec === null || unitPriceSpec === void 0 ? void 0 : unitPriceSpec.eligibleTransactionVolume) === null || _b === void 0 ? void 0 : _b.priceCurrency;
@@ -350,33 +371,38 @@ function validateEventOffers(params) {
350
371
  }
351
372
  // 適用数量検証(全興行オファー承認アクションについて)(2023-11-15~)
352
373
  // 適用数量要件を満たしていなければエラー
353
- const numAcceptedOffersByOfferId = params.authorizeEventServiceOfferActions.reduce((previousNumOffer, currentAction) => {
354
- return previousNumOffer + currentAction.object.acceptedOffer.filter((o) => o.id === offerId).length;
374
+ const numAcceptedOffersByOfferId = params.authorizeEventServiceOfferActions.reduce((previousNumOffer, { result }) => {
375
+ var _a, _b;
376
+ const numOfferOnCurrentAction = (_b = (_a = result === null || result === void 0 ? void 0 : result.offers) === null || _a === void 0 ? void 0 : _a.find(({ id }) => id === offerId)) === null || _b === void 0 ? void 0 : _b.includesObject.amountOfThisGood;
377
+ return previousNumOffer + ((typeof numOfferOnCurrentAction === 'number') ? numOfferOnCurrentAction : 0);
355
378
  }, 0);
356
379
  const eligibleQuantityMaxValue = (_c = unitPriceSpec === null || unitPriceSpec === void 0 ? void 0 : unitPriceSpec.eligibleQuantity) === null || _c === void 0 ? void 0 : _c.maxValue;
357
380
  if (typeof eligibleQuantityMaxValue === 'number') {
381
+ debug('validateEventOffers: numAcceptedOffersByOfferId > eligibleQuantityMaxValue?', numAcceptedOffersByOfferId, eligibleQuantityMaxValue);
358
382
  if (numAcceptedOffersByOfferId > eligibleQuantityMaxValue) {
359
383
  throw new factory.errors.Argument('Transaction', `Number of offer:${offerId} must be less than or equal to ${eligibleQuantityMaxValue}`);
360
384
  }
361
385
  }
362
386
  const eligibleQuantityMinValue = (_d = unitPriceSpec === null || unitPriceSpec === void 0 ? void 0 : unitPriceSpec.eligibleQuantity) === null || _d === void 0 ? void 0 : _d.minValue;
363
387
  if (typeof eligibleQuantityMinValue === 'number') {
388
+ debug('validateEventOffers: numAcceptedOffersByOfferId < eligibleQuantityMinValue?', numAcceptedOffersByOfferId, eligibleQuantityMinValue);
364
389
  if (numAcceptedOffersByOfferId < eligibleQuantityMinValue) {
365
390
  throw new factory.errors.Argument('Transaction', `Number of offer:${offerId} must be more than or equal to ${eligibleQuantityMinValue}`);
366
391
  }
367
392
  }
368
393
  // 利用可能決済方法検証(2023-11-15~)
369
- if (Array.isArray(acceptedOffer.acceptedPaymentMethod)) {
370
- const acceptedPaymentMethodTypes = acceptedOffer.acceptedPaymentMethod.map((paymentMethod) => paymentMethod.identifier);
394
+ if (Array.isArray(acceptedOfferInResult.acceptedPaymentMethod)) {
395
+ const acceptedPaymentMethodTypes = acceptedOfferInResult.acceptedPaymentMethod.map(({ identifier }) => identifier);
371
396
  const satisfyAcceptedPaymentMethod = numCreditCardOrFaceToFacePaymentMethod === 1
372
397
  && typeof firstCreditCardPaymentMethodIdentifier === 'string'
373
398
  && acceptedPaymentMethodTypes.includes(firstCreditCardPaymentMethodIdentifier);
399
+ debug('validateEventOffers: satisfyAcceptedPaymentMethod?', JSON.stringify(acceptedPaymentMethodTypes));
374
400
  if (!satisfyAcceptedPaymentMethod) {
375
401
  throw new factory.errors.Argument('Transaction', `acceptedPaymentMethod requirement not satisfied`);
376
402
  }
377
403
  }
378
- }
379
- });
404
+ });
405
+ }
380
406
  });
381
407
  }
382
408
  exports.validateEventOffers = validateEventOffers;
@@ -49,24 +49,24 @@ function createReturnInvoicePotentialActions(params) {
49
49
  email: emailCustomization,
50
50
  paymentMethodId: params.paymentMethod.paymentMethodId
51
51
  });
52
- const sendActionPurpose = {
53
- typeOf: order.typeOf,
54
- orderNumber: order.orderNumber,
55
- price: order.price,
56
- priceCurrency: order.priceCurrency,
57
- orderDate: order.orderDate
58
- };
52
+ // const sendActionPurpose: factory.action.transfer.send.message.email.IPurpose = {
53
+ // typeOf: order.typeOf,
54
+ // orderNumber: order.orderNumber,
55
+ // price: order.price,
56
+ // priceCurrency: order.priceCurrency,
57
+ // orderDate: order.orderDate
58
+ // };
59
59
  sendEmailMessageOnRefund.push({
60
- project: order.project,
61
- typeOf: factory.actionType.SendAction,
62
- object: emailMessage,
63
- agent: order.project,
64
- recipient: {
65
- typeOf: order.customer.typeOf,
66
- id: order.customer.id
67
- },
68
- potentialActions: {},
69
- purpose: sendActionPurpose
60
+ // project: order.project, // discontinue(2024-06-26~)
61
+ // typeOf: factory.actionType.SendAction, // discontinue(2024-06-26~)
62
+ object: emailMessage
63
+ // agent: order.project, // discontinue(2024-06-26~)
64
+ // recipient: { // discontinue(2024-06-26~)
65
+ // typeOf: order.customer.typeOf,
66
+ // id: order.customer.id
67
+ // },
68
+ // potentialActions: {}, // discontinue(2024-06-25~)
69
+ // purpose: sendActionPurpose // discontinue(2024-06-26~)
70
70
  });
71
71
  }
72
72
  return {
@@ -76,15 +76,15 @@ function createReturnInvoicePotentialActions(params) {
76
76
  }
77
77
  function createReturnPaymentMethodActions(params) {
78
78
  return __awaiter(this, void 0, void 0, function* () {
79
- const order = params.order;
79
+ // const order = params.order;
80
80
  const potentialReturnInvoiceActions = [];
81
- const returnPaymentMethodPurpose = {
82
- typeOf: order.typeOf,
83
- orderNumber: order.orderNumber,
84
- price: order.price,
85
- priceCurrency: order.priceCurrency,
86
- orderDate: order.orderDate
87
- };
81
+ // const returnPaymentMethodPurpose: factory.order.ISimpleOrder = {
82
+ // typeOf: order.typeOf,
83
+ // orderNumber: order.orderNumber,
84
+ // price: order.price,
85
+ // priceCurrency: order.priceCurrency,
86
+ // orderDate: order.orderDate
87
+ // };
88
88
  // MovieTicket決済以外について返品ポリシーのreturnFeesを適用する(2022-08-10~)
89
89
  const returnFees = params.transaction.object.returnPolicy.returnFees;
90
90
  // ReturnFeesCustomerResponsibilityであれば返金はなし、それ以外は返金する
@@ -102,19 +102,21 @@ function createReturnPaymentMethodActions(params) {
102
102
  : undefined));
103
103
  const { paymentStatus } = referencedInvoice, referencedInvoiceAsObject = __rest(referencedInvoice, ["paymentStatus"]);
104
104
  const object = Object.assign(Object.assign({}, referencedInvoiceAsObject), { typeOf: 'Invoice' });
105
- return {
106
- project: order.project,
107
- typeOf: factory.actionType.ReturnAction,
108
- object,
109
- agent: order.project,
110
- recipient: {
111
- typeOf: order.customer.typeOf,
112
- id: order.customer.id,
113
- name: String(order.customer.name)
114
- },
115
- purpose: returnPaymentMethodPurpose,
116
- potentialActions: potentialActionsOnRefund
117
- };
105
+ // optimize(2024-06-19~)
106
+ return { object, potentialActions: potentialActionsOnRefund };
107
+ // return {
108
+ // project: order.project,
109
+ // typeOf: factory.actionType.ReturnAction,
110
+ // object,
111
+ // agent: order.project,
112
+ // recipient: {
113
+ // typeOf: order.customer.typeOf,
114
+ // id: order.customer.id,
115
+ // name: String(order.customer.name)
116
+ // },
117
+ // purpose: returnPaymentMethodPurpose,
118
+ // potentialActions: potentialActionsOnRefund
119
+ // };
118
120
  }))));
119
121
  }
120
122
  // MovieTicket決済について
@@ -128,7 +130,7 @@ exports.createReturnPaymentMethodActions = createReturnPaymentMethodActions;
128
130
  */
129
131
  function createReturnPaymentMethodIssuedThroughMovieTicketActions(params) {
130
132
  return __awaiter(this, void 0, void 0, function* () {
131
- const order = params.order;
133
+ // const order = params.order;
132
134
  const returnFeesMovieTicketByTransaction = params.transaction.object.returnPolicy.returnFeesMovieTicket;
133
135
  return Promise.all(params.order.paymentMethods
134
136
  .filter((invoice) => {
@@ -170,25 +172,27 @@ function createReturnPaymentMethodIssuedThroughMovieTicketActions(params) {
170
172
  : undefined));
171
173
  const { paymentStatus } = referencedInvoice, referencedInvoiceAsObject = __rest(referencedInvoice, ["paymentStatus"]);
172
174
  const object = Object.assign(Object.assign({}, referencedInvoiceAsObject), { typeOf: 'Invoice' });
173
- return {
174
- project: order.project,
175
- typeOf: factory.actionType.ReturnAction,
176
- object,
177
- agent: order.project,
178
- recipient: {
179
- typeOf: order.customer.typeOf,
180
- id: order.customer.id,
181
- name: String(order.customer.name)
182
- },
183
- purpose: {
184
- typeOf: order.typeOf,
185
- orderNumber: order.orderNumber,
186
- price: order.price,
187
- priceCurrency: order.priceCurrency,
188
- orderDate: order.orderDate
189
- },
190
- potentialActions: potentialActionsOnRefund
191
- };
175
+ // optimize(2024-06-19~)
176
+ return { object, potentialActions: potentialActionsOnRefund };
177
+ // return {
178
+ // project: order.project,
179
+ // typeOf: factory.actionType.ReturnAction,
180
+ // object,
181
+ // agent: order.project,
182
+ // recipient: {
183
+ // typeOf: order.customer.typeOf,
184
+ // id: order.customer.id,
185
+ // name: String(order.customer.name)
186
+ // },
187
+ // purpose: {
188
+ // typeOf: order.typeOf,
189
+ // orderNumber: order.orderNumber,
190
+ // price: order.price,
191
+ // priceCurrency: order.priceCurrency,
192
+ // orderDate: order.orderDate
193
+ // },
194
+ // potentialActions: potentialActionsOnRefund
195
+ // };
192
196
  })));
193
197
  });
194
198
  }
@@ -1,6 +1,8 @@
1
1
  import * as factory from '../../../../factory';
2
+ type IPotentialSendEmailMessageAction = factory.action.transfer.returnAction.order.IPotentialSendEmailMessageAction;
2
3
  export declare function createSendEmailMessaegActionsOnReturn(params: {
3
4
  order: factory.order.IOrder;
4
5
  returnOrderActionParams?: factory.transaction.returnOrder.IReturnOrderActionParams;
5
6
  emailMessageOnOrderReturned?: factory.creativeWork.message.email.ICreativeWork;
6
- }): Promise<factory.action.transfer.send.message.email.IAttributes[]>;
7
+ }): Promise<IPotentialSendEmailMessageAction[]>;
8
+ export {};
@@ -11,26 +11,17 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.createSendEmailMessaegActionsOnReturn = void 0;
13
13
  const emailMessageBuilder = require("../../../../emailMessageBuilder");
14
- const factory = require("../../../../factory");
15
- // import { createMaskedCustomer } from '../../../../factory/order';
16
14
  function createSendEmailMessaegActionsOnReturn(params) {
17
15
  var _a, _b;
18
16
  return __awaiter(this, void 0, void 0, function* () {
19
17
  const order = params.order;
20
- const sendActionPurpose = {
21
- typeOf: order.typeOf,
22
- // seller: {
23
- // id: order.seller.id,
24
- // typeOf: order.seller.typeOf,
25
- // name: order.seller.name
26
- // }, // 廃止(2024-03-06~)
27
- // mask
28
- // customer: createMaskedCustomer(order, { noProfile: true }), // 廃止(2024-03-06~)
29
- orderNumber: order.orderNumber,
30
- price: order.price,
31
- priceCurrency: order.priceCurrency,
32
- orderDate: order.orderDate
33
- };
18
+ // const sendActionPurpose: factory.action.transfer.send.message.email.IPurpose = {
19
+ // typeOf: order.typeOf,
20
+ // orderNumber: order.orderNumber,
21
+ // price: order.price,
22
+ // priceCurrency: order.priceCurrency,
23
+ // orderDate: order.orderDate
24
+ // };
34
25
  // 返品後のEメール送信アクション
35
26
  const sendEmailMessaegActionsOnReturn = [];
36
27
  const sendEmailMessage = (_b = (_a = params.returnOrderActionParams) === null || _a === void 0 ? void 0 : _a.potentialActions) === null || _b === void 0 ? void 0 : _b.sendEmailMessage;
@@ -40,17 +31,13 @@ function createSendEmailMessaegActionsOnReturn(params) {
40
31
  ? { emailMessage: params.emailMessageOnOrderReturned }
41
32
  : undefined));
42
33
  return {
43
- project: order.project,
44
- typeOf: factory.actionType.SendAction,
45
- object: emailMessage,
46
- agent: order.project,
47
- recipient: {
48
- typeOf: order.customer.typeOf,
49
- id: order.customer.id
50
- // name: String(order.customer.name)
51
- },
52
- potentialActions: {},
53
- purpose: sendActionPurpose
34
+ // project: order.project, // optimize(2024-06-25~)
35
+ // typeOf: factory.actionType.SendAction, // optimize(2024-06-25~)
36
+ object: emailMessage
37
+ // agent: order.project, // optimize(2024-06-25~)
38
+ // recipient: { typeOf: order.customer.typeOf, id: order.customer.id }, // optimize(2024-06-25~)
39
+ // potentialActions: {} // optimize(2024-06-25~)
40
+ // purpose: sendActionPurpose // optimize(2024-06-25~)
54
41
  };
55
42
  }))));
56
43
  }
@@ -91,11 +91,8 @@ function preStart(params) {
91
91
  validateAppliedReturnPolicy({ merchantReturnPolicy: appliedReturnPolicy });
92
92
  // アイテム検証
93
93
  yield validateItems({ orders, reason: params.object.reason })({ order: repos.order, reservation: repos.reservation });
94
- const transactionObject = {
95
- order: orders.map(({ confirmationNumber, orderNumber }) => ({ confirmationNumber, orderNumber })),
96
- returnPolicy: appliedReturnPolicy,
97
- reason: params.object.reason
98
- };
94
+ const transactionObject = Object.assign({ order: orders.map(({ confirmationNumber, orderNumber }) => ({ confirmationNumber, orderNumber })), returnPolicy: appliedReturnPolicy, reason: params.object.reason }, { usedReservationExists } // for debug(2024-06-26~)
95
+ );
99
96
  // fix expiresInSeconds(2022-11-30~)
100
97
  let expiresInSeconds;
101
98
  if (typeof params.expiresInSeconds === 'number') {
@@ -286,7 +283,8 @@ function getReturnPolicyByProject(params) {
286
283
  return __awaiter(this, void 0, void 0, function* () {
287
284
  // implement with fetch(2024-01-20~)
288
285
  try {
289
- const res = yield fetch(params.sameAs, {
286
+ const { identifier, sameAs } = params;
287
+ const res = yield fetch(sameAs, {
290
288
  method: 'POST',
291
289
  headers: {
292
290
  'Content-Type': 'application/json'
@@ -314,14 +312,11 @@ function getReturnPolicyByProject(params) {
314
312
  throw new Error('invalid return policy');
315
313
  }
316
314
  else {
317
- returnPolicy = {
318
- typeOf: 'MerchantReturnPolicy',
319
- restockingFee: {
315
+ returnPolicy = Object.assign({ typeOf: 'MerchantReturnPolicy', restockingFee: {
320
316
  currency: factory.priceCurrency.JPY,
321
317
  typeOf: 'MonetaryAmount',
322
318
  value: body.restockingFee.value
323
- }
324
- };
319
+ } }, (typeof identifier === 'string') ? { identifier } : undefined);
325
320
  }
326
321
  break;
327
322
  case http_status_1.NOT_FOUND:
@@ -344,13 +339,14 @@ function getReturnPolicyByProject(params) {
344
339
  */
345
340
  // tslint:disable-next-line:max-func-body-length
346
341
  function findApplicableReturnPolicy(params) {
347
- var _a, _b;
342
+ var _a, _b, _c;
348
343
  return __awaiter(this, void 0, void 0, function* () {
349
344
  if (params.reason === factory.transaction.returnOrder.Reason.Seller) {
350
345
  // 販売者都合の場合、手数料なしの返金返品ポリシーを適用
351
346
  return {
352
347
  typeOf: 'MerchantReturnPolicy',
353
348
  returnFees: factory.merchantReturnPolicy.ReturnFeesEnumeration.FreeReturn
349
+ // no identifier in this case
354
350
  };
355
351
  }
356
352
  const returnPolicies = params.returnPolicies;
@@ -360,6 +356,7 @@ function findApplicableReturnPolicy(params) {
360
356
  const returnPolicySameAsByPoject = (_a = params.returnPolicySettingsByProject) === null || _a === void 0 ? void 0 : _a.sameAs;
361
357
  if (typeof returnPolicySameAsByPoject === 'string' && returnPolicySameAsByPoject.length > 0) {
362
358
  const returnPolicyByProject = yield getReturnPolicyByProject({
359
+ identifier: (_b = params.returnPolicySettingsByProject) === null || _b === void 0 ? void 0 : _b.identifier,
363
360
  sameAs: returnPolicySameAsByPoject,
364
361
  order: Object.assign(Object.assign({}, params.orders[0]), { acceptedOffers: params.acceptedOffers })
365
362
  });
@@ -399,23 +396,24 @@ function findApplicableReturnPolicy(params) {
399
396
  const appliedReturnPolicyRestockingFee = (typeof appliedReturnPolicyRestockingFeeValue === 'number')
400
397
  ? appliedReturnPolicyRestockingFeeValue
401
398
  : 0;
402
- const restockingFee = (typeof restockingFeeValue === 'number') ? restockingFeeValue : 0;
403
- if (restockingFee < appliedReturnPolicyRestockingFee) {
399
+ const restockingFeeAsNumber = (typeof restockingFeeValue === 'number') ? restockingFeeValue : 0;
400
+ if (restockingFeeAsNumber < appliedReturnPolicyRestockingFee) {
404
401
  appliedReturnPolicy = returnPolicy;
405
402
  }
406
403
  });
407
404
  let appliedItemCondition;
408
- const appliedItemConditionId = (_b = appliedReturnPolicy.itemCondition) === null || _b === void 0 ? void 0 : _b.id;
405
+ const appliedItemConditionId = (_c = appliedReturnPolicy.itemCondition) === null || _c === void 0 ? void 0 : _c.id;
409
406
  if (typeof appliedItemConditionId === 'string') {
410
407
  appliedItemCondition = params.offerItemConditions.find((o) => o.id === appliedItemConditionId);
411
408
  if (appliedItemCondition === undefined) {
412
409
  throw new factory.errors.NotFound('OfferItemCondition');
413
410
  }
414
411
  }
415
- return Object.assign(Object.assign({ restockingFee: appliedReturnPolicy.restockingFee, returnFees,
416
- returnFeesMovieTicket, typeOf: appliedReturnPolicy.typeOf }, (typeof appliedReturnPolicy.merchantReturnDays === 'number')
417
- ? { merchantReturnDays: appliedReturnPolicy.merchantReturnDays }
418
- : undefined), (typeof (appliedItemCondition === null || appliedItemCondition === void 0 ? void 0 : appliedItemCondition.typeOf) === 'string') ? { itemCondition: appliedItemCondition } : undefined);
412
+ const { restockingFee, typeOf, identifier, merchantReturnDays } = appliedReturnPolicy;
413
+ return Object.assign(Object.assign(Object.assign({ restockingFee,
414
+ returnFees,
415
+ returnFeesMovieTicket,
416
+ typeOf }, (typeof identifier === 'string') ? { identifier } : undefined), (typeof merchantReturnDays === 'number') ? { merchantReturnDays } : undefined), (typeof (appliedItemCondition === null || appliedItemCondition === void 0 ? void 0 : appliedItemCondition.typeOf) === 'string') ? { itemCondition: appliedItemCondition } : undefined);
419
417
  });
420
418
  }
421
419
  // tslint:disable-next-line:cyclomatic-complexity max-func-body-length
@@ -1,4 +1,7 @@
1
1
  import * as factory from '../factory';
2
+ import type { MongoRepository as OrderInTransactionRepo } from '../repo/orderInTransaction';
3
+ import type { RedisRepository as OrderNumberRepo } from '../repo/orderNumber';
4
+ import type { MongoRepository as ProjectRepo } from '../repo/project';
2
5
  import type { MongoRepository as TaskRepo } from '../repo/task';
3
6
  import type { MongoRepository as TransactionRepo } from '../repo/transaction';
4
7
  import { deleteTransaction } from './transaction/deleteTransaction';
@@ -19,11 +22,19 @@ export { deleteTransaction };
19
22
  */
20
23
  export declare function updateAgent(params: {
21
24
  typeOf: factory.transactionType;
25
+ /**
26
+ * 取引ID
27
+ */
22
28
  id: string;
23
- agent: factory.transaction.placeOrder.ICustomer & {
29
+ agent: factory.order.ICustomer & {
24
30
  telephoneRegion?: string;
25
31
  };
26
- }): ITransactionOperation<factory.transaction.placeOrder.ICustomer>;
32
+ }): (repos: {
33
+ orderInTransaction: OrderInTransactionRepo;
34
+ orderNumber: OrderNumberRepo;
35
+ project: ProjectRepo;
36
+ transaction: TransactionRepo;
37
+ }) => Promise<void>;
27
38
  export type IExportTasksOperation<T> = (repos: {
28
39
  task: TaskRepo;
29
40
  transaction: TransactionRepo;
@@ -26,11 +26,7 @@ exports.moneyTransfer = MoneyTransferTransactionService;
26
26
  exports.placeOrder = PlaceOrderTransactionService;
27
27
  exports.placeOrderInProgress = PlaceOrderInProgressTransactionService;
28
28
  exports.returnOrder = ReturnOrderTransactionService;
29
- /**
30
- * 取引人プロフィール更新
31
- */
32
- function updateAgent(params) {
33
- // tslint:disable-next-line:cyclomatic-complexity
29
+ function fixCustomer(params) {
34
30
  return (repos) => __awaiter(this, void 0, void 0, function* () {
35
31
  var _a;
36
32
  let formattedTelephone;
@@ -48,15 +44,10 @@ function updateAgent(params) {
48
44
  const transaction = yield repos.transaction.findInProgressById({
49
45
  typeOf: params.typeOf,
50
46
  id: params.id
51
- }, ['agent', 'object', 'typeOf']);
47
+ }, ['agent', 'object', 'typeOf', 'project']);
52
48
  if (transaction.agent.id !== params.agent.id) {
53
49
  throw new factory.errors.Forbidden('Transaction not yours');
54
50
  }
55
- // 新プロフィール作成
56
- const newAgent = {
57
- typeOf: transaction.agent.typeOf,
58
- id: transaction.agent.id
59
- };
60
51
  // 注文取引の場合、object.customerにも適用
61
52
  let customer;
62
53
  if (transaction.typeOf === factory.transactionType.PlaceOrder) {
@@ -68,8 +59,46 @@ function updateAgent(params) {
68
59
  : undefined), (Array.isArray(params.agent.additionalProperty)) ? { additionalProperty: params.agent.additionalProperty } : {}), (typeof params.agent.age === 'string') ? { age: params.agent.age } : {}), (typeof params.agent.address === 'string') ? { address: params.agent.address } : {}), (typeof params.agent.email === 'string') ? { email: params.agent.email } : {}), (typeof params.agent.familyName === 'string') ? { familyName: params.agent.familyName } : {}), (typeof params.agent.gender === 'string') ? { gender: params.agent.gender } : {}), (typeof params.agent.givenName === 'string') ? { givenName: params.agent.givenName } : {}), (typeof params.agent.name === 'string') ? { name: params.agent.name } : {}), (typeof formattedTelephone === 'string') ? { telephone: formattedTelephone } : {}), (typeof params.agent.url === 'string') ? { url: params.agent.url } : {});
69
60
  }
70
61
  }
71
- yield repos.transaction.updateAgent(Object.assign({ typeOf: params.typeOf, id: params.id, agent: newAgent }, (customer !== undefined) ? { object: { customer } } : undefined));
72
- return newAgent;
62
+ return { customer, transaction };
63
+ });
64
+ }
65
+ /**
66
+ * 取引人プロフィール更新
67
+ */
68
+ function updateAgent(params) {
69
+ return (repos) => __awaiter(this, void 0, void 0, function* () {
70
+ const { customer, transaction } = yield fixCustomer(params)(repos);
71
+ // const newAgent: Pick<factory.transaction.placeOrder.IAgent, 'id'> = {
72
+ // id: transaction.agent.id
73
+ // };
74
+ // discontinue saving in transaction(2024-06-24~)
75
+ // await repos.transaction.updateAgent({
76
+ // typeOf: params.typeOf,
77
+ // id: params.id,
78
+ // agent: newAgent,
79
+ // ...(customer !== undefined) ? { object: { customer } } : undefined
80
+ // });
81
+ // also save in orderInTransaction(2024-06-20~)
82
+ if (customer !== undefined) {
83
+ const orderNumber = yield PlaceOrderInProgressTransactionService.publishOrderNumberIfNotExist({
84
+ project: { id: transaction.project.id },
85
+ id: params.id,
86
+ object: { orderDate: new Date() }
87
+ })(repos);
88
+ const customerName = (typeof customer.name === 'string' && customer.name !== '')
89
+ ? customer.name
90
+ : (typeof customer.givenName === 'string' && typeof customer.familyName === 'string'
91
+ && customer.givenName !== '' && customer.familyName !== '')
92
+ ? `${customer.givenName} ${customer.familyName}`
93
+ : undefined;
94
+ const customerInOrder = Object.assign(Object.assign(Object.assign({}, customer), { identifier: (Array.isArray(customer.identifier)) ? customer.identifier : [] }), (typeof customerName === 'string') ? { name: customerName } : undefined);
95
+ yield repos.orderInTransaction.setCustomer({
96
+ orderNumber,
97
+ project: transaction.project,
98
+ customer: customerInOrder
99
+ });
100
+ }
101
+ // return newAgent;
73
102
  });
74
103
  }
75
104
  exports.updateAgent = updateAgent;
@@ -5,6 +5,7 @@ import * as AccountTransactionIdentifierFactory from './factory/accountTransacti
5
5
  import * as EventFactory from './factory/event';
6
6
  import * as OrderFactory from './factory/order';
7
7
  import * as ReservedAgentIdentifireNamesFactory from './factory/reservedAgentIdentifireNames';
8
+ import * as TaskIdentifierFactory from './factory/taskIdentifier';
8
9
  import * as TransactionFactory from './factory/transaction';
9
10
  import type * as AccountService from './service/account';
10
11
  import type * as AccountTransactionService from './service/accountTransaction';
@@ -85,5 +86,6 @@ export declare namespace factory {
85
86
  export import event = EventFactory;
86
87
  export import order = OrderFactory;
87
88
  export import reservedAgentIdentifireNames = ReservedAgentIdentifireNamesFactory;
89
+ export import taskIdentifier = TaskIdentifierFactory;
88
90
  export import transaction = TransactionFactory;
89
91
  }
@@ -17,6 +17,7 @@ const AccountTransactionIdentifierFactory = require("./factory/accountTransactio
17
17
  const EventFactory = require("./factory/event");
18
18
  const OrderFactory = require("./factory/order");
19
19
  const ReservedAgentIdentifireNamesFactory = require("./factory/reservedAgentIdentifireNames");
20
+ const TaskIdentifierFactory = require("./factory/taskIdentifier");
20
21
  const TransactionFactory = require("./factory/transaction");
21
22
  // import all lazily(2023-10-11~)
22
23
  var account;
@@ -264,6 +265,7 @@ var factory;
264
265
  // tslint:disable-next-line:no-shadowed-variable
265
266
  factory.order = OrderFactory;
266
267
  factory.reservedAgentIdentifireNames = ReservedAgentIdentifireNamesFactory;
268
+ factory.taskIdentifier = TaskIdentifierFactory;
267
269
  // tslint:disable-next-line:no-shadowed-variable
268
270
  factory.transaction = TransactionFactory;
269
271
  })(factory = exports.factory || (exports.factory = {}));