@chevre/domain 24.0.0-alpha.74 → 24.0.0-alpha.76

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 (42) hide show
  1. package/lib/chevre/index.d.ts +0 -2
  2. package/lib/chevre/index.js +0 -8
  3. package/lib/chevre/service/assetTransaction/pay/start/processAuthorize.js +5 -5
  4. package/lib/chevre/service/assetTransaction/registerService/potentialActions.js +0 -1
  5. package/lib/chevre/service/assetTransaction/registerService.d.ts +3 -0
  6. package/lib/chevre/service/assetTransaction/registerService.js +2 -55
  7. package/lib/chevre/service/assetTransaction/reserve/start/createSubReservations.js +35 -69
  8. package/lib/chevre/service/assetTransaction/reserve/start.js +18 -85
  9. package/lib/chevre/service/assetTransaction.d.ts +0 -2
  10. package/lib/chevre/service/assetTransaction.js +1 -10
  11. package/lib/chevre/service/task/payment/payByTask.js +4 -4
  12. package/lib/chevre/service/task/payment/refundByTask.js +4 -4
  13. package/lib/chevre/service/task/payment/voidPaymentByTask.js +4 -4
  14. package/lib/chevre/service/taskHandler.d.ts +6 -1
  15. package/lib/chevre/service/taskHandler.js +10 -1
  16. package/lib/chevre/service.d.ts +0 -4
  17. package/lib/chevre/service.js +1 -21
  18. package/package.json +1 -3
  19. package/lib/chevre/pecorinoapi.d.ts +0 -5
  20. package/lib/chevre/pecorinoapi.js +0 -9
  21. package/lib/chevre/service/assetTransaction/moneyTransfer/potentialActions.d.ts +0 -7
  22. package/lib/chevre/service/assetTransaction/moneyTransfer/potentialActions.js +0 -104
  23. package/lib/chevre/service/assetTransaction/moneyTransfer.d.ts +0 -51
  24. package/lib/chevre/service/assetTransaction/moneyTransfer.js +0 -444
  25. package/lib/chevre/service/assetTransaction/pay/start/account/validation.d.ts +0 -8
  26. package/lib/chevre/service/assetTransaction/pay/start/account/validation.js +0 -43
  27. package/lib/chevre/service/assetTransaction/pay/start/processAuthorizeAccount.d.ts +0 -13
  28. package/lib/chevre/service/assetTransaction/pay/start/processAuthorizeAccount.js +0 -72
  29. package/lib/chevre/service/delivery.d.ts +0 -27
  30. package/lib/chevre/service/delivery.js +0 -315
  31. package/lib/chevre/service/moneyTransfer.d.ts +0 -76
  32. package/lib/chevre/service/moneyTransfer.js +0 -669
  33. package/lib/chevre/service/payment/paymentCard.d.ts +0 -42
  34. package/lib/chevre/service/payment/paymentCard.js +0 -452
  35. package/lib/chevre/service/task/cancelMoneyTransfer.d.ts +0 -6
  36. package/lib/chevre/service/task/cancelMoneyTransfer.js +0 -19
  37. package/lib/chevre/service/task/givePointAward.d.ts +0 -6
  38. package/lib/chevre/service/task/givePointAward.js +0 -65
  39. package/lib/chevre/service/task/moneyTransfer.d.ts +0 -6
  40. package/lib/chevre/service/task/moneyTransfer.js +0 -59
  41. package/lib/chevre/service/task/returnPointAward.d.ts +0 -6
  42. package/lib/chevre/service/task/returnPointAward.js +0 -65
package/package.json CHANGED
@@ -12,7 +12,6 @@
12
12
  "@aws-sdk/client-cognito-identity-provider": "3.600.0",
13
13
  "@aws-sdk/credential-providers": "3.600.0",
14
14
  "@chevre/factory": "7.0.0",
15
- "@cinerino/sdk": "14.0.0",
16
15
  "@motionpicture/coa-service": "10.0.0",
17
16
  "@motionpicture/gmo-service": "6.0.0",
18
17
  "@sendgrid/client": "8.1.4",
@@ -47,7 +46,6 @@
47
46
  "csvtojson": "^2.0.10",
48
47
  "dependency-cruiser": "17.3.8",
49
48
  "eslint": "9.39.2",
50
- "jose": "6.0.12",
51
49
  "mongodb": "6.20.0",
52
50
  "mongoose": "8.23.0",
