@chevre/domain 21.8.0-alpha.6 → 21.8.0-alpha.60

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 (129) hide show
  1. package/example/src/chevre/countOffers.ts +32 -0
  2. package/example/src/chevre/findItemListElementByCatalogId.ts +23 -0
  3. package/example/src/chevre/importOffersFromCOA.ts +7 -1
  4. package/example/src/chevre/migrateAggregateOffers.ts +89 -0
  5. package/example/src/chevre/migrateOrderPaymentMethodIdentifier.ts +81 -0
  6. package/example/src/chevre/migratePayTransactionPaymentMethodId.ts +72 -0
  7. package/example/src/chevre/migratePayTransactionPaymentMethodIdentifier.ts +78 -0
  8. package/example/src/chevre/processPay.ts +3 -4
  9. package/example/src/chevre/publishPermitOwnershipInfoToken.ts +56 -0
  10. package/example/src/chevre/pullAddOnsFromOffer.ts +26 -0
  11. package/example/src/chevre/searchAggregateOffers.ts +48 -0
  12. package/example/src/chevre/searchEventTicketOffers.ts +3 -1
  13. package/example/src/chevre/searchEvents.ts +9 -7
  14. package/example/src/chevre/searchOffersByCatalog.ts +9 -5
  15. package/example/src/chevre/searchOffersFromAggregateOffer.ts +168 -0
  16. package/example/src/chevre/searchOrders.ts +9 -7
  17. package/example/src/chevre/sync2aggregateOffer.ts +27 -0
  18. package/example/src/chevre/syncAggregateOffer.ts +25 -0
  19. package/lib/chevre/emailMessageBuilder.js +6 -5
  20. package/lib/chevre/repo/aggregateOffer.d.ts +62 -0
  21. package/lib/chevre/repo/aggregateOffer.js +534 -0
  22. package/lib/chevre/repo/assetTransaction.d.ts +16 -1
  23. package/lib/chevre/repo/assetTransaction.js +54 -2
  24. package/lib/chevre/repo/mongoose/schemas/aggregateOffer.d.ts +74 -0
  25. package/lib/chevre/repo/mongoose/schemas/aggregateOffer.js +177 -0
  26. package/lib/chevre/repo/mongoose/schemas/authorization.d.ts +3 -3
  27. package/lib/chevre/repo/mongoose/schemas/creativeWork.d.ts +3 -3
  28. package/lib/chevre/repo/mongoose/schemas/event.d.ts +3 -3
  29. package/lib/chevre/repo/mongoose/schemas/offer.d.ts +24 -33
  30. package/lib/chevre/repo/mongoose/schemas/offer.js +4 -3
  31. package/lib/chevre/repo/mongoose/schemas/order.d.ts +3 -0
  32. package/lib/chevre/repo/mongoose/schemas/order.js +7 -0
  33. package/lib/chevre/repo/mongoose/schemas/priceSpecification.d.ts +9 -9
  34. package/lib/chevre/repo/mongoose/schemas/product.d.ts +3 -3
  35. package/lib/chevre/repo/mongoose/schemas/project.d.ts +3 -3
  36. package/lib/chevre/repo/mongoose/schemas/task.d.ts +3 -0
  37. package/lib/chevre/repo/mongoose/schemas/task.js +8 -0
  38. package/lib/chevre/repo/offer.d.ts +82 -47
  39. package/lib/chevre/repo/offer.js +1279 -289
  40. package/lib/chevre/repo/offerCatalog.d.ts +6 -0
  41. package/lib/chevre/repo/offerCatalog.js +13 -0
  42. package/lib/chevre/repo/order.d.ts +15 -0
  43. package/lib/chevre/repo/order.js +58 -26
  44. package/lib/chevre/repo/task.d.ts +7 -1
  45. package/lib/chevre/repo/task.js +100 -0
  46. package/lib/chevre/repository.d.ts +3 -0
  47. package/lib/chevre/repository.js +5 -1
  48. package/lib/chevre/service/aggregation/event/aggregateScreeningEvent.js +2 -1
  49. package/lib/chevre/service/aggregation/event/aggregateUseActionsOnEvent.js +2 -1
  50. package/lib/chevre/service/assetTransaction/pay/account/validation.js +2 -2
  51. package/lib/chevre/service/assetTransaction/pay/factory.js +26 -18
  52. package/lib/chevre/service/assetTransaction/pay/potentialActions.js +3 -3
  53. package/lib/chevre/service/assetTransaction/pay.js +65 -46
  54. package/lib/chevre/service/assetTransaction/refund/factory.js +8 -2
  55. package/lib/chevre/service/assetTransaction/registerService.js +2 -1
  56. package/lib/chevre/service/assetTransaction/reserve.js +111 -35
  57. package/lib/chevre/service/delivery.js +17 -0
  58. package/lib/chevre/service/offer/event/authorize.js +39 -35
  59. package/lib/chevre/service/offer/event/factory.d.ts +1 -1
  60. package/lib/chevre/service/offer/event/factory.js +8 -8
  61. package/lib/chevre/service/offer/event/importFromCOA.d.ts +2 -0
  62. package/lib/chevre/service/offer/event/searchEventTicketOffers.d.ts +1 -0
  63. package/lib/chevre/service/offer/event/searchEventTicketOffers.js +6 -3
  64. package/lib/chevre/service/offer/event/voidTransaction.js +57 -36
  65. package/lib/chevre/service/offer/eventServiceByCOA/factory.d.ts +2 -1
  66. package/lib/chevre/service/offer/eventServiceByCOA/factory.js +7 -11
  67. package/lib/chevre/service/offer/eventServiceByCOA.js +55 -27
  68. package/lib/chevre/service/offer/factory.d.ts +12 -4
  69. package/lib/chevre/service/offer/factory.js +9 -11
  70. package/lib/chevre/service/offer/product/searchProductOffers.d.ts +8 -1
  71. package/lib/chevre/service/offer/product/searchProductOffers.js +10 -3
  72. package/lib/chevre/service/offer/product.d.ts +1 -0
  73. package/lib/chevre/service/offer/product.js +3 -2
  74. package/lib/chevre/service/offer.d.ts +1 -0
  75. package/lib/chevre/service/offer.js +7 -1
  76. package/lib/chevre/service/order/confirmPayTransaction.d.ts +0 -2
  77. package/lib/chevre/service/order/confirmPayTransaction.js +29 -40
  78. package/lib/chevre/service/order/onAssetTransactionStatusChanged.d.ts +27 -0
  79. package/lib/chevre/service/order/onAssetTransactionStatusChanged.js +226 -0
  80. package/lib/chevre/service/order/onOrderStatusChanged/factory.d.ts +8 -6
  81. package/lib/chevre/service/order/onOrderStatusChanged/factory.js +80 -57
  82. package/lib/chevre/service/order/onOrderStatusChanged.js +81 -54
  83. package/lib/chevre/service/order/payOrder.d.ts +2 -10
  84. package/lib/chevre/service/order/payOrder.js +4 -45
  85. package/lib/chevre/service/order/placeOrder.js +11 -13
  86. package/lib/chevre/service/order.d.ts +3 -1
  87. package/lib/chevre/service/order.js +6 -2
  88. package/lib/chevre/service/payment/any/factory.js +33 -8
  89. package/lib/chevre/service/payment/any.js +30 -21
  90. package/lib/chevre/service/payment/creditCard.js +12 -12
  91. package/lib/chevre/service/payment/movieTicket/validation.js +2 -2
  92. package/lib/chevre/service/payment/movieTicket.js +10 -11
  93. package/lib/chevre/service/payment/paymentCard.js +9 -12
  94. package/lib/chevre/service/project.js +1 -1
  95. package/lib/chevre/service/reserve/checkInReservation.d.ts +8 -0
  96. package/lib/chevre/service/reserve/checkInReservation.js +3 -2
  97. package/lib/chevre/service/reserve/potentialActions/onReservationCanceled.d.ts +3 -0
  98. package/lib/chevre/service/reserve/potentialActions/onReservationCanceled.js +4 -5
  99. package/lib/chevre/service/reserve/potentialActions/onReservationCheckedIn.d.ts +8 -0
  100. package/lib/chevre/service/reserve/potentialActions/onReservationCheckedIn.js +16 -11
  101. package/lib/chevre/service/reserve/potentialActions/onReservationConfirmed.js +2 -1
  102. package/lib/chevre/service/reserve/potentialActions/onReservationUsed.d.ts +3 -0
  103. package/lib/chevre/service/reserve/potentialActions/onReservationUsed.js +3 -5
  104. package/lib/chevre/service/task/confirmPayTransaction.js +1 -3
  105. package/lib/chevre/service/task/importOffersFromCOA.js +3 -0
  106. package/lib/chevre/service/task/onAssetTransactionStatusChanged.d.ts +6 -0
  107. package/lib/chevre/service/task/onAssetTransactionStatusChanged.js +37 -0
  108. package/lib/chevre/service/task/onAuthorizationCreated.js +5 -1
  109. package/lib/chevre/service/task/onOrderPaymentCompleted.d.ts +6 -0
  110. package/lib/chevre/service/task/onOrderPaymentCompleted.js +35 -0
  111. package/lib/chevre/service/task/onResourceUpdated/onResourceDeleted.d.ts +2 -0
  112. package/lib/chevre/service/task/onResourceUpdated/onResourceDeleted.js +7 -0
  113. package/lib/chevre/service/task/onResourceUpdated/syncOfferCatalog.d.ts +17 -0
  114. package/lib/chevre/service/task/onResourceUpdated/syncOfferCatalog.js +60 -0
  115. package/lib/chevre/service/task/onResourceUpdated.js +12 -0
  116. package/lib/chevre/service/task/returnPayTransaction.js +8 -3
  117. package/lib/chevre/service/task/syncAggregateOffer.d.ts +7 -0
  118. package/lib/chevre/service/task/syncAggregateOffer.js +23 -0
  119. package/lib/chevre/service/transaction/placeOrderInProgress/result.js +32 -16
  120. package/lib/chevre/service/transaction/placeOrderInProgress/validation/validateMovieTicket.js +13 -11
  121. package/lib/chevre/service/transaction/placeOrderInProgress/validation.js +53 -17
  122. package/lib/chevre/service/transaction/placeOrderInProgress.js +4 -1
  123. package/lib/chevre/service/transaction/returnOrder/potentialActions/returnPaymentMethod.js +7 -6
  124. package/lib/chevre/service/transaction/returnOrder.js +5 -1
  125. package/lib/chevre/settings.d.ts +5 -3
  126. package/lib/chevre/settings.js +6 -6
  127. package/package.json +3 -3
  128. package/example/src/chevre/migrateAuthorizePaymentActionResult.ts +0 -83
  129. package/example/src/chevre/migrateEventOrganizer.ts +0 -154
