@chevre/domain 21.33.0-alpha.9 → 21.33.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 (95) hide show
  1. package/example/src/chevre/findTransactionById.ts +8 -5
  2. package/example/src/chevre/migratePayCreditCardRecipes.ts +104 -0
  3. package/example/src/chevre/migratePayMovieTicketRecipes.ts +100 -0
  4. package/example/src/chevre/migrateTransactionObjectPaymentMethods.ts +147 -0
  5. package/example/src/chevre/reexportTasksByExportAction.ts +37 -0
  6. package/example/src/chevre/searchActionsBySameAs.ts +2 -1
  7. package/example/src/chevre/searchCheckMovieTicketResultYkknInfo.ts +26 -6
  8. package/example/src/chevre/searchTransactions.ts +1 -1
  9. package/example/src/chevre/unsetUnnecessaryFields.ts +3 -18
  10. package/lib/chevre/repo/action.d.ts +51 -0
  11. package/lib/chevre/repo/action.js +122 -2
  12. package/lib/chevre/repo/assetTransaction.d.ts +9 -2
  13. package/lib/chevre/repo/assetTransaction.js +48 -3
  14. package/lib/chevre/repo/mongoose/schemas/actionRecipe.d.ts +5 -0
  15. package/lib/chevre/repo/mongoose/schemas/actionRecipe.js +89 -0
  16. package/lib/chevre/repo/mongoose/schemas/assetTransaction.js +23 -25
  17. package/lib/chevre/repo/mongoose/schemas/transaction.js +5 -52
  18. package/lib/chevre/repo/transaction.d.ts +26 -11
  19. package/lib/chevre/repo/transaction.js +89 -17
  20. package/lib/chevre/service/assetTransaction/pay.d.ts +6 -2
  21. package/lib/chevre/service/assetTransaction/pay.js +49 -5
  22. package/lib/chevre/service/offer/event/voidTransaction.js +4 -6
  23. package/lib/chevre/service/offer/eventServiceByCOA/findAcceptAction.js +2 -1
  24. package/lib/chevre/service/offer/product.js +1 -1
  25. package/lib/chevre/service/payment/any/handlePrePublishedPaymentMethodIdOnAuthorizing.d.ts +23 -0
  26. package/lib/chevre/service/payment/any/handlePrePublishedPaymentMethodIdOnAuthorizing.js +155 -0
  27. package/lib/chevre/service/payment/any.d.ts +10 -2
  28. package/lib/chevre/service/payment/any.js +83 -114
  29. package/lib/chevre/service/payment/creditCard/authorize.d.ts +41 -0
  30. package/lib/chevre/service/payment/creditCard/authorize.js +216 -0
  31. package/lib/chevre/service/payment/creditCard/factory.d.ts +35 -0
  32. package/lib/chevre/service/payment/creditCard/factory.js +57 -0
  33. package/lib/chevre/service/payment/creditCard/getGMOInfoFromSeller.d.ts +20 -0
  34. package/lib/chevre/service/payment/creditCard/getGMOInfoFromSeller.js +47 -0
  35. package/lib/chevre/service/payment/creditCard/gmoError.d.ts +34 -0
  36. package/lib/chevre/service/payment/creditCard/gmoError.js +8 -0
  37. package/lib/chevre/service/payment/creditCard/payCreditCard.d.ts +20 -0
  38. package/lib/chevre/service/payment/creditCard/payCreditCard.js +151 -0
  39. package/lib/chevre/service/payment/creditCard/refundCreditCard.d.ts +26 -0
  40. package/lib/chevre/service/payment/creditCard/refundCreditCard.js +196 -0
  41. package/lib/chevre/service/payment/creditCard/searchGMOTrade.d.ts +13 -0
  42. package/lib/chevre/service/payment/creditCard/searchGMOTrade.js +62 -0
  43. package/lib/chevre/service/payment/creditCard/voidTransaction.d.ts +13 -0
  44. package/lib/chevre/service/payment/creditCard/voidTransaction.js +90 -0
  45. package/lib/chevre/service/payment/creditCard.d.ts +7 -106
  46. package/lib/chevre/service/payment/creditCard.js +12 -638
  47. package/lib/chevre/service/payment/faceToFace.d.ts +1 -1
  48. package/lib/chevre/service/payment/movieTicket/authorize.d.ts +38 -0
  49. package/lib/chevre/service/payment/movieTicket/authorize.js +71 -0
  50. package/lib/chevre/service/payment/movieTicket/checkMovieTicket.d.ts +22 -0
  51. package/lib/chevre/service/payment/movieTicket/checkMovieTicket.js +109 -0
  52. package/lib/chevre/service/payment/movieTicket/factory.d.ts +52 -1
  53. package/lib/chevre/service/payment/movieTicket/factory.js +114 -1
  54. package/lib/chevre/service/payment/movieTicket/payMovieTicket.d.ts +24 -0
  55. package/lib/chevre/service/payment/movieTicket/payMovieTicket.js +157 -0
  56. package/lib/chevre/service/payment/movieTicket/{checkByIdentifier.d.ts → processPurchaseNumberAuth.d.ts} +5 -6
  57. package/lib/chevre/service/payment/movieTicket/{checkByIdentifier.js → processPurchaseNumberAuth.js} +4 -8
  58. package/lib/chevre/service/payment/movieTicket/refundMovieTicket.d.ts +21 -0
  59. package/lib/chevre/service/payment/movieTicket/refundMovieTicket.js +248 -0
  60. package/lib/chevre/service/payment/movieTicket/validation.js +3 -3
  61. package/lib/chevre/service/payment/movieTicket/voidTransaction.d.ts +12 -0
  62. package/lib/chevre/service/payment/movieTicket/voidTransaction.js +74 -0
  63. package/lib/chevre/service/payment/movieTicket.d.ts +7 -75
  64. package/lib/chevre/service/payment/movieTicket.js +11 -567
  65. package/lib/chevre/service/payment/paymentCard.d.ts +1 -1
  66. package/lib/chevre/service/payment.d.ts +9 -1
  67. package/lib/chevre/service/payment.js +2 -1
  68. package/lib/chevre/service/task/acceptCOAOffer.js +2 -1
  69. package/lib/chevre/service/task/authorizePayment.js +2 -1
  70. package/lib/chevre/service/task/checkMovieTicket.js +1 -1
  71. package/lib/chevre/service/task/pay.d.ts +2 -2
  72. package/lib/chevre/service/task/pay.js +3 -2
  73. package/lib/chevre/service/task/publishPaymentUrl.js +2 -1
  74. package/lib/chevre/service/task/voidPayTransaction.d.ts +2 -2
  75. package/lib/chevre/service/task/voidPayTransaction.js +2 -4
  76. package/lib/chevre/service/task/voidPayment.js +0 -1
  77. package/lib/chevre/service/task.js +2 -0
  78. package/lib/chevre/service/transaction/moneyTransfer/exportTasks/factory.d.ts +1 -1
  79. package/lib/chevre/service/transaction/moneyTransfer/potentialActions.d.ts +1 -1
  80. package/lib/chevre/service/transaction/moneyTransfer.js +2 -2
  81. package/lib/chevre/service/transaction/placeOrder.js +2 -3
  82. package/lib/chevre/service/transaction/placeOrderInProgress/confirm.js +3 -2
  83. package/lib/chevre/service/transaction/placeOrderInProgress/potentialActions.d.ts +0 -1
  84. package/lib/chevre/service/transaction/placeOrderInProgress/result.d.ts +1 -1
  85. package/lib/chevre/service/transaction/placeOrderInProgress/validation.d.ts +1 -1
  86. package/lib/chevre/service/transaction/placeOrderInProgress/validation.js +4 -3
  87. package/lib/chevre/service/transaction/returnOrder/exportTasks/factory.d.ts +1 -1
  88. package/lib/chevre/service/transaction/returnOrder/potentialActions/returnPaymentMethod.d.ts +1 -1
  89. package/lib/chevre/service/transaction/returnOrder/potentialActions.d.ts +1 -1
  90. package/lib/chevre/service/transaction/returnOrder.js +2 -2
  91. package/lib/chevre/settings.d.ts +1 -0
  92. package/lib/chevre/settings.js +2 -1
  93. package/package.json +3 -3
  94. package/example/src/chevre/migrateOwnershipInfos2newUserPool.ts +0 -152
  95. package/example/src/chevre/migratePayTransactionReservedTicketIdentifier.ts +0 -95
