@chevre/domain 24.0.0-alpha.25 → 24.0.0-alpha.26

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.
@@ -16,4 +16,18 @@ export declare class AcceptPayActionRepo extends ActionProcessRepo<IAcceptPayAct
16
16
  id: string;
17
17
  };
18
18
  }, inclusion: IKeyOfProjection[]): Promise<IAcceptPayAction[]>;
19
+ /**
20
+ * 決済取引番号から完了済の決済採用アクションを参照する
21
+ */
22
+ findCompletedAcceptActionsByTransactionNumber(params: {
23
+ project: {
24
+ id: string;
25
+ };
26
+ purpose: {
27
+ id: string;
28
+ };
29
+ object: {
30
+ transactionNumber: string;
31
+ };
32
+ }, inclusion: IKeyOfProjection[]): Promise<IAcceptPayAction[]>;
19
33
  }
@@ -68,5 +68,32 @@ class AcceptPayActionRepo extends actionProcess_1.ActionProcessRepo {
68
68
  .lean()
69
69
  .exec();
70
70
  }
71
+ /**
72
+ * 決済取引番号から完了済の決済採用アクションを参照する
73
+ */
74
+ async findCompletedAcceptActionsByTransactionNumber(params, inclusion) {
75
+ const andConditions = [
76
+ { typeOf: { $eq: factory.actionType.AcceptAction } },
77
+ { actionStatus: { $eq: factory.actionStatusType.CompletedActionStatus } },
78
+ { 'project.id': { $eq: params.project.id } },
79
+ { 'purpose.id': { $exists: true, $eq: params.purpose.id } },
80
+ { 'object.typeOf': { $exists: true, $eq: factory.assetTransactionType.Pay } },
81
+ { 'object.transactionNumber': { $exists: true, $eq: params.object.transactionNumber } }
82
+ ];
83
+ let positiveProjectionFields = actionProcess_1.AVAILABLE_PROJECT_FIELDS;
84
+ if (Array.isArray(inclusion) && inclusion.length > 0) {
85
+ positiveProjectionFields = inclusion.filter((key) => actionProcess_1.AVAILABLE_PROJECT_FIELDS.includes(key));
86
+ }
87
+ const projection = {
88
+ _id: 0,
89
+ id: { $toString: '$_id' },
90
+ ...Object.fromEntries(positiveProjectionFields.map((key) => ([key, 1])))
91
+ };
92
+ const query = this.actionModel.find({ $and: andConditions }, projection);
93
+ query.limit(1); // ひとまず1つだけでよい
94
+ return query.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
95
+ .lean()
96
+ .exec();
97
+ }
71
98
  }
72
99
  exports.AcceptPayActionRepo = AcceptPayActionRepo;
@@ -7,18 +7,27 @@ export type IActionRecipe = never;
7
7
  */
