@chevre/domain 21.8.0-alpha.2 → 21.8.0-alpha.21

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 (59) hide show
  1. package/example/src/chevre/db/stats.ts +22 -0
  2. package/example/src/chevre/migrateOrderPaymentMethodIdentifier.ts +81 -0
  3. package/example/src/chevre/migratePayTransactionPaymentMethodId.ts +72 -0
  4. package/example/src/chevre/migratePayTransactionPaymentMethodIdentifier.ts +78 -0
  5. package/example/src/chevre/processPay.ts +3 -4
  6. package/example/src/chevre/searchTasks.ts +31 -0
  7. package/lib/chevre/repo/assetTransaction.d.ts +16 -1
  8. package/lib/chevre/repo/assetTransaction.js +54 -2
  9. package/lib/chevre/repo/mongoose/schemas/order.d.ts +3 -0
  10. package/lib/chevre/repo/mongoose/schemas/order.js +1 -0
  11. package/lib/chevre/repo/mongoose/schemas/task.js +6 -0
  12. package/lib/chevre/repo/order.d.ts +15 -0
  13. package/lib/chevre/repo/order.js +34 -1
  14. package/lib/chevre/repo/task.d.ts +4 -1
  15. package/lib/chevre/repo/task.js +108 -22
  16. package/lib/chevre/service/assetTransaction/pay/account/validation.js +2 -2
  17. package/lib/chevre/service/assetTransaction/pay/factory.js +5 -3
  18. package/lib/chevre/service/assetTransaction/pay/potentialActions.js +3 -3
  19. package/lib/chevre/service/assetTransaction/pay.js +65 -46
  20. package/lib/chevre/service/assetTransaction/reserve.js +48 -7
  21. package/lib/chevre/service/delivery.js +17 -0
  22. package/lib/chevre/service/offer/event/voidTransaction.js +7 -2
  23. package/lib/chevre/service/order/confirmPayTransaction.d.ts +0 -2
  24. package/lib/chevre/service/order/confirmPayTransaction.js +29 -40
  25. package/lib/chevre/service/order/onAssetTransactionStatusChanged.d.ts +27 -0
  26. package/lib/chevre/service/order/onAssetTransactionStatusChanged.js +226 -0
  27. package/lib/chevre/service/order/onOrderStatusChanged/factory.d.ts +8 -5
  28. package/lib/chevre/service/order/onOrderStatusChanged/factory.js +73 -87
  29. package/lib/chevre/service/order/onOrderStatusChanged.js +98 -73
  30. package/lib/chevre/service/order/payOrder.d.ts +2 -10
  31. package/lib/chevre/service/order/payOrder.js +4 -45
  32. package/lib/chevre/service/order/placeOrder.js +12 -11
  33. package/lib/chevre/service/order.d.ts +3 -1
  34. package/lib/chevre/service/order.js +6 -2
  35. package/lib/chevre/service/payment/any/factory.js +24 -7
  36. package/lib/chevre/service/payment/any.js +22 -18
  37. package/lib/chevre/service/payment/creditCard.js +12 -12
  38. package/lib/chevre/service/payment/movieTicket/validation.js +2 -2
  39. package/lib/chevre/service/payment/movieTicket.js +10 -11
  40. package/lib/chevre/service/payment/paymentCard.js +9 -12
  41. package/lib/chevre/service/reserve/potentialActions/onReservationCanceled.d.ts +3 -0
  42. package/lib/chevre/service/reserve/potentialActions/onReservationCanceled.js +1 -4
  43. package/lib/chevre/service/reserve/potentialActions/onReservationCheckedIn.js +1 -5
  44. package/lib/chevre/service/reserve/potentialActions/onReservationUsed.d.ts +3 -0
  45. package/lib/chevre/service/reserve/potentialActions/onReservationUsed.js +1 -4
  46. package/lib/chevre/service/task/confirmPayTransaction.js +1 -3
  47. package/lib/chevre/service/task/onAssetTransactionStatusChanged.d.ts +6 -0
  48. package/lib/chevre/service/task/onAssetTransactionStatusChanged.js +37 -0
  49. package/lib/chevre/service/task/onOrderPaymentCompleted.d.ts +6 -0
  50. package/lib/chevre/service/task/onOrderPaymentCompleted.js +35 -0
  51. package/lib/chevre/service/task/returnPayTransaction.js +8 -3
  52. package/lib/chevre/service/transaction/placeOrderInProgress/result.js +16 -4
  53. package/lib/chevre/service/transaction/placeOrderInProgress.js +4 -1
  54. package/lib/chevre/service/transaction/returnOrder/potentialActions/returnPaymentMethod.js +7 -6
  55. package/lib/chevre/service/transaction/returnOrder.js +5 -1
  56. package/lib/chevre/settings.d.ts +1 -2
  57. package/lib/chevre/settings.js +2 -5
  58. package/package.json +2 -2
  59. package/example/src/chevre/migrateEventOrganizer.ts +0 -154