53
51
  "redis": "4.6.5",
@@ -93,5 +91,5 @@
93
91
  "postversion": "git push origin --tags",
94
92
  "prepublishOnly": "npm run clean && npm run build"
95
93
  },
96
- "version": "24.0.0-alpha.74"
94
+ "version": "24.0.0-alpha.76"
97
95
  }
@@ -1,5 +0,0 @@
1
- /**
2
- * Pecorino API Client
3
- */
4
- import { auth, loadPecorino, pecorino } from '@cinerino/sdk';
5
- export { auth, loadPecorino, pecorino };
@@ -1,9 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.loadPecorino = exports.auth = void 0;
4
- /**
5
- * Pecorino API Client
6
- */
7
- const sdk_1 = require("@cinerino/sdk");
8
- Object.defineProperty(exports, "auth", { enumerable: true, get: function () { return sdk_1.auth; } });
9
- Object.defineProperty(exports, "loadPecorino", { enumerable: true, get: function () { return sdk_1.loadPecorino; } });
@@ -1,7 +0,0 @@
1
- import { factory } from '../../../factory';
2
- /**
3
- * 取引のポストアクションを作成する
4
- */
5
- export declare function createPotentialActions(params: {
6
- transaction: factory.assetTransaction.ITransaction<factory.assetTransactionType.MoneyTransfer>;
7
- }): Promise<factory.assetTransaction.IPotentialActions<factory.assetTransactionType.MoneyTransfer>>;
@@ -1,104 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createPotentialActions = createPotentialActions;
4
- const factory_1 = require("../../../factory");
5
- function createLocations(params) {
6
- const transaction = params.transaction;
7
- let fromLocation = {
8
- typeOf: transaction.agent.typeOf,
9
- name: transaction.agent.name
10
- };
11
- let toLocation = {
12
- typeOf: transaction.recipient.typeOf,
13
- name: transaction.recipient.name
14
- };
15
- const pendingTransactionType = transaction.object.pendingTransaction?.typeOf;
16
- switch (pendingTransactionType) {
17
- case factory_1.factory.account.transactionType.Deposit:
18
- if (typeof transaction.object.fromLocation?.typeOf === 'string') {
19
- fromLocation = {
20
- typeOf: transaction.object.fromLocation.typeOf,
21
- name: transaction.agent.name
22
- };
23
- }
24
- toLocation = {
25
- identifier: transaction.object.toLocation.identifier,
26
- issuedThrough: transaction.object.toLocation.issuedThrough,
27
- typeOf: transaction.object.toLocation.typeOf,
28
- name: transaction.recipient.name
29
- };
30
- break;
31
- case factory_1.factory.account.transactionType.Transfer:
32
- fromLocation = {
33
- identifier: transaction.object.fromLocation.identifier,
34
- issuedThrough: transaction.object.fromLocation.issuedThrough,
35
- typeOf: transaction.object.fromLocation.typeOf,
36
- name: transaction.agent.name
37
- };
38
- toLocation = {
39
- identifier: transaction.object.toLocation.identifier,
40
- issuedThrough: transaction.object.toLocation.issuedThrough,
41
- typeOf: transaction.object.toLocation.typeOf,
42
- name: transaction.recipient.name
43
- };
44
- break;
45
- case factory_1.factory.account.transactionType.Withdraw:
46
- fromLocation = {
47
- identifier: transaction.object.fromLocation.identifier,
48
- issuedThrough: transaction.object.fromLocation.issuedThrough,
49
- typeOf: transaction.object.fromLocation.typeOf,
50
- name: transaction.agent.name
51
- };
52
- if (typeof transaction.object.toLocation?.typeOf === 'string') {
53
- toLocation = {
54
- typeOf: transaction.object.toLocation.typeOf,
55
- name: transaction.recipient.name
56
- };
57
- }
58
- break;
59
- default:
60
- }
61
- return { fromLocation, toLocation };
62
- }
63
- function createMoneyTransferActions(params) {
64
- const transaction = params.transaction;
65
- const { fromLocation, toLocation } = createLocations(params);
66
- return (transaction.object.pendingTransaction !== undefined)
67
- ? [{
68
- project: transaction.project,
69
- typeOf: factory_1.factory.actionType.MoneyTransfer,
70
- description: transaction.object.description,
71
- result: {
72
- amount: transaction.object.amount
73
- },
74
- object: {
75
- typeOf: transaction.object.pendingTransaction.typeOf,
76
- transactionNumber: transaction.object.pendingTransaction.transactionNumber,
77
- pendingTransaction: transaction.object.pendingTransaction
78
- },
79
- agent: transaction.agent,
80
- recipient: transaction.recipient,
81
- amount: transaction.object.amount,
82
- fromLocation: fromLocation,
83
- toLocation: toLocation,
84
- purpose: {
85
- typeOf: transaction.typeOf,
86
- id: transaction.id
87
- }
88
- }]
89
- : [];
90
- }
91
- /**
92
- * 取引のポストアクションを作成する
93
- */
94
- async function createPotentialActions(params) {
95
- // 通貨転送アクション属性作成
96
- const moneyTransferActionAttributesList = createMoneyTransferActions(params);
97
- // まずは1転送アクションのみ対応
98
- if (moneyTransferActionAttributesList.length !== 1) {
99
- throw new factory_1.factory.errors.Argument('Transaction', 'Number of moneyTransfer actions must be 1');
100
- }
101
- return {
102
- moneyTransfer: moneyTransferActionAttributesList
103
- };
104
- }
@@ -1,51 +0,0 @@
1
- import { factory } from '../../factory';
2
- import type { AssetTransactionRepo } from '../../repo/assetTransaction';
3
- import type { ProductRepo } from '../../repo/product';
4
- import type { ProjectRepo } from '../../repo/project';
5
- import type { TaskRepo } from '../../repo/task';
6
- export type IStartOperation<T> = (repos: {
7
- product: ProductRepo;
8
- project: ProjectRepo;
9
- assetTransaction: AssetTransactionRepo;
10
- }) => Promise<T>;
11
- export type ITaskAndTransactionOperation<T> = (repos: {
12
- task: TaskRepo;
13
- assetTransaction: AssetTransactionRepo;
14
- }) => Promise<T>;
15
- export type IConfirmOperation<T> = (repos: {
16
- assetTransaction: AssetTransactionRepo;
17
- }) => Promise<T>;
18
- export type ICancelOperation<T> = (repos: {
19
- assetTransaction: AssetTransactionRepo;
20
- }) => Promise<T>;
21
- /**
22
- * 取引開始
23
- * Pecorinoサービスを利用して口座取引を開始する
24
- */
25
- export declare function start(params: factory.assetTransaction.moneyTransfer.IStartParamsWithoutDetail): IStartOperation<factory.assetTransaction.moneyTransfer.ITransaction>;
26
- /**
27
- * 取引確定
28
- */
29
- export declare function confirm(params: {
30
- id?: string;
31
- transactionNumber?: string;
32
- }): IConfirmOperation<void>;
33
- /**
34
- * 取引中止
35
- */
36
- export declare function cancel(params: {
37
- id?: string;
38
- transactionNumber?: string;
39
- }): ICancelOperation<void>;
40
- /**
41
- * 取引のタスク出力
42
- */
43
- export declare function exportTasksById(params: {
44
- id: string;
45
- /**
46
- * タスク実行日時バッファ
47
- */
48
- runsTasksAfterInSeconds?: number;
49
- }): ITaskAndTransactionOperation<{
50
- id: string;
51
- }[]>;
@@ -1,444 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- var __importDefault = (this && this.__importDefault) || function (mod) {
36
- return (mod && mod.__esModule) ? mod : { "default": mod };
37
- };
38
- Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.start = start;
40
- exports.confirm = confirm;
41
- exports.cancel = cancel;
42
- exports.exportTasksById = exportTasksById;
43
- /**
44
- * 通貨転送取引サービス
45
- */
46
- const moment_1 = __importDefault(require("moment"));
47
- const factory_1 = require("../../factory");
48
- const pecorinoapi = __importStar(require("../../pecorinoapi"));
49
- // import type { TransactionNumberRepo } from '../../repo/transactionNumber';
50
- const MoneyTransferService = __importStar(require("../moneyTransfer"));
51
- const potentialActions_1 = require("./moneyTransfer/potentialActions");
52
- /**
53
- * 取引開始
54
- * Pecorinoサービスを利用して口座取引を開始する
55
- */
56
- function start(params) {
57
- return async (repos) => {
58
- const issuedThroughId = fixIssuedThroughId(params);
59
- // location.issuedThroughIdからプロダクトをfixする
60
- const products = await repos.product.projectFields({
61
- limit: 1,
62
- page: 1,
63
- project: { id: { $eq: params.project.id } },
64
- typeOf: { $eq: factory_1.factory.product.ProductType.PaymentCard },
65
- id: { $eq: issuedThroughId }
66
- }, ['availableChannel', 'serviceOutput']
67
- // []
68
- );
69
- const product = products.shift();
70
- if (product === undefined) {
71
- throw new factory_1.factory.errors.NotFound('Product');
72
- }
73
- // fromとtoをfix
74
- const { fromLocation } = await fixFromLocation(params, product)({});
75
- const { toLocation } = await fixToLocation(params, product)({});
76
- const amount = fixMonetaryAmount(params, product);
77
- // 自動発行廃止(2022-05-17~)
78
- const transactionNumber = params.transactionNumber;
79
- if (typeof transactionNumber !== 'string' || transactionNumber.length === 0) {
80
- throw new factory_1.factory.errors.ArgumentNull('transactionNumber');
81
- }
82
- const transactionType = params.object.pendingTransaction?.typeOf;
83
- if (typeof transactionType !== 'string') {
84
- throw new factory_1.factory.errors.ArgumentNull('object.pendingTransaction.typeOf');
85
- }
86
- // 取引開始
87
- const startParams = {
88
- project: params.project,
89
- transactionNumber: transactionNumber,
90
- typeOf: factory_1.factory.assetTransactionType.MoneyTransfer,
91
- agent: params.agent,
92
- recipient: params.recipient,
93
- object: {
94
- amount,
95
- fromLocation,
96
- toLocation,
97
- pendingTransaction: {
98
- typeOf: transactionType,
99
- transactionNumber: transactionNumber,
100
- ...(typeof params.identifier === 'string') ? { identifier: params.identifier } : undefined
101
- },
102
- ...(typeof params.object.description === 'string') ? { description: params.object.description } : {},
103
- force: params.object.force === true
104
- },
105
- expires: params.expires
106
- };
107
- // 取引開始
108
- const transaction = await repos.assetTransaction.start(startParams);
109
- await authorizeAccount({ transaction })(repos);
110
- return transaction;
111
- };
112
- }
113
- function fixIssuedThroughId(params) {
114
- let issuedThroughId;
115
- const pendingTransactionType = params.object.pendingTransaction?.typeOf;
116
- switch (pendingTransactionType) {
117
- case factory_1.factory.account.transactionType.Deposit:
118
- issuedThroughId = String(params.object.toLocation.issuedThrough?.id);
119
- break;
120
- case factory_1.factory.account.transactionType.Transfer:
121
- case factory_1.factory.account.transactionType.Withdraw:
122
- issuedThroughId = String(params.object.fromLocation.issuedThrough?.id);
123
- break;
124
- default:
125
- throw new factory_1.factory.errors.Argument('AccountTransactionType', `invalid type: ${params.typeOf}`);
126
- }
127
- if (typeof issuedThroughId !== 'string' || issuedThroughId.length === 0) {
128
- throw new factory_1.factory.errors.ArgumentNull('location.issuedThrough.id');
129
- }
130
- return issuedThroughId;
131
- }
132
- function authorizeAccount(params) {
133
- return async (repos) => {
134
- const transaction = params.transaction;
135
- const fromLocation = transaction.object.fromLocation;
136
- const toLocation = transaction.object.toLocation;
137
- if (typeof transaction.object.pendingTransaction?.typeOf !== 'string') {
138
- throw new factory_1.factory.errors.NotFound('transaction.object.pendingTransaction.typeOf');
139
- }
140
- await MoneyTransferService.authorize({
141
- typeOf: transaction.object.pendingTransaction.typeOf,
142
- identifier: transaction.object.pendingTransaction.identifier,
143
- transactionNumber: transaction.object.pendingTransaction.transactionNumber,
144
- project: { typeOf: transaction.project.typeOf, id: transaction.project.id },
145
- agent: transaction.agent,
146
- object: {
147
- force: transaction.object.force === true,
148
- amount: transaction.object.amount.value,
149
- fromLocation: {
150
- ...(typeof fromLocation.identifier === 'string')
151
- ? {
152
- identifier: fromLocation.identifier,
153
- hasNoPermit: fromLocation.hasNoPermit === true,
154
- issuedThrough: { id: fromLocation.issuedThrough?.id }
155
- }
156
- : undefined
157
- },
158
- toLocation: {
159
- ...(typeof toLocation.identifier === 'string')
160
- ? {
161
- identifier: toLocation.identifier,
162
- hasNoPermit: toLocation.hasNoPermit === true,
163
- issuedThrough: { id: toLocation.issuedThrough?.id }
164
- }
165
- : undefined
166
- },
167
- ...(typeof transaction.object.description === 'string')
168
- ? { description: transaction.object.description }
169
- : undefined
170
- },
171
- recipient: transaction.recipient,
172
- purpose: { typeOf: transaction.typeOf, id: transaction.id }
173
- })(repos);
174
- // return pendingTransaction;
175
- };
176
- }
177
- function fixMonetaryAmount(params, product) {
178
- // currencyはプロダクトから自動取得
179
- const currency = product.serviceOutput?.amount?.currency;
180
- if (typeof currency !== 'string') {
181
- throw new factory_1.factory.errors.Argument('amount', 'currency unknown');
182
- }
183
- // 金額をfix
184
- const amountValue = params.object?.amount?.value;
185
- if (typeof amountValue !== 'number') {
186
- throw new factory_1.factory.errors.ArgumentNull('amount.value');
187
- }
188
- return {
189
- typeOf: 'MonetaryAmount',
190
- currency,
191
- value: amountValue
192
- };
193
- }
194
- function fixFromLocation(params, product) {
195
- return async (__) => {
196
- const amount = params.object.amount;
197
- if (typeof amount?.value !== 'number') {
198
- throw new factory_1.factory.errors.ArgumentNull('amount.value');
199
- }
200
- const { permitServiceEndpoint, permitServiceAuthorizeServerDomain, permitServiceClientId, permitServiceClientSecret } = createPermitServiceCredentials({ product });
201
- const permitService = new (await pecorinoapi.loadPecorino()).service.Permit({
202
- endpoint: permitServiceEndpoint,
203
- auth: await pecorinoapi.auth.ClientCredentials.createInstance({
204
- domain: permitServiceAuthorizeServerDomain,
205
- clientId: permitServiceClientId,
206
- clientSecret: permitServiceClientSecret,
207
- scopes: [],
208
- state: ''
209
- })
210
- });
211
- let fromLocation = params.object.fromLocation;
212
- const transactionType = params.object.pendingTransaction?.typeOf;
213
- switch (transactionType) {
214
- case factory_1.factory.account.transactionType.Withdraw:
215
- case factory_1.factory.account.transactionType.Transfer: {
216
- const fromLocationObject = fromLocation;
217
- // Permitの存在しない注文口座に対応する
218
- const hasNoPermit = fromLocationObject.hasNoPermit === true;
219
- let serviceOutput;
220
- if (!hasNoPermit) {
221
- // サービスアウトプット存在確認
222
- serviceOutput = await permitService.findByIdentifier({
223
- project: { id: params.project.id },
224
- identifier: fromLocationObject.identifier,
225
- issuedThrough: { typeOf: factory_1.factory.product.ProductType.PaymentCard }
226
- });
227
- // 出金金額設定を確認
228
- const paymentAmount = serviceOutput.paymentAmount;
229
- if (typeof paymentAmount?.minValue === 'number') {
230
- if (amount.value < paymentAmount.minValue) {
231
- throw new factory_1.factory.errors.Argument('fromLocation', `mininum payment amount requirement not satisfied`);
232
- }
233
- }
234
- if (typeof paymentAmount?.maxValue === 'number') {
235
- if (amount.value > paymentAmount.maxValue) {
236
- throw new factory_1.factory.errors.Argument('fromLocation', `maximum payment amount requirement not satisfied`);
237
- }
238
- }
239
- }
240
- const accountNumber = (serviceOutput !== undefined)
241
- ? String(serviceOutput.paymentAccount?.accountNumber)
242
- : fromLocationObject.identifier;
243
- fromLocation = {
244
- typeOf: (serviceOutput !== undefined) ? serviceOutput.typeOf : factory_1.factory.permit.PermitType.Permit,
245
- identifier: (serviceOutput !== undefined) ? serviceOutput.identifier : accountNumber,
246
- ...(hasNoPermit) ? { hasNoPermit } : undefined,
247
- issuedThrough: { id: fromLocationObject.issuedThrough?.id }
248
- };
249
- break;
250
- }
251
- default:
252
- // no op
253
- }
254
- return { fromLocation };
255
- };
256
- }
257
- function fixToLocation(params, product) {
258
- return async (__) => {
259
- let toLocation = params.object.toLocation;
260
- const amount = params.object.amount;
261
- if (typeof amount?.value !== 'number') {
262
- throw new factory_1.factory.errors.ArgumentNull('amount.value');
263
- }
264
- const { permitServiceEndpoint, permitServiceAuthorizeServerDomain, permitServiceClientId, permitServiceClientSecret } = createPermitServiceCredentials({ product });
265
- const permitService = new (await pecorinoapi.loadPecorino()).service.Permit({
266
- endpoint: permitServiceEndpoint,
267
- auth: await pecorinoapi.auth.ClientCredentials.createInstance({
268
- domain: permitServiceAuthorizeServerDomain,
269
- clientId: permitServiceClientId,
270
- clientSecret: permitServiceClientSecret,
271
- scopes: [],
272
- state: ''
273
- })
274
- });
275
- const transactionType = params.object.pendingTransaction?.typeOf;
276
- switch (transactionType) {
277
- case factory_1.factory.account.transactionType.Deposit:
278
- case factory_1.factory.account.transactionType.Transfer: {
279
- const toLocationObject = toLocation;
280
- // Permitの存在しない注文口座に対応する
281
- const hasNoPermit = toLocationObject.hasNoPermit === true;
282
- let serviceOutput;
283
- if (!hasNoPermit) {
284
- // サービスアウトプット存在確認
285
- serviceOutput = await permitService.findByIdentifier({
286
- project: { id: params.project.id },
287
- identifier: toLocationObject.identifier,
288
- issuedThrough: { typeOf: factory_1.factory.product.ProductType.PaymentCard }
289
- });
290
- // 入金金額設定を確認
291
- const depositAmount = serviceOutput.depositAmount;
292
- if (typeof depositAmount?.minValue === 'number') {
293
- if (amount.value < depositAmount.minValue) {
294
- throw new factory_1.factory.errors.Argument('toLocation', `mininum deposit amount requirement not satisfied`);
295
- }
296
- }
297
- if (typeof depositAmount?.maxValue === 'number') {
298
- if (amount.value > depositAmount.maxValue) {
299
- throw new factory_1.factory.errors.Argument('toLocation', `maximum deposit amount requirement not satisfied`);
300
- }
301
- }
302
- }
303
- const accountNumber = (serviceOutput !== undefined)
304
- ? String(serviceOutput.paymentAccount?.accountNumber)
305
- : toLocationObject.identifier;
306
- toLocation = {
307
- typeOf: (serviceOutput !== undefined) ? serviceOutput.typeOf : factory_1.factory.permit.PermitType.Permit,
308
- identifier: (serviceOutput !== undefined) ? serviceOutput.identifier : accountNumber,
309
- ...(hasNoPermit) ? { hasNoPermit } : undefined,
310
- issuedThrough: { id: toLocationObject.issuedThrough?.id }
311
- };
312
- break;
313
- }
314
- default:
315
- // no op
316
- }
317
- return { toLocation };
318
- };
319
- }
320
- function createPermitServiceCredentials(params) {
321
- const permitServiceEndpoint = params.product.availableChannel?.serviceUrl;
322
- const permitServiceAuthorizeServerDomain = params.product.availableChannel?.credentials?.authorizeServerDomain;
323
- const permitServiceClientId = params.product.availableChannel?.credentials?.clientId;
324
- const permitServiceClientSecret = params.product.availableChannel?.credentials?.clientSecret;
325
- if (typeof permitServiceEndpoint !== 'string' || permitServiceEndpoint.length === 0
326
- || typeof permitServiceAuthorizeServerDomain !== 'string' || permitServiceAuthorizeServerDomain.length === 0
327
- || typeof permitServiceClientId !== 'string' || permitServiceClientId.length === 0
328
- || typeof permitServiceClientSecret !== 'string' || permitServiceClientSecret.length === 0) {
329
- throw new factory_1.factory.errors.Internal('membershipService availableChannel invalid');
330
- }
331
- return {
332
- permitServiceEndpoint,
333
- permitServiceAuthorizeServerDomain,
334
- permitServiceClientId,
335
- permitServiceClientSecret
336
- };
337
- }
338
- /**
339
- * 取引確定
340
- */
341
- function confirm(params) {
342
- return async (repos) => {
343
- let transaction;
344
- // 取引存在確認
345
- if (typeof params.id === 'string') {
346
- transaction = await repos.assetTransaction.findById({
347
- typeOf: factory_1.factory.assetTransactionType.MoneyTransfer,
348
- id: params.id
349
- });
350
- }
351
- else if (typeof params.transactionNumber === 'string') {
352
- transaction = await repos.assetTransaction.findByTransactionNumber({
353
- typeOf: factory_1.factory.assetTransactionType.MoneyTransfer,
354
- transactionNumber: params.transactionNumber
355
- });
356
- }
357
- else {
358
- throw new factory_1.factory.errors.ArgumentNull('Transaction ID or Transaction Number');
359
- }
360
- const potentialActions = await (0, potentialActions_1.createPotentialActions)({
361
- transaction: transaction
362
- });
363
- await repos.assetTransaction.confirm({
364
- typeOf: factory_1.factory.assetTransactionType.MoneyTransfer,
365
- id: transaction.id,
366
- result: {},
367
- potentialActions: potentialActions
368
- });
369
- };
370
- }
371
- /**
372
- * 取引中止
373
- */
374
- function cancel(params) {
375
- return async (repos) => {
376
- await repos.assetTransaction.cancel({
377
- typeOf: factory_1.factory.assetTransactionType.MoneyTransfer,
378
- id: params.id,
379
- transactionNumber: params.transactionNumber
380
- });
381
- };
382
- }
383
- /**
384
- * 取引のタスク出力
385
- */
386
- function exportTasksById(params) {
387
- return async (repos) => {
388
- const transaction = await repos.assetTransaction.findById({
389
- typeOf: factory_1.factory.assetTransactionType.MoneyTransfer,
390
- id: params.id
391
- });
392
- const potentialActions = transaction.potentialActions;
393
- const taskAttributes = [];
394
- // タスク実行日時バッファの指定があれば調整
395
- let taskRunsAt = new Date();
396
- if (typeof params.runsTasksAfterInSeconds === 'number') {
397
- taskRunsAt = (0, moment_1.default)(taskRunsAt)
398
- .add(params.runsTasksAfterInSeconds, 'seconds')
399
- .toDate();
400
- }
401
- switch (transaction.status) {
402
- case factory_1.factory.transactionStatusType.Confirmed:
403
- /* istanbul ignore else */
404
- if (potentialActions !== undefined) {
405
- /* istanbul ignore else */
406
- if (potentialActions.moneyTransfer !== undefined) {
407
- taskAttributes.push(...potentialActions.moneyTransfer.map((a) => {
408
- return {
409
- project: transaction.project,
410
- name: factory_1.factory.taskName.MoneyTransfer,
411
- status: factory_1.factory.taskStatus.Ready,
412
- runsAt: taskRunsAt,
413
- remainingNumberOfTries: 10,
414
- numberOfTried: 0,
415
- executionResults: [],
416
- data: a
417
- };
418
- }));
419
- }
420
- }
421
- break;
422
- case factory_1.factory.transactionStatusType.Canceled:
423
- case factory_1.factory.transactionStatusType.Expired: {
424
- const cancelMoneyTransferTaskAttributes = {
425
- project: { typeOf: transaction.project.typeOf, id: transaction.project.id },
426
- name: factory_1.factory.taskName.CancelMoneyTransfer,
427
- status: factory_1.factory.taskStatus.Ready,
428
- runsAt: taskRunsAt,
429
- remainingNumberOfTries: 10,
430
- numberOfTried: 0,
431
- executionResults: [],
432
- data: {
433
- purpose: { typeOf: transaction.typeOf, id: transaction.id }
434
- }
435
- };
436
- taskAttributes.push(cancelMoneyTransferTaskAttributes);
437
- break;
438
- }
439
- default:
440
- throw new factory_1.factory.errors.NotImplemented(`Transaction status "${transaction.status}" not implemented.`);
441
- }
442
- return repos.task.saveMany(taskAttributes, { emitImmediately: true });
443
- };
444
- }
@@ -1,8 +0,0 @@
1
- /**
2
- * ペイメントカード決済取引バリデーション
3
- */
4
- import type { SellerPaymentAcceptedRepo } from '../../../../../repo/sellerPaymentAccepted';
5
- import { factory } from '../../../../../factory';
6
- export declare function validateAccount(params: factory.assetTransaction.pay.IStartParamsWithoutDetail): (repos: {
7
- paymentAccepted: SellerPaymentAcceptedRepo;
8
- }) => Promise<void>;