8
8
  export declare class AuthorizePaymentMethodActionRepo extends ActionProcessRepo<IAuthorizePaymentMethodAction, IActionRecipe> {
9
9
  /**
10
- * 取引に対するアクションを検索する
10
+ * 取引に対する決済承認アクションを検索する
11
11
  */
12
12
  findAuthorizePaymentMethodActionsByPurpose(params: {
13
+ /**
14
+ * 注文取引でフィルター
15
+ */
13
16
  purpose: {
14
17
  typeOf: factory.transactionType;
15
18
  id: string;
16
19
  };
20
+ /**
21
+ * 決済取引番号でフィルター
22
+ */
17
23
  object?: {
18
24
  paymentMethodId?: {
19
25
  $eq?: string;
20
26
  };
21
27
  };
28
+ /**
29
+ * アクションステータスでフィルター
30
+ */
22
31
  actionStatus?: {
23
32
  $eq?: factory.actionStatusType.CompletedActionStatus;
24
33
  };
@@ -34,7 +34,7 @@ const actionProcess_1 = require("./actionProcess");
34
34
  */
35
35
  class AuthorizePaymentMethodActionRepo extends actionProcess_1.ActionProcessRepo {
36
36
  /**
37
- * 取引に対するアクションを検索する
37
+ * 取引に対する決済承認アクションを検索する
38
38
  */
39
39
  async findAuthorizePaymentMethodActionsByPurpose(params) {
40
40
  const andConditions = [
@@ -76,7 +76,7 @@ class AuthorizePaymentMethodActionRepo extends actionProcess_1.ActionProcessRepo
76
76
  id: { $toString: '$_id' },
77
77
  ...Object.fromEntries(positiveProjectionFields.map((key) => ([key, 1])))
78
78
  };
79
- const query = this.actionModel.find((andConditions.length > 0) ? { $and: andConditions } : {}, projection);
79
+ const query = this.actionModel.find({ $and: andConditions }, projection);
80
80
  if (typeof params.sort?.startDate === 'number') {
81
81
  query.sort({ startDate: params.sort.startDate });
82
82
  }
@@ -1,5 +1,6 @@
1
1
  import * as factory from '../../../../factory';
2
- import type { ActionRepo } from '../../../../repo/action';
2
+ import type { AcceptPayActionRepo } from '../../../../repo/action/acceptPay';
3
+ import type { AuthorizePaymentMethodActionRepo } from '../../../../repo/action/authorizePaymentMethod';
3
4
  import type { AuthorizationRepo } from '../../../../repo/authorization';
4
5
  import type { TicketRepo } from '../../../../repo/ticket';
5
6
  import type { ITransactionInProgress, PlaceOrderRepo } from '../../../../repo/transaction/placeOrder';
@@ -7,7 +8,9 @@ import type { TransactionNumberRepo } from '../../../../repo/transactionNumber';
7
8
  import * as PayTransactionService from '../../../assetTransaction/pay';
8
9
  import { IInvoiceByTicketToken } from '../factory';
9
10
  interface IFixTransactionNumberRepos {
10
- action: ActionRepo;
11
+ action?: never;
12
+ acceptPayAction: AcceptPayActionRepo;
13
+ authorizePaymentMethodAction: AuthorizePaymentMethodActionRepo;
11
14
  authorization: AuthorizationRepo;
12
15
  ticket: TicketRepo;
13
16
  placeOrder: PlaceOrderRepo;
@@ -1,5 +1,6 @@
1
1
  import * as factory from '../../../../factory';
2
- import type { ActionRepo } from '../../../../repo/action';
2
+ import type { AcceptPayActionRepo } from '../../../../repo/action/acceptPay';
3
+ import type { AuthorizePaymentMethodActionRepo } from '../../../../repo/action/authorizePaymentMethod';
3
4
  import type { AuthorizationRepo } from '../../../../repo/authorization';
4
5
  import type { TicketRepo } from '../../../../repo/ticket';
5
6
  import type { ITransactionInProgress, PlaceOrderRepo } from '../../../../repo/transaction/placeOrder';
@@ -10,6 +11,14 @@ interface IAcceptAction2ticketResult {
10
11
  invoiceByTicketToken: IInvoiceByTicketToken;
11
12
  ticketToken: string;
12
13
  }
14
+ interface IHandlePrePublishedPaymentMethodIdOnAuthorizingRepos {
15
+ action?: never;
16
+ acceptPayAction: AcceptPayActionRepo;
17
+ authorizePaymentMethodAction: AuthorizePaymentMethodActionRepo;
18
+ authorization: AuthorizationRepo;
19
+ ticket: TicketRepo;
20
+ placeOrder: PlaceOrderRepo;
21
+ }
13
22
  /**
14
23
  * 決済承認前の決済採用アクションを参照する
15
24
  */
@@ -17,12 +26,7 @@ declare function handlePrePublishedPaymentMethodIdOnAuthorizing(params: {
17
26
  object: Pick<IObjectWithoutDetail, 'amount' | 'issuedThrough' | 'paymentMethod' | 'referencesOrder'>;
18
27
  prePublishedPaymentMethodId: string;
19
28
  transaction: Pick<ITransactionInProgress, 'agent' | 'expires' | 'id' | 'typeOf' | 'project' | 'seller'>;
20
- }): (repos: {
21
- action: ActionRepo;
22
- authorization: AuthorizationRepo;
23
- ticket: TicketRepo;
24
- placeOrder: PlaceOrderRepo;
25
- }) => Promise<{
29
+ }): (repos: IHandlePrePublishedPaymentMethodIdOnAuthorizingRepos) => Promise<{
26
30
  authorizeParams?: {
27
31
  creditCard: factory.action.authorize.paymentMethod.any.ICreditCard;
28
32
  paymentMethodByTransaction: factory.transaction.placeOrder.IPaymentMethodByPaymentUrl;
@@ -37,4 +41,4 @@ declare function handlePrePublishedPaymentMethodIdOnAuthorizing(params: {
37
41
  authorizeParams?: never;
38
42
  acceptAction2ticketResult?: never;
39
43
  }>;
40
- export { handlePrePublishedPaymentMethodIdOnAuthorizing };
44
+ export { IHandlePrePublishedPaymentMethodIdOnAuthorizingRepos, handlePrePublishedPaymentMethodIdOnAuthorizing };
@@ -125,24 +125,32 @@ function handlePrePublishedPaymentMethodIdOnAuthorizing(params) {
125
125
  const paymentMethodByTransaction = await repos.placeOrder.findInProgressPaymentMethodId({ id: params.transaction.id });
126
126
  if (params.prePublishedPaymentMethodId === paymentMethodByTransaction?.paymentMethodId) {
127
127
  // check existence of acceptAction when authorizing payment(2024-06-01~)
128
- acceptPayAction = (await repos.action.search({
129
- limit: 1,
130
- page: 1,
131
- project: { id: { $eq: params.transaction.project.id } },
132
- typeOf: { $eq: factory.actionType.AcceptAction },
133
- actionStatus: { $in: [factory.actionStatusType.CompletedActionStatus] },
134
- purpose: { id: { $in: [params.transaction.id] } },
135
- object: {
136
- transactionNumber: { $eq: params.prePublishedPaymentMethodId },
137
- typeOf: { $eq: factory.assetTransactionType.Pay }
138
- }
128
+ // acceptPayAction = (<Pick<IAcceptPayAction, 'object' | 'result' | 'id' | 'instrument'>[]>await repos.action.search<factory.actionType.AcceptAction>(
129
+ // {
130
+ // limit: 1,
131
+ // page: 1,
132
+ // project: { id: { $eq: params.transaction.project.id } },
133
+ // typeOf: { $eq: factory.actionType.AcceptAction },
134
+ // actionStatus: { $in: [factory.actionStatusType.CompletedActionStatus] },
135
+ // purpose: { id: { $in: [params.transaction.id] } },
136
+ // object: {
137
+ // transactionNumber: { $eq: params.prePublishedPaymentMethodId },
138
+ // typeOf: { $eq: factory.assetTransactionType.Pay }
139
+ // }
140
+ // },
141
+ // ['object', 'result', 'instrument']
142
+ // )).shift();
143
+ acceptPayAction = (await repos.acceptPayAction.findCompletedAcceptActionsByTransactionNumber({
144
+ project: { id: params.transaction.project.id },
145
+ purpose: { id: params.transaction.id },
146
+ object: { transactionNumber: params.prePublishedPaymentMethodId }
139
147
  }, ['object', 'result', 'instrument'])).shift();
140
148
  if (acceptPayAction === undefined) {
141
149
  throw new factory.errors.NotFound(factory.actionType.AcceptAction);
142
150
  }
143
151
  debug('acceptPayAction found:', acceptPayAction.id);
144
152
  // find recipe(2024-06-02~)
145
- const actionRecipe = await repos.action.findRecipeByAction({
153
+ const actionRecipe = await repos.acceptPayAction.findRecipeByAction({
146
154
  project: { id: params.transaction.project.id },
147
155
  recipeFor: { id: acceptPayAction.id }
148
156
  });
@@ -169,13 +177,22 @@ function handlePrePublishedPaymentMethodIdOnAuthorizing(params) {
169
177
  throw new factory.errors.Argument('paymentMethodId', 'pendingPaymentAgencyTransaction not found');
170
178
  }
171
179
  // 既に承認済であれば何もしない(2023-05-15~)
172
- const existingCompletedAuthorizeActions = await repos.action.searchByPurpose({
173
- typeOf: factory.actionType.AuthorizeAction,
180
+ // const existingCompletedAuthorizeActions = <IAuthorizePaymentAction[]>
181
+ // await repos.action.searchByPurpose<factory.actionType.AuthorizeAction>({
182
+ // typeOf: factory.actionType.AuthorizeAction,
183
+ // purpose: { id: params.transaction.id, typeOf: params.transaction.typeOf },
184
+ // actionStatus: { $eq: factory.actionStatusType.CompletedActionStatus },
185
+ // object: {
186
+ // paymentMethodId: { $eq: params.prePublishedPaymentMethodId },
187
+ // typeOf: { $eq: factory.action.authorize.paymentMethod.any.ResultType.Payment }
188
+ // },
189
+ // sort: { startDate: factory.sortType.Ascending }
190
+ // });
191
+ const existingCompletedAuthorizeActions = await repos.authorizePaymentMethodAction.findAuthorizePaymentMethodActionsByPurpose({
174
192
  purpose: { id: params.transaction.id, typeOf: params.transaction.typeOf },
175
193
  actionStatus: { $eq: factory.actionStatusType.CompletedActionStatus },
176
194
  object: {
177
- paymentMethodId: { $eq: params.prePublishedPaymentMethodId },
178
- typeOf: { $eq: factory.action.authorize.paymentMethod.any.ResultType.Payment }
195
+ paymentMethodId: { $eq: params.prePublishedPaymentMethodId }
179
196
  },
180
197
  sort: { startDate: factory.sortType.Ascending }
181
198
  });
@@ -4,6 +4,7 @@ import type { AcceptedPaymentMethodRepo } from '../../../repo/acceptedPaymentMet
4
4
  import type { AccountingReportRepo } from '../../../repo/accountingReport';
5
5
  import type { ActionRepo } from '../../../repo/action';
6
6
  import type { CheckMovieTicketActionRepo } from '../../../repo/action/checkMovieTicket';
7
+ import type { AcceptPayActionRepo } from '../../../repo/action/acceptPay';
7
8
  import type { AuthorizeInvoiceActionRepo } from '../../../repo/action/authorizeInvoice';
8
9
  import type { AuthorizePaymentMethodActionRepo } from '../../../repo/action/authorizePaymentMethod';
9
10
  import type { AssetTransactionRepo } from '../../../repo/assetTransaction';
@@ -28,6 +29,7 @@ interface IAuthorizeRepos {
28
29
  accountingReport: AccountingReportRepo;
29
30
  action: ActionRepo;
30
31
  checkMovieTicketAction: CheckMovieTicketActionRepo;
32
+ acceptPayAction: AcceptPayActionRepo;
31
33
  authorizeInvoiceAction: AuthorizeInvoiceActionRepo;
32
34
  authorizePaymentMethodAction: AuthorizePaymentMethodActionRepo;
33
35
  assetTransaction: AssetTransactionRepo;
@@ -63,7 +63,14 @@ function authorize(params) {
63
63
  object: params.object,
64
64
  transaction,
65
65
  paymentServiceType
66
- })(repos);
66
+ })({
67
+ acceptPayAction: repos.acceptPayAction,
68
+ authorizePaymentMethodAction: repos.authorizePaymentMethodAction,
69
+ authorization: repos.authorization,
70
+ ticket: repos.ticket,
71
+ placeOrder: repos.placeOrder,
72
+ transactionNumber: repos.transactionNumber
73
+ });
67
74
  if (typeof fixTransactionNumberResult.id === 'string') {
68
75
  return { id: fixTransactionNumberResult.id };
69
76
  }
@@ -29,6 +29,7 @@ const acceptedPaymentMethod_1 = require("../../repo/acceptedPaymentMethod");
29
29
  const accountingReport_1 = require("../../repo/accountingReport");
30
30
  const action_1 = require("../../repo/action");
31
31
  const checkMovieTicket_1 = require("../../repo/action/checkMovieTicket");
32
+ const acceptPay_1 = require("../../repo/action/acceptPay");
32
33
  const authorizeInvoice_1 = require("../../repo/action/authorizeInvoice");
33
34
  const authorizePaymentMethod_1 = require("../../repo/action/authorizePaymentMethod");
34
35
  const assetTransaction_1 = require("../../repo/assetTransaction");
@@ -81,6 +82,7 @@ function call(params) {
81
82
  accountingReport: new accountingReport_1.AccountingReportRepo(connection),
82
83
  action: new action_1.ActionRepo(connection),
83
84
  checkMovieTicketAction: new checkMovieTicket_1.CheckMovieTicketActionRepo(connection),
85
+ acceptPayAction: new acceptPay_1.AcceptPayActionRepo(connection),
84
86
  authorizeInvoiceAction: new authorizeInvoice_1.AuthorizeInvoiceActionRepo(connection),
85
87
  authorizePaymentMethodAction: authorizePaymentMethodActionRepo,
86
88
  assetTransaction: new assetTransaction_1.AssetTransactionRepo(connection),
package/package.json CHANGED
@@ -99,5 +99,5 @@
99
99
  "postversion": "git push origin --tags",
100
100
  "prepublishOnly": "npm run clean && npm run build"
101
101
  },
102
- "version": "24.0.0-alpha.25"
102
+ "version": "24.0.0-alpha.26"
103
103
  }