@@ -31,7 +31,7 @@ class MongoRepository {
31
31
  }
32
32
  // tslint:disable-next-line:max-func-body-length
33
33
  static CREATE_MONGO_CONDITIONS(params) {
34
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u;
34
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x;
35
35
  const andConditions = [];
36
36
  const idEq = (_a = params.id) === null || _a === void 0 ? void 0 : _a.$eq;
37
37
  if (typeof idEq === 'string') {
@@ -115,32 +115,21 @@ class MongoRepository {
115
115
  }
116
116
  const objectIdEq = (_k = (_j = (_h = params.data) === null || _h === void 0 ? void 0 : _h.object) === null || _j === void 0 ? void 0 : _j.id) === null || _k === void 0 ? void 0 : _k.$eq;
117
117
  if (typeof objectIdEq === 'string') {
118
- andConditions.push({
119
- 'data.object.id': {
120
- $exists: true,
121
- $eq: objectIdEq
122
- }
123
- });
118
+ andConditions.push({ 'data.object.id': { $exists: true, $eq: objectIdEq } });
124
119
  }
125
- const objectTransactionNumberEq = (_o = (_m = (_l = params.data) === null || _l === void 0 ? void 0 : _l.object) === null || _m === void 0 ? void 0 : _m.transactionNumber) === null || _o === void 0 ? void 0 : _o.$eq;
120
+ const objectOrderNumberEq = (_o = (_m = (_l = params.data) === null || _l === void 0 ? void 0 : _l.object) === null || _m === void 0 ? void 0 : _m.orderNumber) === null || _o === void 0 ? void 0 : _o.$eq;
121
+ if (typeof objectOrderNumberEq === 'string') {
122
+ andConditions.push({ 'data.object.orderNumber': { $exists: true, $eq: objectOrderNumberEq } });
123
+ }
124
+ const objectTransactionNumberEq = (_r = (_q = (_p = params.data) === null || _p === void 0 ? void 0 : _p.object) === null || _q === void 0 ? void 0 : _q.transactionNumber) === null || _r === void 0 ? void 0 : _r.$eq;
126
125
  if (typeof objectTransactionNumberEq === 'string') {
127
- andConditions.push({
128
- 'data.object.transactionNumber': {
129
- $exists: true,
130
- $eq: objectTransactionNumberEq
131
- }
132
- });
126
+ andConditions.push({ 'data.object.transactionNumber': { $exists: true, $eq: objectTransactionNumberEq } });
133
127
  }
134
- const objectPurposeIdEq = (_r = (_q = (_p = params.data) === null || _p === void 0 ? void 0 : _p.purpose) === null || _q === void 0 ? void 0 : _q.id) === null || _r === void 0 ? void 0 : _r.$eq;
128
+ const objectPurposeIdEq = (_u = (_t = (_s = params.data) === null || _s === void 0 ? void 0 : _s.purpose) === null || _t === void 0 ? void 0 : _t.id) === null || _u === void 0 ? void 0 : _u.$eq;
135
129
  if (typeof objectPurposeIdEq === 'string') {
136
- andConditions.push({
137
- 'data.purpose.id': {
138
- $exists: true,
139
- $eq: objectPurposeIdEq
140
- }
141
- });
130
+ andConditions.push({ 'data.purpose.id': { $exists: true, $eq: objectPurposeIdEq } });
142
131
  }
143
- const objectPurposeOrderNumberEq = (_u = (_t = (_s = params.data) === null || _s === void 0 ? void 0 : _s.purpose) === null || _t === void 0 ? void 0 : _t.orderNumber) === null || _u === void 0 ? void 0 : _u.$eq;
132
+ const objectPurposeOrderNumberEq = (_x = (_w = (_v = params.data) === null || _v === void 0 ? void 0 : _v.purpose) === null || _w === void 0 ? void 0 : _w.orderNumber) === null || _x === void 0 ? void 0 : _x.$eq;
144
133
  if (typeof objectPurposeOrderNumberEq === 'string') {
145
134
  andConditions.push({
146
135
  'data.purpose.orderNumber': {
@@ -230,6 +219,103 @@ class MongoRepository {
230
219
  }
231
220
  });
232
221
  }
222
+ createConfirmReserveTransactionTaskIfNotExist(params, options) {
223
+ return __awaiter(this, void 0, void 0, function* () {
224
+ const createdTask = yield this.taskModel.findOneAndUpdate({
225
+ 'project.id': { $eq: params.project.id },
226
+ name: { $eq: params.name },
227
+ 'data.object.transactionNumber': {
228
+ $exists: true,
229
+ $eq: String(params.data.object.transactionNumber)
230
+ },
231
+ 'data.purpose.orderNumber': {
232
+ $exists: true,
233
+ $eq: String(params.data.purpose.orderNumber)
234
+ }
235
+ }, { $setOnInsert: params }, { new: true, upsert: true })
236
+ .select({ _id: 1 })
237
+ .exec();
238
+ if (options.emitImmediately) {
239
+ task_2.taskEventEmitter.emitTaskStatusChanged({
240
+ id: createdTask.id,
241
+ name: params.name,
242
+ status: factory.taskStatus.Ready
243
+ });
244
+ }
245
+ });
246
+ }
247
+ createOnAssetTransactionStatusChangedTaskIfNotExist(params, options) {
248
+ return __awaiter(this, void 0, void 0, function* () {
249
+ const createdTask = yield this.taskModel.findOneAndUpdate({
250
+ 'project.id': { $eq: params.project.id },
251
+ name: { $eq: params.name },
252
+ 'data.object.transactionNumber': {
253
+ $exists: true,
254
+ $eq: String(params.data.object.transactionNumber)
255
+ },
256
+ 'data.purpose.orderNumber': {
257
+ $exists: true,
258
+ $eq: String(params.data.purpose.orderNumber)
259
+ }
260
+ }, { $setOnInsert: params }, { new: true, upsert: true })
261
+ .select({ _id: 1 })
262
+ .exec();
263
+ if (options.emitImmediately) {
264
+ task_2.taskEventEmitter.emitTaskStatusChanged({
265
+ id: createdTask.id,
266
+ name: params.name,
267
+ status: factory.taskStatus.Ready
268
+ });
269
+ }
270
+ });
271
+ }
272
+ createSendOrderTaskIfNotExist(params, options) {
273
+ return __awaiter(this, void 0, void 0, function* () {
274
+ const createdTask = yield this.taskModel.findOneAndUpdate({
275
+ 'project.id': { $eq: params.project.id },
276
+ name: { $eq: params.name },
277
+ 'data.object.orderNumber': {
278
+ $exists: true,
279
+ $eq: String(params.data.object.orderNumber)
280
+ }
281
+ }, { $setOnInsert: params }, { new: true, upsert: true })
282
+ .select({ _id: 1 })
283
+ .exec();
284
+ if (options.emitImmediately) {
285
+ task_2.taskEventEmitter.emitTaskStatusChanged({
286
+ id: createdTask.id,
287
+ name: params.name,
288
+ status: factory.taskStatus.Ready
289
+ });
290
+ }
291
+ });
292
+ }
293
+ // public async createOnOrderPaymentCompletedTaskIfNotExist(
294
+ // params: factory.task.IAttributes<factory.taskName.OnOrderPaymentCompleted>,
295
+ // options: IOptionOnCreate
296
+ // ): Promise<void> {
297
+ // const createdTask = await this.taskModel.findOneAndUpdate(
298
+ // {
299
+ // 'project.id': { $eq: params.project.id },
300
+ // name: { $eq: params.name },
301
+ // 'data.object.orderNumber': {
302
+ // $exists: true,
303
+ // $eq: String(params.data.object.orderNumber)
304
+ // }
305
+ // },
306
+ // { $setOnInsert: params },
307
+ // { new: true, upsert: true }
308
+ // )
309
+ // .select({ _id: 1 })
310
+ // .exec();
311
+ // if (options.emitImmediately) {
312
+ // taskEventEmitter.emitTaskStatusChanged({
313
+ // id: createdTask.id,
314
+ // name: params.name,
315
+ // status: factory.taskStatus.Ready
316
+ // });
317
+ // }
318
+ // }
233
319
  executeById(params) {
234
320
  return __awaiter(this, void 0, void 0, function* () {
235
321
  const doc = yield this.taskModel.findOneAndUpdate({
@@ -15,9 +15,9 @@ function validateAccount(params) {
15
15
  return (repos) => __awaiter(this, void 0, void 0, function* () {
16
16
  var _a, _b, _c, _d;
17
17
  // 引き出し口座の存在を確認する
18
- const paymentMethodType = (_a = params.object.paymentMethod) === null || _a === void 0 ? void 0 : _a.typeOf;
18
+ const paymentMethodType = (_a = params.object.paymentMethod) === null || _a === void 0 ? void 0 : _a.identifier;
19
19
  if (typeof paymentMethodType !== 'string') {
20
- throw new factory.errors.ArgumentNull('object.paymentMethod.typeOf');
20
+ throw new factory.errors.ArgumentNull('object.paymentMethod.identifier');
21
21
  }
22
22
  const accountNumber = (_b = params.object.paymentMethod) === null || _b === void 0 ? void 0 : _b.accountId;
23
23
  if (typeof accountNumber !== 'string') {
@@ -15,9 +15,9 @@ function createStartParams(params) {
15
15
  const paymentMethodType = (params.paymentService !== undefined)
16
16
  // FaceToFace以外は、プロダクトから決済方法タイプを自動取得
17
17
  ? (_a = params.paymentService.serviceType) === null || _a === void 0 ? void 0 : _a.codeValue
18
- : (_b = params.object.paymentMethod) === null || _b === void 0 ? void 0 : _b.typeOf;
18
+ : (_b = params.object.paymentMethod) === null || _b === void 0 ? void 0 : _b.identifier;
19
19
  if (typeof paymentMethodType !== 'string') {
20
- throw new factory.errors.ArgumentNull('object.paymentMethod.typeOf');
20
+ throw new factory.errors.ArgumentNull('object.paymentMethod.identifier');
21
21
  }
22
22
  let totalPaymentDue;
23
23
  switch (params.paymentServiceType) {
@@ -85,7 +85,9 @@ function createStartParams(params) {
85
85
  ? params.object.paymentMethod.name
86
86
  : paymentMethodType,
87
87
  // MonetaryAmount対応(2023-08-14~)
88
- amount: (settings_1.USE_OBJECT_AS_PAY_TRANSACTION_AMOUNT) ? paymentMethodAmount : params.amount, paymentMethodId: params.transactionNumber, typeOf: paymentMethodType }, (typeof ((_t = params.object.paymentMethod) === null || _t === void 0 ? void 0 : _t.description) === 'string')
88
+ amount: (settings_1.USE_OBJECT_AS_PAY_TRANSACTION_AMOUNT) ? paymentMethodAmount : params.amount,
89
+ // paymentMethodId: params.transactionNumber, // object.paymentMethodIdへ完全移行(2023-08-30~)
90
+ identifier: paymentMethodType }, (typeof ((_t = params.object.paymentMethod) === null || _t === void 0 ? void 0 : _t.description) === 'string')
89
91
  ? { description: (_u = params.object.paymentMethod) === null || _u === void 0 ? void 0 : _u.description }
90
92
  : undefined), (totalPaymentDue !== undefined)
91
93
  ? { totalPaymentDue: totalPaymentDue }
@@ -33,9 +33,9 @@ function createPayObject(params) {
33
33
  var _a;
34
34
  const transaction = params.transaction;
35
35
  const paymentMethod = transaction.object.paymentMethod;
36
- const paymentMethodType = String(paymentMethod === null || paymentMethod === void 0 ? void 0 : paymentMethod.typeOf);
36
+ const paymentMethodType = String(paymentMethod === null || paymentMethod === void 0 ? void 0 : paymentMethod.identifier);
37
37
  const additionalProperty = paymentMethod === null || paymentMethod === void 0 ? void 0 : paymentMethod.additionalProperty;
38
- const paymentMethodId = (typeof (paymentMethod === null || paymentMethod === void 0 ? void 0 : paymentMethod.paymentMethodId) === 'string') ? paymentMethod === null || paymentMethod === void 0 ? void 0 : paymentMethod.paymentMethodId : transaction.id;
38
+ const paymentMethodId = transaction.object.paymentMethodId;
39
39
  const paymentMethodName = (typeof (paymentMethod === null || paymentMethod === void 0 ? void 0 : paymentMethod.name) === 'string') ? paymentMethod === null || paymentMethod === void 0 ? void 0 : paymentMethod.name : paymentMethodType;
40
40
  // MonetaryAmount対応(2023-08-13~)
41
41
  const paymentMethodAmountValue = (typeof (paymentMethod === null || paymentMethod === void 0 ? void 0 : paymentMethod.amount) === 'number')
@@ -139,7 +139,7 @@ function createPayObjectServiceOutput(params) {
139
139
  // }
140
140
  break;
141
141
  case factory.service.paymentService.PaymentServiceType.MovieTicket:
142
- const paymentMethodType = paymentMethod === null || paymentMethod === void 0 ? void 0 : paymentMethod.typeOf;
142
+ const paymentMethodType = paymentMethod === null || paymentMethod === void 0 ? void 0 : paymentMethod.identifier;
143
143
  const movieTickets = paymentMethod === null || paymentMethod === void 0 ? void 0 : paymentMethod.movieTickets;
144
144
  if (Array.isArray(movieTickets)) {
145
145
  paymentServiceOutput = movieTickets.map((movieTicket) => {
@@ -12,8 +12,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.searchGMOTrade = exports.exportTasksById = exports.cancel = exports.confirm = exports.start = exports.check = exports.invalidatePaymentUrl = exports.publishPaymentUrl = void 0;
13
13
  const moment = require("moment");
14
14
  const factory = require("../../factory");
15
- const settings_1 = require("../../settings");
16
- const payment_1 = require("../payment");
17
15
  const CreditCardPayment = require("../payment/creditCard");
18
16
  const MovieTicketPayment = require("../payment/movieTicket");
19
17
  const PaymentCardPayment = require("../payment/paymentCard");
@@ -205,7 +203,7 @@ function fixPaymentService(params) {
205
203
  }
206
204
  function validateSeller(params) {
207
205
  return (repos) => __awaiter(this, void 0, void 0, function* () {
208
- var _a, _b, _c;
206
+ var _a, _b, _c, _d;
209
207
  const sellerId = (_a = params.recipient) === null || _a === void 0 ? void 0 : _a.id;
210
208
  if (typeof sellerId !== 'string') {
211
209
  throw new factory.errors.ArgumentNull('recipient.id');
@@ -219,14 +217,26 @@ function validateSeller(params) {
219
217
  if (seller === undefined) {
220
218
  throw new factory.errors.NotFound(factory.organizationType.Corporation);
221
219
  }
222
- const paymentMethodType = (_b = params.object.paymentMethod) === null || _b === void 0 ? void 0 : _b.typeOf;
220
+ const paymentMethodType = (_b = params.object.paymentMethod) === null || _b === void 0 ? void 0 : _b.identifier;
223
221
  if (typeof paymentMethodType !== 'string') {
224
- throw new factory.errors.ArgumentNull('object.paymentMethod.typeOf');
222
+ throw new factory.errors.ArgumentNull('object.paymentMethod.identifier');
225
223
  }
226
- // 販売者の対応決済方法かどうか確認
227
- const paymentAccepted = (_c = seller.paymentAccepted) === null || _c === void 0 ? void 0 : _c.some((a) => a.paymentMethodType === paymentMethodType);
228
- if (paymentAccepted !== true) {
229
- throw new factory.errors.Argument('object.paymentMethod.typeOf', `payment not accepted`);
224
+ // FaceToFaceの場合、決済方法区分未指定に対応(2023-08-29~)
225
+ if (params.object.typeOf === factory.service.paymentService.PaymentServiceType.FaceToFace) {
226
+ if (paymentMethodType.length > 0) {
227
+ // 販売者の対応決済方法かどうか確認
228
+ const paymentAccepted = (_c = seller.paymentAccepted) === null || _c === void 0 ? void 0 : _c.some((a) => a.paymentMethodType === paymentMethodType);
229
+ if (paymentAccepted !== true) {
230
+ throw new factory.errors.Argument('object.paymentMethod.identifier', `payment not accepted`);
231
+ }
232
+ }
233
+ }
234
+ else {
235
+ // 販売者の対応決済方法かどうか確認
236
+ const paymentAccepted = (_d = seller.paymentAccepted) === null || _d === void 0 ? void 0 : _d.some((a) => a.paymentMethodType === paymentMethodType);
237
+ if (paymentAccepted !== true) {
238
+ throw new factory.errors.Argument('object.paymentMethod.identifier', `payment not accepted`);
239
+ }
230
240
  }
231
241
  });
232
242
  }
@@ -301,6 +311,7 @@ function saveAuthorizeResult(params) {
301
311
  */
302
312
  function confirm(params) {
303
313
  return (repos) => __awaiter(this, void 0, void 0, function* () {
314
+ var _a, _b;
304
315
  let transaction;
305
316
  // 取引存在確認
306
317
  if (typeof params.id === 'string') {
@@ -318,29 +329,24 @@ function confirm(params) {
318
329
  else {
319
330
  throw new factory.errors.ArgumentNull('Transaction ID or Transaction Number');
320
331
  }
332
+ let overwritingPaymentMethodIdentifier;
333
+ if (transaction.object.typeOf === factory.service.paymentService.PaymentServiceType.FaceToFace) {
334
+ const specifiedPaymentMethodIdentifire = (_b = (_a = params.object) === null || _a === void 0 ? void 0 : _a.paymentMethod) === null || _b === void 0 ? void 0 : _b.identifier;
335
+ if (typeof specifiedPaymentMethodIdentifire === 'string' && specifiedPaymentMethodIdentifire.length > 0) {
336
+ overwritingPaymentMethodIdentifier = specifiedPaymentMethodIdentifire;
337
+ transaction.object.paymentMethod.identifier = overwritingPaymentMethodIdentifier;
338
+ // transaction.object.paymentMethod.typeOf = overwritingPaymentMethodIdentifier;
339
+ }
340
+ }
321
341
  const order = yield fixOrderAsPurpose(params, transaction)(repos);
322
342
  const potentialActions = (0, potentialActions_1.createPotentialActions)({
323
343
  transaction: transaction,
324
344
  potentialActions: params.potentialActions,
325
345
  order
326
346
  });
327
- yield repos.assetTransaction.confirm({
328
- typeOf: factory.assetTransactionType.Pay,
329
- id: transaction.id,
330
- result: {},
331
- // sync対応(2023-01-14~)
332
- potentialActions: (settings_1.USE_PAY_ASSET_TRANSACTION_SYNC_PROCESSING)
333
- ? { pay: [] }
334
- : potentialActions
335
- });
336
- // sync対応(2023-01-14~)
337
- if (settings_1.USE_PAY_ASSET_TRANSACTION_SYNC_PROCESSING) {
338
- if (Array.isArray(potentialActions.pay)) {
339
- for (const payAction of potentialActions.pay) {
340
- yield (0, payment_1.pay)(payAction)(repos);
341
- }
342
- }
343
- }
347
+ yield repos.assetTransaction.confirm(Object.assign({ typeOf: factory.assetTransactionType.Pay, id: transaction.id, result: {}, potentialActions: potentialActions }, (typeof overwritingPaymentMethodIdentifier === 'string')
348
+ ? { object: { paymentMethod: { identifier: overwritingPaymentMethodIdentifier } } }
349
+ : undefined));
344
350
  });
345
351
  }
346
352
  exports.confirm = confirm;
@@ -373,23 +379,11 @@ function fixOrderAsPurpose(params, transaction) {
373
379
  */
374
380
  function cancel(params) {
375
381
  return (repos) => __awaiter(this, void 0, void 0, function* () {
376
- const transaction = yield repos.assetTransaction.cancel({
382
+ yield repos.assetTransaction.cancel({
377
383
  typeOf: factory.assetTransactionType.Pay,
378
384
  id: params.id,
379
385
  transactionNumber: params.transactionNumber
380
386
  });
381
- // sync対応(2023-01-14~)
382
- if (settings_1.USE_PAY_ASSET_TRANSACTION_SYNC_PROCESSING) {
383
- const payTransactionAsObject = {
384
- project: transaction.project,
385
- typeOf: transaction.typeOf,
386
- id: transaction.id,
387
- transactionNumber: transaction.transactionNumber,
388
- object: transaction.object,
389
- recipient: transaction.recipient
390
- };
391
- yield (0, payment_1.voidPayment)({ object: payTransactionAsObject })(repos);
392
- }
393
387
  });
394
388
  }
395
389
  exports.cancel = cancel;
@@ -404,6 +398,9 @@ function exportTasksById(params) {
404
398
  id: params.id
405
399
  });
406
400
  const potentialActions = transaction.potentialActions;
401
+ if (transaction.status === factory.transactionStatusType.InProgress) {
402
+ throw new factory.errors.NotImplemented(`Transaction status "${transaction.status}" not implemented.`);
403
+ }
407
404
  const taskAttributes = [];
408
405
  // タスク実行日時バッファの指定があれば調整
409
406
  let taskRunsAt = new Date();
@@ -430,6 +427,31 @@ function exportTasksById(params) {
430
427
  executionResults: [],
431
428
  data: { object: payTransactionAsObject }
432
429
  };
430
+ // OnAssetTransactionStatusChangedを追加(2023-08-30~)
431
+ const onAssetTransactionStatusChangedTaskData = {
432
+ project: transaction.project,
433
+ object: {
434
+ typeOf: factory.assetTransactionType.Pay,
435
+ transactionNumber: transaction.transactionNumber,
436
+ status: transaction.status
437
+ },
438
+ purpose: {
439
+ confirmationNumber: '',
440
+ orderNumber: '',
441
+ typeOf: 'Order'
442
+ },
443
+ useOnOrderStatusChanged: true
444
+ };
445
+ const onAssetTransactionStatusChangedTask = {
446
+ project: transaction.project,
447
+ name: factory.taskName.OnAssetTransactionStatusChanged,
448
+ status: factory.taskStatus.Ready,
449
+ runsAt: taskRunsAt,
450
+ remainingNumberOfTries: 10,
451
+ numberOfTried: 0,
452
+ executionResults: [],
453
+ data: onAssetTransactionStatusChangedTaskData
454
+ };
433
455
  switch (transaction.status) {
434
456
  case factory.transactionStatusType.Confirmed:
435
457
  const payActions = potentialActions === null || potentialActions === void 0 ? void 0 : potentialActions.pay;
@@ -450,13 +472,10 @@ function exportTasksById(params) {
450
472
  }
451
473
  break;
452
474
  case factory.transactionStatusType.Canceled:
453
- // sync対応(2023-01-14~)
454
- if (!settings_1.USE_PAY_ASSET_TRANSACTION_SYNC_PROCESSING) {
455
- taskAttributes.push(voidPaymentTasks);
456
- }
475
+ taskAttributes.push(voidPaymentTasks, onAssetTransactionStatusChangedTask);
457
476
  break;
458
477
  case factory.transactionStatusType.Expired:
459
- taskAttributes.push(voidPaymentTasks);
478
+ taskAttributes.push(voidPaymentTasks, onAssetTransactionStatusChangedTask);
460
479
  break;
461
480
  default:
462
481
  throw new factory.errors.NotImplemented(`Transaction status "${transaction.status}" not implemented.`);
@@ -482,9 +501,9 @@ function searchGMOTrade(params) {
482
501
  // throw new factory.errors.Argument('transactionNumber', 'must be confirmed');
483
502
  // }
484
503
  // CreditCard系統の決済方法タイプは動的
485
- const paymentMethodType = (_a = assetTransaction.object.paymentMethod) === null || _a === void 0 ? void 0 : _a.typeOf;
504
+ const paymentMethodType = (_a = assetTransaction.object.paymentMethod) === null || _a === void 0 ? void 0 : _a.identifier;
486
505
  if (typeof paymentMethodType !== 'string') {
487
- throw new factory.errors.ArgumentNull('object.paymentMethod.typeOf');
506
+ throw new factory.errors.ArgumentNull('object.paymentMethod.identifier');
488
507
  }
489
508
  const paymentServiceId = String(assetTransaction.object.id);
490
509
  const availableChannel = yield repos.product.findAvailableChannel({
@@ -386,21 +386,62 @@ function createReservations4transactionObject(params) {
386
386
  }
387
387
  }
388
388
  // 指定されたアドオンがオファーに存在すれば、アドオンの単価仕様作成
389
- let acceptedAddOns = [];
389
+ const acceptedAddOns = [];
390
390
  let availableAddOns;
391
- const acceptedAddOnParams = acceptedOffer.addOn;
392
- if (Array.isArray(acceptedAddOnParams) && acceptedAddOnParams.length > 0) {
391
+ const acceptedAddOnsParams = acceptedOffer.addOn;
392
+ if (Array.isArray(acceptedAddOnsParams) && acceptedAddOnsParams.length > 0) {
393
393
  // アドオンオファー検索(2023-03-02~)
394
394
  availableAddOns = yield searchAvailableAddOns({
395
- ids: acceptedAddOnParams.map((acceptedAddOn) => String(acceptedAddOn.id)),
395
+ ids: acceptedAddOnsParams.map((acceptedAddOn) => String(acceptedAddOn.id)),
396
396
  project: { id: params.transaction.project.id },
397
397
  ticketOffer,
398
398
  availableAtOrFrom: params.availableAtOrFrom
399
399
  })(repos);
400
400
  }
401
- // availableAddOns = <factory.product.ITicketAddOn[] | undefined>ticketOffer.addOn;
402
- if (Array.isArray(availableAddOns) && Array.isArray(acceptedAddOnParams)) {
403
- acceptedAddOns = availableAddOns.filter((availableAddOn) => acceptedAddOnParams.some((acceptedAddOn) => availableAddOn.id === acceptedAddOn.id));
401
+ if (Array.isArray(availableAddOns) && Array.isArray(acceptedAddOnsParams)) {
402
+ acceptedAddOnsParams.forEach((acceptedAddOnParams) => {
403
+ var _a, _b, _c;
404
+ const availableAddOn = availableAddOns === null || availableAddOns === void 0 ? void 0 : availableAddOns.find((addOn) => addOn.id === acceptedAddOnParams.id);
405
+ if (availableAddOn !== undefined) {
406
+ // acceptedAddOnsの重複を避ける(単価オファーIDに対して)
407
+ if (!acceptedAddOns.some((addOn) => addOn.id === availableAddOn.id)) {
408
+ const availableAddOnReferenceQuantityValue = availableAddOn.priceSpecification.referenceQuantity.value;
409
+ if (typeof availableAddOnReferenceQuantityValue !== 'number') {
410
+ throw new factory.errors.NotImplemented('addOn.priceSpecification.referenceQuantity.value must be number');
411
+ }
412
+ // 受入数量はデフォルトで単価オファーの基準数量
413
+ let referenceQuantityValueAccepted = availableAddOnReferenceQuantityValue;
414
+ // 数量指定を検証(2023-08-31~)
415
+ const specifiedReferencedQuantityValue = (_b = (_a = acceptedAddOnParams.priceSpecification) === null || _a === void 0 ? void 0 : _a.referenceQuantity) === null || _b === void 0 ? void 0 : _b.value;
416
+ if (typeof specifiedReferencedQuantityValue === 'number') {
417
+ if (specifiedReferencedQuantityValue < 1) {
418
+ throw new factory.errors.Argument('addOn.priceSpecification.referenceQuantity.value must be > 0');
419
+ }
420
+ // 数量が適用単位要件を満たしていなければエラー
421
+ if (specifiedReferencedQuantityValue % availableAddOnReferenceQuantityValue !== 0) {
422
+ throw new factory.errors.Argument('addOn.priceSpecification.referenceQuantity.value', `Offer ${availableAddOn.id} requires reference quantity value ${specifiedReferencedQuantityValue}`);
423
+ }
424
+ // 基準数量上書き
425
+ referenceQuantityValueAccepted = specifiedReferencedQuantityValue;
426
+ }
427
+ const priceAccepted = availableAddOn.priceSpecification.price *
428
+ (referenceQuantityValueAccepted / availableAddOnReferenceQuantityValue);
429
+ const accountsReceivableAccepted = (typeof ((_c = availableAddOn.priceSpecification.accounting) === null || _c === void 0 ? void 0 : _c.accountsReceivable) === 'number')
430
+ ? availableAddOn.priceSpecification.accounting.accountsReceivable *
431
+ (referenceQuantityValueAccepted / availableAddOnReferenceQuantityValue)
432
+ : undefined;
433
+ const acceptedAddOn = Object.assign(Object.assign({}, availableAddOn), { priceSpecification: Object.assign(Object.assign(Object.assign({}, availableAddOn.priceSpecification), (typeof accountsReceivableAccepted === 'number')
434
+ ? {
435
+ accounting: Object.assign(Object.assign({}, availableAddOn.priceSpecification.accounting), { accountsReceivable: accountsReceivableAccepted, typeOf: 'Accounting' })
436
+ }
437
+ : undefined), { price: priceAccepted, referenceQuantity: Object.assign(Object.assign({}, availableAddOn.priceSpecification.referenceQuantity), { value: referenceQuantityValueAccepted }) }) });
438
+ acceptedAddOns.push(acceptedAddOn);
439
+ }
440
+ }
441
+ });
442
+ // acceptedAddOns = availableAddOns.filter(
443
+ // (availableAddOn) => acceptedAddOnsParams.some((acceptedAddOn) => availableAddOn.id === acceptedAddOn.id)
444
+ // );
404
445
  }
405
446
  const subReservation = (_j = (_h = acceptedOffer.itemOffered) === null || _h === void 0 ? void 0 : _h.serviceOutput) === null || _j === void 0 ? void 0 : _j.subReservation;
406
447
  const reservationId = `${reservationNumber}-${reservationIndex}`;
@@ -29,6 +29,23 @@ const accountTransactionIdentifier_1 = require("../factory/accountTransactionIde
29
29
  */
30
30
  function givePointAward(params) {
31
31
  return (repos) => __awaiter(this, void 0, void 0, function* () {
32
+ // 入金識別子が存在する場合、冪等性の確保(2023-08-24~)
33
+ const pendingTransactionIdentifier = params.object.identifier;
34
+ if (typeof pendingTransactionIdentifier === 'string' && pendingTransactionIdentifier.length > 0) {
35
+ // すでにConfirmedのMoneyTransfer取引が存在すれば何もしない
36
+ const assetTransactions = yield repos.assetTransaction.search({
37
+ limit: 1,
38
+ project: { id: { $eq: params.project.id } },
39
+ typeOf: factory.assetTransactionType.MoneyTransfer,
40
+ statuses: [factory.transactionStatusType.Confirmed],
41
+ object: {
42
+ pendingTransaction: { identifier: { $eq: pendingTransactionIdentifier } }
43
+ }
44
+ }, ['_id']);
45
+ if (assetTransactions.length > 0) {
46
+ return;
47
+ }
48
+ }
32
49
  // アクション開始
33
50
  const action = yield repos.action.start(params);
34
51
  try {
@@ -26,6 +26,7 @@ exports.WebAPIIdentifier = factory.service.webAPI.Identifier;
26
26
  */
27
27
  function voidTransaction(params) {
28
28
  return (repos) => __awaiter(this, void 0, void 0, function* () {
29
+ var _a, _b;
29
30
  const transaction = yield repos.transaction.findById({
30
31
  typeOf: params.purpose.typeOf,
31
32
  id: params.purpose.id,
@@ -46,8 +47,12 @@ function voidTransaction(params) {
46
47
  throw new factory.errors.NotImplemented(`${transaction.status} not implemented`);
47
48
  // 確定取引に対応(2023-05-07~)
48
49
  case factory.transactionStatusType.Confirmed:
49
- // アクションステータスを検証する
50
- authorizeActions = authorizeActions.filter((a) => a.actionStatus !== factory.actionStatusType.CompletedActionStatus);
50
+ // OrderCancelledを考慮(2023-08-30~)
51
+ const orderCancelled = ((_b = (_a = params.purpose.result) === null || _a === void 0 ? void 0 : _a.order) === null || _b === void 0 ? void 0 : _b.orderStatus) === factory.orderStatus.OrderCancelled;
52
+ if (!orderCancelled) {
53
+ // 取り消すべきアクションに絞る
54
+ authorizeActions = authorizeActions.filter((a) => a.actionStatus !== factory.actionStatusType.CompletedActionStatus);
55
+ }
51
56
  break;
52
57
  default:
53
58
  // no op
@@ -1,7 +1,6 @@
1
1
  import * as factory from '../../factory';
2
2
  import { MongoRepository as AccountingReportRepo } from '../../repo/accountingReport';
3
3
  import { MongoRepository as ActionRepo } from '../../repo/action';
4
- import { RedisRepository as RegisterServiceInProgressRepo } from '../../repo/action/registerServiceInProgress';
5
4
  import { MongoRepository as AssetTransactionRepo } from '../../repo/assetTransaction';
6
5
  import { MongoRepository as EventRepo } from '../../repo/event';
7
6
  import { MongoRepository as OrderRepo } from '../../repo/order';
@@ -21,6 +20,5 @@ declare function confirmPayTransaction(data: factory.task.IData<factory.taskName
21
20
  seller: SellerRepo;
22
21
  task: TaskRepo;
23
22
  transaction: TransactionRepo;
24
- registerServiceInProgress: RegisterServiceInProgressRepo;
25
23
  }) => Promise<void>;
26
24
  export { confirmPayTransaction };