@@ -290,11 +290,12 @@ class MongoRepository {
290
290
  /**
291
291
  * 特定取引検索
292
292
  */
293
- findById(params) {
293
+ findById(params, inclusion, // make required(2024-05-31~)
294
+ exclusion) {
294
295
  return __awaiter(this, void 0, void 0, function* () {
295
296
  let projection = {};
296
- if (Array.isArray(params.inclusion) && params.inclusion.length > 0) {
297
- params.inclusion.forEach((field) => {
297
+ if (Array.isArray(inclusion) && inclusion.length > 0) {
298
+ inclusion.forEach((field) => {
298
299
  projection[field] = 1;
299
300
  });
300
301
  }
@@ -304,8 +305,8 @@ class MongoRepository {
304
305
  createdAt: 0,
305
306
  updatedAt: 0
306
307
  };
307
- if (Array.isArray(params.exclusion) && params.exclusion.length > 0) {
308
- params.exclusion.forEach((field) => {
308
+ if (Array.isArray(exclusion) && exclusion.length > 0) {
309
+ exclusion.forEach((field) => {
309
310
  projection[field] = 0;
310
311
  });
311
312
  }
@@ -360,6 +361,23 @@ class MongoRepository {
360
361
  return doc.toObject();
361
362
  });
362
363
  }
364
+ /**
365
+ * 進行中取引に保管された採用済決済方法を検索する
366
+ */
367
+ findInProgressPaymentMethodId(params) {
368
+ return __awaiter(this, void 0, void 0, function* () {
369
+ const doc = yield this.transactionModel.findOne({
370
+ _id: { $eq: params.id },
371
+ typeOf: { $eq: factory.transactionType.PlaceOrder },
372
+ status: { $eq: factory.transactionStatusType.InProgress }
373
+ }, { 'object.paymentMethods': 1 })
374
+ .exec();
375
+ if (doc === null) {
376
+ throw new factory.errors.NotFound(this.transactionModel.modelName);
377
+ }
378
+ return doc.toObject().object.paymentMethods;
379
+ });
380
+ }
363
381
  /**
364
382
  * 取引の注文番号を検索する
365
383
  */
@@ -481,14 +499,14 @@ class MongoRepository {
481
499
  .exec();
482
500
  // NotFoundであれば取引状態確認
483
501
  if (doc === null) {
484
- const transaction = yield this.findById({ typeOf: params.typeOf, id: params.id });
485
- if (transaction.status === factory.transactionStatusType.Confirmed) {
502
+ const { status } = yield this.findById({ typeOf: params.typeOf, id: params.id }, ['status']);
503
+ if (status === factory.transactionStatusType.Confirmed) {
486
504
  // すでに確定済の場合スルー
487
505
  }
488
- else if (transaction.status === factory.transactionStatusType.Expired) {
506
+ else if (status === factory.transactionStatusType.Expired) {
489
507
  throw new factory.errors.Argument('Transaction id', 'Already expired');
490
508
  }
491
- else if (transaction.status === factory.transactionStatusType.Canceled) {
509
+ else if (status === factory.transactionStatusType.Canceled) {
492
510
  throw new factory.errors.Argument('Transaction id', 'Already canceled');
493
511
  }
494
512
  else {
@@ -530,12 +548,11 @@ class MongoRepository {
530
548
  .then((doc) => (doc === null) ? null : doc.toObject());
531
549
  });
532
550
  }
533
- // tslint:disable-next-line:no-suspicious-comment
534
551
  /**
535
552
  * タスクエクスポートリトライ
536
- * TODO updatedAtを基準にしているが、タスクエクスポートトライ日時を持たせた方が安全か?
553
+ * @deprecated use reexportTasksByExportAction
537
554
  */
538
- reexportTasks(params) {
555
+ reexportTasksByExportationStatus(params) {
539
556
  return __awaiter(this, void 0, void 0, function* () {
540
557
  const reexportingTransactions = yield this.transactionModel.find({
541
558
  tasksExportationStatus: { $eq: factory.transactionTasksExportationStatus.Exporting },
@@ -573,6 +590,46 @@ class MongoRepository {
573
590
  }
574
591
  });
575
592
  }
593
+ reexportTasksByExportAction(params) {
594
+ return __awaiter(this, void 0, void 0, function* () {
595
+ const reexportingTransactions = yield this.transactionModel.find({
596
+ 'tasksExportAction.actionStatus': {
597
+ $exists: true,
598
+ $eq: factory.actionStatusType.ActiveActionStatus
599
+ },
600
+ 'tasksExportAction.startDate': {
601
+ $exists: true,
602
+ $lt: moment()
603
+ .add(-params.intervalInMinutes, 'minutes')
604
+ .toDate()
605
+ }
606
+ }, { _id: 1, typeOf: 1, status: 1 })
607
+ .setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
608
+ .exec();
609
+ if (reexportingTransactions.length > 0) {
610
+ for (const reexportingTransaction of reexportingTransactions) {
611
+ yield this.transactionModel.updateOne({
612
+ _id: { $eq: reexportingTransaction.id },
613
+ 'tasksExportAction.actionStatus': {
614
+ $exists: true,
615
+ $eq: factory.actionStatusType.ActiveActionStatus
616
+ }
617
+ }, {
618
+ tasksExportAction: {
619
+ actionStatus: factory.actionStatusType.PotentialActionStatus
620
+ },
621
+ tasksExportationStatus: factory.transactionTasksExportationStatus.Unexported
622
+ })
623
+ .exec();
624
+ transaction_1.transactionEventEmitter.emitTransactionStatusChanged({
625
+ id: reexportingTransaction.id,
626
+ typeOf: reexportingTransaction.typeOf,
627
+ status: reexportingTransaction.status
628
+ });
629
+ }
630
+ }
631
+ });
632
+ }
576
633
  /**
577
634
  * タスクエクスポートの遅延している取引について明示的にemitTransactionStatusChangedを実行する
578
635
  */
@@ -684,14 +741,14 @@ class MongoRepository {
684
741
  .exec();
685
742
  // NotFoundであれば取引状態確認
686
743
  if (doc === null) {
687
- const transaction = yield this.findById(params);
688
- if (transaction.status === factory.transactionStatusType.Canceled) {
744
+ const { status } = yield this.findById(params, ['status']);
745
+ if (status === factory.transactionStatusType.Canceled) {
689
746
  // すでに中止済の場合スルー
690
747
  }
691
- else if (transaction.status === factory.transactionStatusType.Expired) {
748
+ else if (status === factory.transactionStatusType.Expired) {
692
749
  throw new factory.errors.Argument('Transaction id', 'Transaction already expired');
693
750
  }
694
- else if (transaction.status === factory.transactionStatusType.Confirmed) {
751
+ else if (status === factory.transactionStatusType.Confirmed) {
695
752
  throw new factory.errors.Argument('Transaction id', 'Confirmed transaction unable to cancel');
696
753
  }
697
754
  else {
@@ -758,7 +815,7 @@ class MongoRepository {
758
815
  });
759
816
  }
760
817
  /**
761
- * 特定の取引を更新する(汎用)
818
+ * 特定の進行中取引を更新する(汎用)
762
819
  */
763
820
  findByIdAndUpdateInProgress(params) {
764
821
  return __awaiter(this, void 0, void 0, function* () {
@@ -777,6 +834,21 @@ class MongoRepository {
777
834
  });
778
835
  });
779
836
  }
837
+ findByIdAndUpdate4migrate(params) {
838
+ return __awaiter(this, void 0, void 0, function* () {
839
+ yield this.transactionModel.findOneAndUpdate({
840
+ _id: { $eq: params.id }
841
+ }, params.update, {
842
+ projection: { _id: 1 }
843
+ })
844
+ .exec()
845
+ .then((doc) => {
846
+ if (doc === null) {
847
+ throw new factory.errors.ArgumentNull(this.transactionModel.modelName);
848
+ }
849
+ });
850
+ });
851
+ }
780
852
  saveOrderNumberIfNotExist(params) {
781
853
  return __awaiter(this, void 0, void 0, function* () {
782
854
  yield this.transactionModel.updateOne({
@@ -74,7 +74,7 @@ export type IPublishPaymentUrlResult = CreditCardPayment.IPaymentAgencyTransacti
74
74
  paymentUrl: string;
75
75
  };
76
76
  /**
77
- * 外部決済ロケーション発行
77
+ * 決済ロケーション発行
78
78
  */
79
79
  export declare function publishPaymentUrl(params: factory.assetTransaction.pay.IStartParamsWithoutDetail, options: {
80
80
  purposeAsTransaction: {
@@ -95,7 +95,11 @@ export declare function publishPaymentUrl(params: factory.assetTransaction.pay.I
95
95
  * 決済ロケーションを無効化する
96
96
  * 実質、外部で実行された決済に対する返金処理
97
97
  */
98
- export declare function invalidatePaymentUrl(params: factory.task.refund.IData): IInvalidatePaymentUrlOperation<void>;
98
+ export declare function invalidatePaymentUrl(params: Omit<factory.task.refund.IData, 'sameAs'> & {
99
+ sameAs?: {
100
+ id: string;
101
+ };
102
+ }): IInvalidatePaymentUrlOperation<void>;
99
103
  /**
100
104
  * 決済方法認証
101
105
  */
@@ -19,11 +19,46 @@ const PaymentCardPayment = require("../payment/paymentCard");
19
19
  const validation_1 = require("./pay/account/validation");
20
20
  const factory_1 = require("./pay/factory");
21
21
  const debug = createDebug('chevre-domain:service:assetTransaction');
22
+ function publishPaymentUrlResult2recipe(params) {
23
+ const { project, action, result } = params;
24
+ return {
25
+ project: { id: project.id, typeOf: factory.organizationType.Project },
26
+ typeOf: 'Recipe',
27
+ recipeCategory: factory.recipe.RecipeCategory.publishPaymentUrl,
28
+ recipeFor: { id: action.id, typeOf: action.typeOf },
29
+ step: [{
30
+ typeOf: 'HowToSection',
31
+ itemListElement: [
32
+ {
33
+ typeOf: 'HowToStep',
34
+ identifier: factory.recipe.StepIdentifier.entryTran,
35
+ itemListElement: [{
36
+ typeOf: 'HowToDirection',
37
+ beforeMedia: result.entryTranArgs,
38
+ afterMedia: result.entryTranResult
39
+ // text: 'entryTran'
40
+ }]
41
+ },
42
+ {
43
+ typeOf: 'HowToStep',
44
+ identifier: factory.recipe.StepIdentifier.execTran,
45
+ itemListElement: [{
46
+ typeOf: 'HowToDirection',
47
+ beforeMedia: result.execTranArgs,
48
+ afterMedia: result.execTranResult
49
+ // text: 'execTran'
50
+ }]
51
+ }
52
+ ]
53
+ }]
54
+ };
55
+ }
22
56
  /**
23
- * 外部決済ロケーション発行
57
+ * 決済ロケーション発行
24
58
  */
25
59
  // tslint:disable-next-line:max-func-body-length
26
60
  function publishPaymentUrl(params, options) {
61
+ // tslint:disable-next-line:max-func-body-length
27
62
  return (repos) => __awaiter(this, void 0, void 0, function* () {
28
63
  var _a, _b, _c, _d, _e;
29
64
  const paymentServiceType = (_a = params.object) === null || _a === void 0 ? void 0 : _a.typeOf;
@@ -77,6 +112,13 @@ function publishPaymentUrl(params, options) {
77
112
  execTranArgs: authorizeResult.execTranArgs,
78
113
  execTranResult: authorizeResult.execTranResult
79
114
  };
115
+ // create recipe(2024-06-02~)
116
+ const saveRecipeResult = yield repos.action.saveOneRecipe(publishPaymentUrlResult2recipe({
117
+ project: { id: params.project.id },
118
+ action: { id: action.id, typeOf: action.typeOf },
119
+ result
120
+ }));
121
+ debug('publishPaymentUrl: recipe saved.', JSON.stringify(saveRecipeResult));
80
122
  break;
81
123
  default:
82
124
  throw new factory.errors.NotImplemented(`Payment service '${paymentServiceType}' not implemented`);
@@ -147,7 +189,7 @@ exports.check = check;
147
189
  */
148
190
  function start(params, options) {
149
191
  return (repos) => __awaiter(this, void 0, void 0, function* () {
150
- var _a, _b, _c;
192
+ var _a, _b, _c, _d;
151
193
  // 金額をfix
152
194
  const amount = (_a = params.object.paymentMethod) === null || _a === void 0 ? void 0 : _a.amount;
153
195
  if (typeof amount !== 'number') {
@@ -183,7 +225,9 @@ function start(params, options) {
183
225
  break;
184
226
  case factory.service.paymentService.PaymentServiceType.MovieTicket:
185
227
  transaction =
186
- yield processAuthorizeMovieTicket(params, transaction, String(paymentService === null || paymentService === void 0 ? void 0 : paymentService.id), options.useCheckMovieTicketBeforePay, options.useCheckByIdentifierIfNotYet)(repos);
228
+ yield processAuthorizeMovieTicket(params, transaction, String(paymentService === null || paymentService === void 0 ? void 0 : paymentService.id), options.useCheckMovieTicketBeforePay, options.useCheckByIdentifierIfNotYet, {
229
+ executor: (typeof ((_d = options.executor) === null || _d === void 0 ? void 0 : _d.id) === 'string') ? { id: options.executor.id } : {}
230
+ })(repos);
187
231
  break;
188
232
  default:
189
233
  throw new factory.errors.NotImplemented(`Payment service '${paymentServiceType}' not implemented`);
@@ -347,9 +391,9 @@ function processAuthorizeCreditCard(params, transaction, paymentServiceId, optio
347
391
  })(repos);
348
392
  });
349
393
  }
350
- function processAuthorizeMovieTicket(params, transaction, paymentServiceId, useCheckMovieTicketBeforePay, useCheckByIdentifierIfNotYet) {
394
+ function processAuthorizeMovieTicket(params, transaction, paymentServiceId, useCheckMovieTicketBeforePay, useCheckByIdentifierIfNotYet, options) {
351
395
  return (repos) => __awaiter(this, void 0, void 0, function* () {
352
- const { accountId, payAction, accountsReceivablesByServiceType } = yield MovieTicketPayment.authorize(params, transaction, paymentServiceId, useCheckMovieTicketBeforePay, useCheckByIdentifierIfNotYet)(repos);
396
+ const { accountId, payAction, accountsReceivablesByServiceType } = yield MovieTicketPayment.authorize(params, transaction, paymentServiceId, useCheckMovieTicketBeforePay, useCheckByIdentifierIfNotYet, options)(repos);
353
397
  const payActionInObject = {
354
398
  actionStatus: payAction.actionStatus,
355
399
  id: payAction.id,
@@ -31,9 +31,8 @@ function voidTransaction(params) {
31
31
  const cancelAction = Object.assign({ startTime: new Date(), agent: { id: params.project.id, typeOf: factory.organizationType.Project } }, (typeof ((_a = params.sameAs) === null || _a === void 0 ? void 0 : _a.id) === 'string') ? { sameAs: { id: params.sameAs.id, typeOf: 'Task' } } : undefined);
32
32
  const transaction = yield repos.transaction.findById({
33
33
  typeOf: params.purpose.typeOf,
34
- id: params.purpose.id,
35
- inclusion: ['_id', 'typeOf', 'status', 'object.orderNumber']
36
- });
34
+ id: params.purpose.id
35
+ }, ['typeOf', 'status', 'object.orderNumber']);
37
36
  // 興行オファー承認アクション検索
38
37
  let authorizeActions = yield repos.action.searchByPurpose({
39
38
  typeOf: factory.actionType.AuthorizeAction,
@@ -104,9 +103,8 @@ function cancelAcceptActions(params) {
104
103
  const cancelAction = Object.assign({ startTime: new Date(), agent: { id: params.project.id, typeOf: factory.organizationType.Project } }, (typeof ((_a = params.sameAs) === null || _a === void 0 ? void 0 : _a.id) === 'string') ? { sameAs: { id: params.sameAs.id, typeOf: 'Task' } } : undefined);
105
104
  const transaction = yield repos.transaction.findById({
106
105
  typeOf: params.purpose.typeOf,
107
- id: params.purpose.id,
108
- inclusion: ['_id', 'typeOf', 'status']
109
- });
106
+ id: params.purpose.id
107
+ }, ['typeOf', 'status']);
110
108
  // 興行オファー承認アクション検索
111
109
  const completedAuthorizeActions = yield repos.action.searchByPurpose({
112
110
  typeOf: factory.actionType.AuthorizeAction,
@@ -43,7 +43,8 @@ function findAcceptAction(params) {
43
43
  default:
44
44
  // タスクがReadyでなければアクション検索
45
45
  const acceptAction = (yield repos.action.searchBySameAs({
46
- sameAs: { id: { $eq: task.id } }
46
+ sameAs: { id: { $eq: task.id } },
47
+ typeOf: { $eq: factory.actionType.AcceptAction }
47
48
  // purpose: { id: { $eq: String(params.purpose.id) } }
48
49
  })).shift();
49
50
  if (acceptAction !== undefined) {
@@ -192,7 +192,7 @@ function voidTransaction(params) {
192
192
  const transaction = yield repos.transaction.findById({
193
193
  typeOf: params.purpose.typeOf,
194
194
  id: params.purpose.id
195
- });
195
+ }, ['agent', 'status', 'typeOf']);
196
196
  if (transaction.status !== factory.transactionStatusType.Canceled
197
197
  && transaction.status !== factory.transactionStatusType.Expired
198
198
  && transaction.status !== factory.transactionStatusType.InProgress) {
@@ -0,0 +1,23 @@
1
+ import * as factory from '../../../factory';
2
+ import type { MongoRepository as ActionRepo } from '../../../repo/action';
3
+ import type { ITransactionInProgress, MongoRepository as TransactionRepo } from '../../../repo/transaction';
4
+ import * as PayTransactionService from '../../assetTransaction/pay';
5
+ type IObjectWithoutDetail = factory.action.authorize.paymentMethod.any.IObjectWithoutDetail;
6
+ declare function handlePrePublishedPaymentMethodIdOnAuthorizing(params: {
7
+ object: Pick<IObjectWithoutDetail, 'amount' | 'issuedThrough' | 'paymentMethod'>;
8
+ prePublishedPaymentMethodId: string;
9
+ transaction: Pick<ITransactionInProgress<factory.transactionType.PlaceOrder>, 'agent' | 'expires' | 'id' | 'typeOf' | 'project' | 'seller'>;
10
+ }): (repos: {
11
+ action: ActionRepo;
12
+ transaction: TransactionRepo;
13
+ }) => Promise<{
14
+ authorizeParams?: {
15
+ creditCard: factory.action.authorize.paymentMethod.any.ICreditCard;
16
+ paymentMethodByTransaction: factory.transaction.placeOrder.IPaymentMethodByPaymentUrl;
17
+ pendingPaymentAgencyTransaction: PayTransactionService.IPaymentAgencyTransaction;
18
+ } | undefined;
19
+ existingCompletedAuthorizeAction?: {
20
+ id: string;
21
+ } | undefined;
22
+ }>;
23
+ export { handlePrePublishedPaymentMethodIdOnAuthorizing };
@@ -0,0 +1,155 @@
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.handlePrePublishedPaymentMethodIdOnAuthorizing = void 0;
13
+ const createDebug = require("debug");
14
+ const factory = require("../../../factory");
15
+ const debug = createDebug('chevre-domain:service:payment');
16
+ function recipe2paymentAgencyTransaction(actionRecipe) {
17
+ var _a;
18
+ let entryTranArgs;
19
+ let entryTranResult;
20
+ let execTranArgs;
21
+ let execTranResult;
22
+ if (actionRecipe.recipeCategory !== factory.recipe.RecipeCategory.publishPaymentUrl) {
23
+ throw new factory.errors.NotFound('', `Recipe with category ${factory.recipe.RecipeCategory.publishPaymentUrl} not found`);
24
+ }
25
+ const howToSection = actionRecipe.step;
26
+ const howToSteps = (_a = howToSection.at(0)) === null || _a === void 0 ? void 0 : _a.itemListElement;
27
+ if (Array.isArray(howToSteps)) {
28
+ howToSteps.forEach((howToStep) => {
29
+ var _a, _b, _c, _d;
30
+ const stepIdentifier = howToStep.identifier;
31
+ if (stepIdentifier === factory.recipe.StepIdentifier.entryTran) {
32
+ entryTranArgs = (_a = howToStep.itemListElement.at(0)) === null || _a === void 0 ? void 0 : _a.beforeMedia;
33
+ entryTranResult = (_b = howToStep.itemListElement.at(0)) === null || _b === void 0 ? void 0 : _b.afterMedia;
34
+ }
35
+ else if (stepIdentifier === factory.recipe.StepIdentifier.execTran) {
36
+ execTranArgs = (_c = howToStep.itemListElement.at(0)) === null || _c === void 0 ? void 0 : _c.beforeMedia;
37
+ execTranResult = (_d = howToStep.itemListElement.at(0)) === null || _d === void 0 ? void 0 : _d.afterMedia;
38
+ }
39
+ else {
40
+ throw new factory.errors.NotImplemented(`howToStep.identifier '${stepIdentifier}' not implemented`);
41
+ }
42
+ });
43
+ }
44
+ if (entryTranArgs === undefined || entryTranResult === undefined
45
+ || execTranArgs === undefined || execTranResult === undefined) {
46
+ throw new factory.errors.NotFound(`beforeMedia or afterMedia of actionRecipe`);
47
+ }
48
+ return { entryTranArgs, entryTranResult, execTranArgs, execTranResult };
49
+ }
50
+ function handlePrePublishedPaymentMethodIdOnAuthorizing(params) {
51
+ return (repos) => __awaiter(this, void 0, void 0, function* () {
52
+ let creditCard;
53
+ let pendingPaymentAgencyTransaction;
54
+ let existingCompletedAuthorizeAction;
55
+ // transaction.objectへのアクセス回避(2024-05-30~)
56
+ // const paymentMethodByTransaction = transaction.object.paymentMethods;
57
+ const paymentMethodByTransaction = yield repos.transaction.findInProgressPaymentMethodId({ id: params.transaction.id });
58
+ if (params.prePublishedPaymentMethodId === (paymentMethodByTransaction === null || paymentMethodByTransaction === void 0 ? void 0 : paymentMethodByTransaction.paymentMethodId)) {
59
+ // check existence of acceptAction when authorizing payment(2024-06-01~)
60
+ const acceptPayAction = (yield repos.action.search({
61
+ limit: 1,
62
+ page: 1,
63
+ project: { id: { $eq: params.transaction.project.id } },
64
+ typeOf: { $eq: factory.actionType.AcceptAction },
65
+ actionStatus: { $in: [factory.actionStatusType.CompletedActionStatus] },
66
+ purpose: { id: { $in: [params.transaction.id] } },
67
+ object: {
68
+ transactionNumber: { $eq: params.prePublishedPaymentMethodId },
69
+ typeOf: { $eq: factory.assetTransactionType.Pay }
70
+ }
71
+ }, ['object', 'result'], [])).shift();
72
+ if (acceptPayAction === undefined) {
73
+ throw new factory.errors.NotFound(factory.actionType.AcceptAction);
74
+ }
75
+ debug('acceptPayAction found:', acceptPayAction.id);
76
+ // find recipe(2024-06-02~)
77
+ const actionRecipe = yield repos.action.findRecipeByAction({
78
+ project: { id: params.transaction.project.id },
79
+ recipeFor: { id: acceptPayAction.id }
80
+ });
81
+ debug('actionRecipe found:', actionRecipe === null || actionRecipe === void 0 ? void 0 : actionRecipe.recipeCategory);
82
+ // 検証強化(2024-01-04~)
83
+ validatePaymentMethodByTransaction({
84
+ object: params.object,
85
+ acceptObject: acceptPayAction.object
86
+ });
87
+ // use actionRecipe(2024-06-02~)
88
+ if (typeof (actionRecipe === null || actionRecipe === void 0 ? void 0 : actionRecipe.recipeCategory) === 'string') {
89
+ pendingPaymentAgencyTransaction = recipe2paymentAgencyTransaction(actionRecipe);
90
+ creditCard = acceptPayAction.object.object.paymentMethod.creditCard;
91
+ }
92
+ else {
93
+ // discontinue(2024-06-05~)
94
+ // const { entryTranArgs, entryTranResult, execTranArgs, execTranResult } = paymentMethodByTransaction;
95
+ // pendingPaymentAgencyTransaction = { entryTranArgs, entryTranResult, execTranArgs, execTranResult };
96
+ }
97
+ if (creditCard === undefined) {
98
+ throw new factory.errors.Argument('paymentMethodId', 'creditCard not found');
99
+ }
100
+ if (pendingPaymentAgencyTransaction === undefined) {
101
+ throw new factory.errors.Argument('paymentMethodId', 'pendingPaymentAgencyTransaction not found');
102
+ }
103
+ // 既に承認済であれば何もしない(2023-05-15~)
104
+ const existingCompletedAuthorizeActions = yield repos.action.searchByPurpose({
105
+ typeOf: factory.actionType.AuthorizeAction,
106
+ purpose: { id: params.transaction.id, typeOf: params.transaction.typeOf },
107
+ actionStatus: { $eq: factory.actionStatusType.CompletedActionStatus },
108
+ object: {
109
+ paymentMethodId: { $eq: params.prePublishedPaymentMethodId },
110
+ typeOf: { $eq: factory.action.authorize.paymentMethod.any.ResultType.Payment }
111
+ },
112
+ sort: { startDate: factory.sortType.Ascending }
113
+ });
114
+ existingCompletedAuthorizeAction = existingCompletedAuthorizeActions.shift();
115
+ if (existingCompletedAuthorizeAction !== undefined) {
116
+ return { existingCompletedAuthorizeAction: { id: existingCompletedAuthorizeAction.id } };
117
+ }
118
+ return {
119
+ authorizeParams: { creditCard, pendingPaymentAgencyTransaction, paymentMethodByTransaction }
120
+ };
121
+ }
122
+ else {
123
+ // 取引にないpaymentMethodIdの指定はクライアントエラー
124
+ throw new factory.errors.Argument('paymentMethodId', 'invalid paymentMethodId for the transaction');
125
+ }
126
+ });
127
+ }
128
+ exports.handlePrePublishedPaymentMethodIdOnAuthorizing = handlePrePublishedPaymentMethodIdOnAuthorizing;
129
+ /**
130
+ * 注文取引に保管された決済情報を承認しようとしている決済の整合性を検証する
131
+ */
132
+ function validatePaymentMethodByTransaction(params) {
133
+ var _a, _b;
134
+ const paymentServiceIdByObject = params.object.issuedThrough.id;
135
+ const amountByObject = params.object.amount;
136
+ const paymentMethodTypeByObject = params.object.paymentMethod;
137
+ // const paymentServiceIdByTransaction = params.paymentMethodByTransaction.issuedThrough.id;
138
+ // const amountByTransaction = params.paymentMethodByTransaction.paymentMethod?.amount;
139
+ // const paymentMethodTypeByTransaction = params.paymentMethodByTransaction.paymentMethod?.identifier;
140
+ const paymentServiceIdByTransaction = params.acceptObject.object.id;
141
+ const amountByTransaction = (_a = params.acceptObject.object.paymentMethod) === null || _a === void 0 ? void 0 : _a.amount;
142
+ const paymentMethodTypeByTransaction = (_b = params.acceptObject.object.paymentMethod) === null || _b === void 0 ? void 0 : _b.identifier;
143
+ // 決済サービスID検証
144
+ if (paymentServiceIdByObject !== paymentServiceIdByTransaction) {
145
+ throw new factory.errors.Argument('object.issuedThrough.id', 'issuedThrough.id must match the target of the paymentUrl');
146
+ }
147
+ // 金額検証
148
+ if (amountByObject !== amountByTransaction) {
149
+ throw new factory.errors.Argument('object.amount', 'amount must match the target of the paymentUrl');
150
+ }
151
+ // 決済方法区分検証
152
+ if (paymentMethodTypeByObject !== paymentMethodTypeByTransaction) {
153
+ throw new factory.errors.Argument('object.paymentMethod', 'paymentMethod must match the target of the paymentUrl');
154
+ }
155
+ }
@@ -24,7 +24,11 @@ import { person2username } from './any/person2username';
24
24
  * 決済承認中止
25
25
  * タスクから決済承認を取り消す
26
26
  */
27
- declare function voidPayTransaction(params: factory.task.IData<factory.taskName.VoidPayTransaction>): (repos: {
27
+ declare function voidPayTransaction(params: factory.task.IData<factory.taskName.VoidPayTransaction> & {
28
+ sameAs?: {
29
+ id: string;
30
+ };
31
+ }): (repos: {
28
32
  accountingReport: AccountingReportRepo;
29
33
  action: ActionRepo;
30
34
  assetTransaction: AssetTransactionRepo;
@@ -34,7 +38,11 @@ declare function voidPayTransaction(params: factory.task.IData<factory.taskName.
34
38
  task: TaskRepo;
35
39
  transaction: TransactionRepo;
36
40
  }) => Promise<void>;
37
- declare function invalidatePaymentUrl(params: factory.task.IData<factory.taskName.VoidPayTransaction>): (repos: {
41
+ declare function invalidatePaymentUrl(params: factory.task.IData<factory.taskName.VoidPayTransaction> & {
42
+ sameAs?: {
43
+ id: string;
44
+ };
45
+ }): (repos: {
38
46
  accountingReport: AccountingReportRepo;
39
47
  action: ActionRepo;
40
48
  assetTransaction: AssetTransactionRepo;