@@ -12,16 +12,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.confirmPayTransaction = void 0;
13
13
  const factory = require("../../factory");
14
14
  const PayTransactionService = require("../assetTransaction/pay");
15
- const payOrder_1 = require("../order/payOrder");
16
15
  function confirmPayTransaction(data) {
17
16
  return (repos) => __awaiter(this, void 0, void 0, function* () {
17
+ var _a, _b;
18
18
  // アクション開始
19
19
  const action = yield repos.action.start(data);
20
20
  try {
21
21
  for (const confirmingTransaction of data.object) {
22
- yield PayTransactionService.confirm({
23
- transactionNumber: confirmingTransaction.transactionNumber,
24
- potentialActions: {
22
+ yield PayTransactionService.confirm(Object.assign({ transactionNumber: confirmingTransaction.transactionNumber, potentialActions: {
25
23
  pay: {
26
24
  purpose: {
27
25
  typeOf: data.purpose.typeOf,
@@ -29,8 +27,9 @@ function confirmPayTransaction(data) {
29
27
  orderNumber: data.purpose.orderNumber
30
28
  }
31
29
  }
32
- }
33
- })({
30
+ } }, (typeof ((_b = (_a = confirmingTransaction.object) === null || _a === void 0 ? void 0 : _a.paymentMethod) === null || _b === void 0 ? void 0 : _b.identifier) === 'string')
31
+ ? { object: { paymentMethod: { identifier: confirmingTransaction.object.paymentMethod.identifier } } }
32
+ : undefined))({
34
33
  action: repos.action,
35
34
  accountingReport: repos.accountingReport,
36
35
  assetTransaction: repos.assetTransaction,
@@ -59,50 +58,40 @@ function confirmPayTransaction(data) {
59
58
  yield repos.action.complete({ typeOf: action.typeOf, id: action.id, result: actionResult });
60
59
  // processOrder連携(2023-08-23~)
61
60
  yield onConfirmed(data)({
62
- assetTransaction: repos.assetTransaction,
63
- order: repos.order,
64
- registerActionInProgress: repos.registerServiceInProgress,
65
- task: repos.task,
66
- transaction: repos.transaction
61
+ task: repos.task
67
62
  });
68
63
  });
69
64
  }
70
65
  exports.confirmPayTransaction = confirmPayTransaction;
71
66
  function onConfirmed(params) {
72
67
  return (repos) => __awaiter(this, void 0, void 0, function* () {
68
+ var _a, _b;
73
69
  if (params.processOrder === true) {
74
- // 注文のpaymentMethodIdを取得
75
- const order = yield repos.order.findByOrderNumber({
76
- orderNumber: params.purpose.orderNumber,
77
- project: { id: params.project.id },
78
- inclusion: ['paymentMethods'],
79
- exclusion: []
80
- });
81
- // PayTransactionのステータス検証
82
- let allPayTransactionConfirmed = false;
83
- const paymentMethodIds = order.paymentMethods.filter((invoice) => typeof invoice.paymentMethodId === 'string' && invoice.paymentMethodId.length > 0)
84
- .map((invoice) => invoice.paymentMethodId);
85
- if (paymentMethodIds.length > 0) {
86
- const referencedPayTransactions = yield repos.assetTransaction.search({
87
- project: { id: { $eq: params.project.id } },
88
- typeOf: factory.assetTransactionType.Pay,
89
- transactionNumber: { $in: paymentMethodIds }
90
- }, ['status']);
91
- allPayTransactionConfirmed =
92
- referencedPayTransactions.every((payTransation) => payTransation.status === factory.transactionStatusType.Confirmed);
93
- }
94
- else {
95
- allPayTransactionConfirmed = true;
96
- }
97
- if (allPayTransactionConfirmed) {
98
- yield (0, payOrder_1.payOrder)({
99
- project: { id: params.project.id },
100
- object: {
70
+ for (const confirmingTransaction of params.object) {
71
+ // タスク冪等作成
72
+ const onAssetTransactionStatusChangedTaskData = {
73
+ project: { id: params.project.id, typeOf: factory.organizationType.Project },
74
+ object: Object.assign({ typeOf: factory.assetTransactionType.Pay, transactionNumber: confirmingTransaction.transactionNumber, status: factory.transactionStatusType.Confirmed }, (typeof ((_b = (_a = confirmingTransaction.object) === null || _a === void 0 ? void 0 : _a.paymentMethod) === null || _b === void 0 ? void 0 : _b.identifier) === 'string')
75
+ ? { object: { paymentMethod: { identifier: confirmingTransaction.object.paymentMethod.identifier } } }
76
+ : undefined),
77
+ purpose: {
101
78
  confirmationNumber: params.purpose.confirmationNumber,
102
- orderNumber: params.purpose.orderNumber
79
+ orderNumber: params.purpose.orderNumber,
80
+ typeOf: 'Order'
103
81
  },
104
82
  useOnOrderStatusChanged: params.useOnOrderStatusChanged === true
105
- })(repos);
83
+ };
84
+ const onAssetTransactionStatusChangedTask = {
85
+ project: { id: params.project.id, typeOf: factory.organizationType.Project },
86
+ name: factory.taskName.OnAssetTransactionStatusChanged,
87
+ status: factory.taskStatus.Ready,
88
+ runsAt: new Date(),
89
+ remainingNumberOfTries: 10,
90
+ numberOfTried: 0,
91
+ executionResults: [],
92
+ data: onAssetTransactionStatusChangedTaskData
93
+ };
94
+ yield repos.task.createOnAssetTransactionStatusChangedTaskIfNotExist(onAssetTransactionStatusChangedTask, { emitImmediately: true });
106
95
  }
107
96
  }
108
97
  });
@@ -0,0 +1,27 @@
1
+ import { RedisRepository as RegisterServiceInProgressRepo } from '../../repo/action/registerServiceInProgress';
2
+ import { MongoRepository as AssetTransactionRepo } from '../../repo/assetTransaction';
3
+ import { MongoRepository as OrderRepo } from '../../repo/order';
4
+ import { MongoRepository as TaskRepo } from '../../repo/task';
5
+ import { MongoRepository as TransactionRepo } from '../../repo/transaction';
6
+ import * as factory from '../../factory';
7
+ declare function onAssetTransactionStatusChanged(params: factory.task.IData<factory.taskName.OnAssetTransactionStatusChanged>): (repos: {
8
+ assetTransaction: AssetTransactionRepo;
9
+ order: OrderRepo;
10
+ registerActionInProgress: RegisterServiceInProgressRepo;
11
+ task: TaskRepo;
12
+ transaction: TransactionRepo;
13
+ }) => Promise<void>;
14
+ declare function paymentDue2Processing(params: {
15
+ project: {
16
+ id: string;
17
+ };
18
+ confirmationNumber: string;
19
+ orderNumber: string;
20
+ useOnOrderStatusChanged: boolean;
21
+ }): (repos: {
22
+ order: OrderRepo;
23
+ registerActionInProgress: RegisterServiceInProgressRepo;
24
+ task: TaskRepo;
25
+ transaction: TransactionRepo;
26
+ }) => Promise<void>;
27
+ export { onAssetTransactionStatusChanged, paymentDue2Processing };
@@ -0,0 +1,226 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.paymentDue2Processing = exports.onAssetTransactionStatusChanged = void 0;
13
+ const findPlaceOrderTransaction_1 = require("./findPlaceOrderTransaction");
14
+ const onOrderStatusChanged_1 = require("./onOrderStatusChanged");
15
+ const factory = require("../../factory");
16
+ function onAssetTransactionStatusChanged(params) {
17
+ return (repos) => __awaiter(this, void 0, void 0, function* () {
18
+ var _a, _b, _c, _d, _e;
19
+ if (typeof params.useOnOrderStatusChanged !== 'boolean') {
20
+ throw new factory.errors.Argument('useOnOrderStatusChanged', 'must be boolean');
21
+ }
22
+ switch (params.object.status) {
23
+ case factory.transactionStatusType.Confirmed:
24
+ switch (params.object.typeOf) {
25
+ case factory.assetTransactionType.Pay:
26
+ const orderNumber = (_a = params.purpose) === null || _a === void 0 ? void 0 : _a.orderNumber;
27
+ const confirmationNumber = (_b = params.purpose) === null || _b === void 0 ? void 0 : _b.confirmationNumber;
28
+ // 確定時の決済方法区分指定(2023-08-29~)
29
+ const specifiedPaymentMethodIdentifire = (_e = (_d = (_c = params.object) === null || _c === void 0 ? void 0 : _c.object) === null || _d === void 0 ? void 0 : _d.paymentMethod) === null || _e === void 0 ? void 0 : _e.identifier;
30
+ if (typeof specifiedPaymentMethodIdentifire === 'string' && specifiedPaymentMethodIdentifire.length > 0) {
31
+ yield fixPaymentMethodIdentifierIfPossible({
32
+ project: { id: params.project.id },
33
+ paymentMethodId: params.object.transactionNumber,
34
+ paymentMethod: { identifier: specifiedPaymentMethodIdentifire },
35
+ referencesOrder: { orderNumber }
36
+ })(repos);
37
+ }
38
+ if (typeof orderNumber === 'string' && typeof confirmationNumber === 'string') {
39
+ // PayTransactionのステータス検証
40
+ const processable = yield isProcessable({ project: { id: params.project.id }, orderNumber })(repos);
41
+ if (processable) {
42
+ yield paymentDue2Processing({
43
+ project: { id: params.project.id },
44
+ confirmationNumber,
45
+ orderNumber,
46
+ useOnOrderStatusChanged: params.useOnOrderStatusChanged
47
+ })(repos);
48
+ }
49
+ }
50
+ break;
51
+ default:
52
+ // no op
53
+ }
54
+ break;
55
+ case factory.transactionStatusType.Canceled:
56
+ case factory.transactionStatusType.Expired:
57
+ switch (params.object.typeOf) {
58
+ case factory.assetTransactionType.Pay:
59
+ // 注文が存在すればキャンセル(2023-08-30~)
60
+ yield cancelOrderIfExist({
61
+ project: { id: params.project.id },
62
+ paymentMethodId: params.object.transactionNumber,
63
+ useOnOrderStatusChanged: params.useOnOrderStatusChanged
64
+ })(repos);
65
+ break;
66
+ default:
67
+ // no op
68
+ }
69
+ break;
70
+ default:
71
+ // no op
72
+ }
73
+ });
74
+ }
75
+ exports.onAssetTransactionStatusChanged = onAssetTransactionStatusChanged;
76
+ function fixPaymentMethodIdentifierIfPossible(params) {
77
+ return (repos) => __awaiter(this, void 0, void 0, function* () {
78
+ const referencedPayTransactions = yield repos.assetTransaction.search({
79
+ project: { id: { $eq: params.project.id } },
80
+ typeOf: factory.assetTransactionType.Pay,
81
+ statuses: [factory.transactionStatusType.Confirmed],
82
+ transactionNumber: { $in: [params.paymentMethodId] }
83
+ }, ['object']);
84
+ const referencedPayTransaction = referencedPayTransactions.shift();
85
+ if (referencedPayTransaction === undefined) {
86
+ throw new factory.errors.NotFound(factory.assetTransactionType.Pay);
87
+ }
88
+ // 対面決済かつ決済取引上の決済方法区分と一致すれば、注文を変更
89
+ if (referencedPayTransaction.object.typeOf === factory.service.paymentService.PaymentServiceType.FaceToFace
90
+ && referencedPayTransaction.object.paymentMethod.identifier === params.paymentMethod.identifier) {
91
+ yield repos.order.fixPaymentMethodIdentifier({
92
+ project: { id: params.project.id },
93
+ orderNumber: params.referencesOrder.orderNumber,
94
+ invoice: {
95
+ paymentMethodId: params.paymentMethodId,
96
+ paymentMethod: { identifier: params.paymentMethod.identifier }
97
+ }
98
+ });
99
+ }
100
+ });
101
+ }
102
+ function isProcessable(params) {
103
+ return (repos) => __awaiter(this, void 0, void 0, function* () {
104
+ // 注文のpaymentMethodIdを取得
105
+ const order = yield repos.order.findByOrderNumber({
106
+ orderNumber: params.orderNumber,
107
+ project: { id: params.project.id },
108
+ inclusion: ['paymentMethods'],
109
+ exclusion: []
110
+ });
111
+ // PayTransactionのステータス検証
112
+ let allPayTransactionConfirmed = false;
113
+ const paymentMethodIds = order.paymentMethods.filter((invoice) => typeof invoice.paymentMethodId === 'string' && invoice.paymentMethodId.length > 0)
114
+ .map((invoice) => invoice.paymentMethodId);
115
+ if (paymentMethodIds.length > 0) {
116
+ const referencedPayTransactions = yield repos.assetTransaction.search({
117
+ project: { id: { $eq: params.project.id } },
118
+ typeOf: factory.assetTransactionType.Pay,
119
+ transactionNumber: { $in: paymentMethodIds }
120
+ }, ['status']);
121
+ allPayTransactionConfirmed =
122
+ referencedPayTransactions.every((payTransation) => payTransation.status === factory.transactionStatusType.Confirmed);
123
+ }
124
+ else {
125
+ allPayTransactionConfirmed = true;
126
+ }
127
+ return allPayTransactionConfirmed;
128
+ });
129
+ }
130
+ function paymentDue2Processing(params) {
131
+ return (repos) => __awaiter(this, void 0, void 0, function* () {
132
+ const placeOrderTransaction = yield (0, findPlaceOrderTransaction_1.findPlaceOrderTransaction)({
133
+ project: { id: params.project.id },
134
+ confirmationNumber: params.confirmationNumber,
135
+ orderNumber: params.orderNumber
136
+ })({ transaction: repos.transaction });
137
+ let order = yield repos.order.findByOrderNumber({
138
+ orderNumber: params.orderNumber,
139
+ project: { id: params.project.id },
140
+ inclusion: [],
141
+ exclusion: []
142
+ });
143
+ try {
144
+ order = yield repos.order.changeStatus({
145
+ project: { id: order.project.id },
146
+ orderNumber: params.orderNumber,
147
+ orderStatus: factory.orderStatus.OrderProcessing,
148
+ previousOrderStatus: factory.orderStatus.OrderPaymentDue
149
+ });
150
+ }
151
+ catch (error) {
152
+ let throwsError = true;
153
+ // すでにステータスが煤でいた場合、OrderPaymentDue->OrderProcessingの処理自体は成功しているので、後処理を続行する
154
+ order = yield repos.order.findByOrderNumber({
155
+ orderNumber: params.orderNumber,
156
+ project: { id: params.project.id },
157
+ inclusion: [],
158
+ exclusion: []
159
+ });
160
+ if (order.orderStatus === factory.orderStatus.OrderDelivered
161
+ || order.orderStatus === factory.orderStatus.OrderReturned) {
162
+ throwsError = false;
163
+ }
164
+ if (throwsError) {
165
+ throw error;
166
+ }
167
+ }
168
+ if (params.useOnOrderStatusChanged) {
169
+ yield (0, onOrderStatusChanged_1.onOrderStatusChanged)({
170
+ order: Object.assign(Object.assign({}, order), { orderStatus: factory.orderStatus.OrderProcessing // 強制的にOrderProcessingとして処理する
171
+ }),
172
+ placeOrderTransaction
173
+ })({
174
+ registerActionInProgress: repos.registerActionInProgress,
175
+ task: repos.task
176
+ });
177
+ }
178
+ });
179
+ }
180
+ exports.paymentDue2Processing = paymentDue2Processing;
181
+ function cancelOrderIfExist(params) {
182
+ return (repos) => __awaiter(this, void 0, void 0, function* () {
183
+ if (params.paymentMethodId.length === 0) {
184
+ return;
185
+ }
186
+ // 注文のpaymentMethodIdを取得
187
+ const ordersByPaymentMethodId = yield repos.order.search({
188
+ limit: 1,
189
+ page: 1,
190
+ paymentMethods: {
191
+ paymentMethodIds: [params.paymentMethodId]
192
+ },
193
+ project: { id: { $eq: params.project.id } }
194
+ }, { confirmationNumber: 1, orderNumber: 1 });
195
+ const orderByPaymentMethodId = ordersByPaymentMethodId.shift();
196
+ if (orderByPaymentMethodId !== undefined) {
197
+ const placeOrderTransaction = yield (0, findPlaceOrderTransaction_1.findPlaceOrderTransaction)({
198
+ project: { id: params.project.id },
199
+ confirmationNumber: orderByPaymentMethodId.confirmationNumber,
200
+ orderNumber: orderByPaymentMethodId.orderNumber
201
+ })({ transaction: repos.transaction });
202
+ let order;
203
+ try {
204
+ order = yield repos.order.changeStatus({
205
+ project: { id: params.project.id },
206
+ orderNumber: orderByPaymentMethodId.orderNumber,
207
+ orderStatus: factory.orderStatus.OrderCancelled,
208
+ previousOrderStatus: factory.orderStatus.OrderPaymentDue
209
+ });
210
+ }
211
+ catch (error) {
212
+ throw error;
213
+ }
214
+ if (params.useOnOrderStatusChanged) {
215
+ yield (0, onOrderStatusChanged_1.onOrderStatusChanged)({
216
+ order: Object.assign(Object.assign({}, order), { orderStatus: factory.orderStatus.OrderCancelled // 強制的にOrderCancelledとして処理する
217
+ }),
218
+ placeOrderTransaction
219
+ })({
220
+ registerActionInProgress: repos.registerActionInProgress,
221
+ task: repos.task
222
+ });
223
+ }
224
+ }
225
+ });
226
+ }
@@ -21,20 +21,22 @@ export declare function createConfirmRegisterServiceActionObjectByOrder(params:
21
21
  order: factory.order.IOrder;
22
22
  }): factory.action.interact.confirm.registerService.IObject[];
23
23
  export type IExternalOrder = Pick<factory.order.IOrder, 'project' | 'typeOf' | 'seller' | 'customer' | 'confirmationNumber' | 'orderNumber' | 'price' | 'priceCurrency' | 'orderDate' | 'name' | 'orderStatus' | 'orderedItem' | 'paymentMethods'>;
24
- export declare function createOnPlaceOrderTasksByTransaction(params: {
25
- object: factory.order.IOrder | IExternalOrder;
26
- potentialActions?: factory.action.trade.order.IPotentialActions;
27
- }): factory.task.IAttributes<factory.taskName>[];
28
24
  /**
29
25
  * 注文配送後のアクション
30
26
  */
31
27
  export declare function createOnOrderSentTasksByTransaction(params: {
32
28
  potentialActions?: factory.action.transfer.send.order.IPotentialActions;
33
- }): (import("@chevre/factory/lib/task").IAttributes | import("@chevre/factory/lib/task/confirmMoneyTransfer").IAttributes | import("@chevre/factory/lib/task/confirmRegisterService").IAttributes | import("@chevre/factory/lib/task/confirmPayTransaction").IAttributes | import("@chevre/factory/lib/task/confirmRegisterServiceTransaction").IAttributes | import("@chevre/factory/lib/task/confirmReserveTransaction").IAttributes | import("@chevre/factory/lib/task/createEvent").IAttributes | import("@chevre/factory/lib/task/deleteTransaction").IAttributes | import("@chevre/factory/lib/task/givePointAward").IAttributes | import("@chevre/factory/lib/task/onAuthorizationCreated").IAttributes | import("@chevre/factory/lib/task/onEventChanged").IAttributes | import("@chevre/factory/lib/task/onResourceUpdated").IAttributes | import("@chevre/factory/lib/task/placeOrder").IAttributes | import("@chevre/factory/lib/task/returnOrder").IAttributes | import("@chevre/factory/lib/task/returnMoneyTransfer").IAttributes | import("@chevre/factory/lib/task/returnPayTransaction").IAttributes | import("@chevre/factory/lib/task/returnPointAward").IAttributes | import("@chevre/factory/lib/task/returnReserveTransaction").IAttributes | import("@chevre/factory/lib/task/sendEmailMessage").IAttributes | import("@chevre/factory/lib/task/sendOrder").IAttributes | import("@chevre/factory/lib/task/syncScreeningRooms").IAttributes | import("@chevre/factory/lib/task/triggerWebhook").IAttributes | import("@chevre/factory/lib/task/useReservation").IAttributes | import("@chevre/factory/lib/task/voidMoneyTransferTransaction").IAttributes | import("@chevre/factory/lib/task/voidPayTransaction").IAttributes | import("@chevre/factory/lib/task/voidRegisterServiceTransaction").IAttributes | import("@chevre/factory/lib/task/voidReserveTransaction").IAttributes)[];
29
+ }): (import("@chevre/factory/lib/task/syncAggregateOffer").IAttributes | import("@chevre/factory/lib/task").IAttributes | import("@chevre/factory/lib/task/confirmMoneyTransfer").IAttributes | import("@chevre/factory/lib/task/confirmRegisterService").IAttributes | import("@chevre/factory/lib/task/confirmPayTransaction").IAttributes | import("@chevre/factory/lib/task/confirmRegisterServiceTransaction").IAttributes | import("@chevre/factory/lib/task/confirmReserveTransaction").IAttributes | import("@chevre/factory/lib/task/createEvent").IAttributes | import("@chevre/factory/lib/task/deleteTransaction").IAttributes | import("@chevre/factory/lib/task/givePointAward").IAttributes | import("@chevre/factory/lib/task/onAssetTransactionStatusChanged").IAttributes | import("@chevre/factory/lib/task/onAuthorizationCreated").IAttributes | import("@chevre/factory/lib/task/onEventChanged").IAttributes | import("@chevre/factory/lib/task/onResourceUpdated").IAttributes | import("@chevre/factory/lib/task/onOrderPaymentCompleted").IAttributes | import("@chevre/factory/lib/task/placeOrder").IAttributes | import("@chevre/factory/lib/task/returnOrder").IAttributes | import("@chevre/factory/lib/task/returnMoneyTransfer").IAttributes | import("@chevre/factory/lib/task/returnPayTransaction").IAttributes | import("@chevre/factory/lib/task/returnPointAward").IAttributes | import("@chevre/factory/lib/task/returnReserveTransaction").IAttributes | import("@chevre/factory/lib/task/sendEmailMessage").IAttributes | import("@chevre/factory/lib/task/sendOrder").IAttributes | import("@chevre/factory/lib/task/syncScreeningRooms").IAttributes | import("@chevre/factory/lib/task/triggerWebhook").IAttributes | import("@chevre/factory/lib/task/useReservation").IAttributes | import("@chevre/factory/lib/task/voidMoneyTransferTransaction").IAttributes | import("@chevre/factory/lib/task/voidPayTransaction").IAttributes | import("@chevre/factory/lib/task/voidRegisterServiceTransaction").IAttributes | import("@chevre/factory/lib/task/voidReserveTransaction").IAttributes)[];
34
30
  /**
35
31
  * 注文返品後のアクション
36
32
  */
37
33
  export declare function createOnOrderReturnedTasksByTransaction(params: {
38
34
  potentialActions?: factory.action.transfer.returnAction.order.IPotentialActions;
39
- }): (import("@chevre/factory/lib/task").IAttributes | import("@chevre/factory/lib/task/confirmMoneyTransfer").IAttributes | import("@chevre/factory/lib/task/confirmRegisterService").IAttributes | import("@chevre/factory/lib/task/confirmPayTransaction").IAttributes | import("@chevre/factory/lib/task/confirmRegisterServiceTransaction").IAttributes | import("@chevre/factory/lib/task/confirmReserveTransaction").IAttributes | import("@chevre/factory/lib/task/createEvent").IAttributes | import("@chevre/factory/lib/task/deleteTransaction").IAttributes | import("@chevre/factory/lib/task/givePointAward").IAttributes | import("@chevre/factory/lib/task/onAuthorizationCreated").IAttributes | import("@chevre/factory/lib/task/onEventChanged").IAttributes | import("@chevre/factory/lib/task/onResourceUpdated").IAttributes | import("@chevre/factory/lib/task/placeOrder").IAttributes | import("@chevre/factory/lib/task/returnOrder").IAttributes | import("@chevre/factory/lib/task/returnMoneyTransfer").IAttributes | import("@chevre/factory/lib/task/returnPayTransaction").IAttributes | import("@chevre/factory/lib/task/returnPointAward").IAttributes | import("@chevre/factory/lib/task/returnReserveTransaction").IAttributes | import("@chevre/factory/lib/task/sendEmailMessage").IAttributes | import("@chevre/factory/lib/task/sendOrder").IAttributes | import("@chevre/factory/lib/task/syncScreeningRooms").IAttributes | import("@chevre/factory/lib/task/triggerWebhook").IAttributes | import("@chevre/factory/lib/task/useReservation").IAttributes | import("@chevre/factory/lib/task/voidMoneyTransferTransaction").IAttributes | import("@chevre/factory/lib/task/voidPayTransaction").IAttributes | import("@chevre/factory/lib/task/voidRegisterServiceTransaction").IAttributes | import("@chevre/factory/lib/task/voidReserveTransaction").IAttributes)[];
35
+ }): (import("@chevre/factory/lib/task/syncAggregateOffer").IAttributes | import("@chevre/factory/lib/task").IAttributes | import("@chevre/factory/lib/task/confirmMoneyTransfer").IAttributes | import("@chevre/factory/lib/task/confirmRegisterService").IAttributes | import("@chevre/factory/lib/task/confirmPayTransaction").IAttributes | import("@chevre/factory/lib/task/confirmRegisterServiceTransaction").IAttributes | import("@chevre/factory/lib/task/confirmReserveTransaction").IAttributes | import("@chevre/factory/lib/task/createEvent").IAttributes | import("@chevre/factory/lib/task/deleteTransaction").IAttributes | import("@chevre/factory/lib/task/givePointAward").IAttributes | import("@chevre/factory/lib/task/onAssetTransactionStatusChanged").IAttributes | import("@chevre/factory/lib/task/onAuthorizationCreated").IAttributes | import("@chevre/factory/lib/task/onEventChanged").IAttributes | import("@chevre/factory/lib/task/onResourceUpdated").IAttributes | import("@chevre/factory/lib/task/onOrderPaymentCompleted").IAttributes | import("@chevre/factory/lib/task/placeOrder").IAttributes | import("@chevre/factory/lib/task/returnOrder").IAttributes | import("@chevre/factory/lib/task/returnMoneyTransfer").IAttributes | import("@chevre/factory/lib/task/returnPayTransaction").IAttributes | import("@chevre/factory/lib/task/returnPointAward").IAttributes | import("@chevre/factory/lib/task/returnReserveTransaction").IAttributes | import("@chevre/factory/lib/task/sendEmailMessage").IAttributes | import("@chevre/factory/lib/task/sendOrder").IAttributes | import("@chevre/factory/lib/task/syncScreeningRooms").IAttributes | import("@chevre/factory/lib/task/triggerWebhook").IAttributes | import("@chevre/factory/lib/task/useReservation").IAttributes | import("@chevre/factory/lib/task/voidMoneyTransferTransaction").IAttributes | import("@chevre/factory/lib/task/voidPayTransaction").IAttributes | import("@chevre/factory/lib/task/voidRegisterServiceTransaction").IAttributes | import("@chevre/factory/lib/task/voidReserveTransaction").IAttributes)[];
36
+ /**
37
+ * 注文中止時のアクション
38
+ */
39
+ export declare function createOnOrderCancelledTasksByTransaction(params: {
40
+ transaction?: factory.transaction.placeOrder.ITransaction;
41
+ }): (import("@chevre/factory/lib/task/syncAggregateOffer").IAttributes | import("@chevre/factory/lib/task").IAttributes | import("@chevre/factory/lib/task/confirmMoneyTransfer").IAttributes | import("@chevre/factory/lib/task/confirmRegisterService").IAttributes | import("@chevre/factory/lib/task/confirmPayTransaction").IAttributes | import("@chevre/factory/lib/task/confirmRegisterServiceTransaction").IAttributes | import("@chevre/factory/lib/task/confirmReserveTransaction").IAttributes | import("@chevre/factory/lib/task/createEvent").IAttributes | import("@chevre/factory/lib/task/deleteTransaction").IAttributes | import("@chevre/factory/lib/task/givePointAward").IAttributes | import("@chevre/factory/lib/task/onAssetTransactionStatusChanged").IAttributes | import("@chevre/factory/lib/task/onAuthorizationCreated").IAttributes | import("@chevre/factory/lib/task/onEventChanged").IAttributes | import("@chevre/factory/lib/task/onResourceUpdated").IAttributes | import("@chevre/factory/lib/task/onOrderPaymentCompleted").IAttributes | import("@chevre/factory/lib/task/placeOrder").IAttributes | import("@chevre/factory/lib/task/returnOrder").IAttributes | import("@chevre/factory/lib/task/returnMoneyTransfer").IAttributes | import("@chevre/factory/lib/task/returnPayTransaction").IAttributes | import("@chevre/factory/lib/task/returnPointAward").IAttributes | import("@chevre/factory/lib/task/returnReserveTransaction").IAttributes | import("@chevre/factory/lib/task/sendEmailMessage").IAttributes | import("@chevre/factory/lib/task/sendOrder").IAttributes | import("@chevre/factory/lib/task/syncScreeningRooms").IAttributes | import("@chevre/factory/lib/task/triggerWebhook").IAttributes | import("@chevre/factory/lib/task/useReservation").IAttributes | import("@chevre/factory/lib/task/voidMoneyTransferTransaction").IAttributes | import("@chevre/factory/lib/task/voidPayTransaction").IAttributes | import("@chevre/factory/lib/task/voidRegisterServiceTransaction").IAttributes | import("@chevre/factory/lib/task/voidReserveTransaction").IAttributes)[];
40
42
  export {};
@@ -10,7 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  var _a;
12
12
  Object.defineProperty(exports, "__esModule", { value: true });
13
- exports.createOnOrderReturnedTasksByTransaction = exports.createOnOrderSentTasksByTransaction = exports.createOnPlaceOrderTasksByTransaction = exports.createConfirmRegisterServiceActionObjectByOrder = exports.createConfirmReservationActionObject4COAByOrder = exports.createConfirmReservationActionObject4ChevreByOrder = exports.createInformTasks = exports.getOrderWithToken = void 0;
13
+ exports.createOnOrderCancelledTasksByTransaction = exports.createOnOrderReturnedTasksByTransaction = exports.createOnOrderSentTasksByTransaction = exports.createConfirmRegisterServiceActionObjectByOrder = exports.createConfirmReservationActionObject4COAByOrder = exports.createConfirmReservationActionObject4ChevreByOrder = exports.createInformTasks = exports.getOrderWithToken = void 0;
14
14
  const google_libphonenumber_1 = require("google-libphonenumber");
15
15
  const jwt = require("jsonwebtoken");
16
16
  const util_1 = require("util");
@@ -262,62 +262,38 @@ function createConfirmRegisterServiceActionObjectByOrder(params) {
262
262
  });
263
263
  }
264
264
  exports.createConfirmRegisterServiceActionObjectByOrder = createConfirmRegisterServiceActionObjectByOrder;
265
- function createOnPlaceOrderTasksByTransaction(params) {
266
- const potentialActions = params.potentialActions;
267
- const now = new Date();
268
- // potentialActionsのためのタスクを生成
269
- const taskAttributes = [];
270
- // tslint:disable-next-line:no-single-line-block-comment
271
- /* istanbul ignore else */
272
- if (potentialActions !== undefined) {
273
- // 冗長なsendOrderタスク作成を回避(createSendOrderTransactionTaskIfNotExistへ移行)(2023-08-24~)
274
- // tslint:disable-next-line:no-single-line-block-comment
275
- /* istanbul ignore else */
276
- // if (potentialActions.sendOrder !== undefined) {
277
- // const sendOrderTaskData: factory.task.IData<factory.taskName.SendOrder> = {
278
- // project: potentialActions.sendOrder.project,
279
- // object: {
280
- // ...potentialActions.sendOrder.object,
281
- // confirmationNumber: params.object.confirmationNumber
282
- // }
283
- // // 廃止(2023-08-21~)
284
- // // ...(potentialActions.sendOrder.potentialActions !== undefined)
285
- // // ? { potentialActions: potentialActions.sendOrder.potentialActions }
286
- // // : undefined
287
- // };
288
- // const sendOrderTask: factory.task.IAttributes<factory.taskName.SendOrder> = {
289
- // project: potentialActions.sendOrder.project,
290
- // name: factory.taskName.SendOrder,
291
- // status: factory.taskStatus.Ready,
292
- // runsAt: now, // なるはやで実行
293
- // remainingNumberOfTries: 10,
294
- // numberOfTried: 0,
295
- // executionResults: [],
296
- // data: sendOrderTaskData
297
- // };
298
- // taskAttributes.push(sendOrderTask);
299
- // }
300
- // ポイント付与
301
- // tslint:disable-next-line:no-single-line-block-comment
302
- /* istanbul ignore else */
303
- if (Array.isArray(potentialActions.givePointAward)) {
304
- taskAttributes.push(...potentialActions.givePointAward.map((a) => {
305
- return {
306
- project: a.project,
307
- name: factory.taskName.GivePointAward,
308
- status: factory.taskStatus.Ready,
309
- runsAt: now,
310
- remainingNumberOfTries: 10,
311
- numberOfTried: 0,
312
- executionResults: [],
313
- data: a
314
- };
315
- }));
316
- }
317
- }
318
- return taskAttributes;
319
- }
320
- exports.createOnPlaceOrderTasksByTransaction = createOnPlaceOrderTasksByTransaction;
265
+ // export function createOnPlaceOrderTasksByTransaction(params: {
266
+ // object: factory.order.IOrder | IExternalOrder;
267
+ // potentialActions?: factory.action.trade.order.IPotentialActions;
268
+ // }): factory.task.IAttributes<factory.taskName>[] {
269
+ // const potentialActions = params.potentialActions;
270
+ // const now = new Date();
271
+ // // potentialActionsのためのタスクを生成
272
+ // const taskAttributes: factory.task.IAttributes<factory.taskName>[] = [];
273
+ // // tslint:disable-next-line:no-single-line-block-comment
274
+ // /* istanbul ignore else */
275
+ // if (potentialActions !== undefined) {
276
+ // // ポイント付与
277
+ // // tslint:disable-next-line:no-single-line-block-comment
278
+ // /* istanbul ignore else */
279
+ // if (Array.isArray(potentialActions.givePointAward)) {
280
+ // taskAttributes.push(...potentialActions.givePointAward.map(
281
+ // (a): factory.task.IAttributes<factory.taskName.GivePointAward> => {
282
+ // return {
283
+ // project: a.project,
284
+ // name: factory.taskName.GivePointAward,
285
+ // status: factory.taskStatus.Ready,
286
+ // runsAt: now, // なるはやで実行
287
+ // remainingNumberOfTries: 10,
288
+ // numberOfTried: 0,
289
+ // executionResults: [],
290
+ // data: a
291
+ // };
292
+ // }));
293
+ // }
294
+ // }
295
+ // return taskAttributes;
296
+ // }
321
297
  /**
322
298
  * 注文配送後のアクション
323
299
  */
@@ -442,3 +418,50 @@ function createOnOrderReturnedTasksByTransaction(params) {
442
418
  return taskAttributes;
443
419
  }
444
420
  exports.createOnOrderReturnedTasksByTransaction = createOnOrderReturnedTasksByTransaction;
421
+ /**
422
+ * 注文中止時のアクション
423
+ */
424
+ function createOnOrderCancelledTasksByTransaction(params) {
425
+ var _a;
426
+ const now = new Date();
427
+ const taskAttributes = [];
428
+ if (typeof ((_a = params.transaction) === null || _a === void 0 ? void 0 : _a.id) === 'string') {
429
+ const voidPaymentTaskAttributes = {
430
+ project: params.transaction.project,
431
+ name: factory.taskName.VoidPayTransaction,
432
+ status: factory.taskStatus.Ready,
433
+ runsAt: now,
434
+ remainingNumberOfTries: 10,
435
+ numberOfTried: 0,
436
+ executionResults: [],
437
+ data: {
438
+ project: params.transaction.project,
439
+ purpose: {
440
+ typeOf: params.transaction.typeOf,
441
+ id: params.transaction.id,
442
+ result: { order: { orderStatus: factory.orderStatus.OrderCancelled } }
443
+ }
444
+ }
445
+ };
446
+ const voidReserveTaskAttributes = {
447
+ project: params.transaction.project,
448
+ name: factory.taskName.VoidReserveTransaction,
449
+ status: factory.taskStatus.Ready,
450
+ runsAt: now,
451
+ remainingNumberOfTries: 10,
452
+ numberOfTried: 0,
453
+ executionResults: [],
454
+ data: {
455
+ project: params.transaction.project,
456
+ purpose: {
457
+ typeOf: params.transaction.typeOf,
458
+ id: params.transaction.id,
459
+ result: { order: { orderStatus: factory.orderStatus.OrderCancelled } }
460
+ }
461
+ }
462
+ };
463
+ taskAttributes.push(voidPaymentTaskAttributes, voidReserveTaskAttributes);
464
+ }
465
+ return taskAttributes;
466
+ }
467
+ exports.createOnOrderCancelledTasksByTransaction = createOnOrderCancelledTasksByTransaction;