@chevre/domain 21.2.0-alpha.46 → 21.2.0-alpha.48

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.
@@ -82,7 +82,18 @@ export declare class MongoRepository {
82
82
  typeOf?: T;
83
83
  purpose: {
84
84
  typeOf: factory.transactionType;
85
- id?: string;
85
+ id: string;
86
+ };
87
+ object?: {
88
+ typeOf?: {
89
+ $eq?: factory.action.authorize.offer.seatReservation.ObjectType.SeatReservation | factory.action.authorize.paymentMethod.any.ResultType.Payment;
90
+ };
91
+ paymentMethodId?: {
92
+ $eq?: string;
93
+ };
94
+ };
95
+ actionStatus?: {
96
+ $eq?: factory.actionStatusType;
86
97
  };
87
98
  sort?: factory.action.ISortOrder;
88
99
  }): Promise<IAction<T>[]>;
@@ -528,32 +528,16 @@ class MongoRepository {
528
528
  * 取引に対するアクション検索時などに使用
529
529
  */
530
530
  searchByPurpose(params) {
531
- var _a;
531
+ var _a, _b, _c, _d, _e, _f;
532
532
  return __awaiter(this, void 0, void 0, function* () {
533
- const conditions = {
534
- 'purpose.typeOf': {
535
- $exists: true,
536
- $eq: params.purpose.typeOf
537
- }
538
- };
539
- if (params.typeOf !== undefined) {
540
- conditions.typeOf = params.typeOf;
541
- }
542
- if (params.purpose.id !== undefined) {
543
- conditions['purpose.id'] = {
544
- $exists: true,
545
- $eq: params.purpose.id
546
- };
547
- }
548
- const query = this.actionModel.find(conditions)
549
- .select({ __v: 0, createdAt: 0, updatedAt: 0 });
550
- // tslint:disable-next-line:no-single-line-block-comment
551
- /* istanbul ignore else */
552
- if (((_a = params.sort) === null || _a === void 0 ? void 0 : _a.startDate) !== undefined) {
553
- query.sort({ startDate: params.sort.startDate });
554
- }
555
- return query.exec()
556
- .then((docs) => docs.map((doc) => doc.toObject()));
533
+ return this.search(Object.assign(Object.assign(Object.assign({ purpose: {
534
+ id: { $in: [params.purpose.id] },
535
+ typeOf: { $in: [params.purpose.typeOf] }
536
+ }, object: Object.assign(Object.assign({}, (typeof ((_b = (_a = params.object) === null || _a === void 0 ? void 0 : _a.typeOf) === null || _b === void 0 ? void 0 : _b.$eq) === 'string')
537
+ ? { typeOf: { $eq: params.object.typeOf.$eq } }
538
+ : undefined), (typeof ((_d = (_c = params.object) === null || _c === void 0 ? void 0 : _c.paymentMethodId) === null || _d === void 0 ? void 0 : _d.$eq) === 'string')
539
+ ? { paymentMethodId: { $eq: params.object.paymentMethodId.$eq } }
540
+ : undefined) }, (typeof ((_e = params.actionStatus) === null || _e === void 0 ? void 0 : _e.$eq) === 'string') ? { actionStatus: { $in: [params.actionStatus.$eq] } } : undefined), (typeof params.typeOf === 'string') ? { typeOf: { $eq: params.typeOf } } : undefined), (typeof ((_f = params.sort) === null || _f === void 0 ? void 0 : _f.startDate) === 'number') ? { sort: params.sort } : undefined), [], []);
557
541
  });
558
542
  }
559
543
  /**
@@ -330,10 +330,10 @@ class MongoRepository {
330
330
  // すでに確定済の場合スルー
331
331
  }
332
332
  else if (transaction.status === factory.transactionStatusType.Expired) {
333
- throw new factory.errors.Argument('Transaction id', 'Transaction already expired');
333
+ throw new factory.errors.Argument('Transaction id', `Transaction ${transaction.typeOf} ${transaction.transactionNumber} already expired`);
334
334
  }
335
335
  else if (transaction.status === factory.transactionStatusType.Canceled) {
336
- throw new factory.errors.Argument('Transaction id', 'Transaction already canceled');
336
+ throw new factory.errors.Argument('Transaction id', `Transaction ${transaction.typeOf} ${transaction.transactionNumber} already canceled`);
337
337
  }
338
338
  else {
339
339
  throw new factory.errors.NotFound(this.transactionModel.modelName);
@@ -558,10 +558,10 @@ class MongoRepository {
558
558
  // すでに中止済の場合スルー
559
559
  }
560
560
  else if (transaction.status === factory.transactionStatusType.Expired) {
561
- throw new factory.errors.Argument('Transaction id', 'Transaction already expired');
561
+ throw new factory.errors.Argument('Transaction id', `Transaction ${transaction.typeOf} ${transaction.transactionNumber} already expired`);
562
562
  }
563
563
  else if (transaction.status === factory.transactionStatusType.Confirmed) {
564
- throw new factory.errors.Argument('Transaction id', 'Confirmed transaction unable to cancel');
564
+ throw new factory.errors.Argument('Transaction id', `Confirmed transaction ${transaction.typeOf} ${transaction.transactionNumber} unable to cancel`);
565
565
  }
566
566
  else {
567
567
  throw new factory.errors.NotFound(this.transactionModel.modelName);
@@ -272,10 +272,16 @@ function processAuthorizeCreditCard(params, transaction, paymentServiceId) {
272
272
  }
273
273
  function processAuthorizeMovieTicket(params, transaction, paymentServiceId, useCheckMovieTicketBeforePay) {
274
274
  return (repos) => __awaiter(this, void 0, void 0, function* () {
275
- const { accountId, checkResult, payAction } = yield MovieTicketPayment.authorize(params, transaction, paymentServiceId, useCheckMovieTicketBeforePay)(repos);
275
+ const { accountId, payAction, accountsReceivablesByServiceType } = yield MovieTicketPayment.authorize(params, transaction, paymentServiceId, useCheckMovieTicketBeforePay)(repos);
276
276
  return saveAuthorizeResult({
277
277
  id: transaction.id,
278
- update: Object.assign({ 'object.accountId': accountId, 'object.paymentMethod.accountId': accountId, 'object.payAction': payAction }, (checkResult !== undefined) ? { 'object.checkResult': checkResult } : undefined)
278
+ update: {
279
+ 'object.accountId': accountId,
280
+ 'object.paymentMethod.accountId': accountId,
281
+ 'object.payAction': payAction,
282
+ // 認証レスポンスより計上金額を保管(2023-05-15~)
283
+ 'object.accountsReceivablesByServiceType': accountsReceivablesByServiceType
284
+ }
279
285
  })(repos);
280
286
  });
281
287
  }
@@ -157,9 +157,13 @@ function triggerWebhook(params) {
157
157
  while (numberOfTry >= 0) {
158
158
  try {
159
159
  numberOfTry += 1;
160
- if (numberOfTry > settings_1.MAX_RETRY_COUNT_TRIGGER_WEBHOOK) {
160
+ if (numberOfTry > settings_1.TRIGGER_WEBHOOK_MAX_RETRY_COUNT) {
161
161
  retry = false;
162
162
  }
163
+ // retryInterval
164
+ if (numberOfTry > 1) {
165
+ yield sleep(settings_1.TRIGGER_WEBHOOK_RETRY_INTERVAL_IN_MS * (numberOfTry - 1));
166
+ }
163
167
  yield processInformAction(params)(repos);
164
168
  break;
165
169
  }
@@ -175,6 +179,15 @@ function triggerWebhook(params) {
175
179
  });
176
180
  }
177
181
  exports.triggerWebhook = triggerWebhook;
182
+ function sleep(waitTime) {
183
+ return __awaiter(this, void 0, void 0, function* () {
184
+ return new Promise((resolve) => {
185
+ setTimeout(() => {
186
+ resolve();
187
+ }, waitTime);
188
+ });
189
+ });
190
+ }
178
191
  function processInformAction(params) {
179
192
  return (repos) => __awaiter(this, void 0, void 0, function* () {
180
193
  var _a, _b;
@@ -240,6 +240,7 @@ exports.publishPaymentUrl = publishPaymentUrl;
240
240
  * 決済承認
241
241
  */
242
242
  function authorize(params) {
243
+ // tslint:disable-next-line:max-func-body-length
243
244
  return (repos) => __awaiter(this, void 0, void 0, function* () {
244
245
  var _a, _b;
245
246
  const transaction = yield repos.transaction.findInProgressById({ typeOf: params.purpose.typeOf, id: params.purpose.id });
@@ -251,6 +252,21 @@ function authorize(params) {
251
252
  const paymentMethodIdByTransaction = (_a = transaction.object.paymentMethods) === null || _a === void 0 ? void 0 : _a.paymentMethodId;
252
253
  if (params.object.paymentMethodId === paymentMethodIdByTransaction) {
253
254
  transactionNumber = params.object.paymentMethodId;
255
+ // 既に承認済であれば何もしない(2023-05-15~)
256
+ const existingCompletedAuthorizeActions = yield repos.action.searchByPurpose({
257
+ typeOf: factory.actionType.AuthorizeAction,
258
+ purpose: { id: transaction.id, typeOf: transaction.typeOf },
259
+ actionStatus: { $eq: factory.actionStatusType.CompletedActionStatus },
260
+ object: {
261
+ paymentMethodId: { $eq: transactionNumber },
262
+ typeOf: { $eq: factory.action.authorize.paymentMethod.any.ResultType.Payment }
263
+ },
264
+ sort: { startDate: factory.sortType.Ascending }
265
+ });
266
+ const existingCompletedAuthorizeAction = existingCompletedAuthorizeActions.shift();
267
+ if (existingCompletedAuthorizeAction !== undefined) {
268
+ return existingCompletedAuthorizeAction;
269
+ }
254
270
  }
255
271
  else {
256
272
  // 取引にないpaymentMethodIdの指定はクライアントエラー
@@ -6,10 +6,14 @@ import { MongoRepository as EventRepo } from '../../../repo/event';
6
6
  import { MongoRepository as ProductRepo } from '../../../repo/product';
7
7
  import { MongoRepository as ProjectRepo } from '../../../repo/project';
8
8
  import { MongoRepository as SellerRepo } from '../../../repo/seller';
9
- import { ICheckResult } from './checkByIdentifier';
10
9
  export declare function validateMovieTicket(params: factory.assetTransaction.pay.IStartParamsWithoutDetail, paymentServiceId: string, useCheckMovieTicketBeforePay: boolean): (repos: {
11
10
  event: EventRepo;
12
11
  product: ProductRepo;
13
12
  project: ProjectRepo;
14
13
  seller: SellerRepo;
15
- }) => Promise<ICheckResult | undefined>;
14
+ }) => Promise<{
15
+ accountsReceivablesByServiceType: {
16
+ serviceType: string;
17
+ accountsReceivable?: number;
18
+ }[];
19
+ }>;
@@ -15,8 +15,8 @@ exports.validateMovieTicket = void 0;
15
15
  */
16
16
  const factory = require("../../../factory");
17
17
  const checkByIdentifier_1 = require("./checkByIdentifier");
18
- // tslint:disable-next-line:max-func-body-length
19
18
  function validateMovieTicket(params, paymentServiceId, useCheckMovieTicketBeforePay) {
19
+ // tslint:disable-next-line:max-func-body-length
20
20
  return (repos) => __awaiter(this, void 0, void 0, function* () {
21
21
  var _a, _b, _c, _d;
22
22
  const movieTickets = (_a = params.object.paymentMethod) === null || _a === void 0 ? void 0 : _a.movieTickets;
@@ -54,7 +54,7 @@ function validateMovieTicket(params, paymentServiceId, useCheckMovieTicketBefore
54
54
  }
55
55
  // オプション追加(2023-03-06~)
56
56
  if (!useCheckMovieTicketBeforePay) {
57
- return;
57
+ return { accountsReceivablesByServiceType: [] };
58
58
  }
59
59
  const checkResult = yield (0, checkByIdentifier_1.checkByIdentifier)({
60
60
  movieTickets: movieTickets,
@@ -62,24 +62,16 @@ function validateMovieTicket(params, paymentServiceId, useCheckMovieTicketBefore
62
62
  screeningEvent: screeningEvent,
63
63
  paymentServiceId
64
64
  })(repos);
65
- // checkResult.movieTicketsへの依存排除(2023-03-24~)
66
- // 要求に対して十分かどうか検証する
67
- // const availableMovieTickets = checkResult.movieTickets.filter((t) => t.amount?.validThrough === undefined);
68
- // 総数が足りているか(券種ごとに枚数検証を実行するので不要)
69
- // if (availableMovieTickets.length < movieTickets.length) {
70
- // throw new factory.errors.Argument(
71
- // 'movieTickets',
72
- // `${movieTickets.length - availableMovieTickets.length} movie tickets short`
73
- // );
74
- // }
65
+ const accountsReceivablesByServiceType = [];
75
66
  // 券種ごとに枚数が足りているか
76
67
  const serviceTypes = [...new Set(movieTickets.map((t) => t.serviceType))];
77
68
  serviceTypes.forEach((serviceType) => {
78
- var _a, _b, _c;
69
+ var _a, _b;
79
70
  const requiredMovieTicketsCountByServiceType = movieTickets.filter((t) => t.serviceType === serviceType).length;
80
71
  let availableMovieTicketsCountByServiceType = 0;
81
72
  const ykknInfos = (_b = (_a = checkResult.purchaseNumberAuthResult.knyknrNoInfoOut) === null || _a === void 0 ? void 0 : _a.find((knyknrNoInfoOut) => knyknrNoInfoOut.knyknrNo === movieTicketIdentifiers[0])) === null || _b === void 0 ? void 0 : _b.ykknInfo;
82
- const ykknKnshbtsmiNum = (_c = ykknInfos === null || ykknInfos === void 0 ? void 0 : ykknInfos.find((ykknInfo) => ykknInfo.ykknshTyp === serviceType)) === null || _c === void 0 ? void 0 : _c.ykknKnshbtsmiNum;
73
+ const ykknInfoOfServiceType = ykknInfos === null || ykknInfos === void 0 ? void 0 : ykknInfos.find((ykknInfo) => ykknInfo.ykknshTyp === serviceType);
74
+ const ykknKnshbtsmiNum = ykknInfoOfServiceType === null || ykknInfoOfServiceType === void 0 ? void 0 : ykknInfoOfServiceType.ykknKnshbtsmiNum;
83
75
  if (typeof ykknKnshbtsmiNum === 'string') {
84
76
  availableMovieTicketsCountByServiceType = Number(ykknKnshbtsmiNum);
85
77
  }
@@ -87,18 +79,13 @@ function validateMovieTicket(params, paymentServiceId, useCheckMovieTicketBefore
87
79
  const shortNumber = requiredMovieTicketsCountByServiceType - availableMovieTicketsCountByServiceType;
88
80
  throw new factory.errors.Argument('movieTickets', `${shortNumber} movie tickets by service type ${serviceType} short`);
89
81
  }
90
- // const availableMovieTicketsByServiceType = availableMovieTickets.filter((t) => t.serviceType === serviceType);
91
- // if (availableMovieTicketsByServiceType.length < requiredMovieTicketsCountByServiceType) {
92
- // const shortNumber = requiredMovieTicketsCountByServiceType - availableMovieTicketsByServiceType.length;
93
- // throw new factory.errors.Argument(
94
- // 'movieTickets',
95
- // `${shortNumber} movie tickets by service type ${serviceType} short`
96
- // );
97
- // }
82
+ // checkResultから計上金額を取得
83
+ const accountsReceivableByResponse = ykknInfoOfServiceType === null || ykknInfoOfServiceType === void 0 ? void 0 : ykknInfoOfServiceType.kijUnip;
84
+ accountsReceivablesByServiceType.push(Object.assign({ serviceType }, (typeof accountsReceivableByResponse === 'string')
85
+ ? { accountsReceivable: Number(accountsReceivableByResponse) }
86
+ : undefined));
98
87
  });
99
- // checkはするが保管は保留(2023-03-09~)
100
- return;
101
- // return checkResult;
88
+ return { accountsReceivablesByServiceType };
102
89
  });
103
90
  }
104
91
  exports.validateMovieTicket = validateMovieTicket;
@@ -42,7 +42,10 @@ declare function checkMovieTicket(params: factory.action.check.paymentMethod.mov
42
42
  }>;
43
43
  interface IAuthorizeResult {
44
44
  accountId: string;
45
- checkResult?: ICheckResult;
45
+ accountsReceivablesByServiceType: {
46
+ serviceType: string;
47
+ accountsReceivable?: number;
48
+ }[];
46
49
  payAction: factory.action.trade.pay.IAction;
47
50
  }
48
51
  /**
@@ -106,11 +106,12 @@ function authorize(params, transaction, paymentServiceId, useCheckMovieTicketBef
106
106
  return (repos) => __awaiter(this, void 0, void 0, function* () {
107
107
  var _a, _b;
108
108
  let accountId;
109
- let checkResult;
110
109
  let payAction;
110
+ let accountsReceivablesByServiceType = [];
111
111
  try {
112
112
  // MovieTicket決済の場合、認証
113
- checkResult = yield (0, validation_1.validateMovieTicket)(params, paymentServiceId, useCheckMovieTicketBeforePay)(repos);
113
+ const validateMovieTicketResult = yield (0, validation_1.validateMovieTicket)(params, paymentServiceId, useCheckMovieTicketBeforePay)(repos);
114
+ accountsReceivablesByServiceType = validateMovieTicketResult.accountsReceivablesByServiceType;
114
115
  const paymentMethod = transaction.object.paymentMethod;
115
116
  const paymentMethodType = String(paymentMethod === null || paymentMethod === void 0 ? void 0 : paymentMethod.typeOf);
116
117
  const additionalProperty = paymentMethod === null || paymentMethod === void 0 ? void 0 : paymentMethod.additionalProperty;
@@ -141,7 +142,7 @@ function authorize(params, transaction, paymentServiceId, useCheckMovieTicketBef
141
142
  catch (error) {
142
143
  throw (0, errorHandler_1.handleMvtkReserveError)(error);
143
144
  }
144
- return { accountId, checkResult, payAction };
145
+ return { accountId, payAction, accountsReceivablesByServiceType };
145
146
  });
146
147
  }
147
148
  exports.authorize = authorize;
@@ -1,5 +1,7 @@
1
1
  import * as moment from 'moment';
2
2
  import * as factory from './factory';
3
+ export declare const TRIGGER_WEBHOOK_MAX_RETRY_COUNT: number;
4
+ export declare const TRIGGER_WEBHOOK_RETRY_INTERVAL_IN_MS: number;
3
5
  export declare const ABORTED_TASKS_WITHOUT_REPORT: string[];
4
6
  /**
5
7
  * 資産取引保管期間
@@ -32,7 +34,6 @@ export declare const USE_ASSET_TRANSACTION_SYNC_PROCESSING: boolean;
32
34
  export declare const USE_PAY_ASSET_TRANSACTION_SYNC_PROCESSING: boolean;
33
35
  export declare const USE_NEW_EVENT_AVAILABILITY_KEY_FROM: moment.Moment;
34
36
  export declare const INFORM_RESERVATION_TASK_DELAY_IN_SECONDS: number;
35
- export declare const MAX_RETRY_COUNT_TRIGGER_WEBHOOK: number;
36
37
  /**
37
38
  * グローバル設定
38
39
  */
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.settings = exports.MAX_RETRY_COUNT_TRIGGER_WEBHOOK = exports.INFORM_RESERVATION_TASK_DELAY_IN_SECONDS = exports.USE_NEW_EVENT_AVAILABILITY_KEY_FROM = exports.USE_PAY_ASSET_TRANSACTION_SYNC_PROCESSING = exports.USE_ASSET_TRANSACTION_SYNC_PROCESSING = exports.DEFAULT_TASKS_EXPORT_AGENT_NAME = exports.DEFAULT_PAYMENT_METHOD_TYPE_FOR_CREDIT_CARD = exports.DEFAULT_SENDER_EMAIL = exports.TRANSACTION_CANCELED_STORAGE_PERIOD_IN_DAYS = exports.TRANSACTION_CONFIRMED_STORAGE_PERIOD_IN_DAYS = exports.ASSET_TRANSACTION_STORAGE_PERIOD_IN_DAYS = exports.ABORTED_TASKS_WITHOUT_REPORT = void 0;
3
+ exports.settings = exports.INFORM_RESERVATION_TASK_DELAY_IN_SECONDS = exports.USE_NEW_EVENT_AVAILABILITY_KEY_FROM = exports.USE_PAY_ASSET_TRANSACTION_SYNC_PROCESSING = exports.USE_ASSET_TRANSACTION_SYNC_PROCESSING = exports.DEFAULT_TASKS_EXPORT_AGENT_NAME = exports.DEFAULT_PAYMENT_METHOD_TYPE_FOR_CREDIT_CARD = exports.DEFAULT_SENDER_EMAIL = exports.TRANSACTION_CANCELED_STORAGE_PERIOD_IN_DAYS = exports.TRANSACTION_CONFIRMED_STORAGE_PERIOD_IN_DAYS = exports.ASSET_TRANSACTION_STORAGE_PERIOD_IN_DAYS = exports.ABORTED_TASKS_WITHOUT_REPORT = exports.TRIGGER_WEBHOOK_RETRY_INTERVAL_IN_MS = exports.TRIGGER_WEBHOOK_MAX_RETRY_COUNT = void 0;
4
4
  const moment = require("moment");
5
5
  const factory = require("./factory");
6
6
  const transactionWebhookUrls = (typeof process.env.INFORM_TRANSACTION_URL === 'string')
@@ -14,6 +14,12 @@ const informReservationUrls = (typeof process.env.INFORM_RESERVATION_URL === 'st
14
14
  : [];
15
15
  // tslint:disable-next-line:no-magic-numbers
16
16
  const triggerWebhookTimeout = (process.env.TRIGGER_WEBHOOK_TIMEOUT !== undefined) ? Number(process.env.TRIGGER_WEBHOOK_TIMEOUT) : 15000;
17
+ exports.TRIGGER_WEBHOOK_MAX_RETRY_COUNT = (typeof process.env.TRIGGER_WEBHOOK_MAX_RETRY_COUNT === 'string')
18
+ ? Number(process.env.TRIGGER_WEBHOOK_MAX_RETRY_COUNT)
19
+ : 0;
20
+ exports.TRIGGER_WEBHOOK_RETRY_INTERVAL_IN_MS = (typeof process.env.TRIGGER_WEBHOOK_RETRY_INTERVAL_IN_MS === 'string')
21
+ ? Number(process.env.TRIGGER_WEBHOOK_RETRY_INTERVAL_IN_MS)
22
+ : 0;
17
23
  const MAXIMUM_RESERVATION_GRACE_PERIOD_IN_DAYS = (typeof process.env.MAXIMUM_RESERVATION_GRACE_PERIOD_IN_DAYS === 'string')
18
24
  ? Number(process.env.MAXIMUM_RESERVATION_GRACE_PERIOD_IN_DAYS)
19
25
  // tslint:disable-next-line:no-magic-numbers
@@ -53,9 +59,6 @@ exports.USE_NEW_EVENT_AVAILABILITY_KEY_FROM = (typeof process.env.USE_NEW_EVENT_
53
59
  exports.INFORM_RESERVATION_TASK_DELAY_IN_SECONDS = (typeof process.env.INFORM_RESERVATION_TASK_DELAY_IN_SECONDS === 'string')
54
60
  ? Number(process.env.INFORM_RESERVATION_TASK_DELAY_IN_SECONDS)
55
61
  : 0;
56
- exports.MAX_RETRY_COUNT_TRIGGER_WEBHOOK = (typeof process.env.MAX_RETRY_COUNT_TRIGGER_WEBHOOK === 'string')
57
- ? Number(process.env.MAX_RETRY_COUNT_TRIGGER_WEBHOOK)
58
- : 0;
59
62
  /**
60
63
  * グローバル設定
61
64
  */
package/package.json CHANGED
@@ -117,5 +117,5 @@
117
117
  "postversion": "git push origin --tags",
118
118
  "prepublishOnly": "npm run clean && npm run build && npm test && npm run doc"
119
119
  },
120
- "version": "21.2.0-alpha.46"
120
+ "version": "21.2.0-alpha.48"
121
121
  }