@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.
- package/lib/chevre/index.d.ts +0 -2
- package/lib/chevre/index.js +0 -8
- package/lib/chevre/service/assetTransaction/pay/start/processAuthorize.js +5 -5
- package/lib/chevre/service/assetTransaction/registerService/potentialActions.js +0 -1
- package/lib/chevre/service/assetTransaction/registerService.d.ts +3 -0
- package/lib/chevre/service/assetTransaction/registerService.js +2 -55
- package/lib/chevre/service/assetTransaction/reserve/start/createSubReservations.js +35 -69
- package/lib/chevre/service/assetTransaction/reserve/start.js +18 -85
- package/lib/chevre/service/assetTransaction.d.ts +0 -2
- package/lib/chevre/service/assetTransaction.js +1 -10
- package/lib/chevre/service/task/payment/payByTask.js +4 -4
- package/lib/chevre/service/task/payment/refundByTask.js +4 -4
- package/lib/chevre/service/task/payment/voidPaymentByTask.js +4 -4
- package/lib/chevre/service/taskHandler.d.ts +6 -1
- package/lib/chevre/service/taskHandler.js +10 -1
- package/lib/chevre/service.d.ts +0 -4
- package/lib/chevre/service.js +1 -21
- package/package.json +1 -3
- package/lib/chevre/pecorinoapi.d.ts +0 -5
- package/lib/chevre/pecorinoapi.js +0 -9
- package/lib/chevre/service/assetTransaction/moneyTransfer/potentialActions.d.ts +0 -7
- package/lib/chevre/service/assetTransaction/moneyTransfer/potentialActions.js +0 -104
- package/lib/chevre/service/assetTransaction/moneyTransfer.d.ts +0 -51
- package/lib/chevre/service/assetTransaction/moneyTransfer.js +0 -444
- package/lib/chevre/service/assetTransaction/pay/start/account/validation.d.ts +0 -8
- package/lib/chevre/service/assetTransaction/pay/start/account/validation.js +0 -43
- package/lib/chevre/service/assetTransaction/pay/start/processAuthorizeAccount.d.ts +0 -13
- package/lib/chevre/service/assetTransaction/pay/start/processAuthorizeAccount.js +0 -72
- package/lib/chevre/service/delivery.d.ts +0 -27
- package/lib/chevre/service/delivery.js +0 -315
- package/lib/chevre/service/moneyTransfer.d.ts +0 -76
- package/lib/chevre/service/moneyTransfer.js +0 -669
- package/lib/chevre/service/payment/paymentCard.d.ts +0 -42
- package/lib/chevre/service/payment/paymentCard.js +0 -452
- package/lib/chevre/service/task/cancelMoneyTransfer.d.ts +0 -6
- package/lib/chevre/service/task/cancelMoneyTransfer.js +0 -19
- package/lib/chevre/service/task/givePointAward.d.ts +0 -6
- package/lib/chevre/service/task/givePointAward.js +0 -65
- package/lib/chevre/service/task/moneyTransfer.d.ts +0 -6
- package/lib/chevre/service/task/moneyTransfer.js +0 -59
- package/lib/chevre/service/task/returnPointAward.d.ts +0 -6
- package/lib/chevre/service/task/returnPointAward.js +0 -65
|
@@ -1,669 +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.authorize = authorize;
|
|
40
|
-
exports.cancelMoneyTransfer = cancelMoneyTransfer;
|
|
41
|
-
exports.moneyTransfer = moneyTransfer;
|
|
42
|
-
/**
|
|
43
|
-
* 通貨転送サービス
|
|
44
|
-
*/
|
|
45
|
-
const moment_1 = __importDefault(require("moment"));
|
|
46
|
-
const pecorinoapi = __importStar(require("../pecorinoapi"));
|
|
47
|
-
const factory_1 = require("../factory");
|
|
48
|
-
const errorHandler_1 = require("../errorHandler");
|
|
49
|
-
/**
|
|
50
|
-
* 口座残高差し押さえ
|
|
51
|
-
*/
|
|
52
|
-
function authorize(params) {
|
|
53
|
-
return async (repos) => {
|
|
54
|
-
const project = await repos.project.findById({
|
|
55
|
-
id: params.project.id,
|
|
56
|
-
inclusion: ['settings', 'typeOf']
|
|
57
|
-
});
|
|
58
|
-
const transaction = await repos.assetTransaction.findById({
|
|
59
|
-
typeOf: params.purpose.typeOf,
|
|
60
|
-
id: params.purpose.id
|
|
61
|
-
});
|
|
62
|
-
// 口座取引開始
|
|
63
|
-
// let pendingTransaction: factory.action.transfer.moneyTransfer.IPendingTransaction;
|
|
64
|
-
try {
|
|
65
|
-
await processAccountTransaction({
|
|
66
|
-
typeOf: params.typeOf,
|
|
67
|
-
identifier: params.identifier,
|
|
68
|
-
transactionNumber: params.transactionNumber,
|
|
69
|
-
project: { id: project.id, typeOf: project.typeOf },
|
|
70
|
-
object: params.object,
|
|
71
|
-
agent: params.agent,
|
|
72
|
-
recipient: params.recipient,
|
|
73
|
-
transaction: transaction
|
|
74
|
-
})(repos);
|
|
75
|
-
}
|
|
76
|
-
catch (error) {
|
|
77
|
-
// PecorinoAPIのエラーをハンドリング
|
|
78
|
-
const handledError = (0, errorHandler_1.handlePecorinoError)(error);
|
|
79
|
-
throw handledError;
|
|
80
|
-
}
|
|
81
|
-
// return pendingTransaction;
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
function processAccountTransaction(params) {
|
|
85
|
-
return async (repos) => {
|
|
86
|
-
const transaction = params.transaction;
|
|
87
|
-
const agent = createAccountTransactionAgent(params);
|
|
88
|
-
const recipient = createAccountTransactionRecipient(params);
|
|
89
|
-
const description = (typeof params.object.description === 'string') ? params.object.description : `for transaction ${transaction.id}`;
|
|
90
|
-
// 最大1ヵ月のオーソリ
|
|
91
|
-
const expires = (0, moment_1.default)()
|
|
92
|
-
.add(1, 'month')
|
|
93
|
-
.toDate();
|
|
94
|
-
const issuedThroughId = getIssuedThroughId(params);
|
|
95
|
-
const permitServiceCredentials = await createPermitServiceCredentials({ issuedThrough: { id: issuedThroughId } })(repos);
|
|
96
|
-
const permitService = new (await pecorinoapi.loadPecorino()).service.Permit({
|
|
97
|
-
endpoint: permitServiceCredentials.permitServiceEndpoint,
|
|
98
|
-
auth: await pecorinoapi.auth.ClientCredentials.createInstance({
|
|
99
|
-
domain: permitServiceCredentials.permitServiceAuthorizeServerDomain,
|
|
100
|
-
clientId: permitServiceCredentials.permitServiceClientId,
|
|
101
|
-
clientSecret: permitServiceCredentials.permitServiceClientSecret,
|
|
102
|
-
scopes: [],
|
|
103
|
-
state: ''
|
|
104
|
-
})
|
|
105
|
-
});
|
|
106
|
-
switch (params.typeOf) {
|
|
107
|
-
case factory_1.factory.account.transactionType.Deposit:
|
|
108
|
-
await processDepositTransaction({
|
|
109
|
-
identifier: params.identifier,
|
|
110
|
-
transactionNumber: params.transactionNumber,
|
|
111
|
-
project: params.project,
|
|
112
|
-
object: params.object,
|
|
113
|
-
agent,
|
|
114
|
-
recipient,
|
|
115
|
-
expires,
|
|
116
|
-
description,
|
|
117
|
-
permitServiceCredentials
|
|
118
|
-
})({ permit: permitService });
|
|
119
|
-
break;
|
|
120
|
-
case factory_1.factory.account.transactionType.Transfer:
|
|
121
|
-
await processTransferTransaction({
|
|
122
|
-
identifier: params.identifier,
|
|
123
|
-
transactionNumber: params.transactionNumber,
|
|
124
|
-
project: params.project,
|
|
125
|
-
object: params.object,
|
|
126
|
-
agent,
|
|
127
|
-
recipient,
|
|
128
|
-
expires,
|
|
129
|
-
description,
|
|
130
|
-
permitServiceCredentials
|
|
131
|
-
})({ permit: permitService });
|
|
132
|
-
break;
|
|
133
|
-
case factory_1.factory.account.transactionType.Withdraw:
|
|
134
|
-
await processWithdrawTransaction({
|
|
135
|
-
identifier: params.identifier,
|
|
136
|
-
transactionNumber: params.transactionNumber,
|
|
137
|
-
project: params.project,
|
|
138
|
-
object: params.object,
|
|
139
|
-
agent,
|
|
140
|
-
recipient,
|
|
141
|
-
expires,
|
|
142
|
-
description,
|
|
143
|
-
permitServiceCredentials
|
|
144
|
-
})({ permit: permitService });
|
|
145
|
-
break;
|
|
146
|
-
default:
|
|
147
|
-
throw new factory_1.factory.errors.Argument('Object', 'At least one of accounts from and to must be specified');
|
|
148
|
-
}
|
|
149
|
-
// return pendingTransaction;
|
|
150
|
-
};
|
|
151
|
-
}
|
|
152
|
-
function processDepositTransaction(params) {
|
|
153
|
-
return async (repos) => {
|
|
154
|
-
const accountTransactionService = new (await pecorinoapi.loadPecorino()).service.AccountTransaction({
|
|
155
|
-
endpoint: params.permitServiceCredentials.permitServiceEndpoint,
|
|
156
|
-
auth: await pecorinoapi.auth.ClientCredentials.createInstance({
|
|
157
|
-
domain: params.permitServiceCredentials.permitServiceAuthorizeServerDomain,
|
|
158
|
-
clientId: params.permitServiceCredentials.permitServiceClientId,
|
|
159
|
-
clientSecret: params.permitServiceCredentials.permitServiceClientSecret,
|
|
160
|
-
scopes: [],
|
|
161
|
-
state: ''
|
|
162
|
-
})
|
|
163
|
-
});
|
|
164
|
-
if (typeof params.object.toLocation.identifier !== 'string') {
|
|
165
|
-
throw new factory_1.factory.errors.ArgumentNull('object.toLocation.identifier');
|
|
166
|
-
}
|
|
167
|
-
const permit = await repos.permit.findByIdentifier({
|
|
168
|
-
project: { id: params.project.id },
|
|
169
|
-
identifier: params.object.toLocation.identifier,
|
|
170
|
-
issuedThrough: { typeOf: factory_1.factory.product.ProductType.PaymentCard }
|
|
171
|
-
});
|
|
172
|
-
return accountTransactionService.start({
|
|
173
|
-
transactionNumber: params.transactionNumber,
|
|
174
|
-
project: { typeOf: params.project.typeOf, id: params.project.id },
|
|
175
|
-
typeOf: factory_1.factory.account.transactionType.Deposit,
|
|
176
|
-
agent: params.agent,
|
|
177
|
-
expires: params.expires,
|
|
178
|
-
recipient: params.recipient,
|
|
179
|
-
object: {
|
|
180
|
-
amount: { value: params.object.amount },
|
|
181
|
-
description: params.description,
|
|
182
|
-
toLocation: {
|
|
183
|
-
accountNumber: String(permit.paymentAccount?.accountNumber)
|
|
184
|
-
}
|
|
185
|
-
},
|
|
186
|
-
...(typeof params.identifier === 'string') ? { identifier: params.identifier } : undefined
|
|
187
|
-
});
|
|
188
|
-
};
|
|
189
|
-
}
|
|
190
|
-
function processTransferTransaction(params) {
|
|
191
|
-
return async (repos) => {
|
|
192
|
-
const accountTransactionService = new (await pecorinoapi.loadPecorino()).service.AccountTransaction({
|
|
193
|
-
endpoint: params.permitServiceCredentials.permitServiceEndpoint,
|
|
194
|
-
auth: await pecorinoapi.auth.ClientCredentials.createInstance({
|
|
195
|
-
domain: params.permitServiceCredentials.permitServiceAuthorizeServerDomain,
|
|
196
|
-
clientId: params.permitServiceCredentials.permitServiceClientId,
|
|
197
|
-
clientSecret: params.permitServiceCredentials.permitServiceClientSecret,
|
|
198
|
-
scopes: [],
|
|
199
|
-
state: ''
|
|
200
|
-
})
|
|
201
|
-
});
|
|
202
|
-
if (typeof params.object.fromLocation.identifier !== 'string') {
|
|
203
|
-
throw new factory_1.factory.errors.ArgumentNull('object.fromLocation.identifier');
|
|
204
|
-
}
|
|
205
|
-
if (typeof params.object.toLocation.identifier !== 'string') {
|
|
206
|
-
throw new factory_1.factory.errors.ArgumentNull('object.toLocation.identifier');
|
|
207
|
-
}
|
|
208
|
-
let fromAccountNumber = params.object.fromLocation.identifier;
|
|
209
|
-
if (params.object.fromLocation.hasNoPermit === true) {
|
|
210
|
-
// no op
|
|
211
|
-
}
|
|
212
|
-
else {
|
|
213
|
-
const fromLocationPermit = await repos.permit.findByIdentifier({
|
|
214
|
-
project: { id: params.project.id },
|
|
215
|
-
identifier: params.object.fromLocation.identifier,
|
|
216
|
-
issuedThrough: { typeOf: factory_1.factory.product.ProductType.PaymentCard }
|
|
217
|
-
});
|
|
218
|
-
fromAccountNumber = String(fromLocationPermit.paymentAccount?.accountNumber);
|
|
219
|
-
}
|
|
220
|
-
let toAccountNumber = params.object.toLocation.identifier;
|
|
221
|
-
if (params.object.toLocation.hasNoPermit === true) {
|
|
222
|
-
// no op
|
|
223
|
-
}
|
|
224
|
-
else {
|
|
225
|
-
const toLocationPermit = await repos.permit.findByIdentifier({
|
|
226
|
-
project: { id: params.project.id },
|
|
227
|
-
identifier: params.object.toLocation.identifier,
|
|
228
|
-
issuedThrough: { typeOf: factory_1.factory.product.ProductType.PaymentCard }
|
|
229
|
-
});
|
|
230
|
-
toAccountNumber = String(toLocationPermit.paymentAccount?.accountNumber);
|
|
231
|
-
}
|
|
232
|
-
return accountTransactionService.start({
|
|
233
|
-
transactionNumber: params.transactionNumber,
|
|
234
|
-
project: { typeOf: params.project.typeOf, id: params.project.id },
|
|
235
|
-
typeOf: factory_1.factory.account.transactionType.Transfer,
|
|
236
|
-
agent: params.agent,
|
|
237
|
-
expires: params.expires,
|
|
238
|
-
recipient: params.recipient,
|
|
239
|
-
object: {
|
|
240
|
-
amount: { value: params.object.amount },
|
|
241
|
-
description: params.description,
|
|
242
|
-
fromLocation: { accountNumber: fromAccountNumber },
|
|
243
|
-
toLocation: { accountNumber: toAccountNumber }
|
|
244
|
-
},
|
|
245
|
-
...(typeof params.identifier === 'string') ? { identifier: params.identifier } : undefined
|
|
246
|
-
});
|
|
247
|
-
};
|
|
248
|
-
}
|
|
249
|
-
function processWithdrawTransaction(params) {
|
|
250
|
-
return async (repos) => {
|
|
251
|
-
// 転送先口座が指定されていない場合は、出金取引
|
|
252
|
-
const accountTransactionService = new (await pecorinoapi.loadPecorino()).service.AccountTransaction({
|
|
253
|
-
endpoint: params.permitServiceCredentials.permitServiceEndpoint,
|
|
254
|
-
auth: await pecorinoapi.auth.ClientCredentials.createInstance({
|
|
255
|
-
domain: params.permitServiceCredentials.permitServiceAuthorizeServerDomain,
|
|
256
|
-
clientId: params.permitServiceCredentials.permitServiceClientId,
|
|
257
|
-
clientSecret: params.permitServiceCredentials.permitServiceClientSecret,
|
|
258
|
-
scopes: [],
|
|
259
|
-
state: ''
|
|
260
|
-
})
|
|
261
|
-
});
|
|
262
|
-
if (typeof params.object.fromLocation.identifier !== 'string') {
|
|
263
|
-
throw new factory_1.factory.errors.ArgumentNull('object.toLocation.identifier');
|
|
264
|
-
}
|
|
265
|
-
const fromLocationPermit4withdraw = await repos.permit.findByIdentifier({
|
|
266
|
-
project: { id: params.project.id },
|
|
267
|
-
identifier: params.object.fromLocation.identifier,
|
|
268
|
-
issuedThrough: { typeOf: factory_1.factory.product.ProductType.PaymentCard }
|
|
269
|
-
});
|
|
270
|
-
return accountTransactionService.start({
|
|
271
|
-
transactionNumber: params.transactionNumber,
|
|
272
|
-
project: { typeOf: params.project.typeOf, id: params.project.id },
|
|
273
|
-
typeOf: factory_1.factory.account.transactionType.Withdraw,
|
|
274
|
-
agent: params.agent,
|
|
275
|
-
expires: params.expires,
|
|
276
|
-
recipient: params.recipient,
|
|
277
|
-
object: {
|
|
278
|
-
amount: { value: params.object.amount },
|
|
279
|
-
description: params.description,
|
|
280
|
-
fromLocation: {
|
|
281
|
-
accountNumber: String(fromLocationPermit4withdraw.paymentAccount?.accountNumber)
|
|
282
|
-
},
|
|
283
|
-
force: params.object.force === true
|
|
284
|
-
},
|
|
285
|
-
...(typeof params.identifier === 'string') ? { identifier: params.identifier } : undefined
|
|
286
|
-
});
|
|
287
|
-
};
|
|
288
|
-
}
|
|
289
|
-
function createAccountTransactionAgent(params) {
|
|
290
|
-
return {
|
|
291
|
-
typeOf: params.agent.typeOf,
|
|
292
|
-
id: String(params.agent.id),
|
|
293
|
-
name: (typeof params.agent.name === 'string')
|
|
294
|
-
? params.agent.name
|
|
295
|
-
: `${params.transaction.typeOf} Transaction ${params.transaction.id}`
|
|
296
|
-
};
|
|
297
|
-
}
|
|
298
|
-
function createAccountTransactionRecipient(params) {
|
|
299
|
-
const transaction = params.transaction;
|
|
300
|
-
let recipient;
|
|
301
|
-
const recipientType = params.recipient.typeOf;
|
|
302
|
-
if (recipientType === factory_1.factory.organizationType.Corporation) {
|
|
303
|
-
recipient = {
|
|
304
|
-
typeOf: recipientType,
|
|
305
|
-
id: String(params.recipient.id),
|
|
306
|
-
name: (typeof params.recipient.name === 'string')
|
|
307
|
-
? params.recipient.name
|
|
308
|
-
: `${transaction.typeOf} Transaction ${transaction.id}`
|
|
309
|
-
};
|
|
310
|
-
}
|
|
311
|
-
else {
|
|
312
|
-
if (recipientType === factory_1.factory.creativeWorkType.SoftwareApplication) {
|
|
313
|
-
throw new factory_1.factory.errors.NotImplemented(`recipient.typeOf [${recipientType}] not implemented`);
|
|
314
|
-
}
|
|
315
|
-
const recipientButSeller = {
|
|
316
|
-
typeOf: recipientType,
|
|
317
|
-
id: String(params.recipient.id),
|
|
318
|
-
name: (typeof params.recipient.name === 'string')
|
|
319
|
-
? params.recipient.name
|
|
320
|
-
: `${transaction.typeOf} Transaction ${transaction.id}`
|
|
321
|
-
};
|
|
322
|
-
recipient = recipientButSeller;
|
|
323
|
-
}
|
|
324
|
-
return recipient;
|
|
325
|
-
}
|
|
326
|
-
function getIssuedThroughId(params) {
|
|
327
|
-
let issuedThroughId;
|
|
328
|
-
switch (params.typeOf) {
|
|
329
|
-
case factory_1.factory.account.transactionType.Deposit:
|
|
330
|
-
issuedThroughId = String(params.object.toLocation.issuedThrough?.id);
|
|
331
|
-
break;
|
|
332
|
-
case factory_1.factory.account.transactionType.Transfer:
|
|
333
|
-
case factory_1.factory.account.transactionType.Withdraw:
|
|
334
|
-
issuedThroughId = String(params.object.fromLocation.issuedThrough?.id);
|
|
335
|
-
break;
|
|
336
|
-
default:
|
|
337
|
-
throw new factory_1.factory.errors.Argument('AccountTransactionType', `invalid type: ${params.typeOf}`);
|
|
338
|
-
}
|
|
339
|
-
return issuedThroughId;
|
|
340
|
-
}
|
|
341
|
-
function getIssuedThroughIdByTransaction(params) {
|
|
342
|
-
let issuedThroughId;
|
|
343
|
-
const pendingTransactionType = params.transaction.object.pendingTransaction?.typeOf;
|
|
344
|
-
switch (pendingTransactionType) {
|
|
345
|
-
case factory_1.factory.account.transactionType.Deposit:
|
|
346
|
-
issuedThroughId =
|
|
347
|
-
String(params.transaction.object.toLocation.issuedThrough?.id);
|
|
348
|
-
break;
|
|
349
|
-
case factory_1.factory.account.transactionType.Transfer:
|
|
350
|
-
case factory_1.factory.account.transactionType.Withdraw:
|
|
351
|
-
issuedThroughId =
|
|
352
|
-
String(params.transaction.object.fromLocation.issuedThrough?.id);
|
|
353
|
-
break;
|
|
354
|
-
default:
|
|
355
|
-
throw new factory_1.factory.errors.Argument('AccountTransactionType', `invalid type: ${pendingTransactionType}`);
|
|
356
|
-
}
|
|
357
|
-
return issuedThroughId;
|
|
358
|
-
}
|
|
359
|
-
function getIssuedThroughIdByAction(params) {
|
|
360
|
-
let issuedThroughId;
|
|
361
|
-
const pendingTransactionType = params.pendingTransactionType;
|
|
362
|
-
switch (pendingTransactionType) {
|
|
363
|
-
case factory_1.factory.account.transactionType.Deposit:
|
|
364
|
-
issuedThroughId =
|
|
365
|
-
String(params.action.toLocation.issuedThrough?.id);
|
|
366
|
-
break;
|
|
367
|
-
case factory_1.factory.account.transactionType.Transfer:
|
|
368
|
-
case factory_1.factory.account.transactionType.Withdraw:
|
|
369
|
-
issuedThroughId =
|
|
370
|
-
String(params.action.fromLocation.issuedThrough?.id);
|
|
371
|
-
break;
|
|
372
|
-
default:
|
|
373
|
-
throw new factory_1.factory.errors.Argument('AccountTransactionType', `invalid type: ${pendingTransactionType}`);
|
|
374
|
-
}
|
|
375
|
-
return issuedThroughId;
|
|
376
|
-
}
|
|
377
|
-
function createPermitServiceCredentials(params) {
|
|
378
|
-
return async (repos) => {
|
|
379
|
-
const paymentCardService = (await repos.product.projectFields({
|
|
380
|
-
limit: 1,
|
|
381
|
-
page: 1,
|
|
382
|
-
id: { $eq: params.issuedThrough.id },
|
|
383
|
-
typeOf: { $eq: factory_1.factory.product.ProductType.PaymentCard }
|
|
384
|
-
}, ['availableChannel']
|
|
385
|
-
// []
|
|
386
|
-
)).shift();
|
|
387
|
-
if (paymentCardService === undefined) {
|
|
388
|
-
throw new factory_1.factory.errors.NotFound(factory_1.factory.product.ProductType.PaymentCard);
|
|
389
|
-
}
|
|
390
|
-
const permitServiceEndpoint = paymentCardService.availableChannel?.serviceUrl;
|
|
391
|
-
const permitServiceAuthorizeServerDomain = paymentCardService.availableChannel?.credentials?.authorizeServerDomain;
|
|
392
|
-
const permitServiceClientId = paymentCardService.availableChannel?.credentials?.clientId;
|
|
393
|
-
const permitServiceClientSecret = paymentCardService.availableChannel?.credentials?.clientSecret;
|
|
394
|
-
if (typeof permitServiceEndpoint !== 'string' || permitServiceEndpoint.length === 0
|
|
395
|
-
|| typeof permitServiceAuthorizeServerDomain !== 'string' || permitServiceAuthorizeServerDomain.length === 0
|
|
396
|
-
|| typeof permitServiceClientId !== 'string' || permitServiceClientId.length === 0
|
|
397
|
-
|| typeof permitServiceClientSecret !== 'string' || permitServiceClientSecret.length === 0) {
|
|
398
|
-
throw new factory_1.factory.errors.Internal('membershipService availableChannel invalid');
|
|
399
|
-
}
|
|
400
|
-
return {
|
|
401
|
-
permitServiceEndpoint,
|
|
402
|
-
permitServiceAuthorizeServerDomain,
|
|
403
|
-
permitServiceClientId,
|
|
404
|
-
permitServiceClientSecret
|
|
405
|
-
};
|
|
406
|
-
};
|
|
407
|
-
}
|
|
408
|
-
/**
|
|
409
|
-
* 口座承認取消
|
|
410
|
-
*/
|
|
411
|
-
function cancelMoneyTransfer(params) {
|
|
412
|
-
return async (repos) => {
|
|
413
|
-
const transactions = await repos.assetTransaction.search({
|
|
414
|
-
typeOf: factory_1.factory.assetTransactionType.MoneyTransfer,
|
|
415
|
-
ids: [params.purpose.id]
|
|
416
|
-
});
|
|
417
|
-
if (transactions.length > 0) {
|
|
418
|
-
for (const transaction of transactions) {
|
|
419
|
-
const pendingTransaction = transaction.object?.pendingTransaction;
|
|
420
|
-
if (typeof pendingTransaction?.transactionNumber === 'string') {
|
|
421
|
-
const issuedThroughId = getIssuedThroughIdByTransaction({ transaction });
|
|
422
|
-
const { permitServiceEndpoint, permitServiceAuthorizeServerDomain, permitServiceClientId, permitServiceClientSecret } = await createPermitServiceCredentials({ issuedThrough: { id: issuedThroughId } })(repos);
|
|
423
|
-
// 汎用中止サービスを使用(2022-09-27~)
|
|
424
|
-
const accountTransactionService = new (await pecorinoapi.loadPecorino()).service.AccountTransaction({
|
|
425
|
-
endpoint: permitServiceEndpoint,
|
|
426
|
-
auth: await pecorinoapi.auth.ClientCredentials.createInstance({
|
|
427
|
-
domain: permitServiceAuthorizeServerDomain,
|
|
428
|
-
clientId: permitServiceClientId,
|
|
429
|
-
clientSecret: permitServiceClientSecret,
|
|
430
|
-
scopes: [],
|
|
431
|
-
state: ''
|
|
432
|
-
})
|
|
433
|
-
});
|
|
434
|
-
// 取引存在検証(2022-10-26~)
|
|
435
|
-
const searchAccountTransactionsResult = await accountTransactionService.search({
|
|
436
|
-
limit: 1,
|
|
437
|
-
project: { id: { $eq: transaction.project.id } },
|
|
438
|
-
transactionNumber: { $eq: pendingTransaction.transactionNumber }
|
|
439
|
-
});
|
|
440
|
-
if (searchAccountTransactionsResult.data.length > 0) {
|
|
441
|
-
await accountTransactionService.cancelSync({ transactionNumber: pendingTransaction.transactionNumber });
|
|
442
|
-
}
|
|
443
|
-
}
|
|
444
|
-
}
|
|
445
|
-
}
|
|
446
|
-
};
|
|
447
|
-
}
|
|
448
|
-
function moneyTransfer(params) {
|
|
449
|
-
return async (repos) => {
|
|
450
|
-
const action = await repos.action.start(params);
|
|
451
|
-
try {
|
|
452
|
-
const pendingTransaction = params.object.pendingTransaction;
|
|
453
|
-
let transactionType = params.object.typeOf;
|
|
454
|
-
if (pendingTransaction !== undefined) {
|
|
455
|
-
transactionType = pendingTransaction.typeOf;
|
|
456
|
-
}
|
|
457
|
-
const transactionNumber = await fixAccountTransactionNumber(params)({ transactionNumber: repos.transactionNumber });
|
|
458
|
-
const issuedThroughId = getIssuedThroughIdByAction({ action: params, pendingTransactionType: transactionType });
|
|
459
|
-
const permitServiceCredentials = await createPermitServiceCredentials({ issuedThrough: { id: issuedThroughId } })(repos);
|
|
460
|
-
const accountTransactionService = new (await pecorinoapi.loadPecorino()).service.AccountTransaction({
|
|
461
|
-
endpoint: permitServiceCredentials.permitServiceEndpoint,
|
|
462
|
-
auth: await pecorinoapi.auth.ClientCredentials.createInstance({
|
|
463
|
-
domain: permitServiceCredentials.permitServiceAuthorizeServerDomain,
|
|
464
|
-
clientId: permitServiceCredentials.permitServiceClientId,
|
|
465
|
-
clientSecret: permitServiceCredentials.permitServiceClientSecret,
|
|
466
|
-
scopes: [],
|
|
467
|
-
state: ''
|
|
468
|
-
})
|
|
469
|
-
});
|
|
470
|
-
// 入金取引の場合、承認済でないケースがある(ポイント付与など)
|
|
471
|
-
if (transactionType === factory_1.factory.account.transactionType.Deposit && pendingTransaction === undefined) {
|
|
472
|
-
await processDepositFromNow(params, permitServiceCredentials, transactionNumber)({
|
|
473
|
-
accountTransactionService
|
|
474
|
-
});
|
|
475
|
-
}
|
|
476
|
-
else {
|
|
477
|
-
await accountTransactionService.confirmSync({ transactionNumber: transactionNumber });
|
|
478
|
-
}
|
|
479
|
-
}
|
|
480
|
-
catch (error) {
|
|
481
|
-
try {
|
|
482
|
-
await repos.action.giveUp({ typeOf: action.typeOf, id: action.id, error });
|
|
483
|
-
}
|
|
484
|
-
catch (__) {
|
|
485
|
-
// no op
|
|
486
|
-
}
|
|
487
|
-
throw error;
|
|
488
|
-
}
|
|
489
|
-
const actionResult = {};
|
|
490
|
-
await repos.action.completeWithVoid({ typeOf: action.typeOf, id: action.id, result: actionResult });
|
|
491
|
-
};
|
|
492
|
-
}
|
|
493
|
-
function fixAccountTransactionNumber(params) {
|
|
494
|
-
return async (repos) => {
|
|
495
|
-
const pendingTransaction = params.object.pendingTransaction;
|
|
496
|
-
let transactionNumber = params.object.transactionNumber;
|
|
497
|
-
if (pendingTransaction !== undefined) {
|
|
498
|
-
transactionNumber = pendingTransaction.transactionNumber;
|
|
499
|
-
}
|
|
500
|
-
// 取引番号指定でなければ発行
|
|
501
|
-
if (typeof transactionNumber !== 'string') {
|
|
502
|
-
const publishTransactionNumberResult = await repos.transactionNumber.publishByTimestamp({
|
|
503
|
-
startDate: new Date()
|
|
504
|
-
});
|
|
505
|
-
transactionNumber = publishTransactionNumberResult.transactionNumber;
|
|
506
|
-
}
|
|
507
|
-
return transactionNumber;
|
|
508
|
-
};
|
|
509
|
-
}
|
|
510
|
-
/**
|
|
511
|
-
* 新規で入金取引を確定させる
|
|
512
|
-
* 処理順序は?
|
|
513
|
-
* 1.Confirmedでない取引があれば中止する
|
|
514
|
-
* 2.Confirmedの取引があれば再度confirmSync
|
|
515
|
-
* 3.取引が存在しなければ新たに取引開始してconfirmSync
|
|
516
|
-
*/
|
|
517
|
-
function processDepositFromNow(params, permitServiceCredentials, transactionNumber) {
|
|
518
|
-
return async (repos) => {
|
|
519
|
-
const accountTransactionIdentifier = params.purpose.identifier;
|
|
520
|
-
// すでに入金済かどうか確認
|
|
521
|
-
let confirmedAccountTransactionNumber;
|
|
522
|
-
if (typeof accountTransactionIdentifier === 'string') {
|
|
523
|
-
// 口座取引で確認する(2022-10-27~)
|
|
524
|
-
const searchAccountTransactionsResult = await repos.accountTransactionService.search({
|
|
525
|
-
limit: 100,
|
|
526
|
-
project: { id: { $eq: params.project.id } },
|
|
527
|
-
identifier: { $eq: accountTransactionIdentifier }
|
|
528
|
-
});
|
|
529
|
-
const existingAccountTransactions = searchAccountTransactionsResult.data;
|
|
530
|
-
for (const existingAccountTransaction of existingAccountTransactions) {
|
|
531
|
-
if (existingAccountTransaction.status === factory_1.factory.transactionStatusType.Confirmed) {
|
|
532
|
-
confirmedAccountTransactionNumber = existingAccountTransaction.transactionNumber;
|
|
533
|
-
}
|
|
534
|
-
else {
|
|
535
|
-
await repos.accountTransactionService.cancelSync({ transactionNumber: existingAccountTransaction.transactionNumber });
|
|
536
|
-
}
|
|
537
|
-
}
|
|
538
|
-
}
|
|
539
|
-
if (typeof confirmedAccountTransactionNumber === 'string') {
|
|
540
|
-
// 念のためconfirm
|
|
541
|
-
await repos.accountTransactionService.confirmSync({ transactionNumber: confirmedAccountTransactionNumber });
|
|
542
|
-
return;
|
|
543
|
-
}
|
|
544
|
-
const agent = createAgent4depositFromNow(params);
|
|
545
|
-
const recipient = createRecipient4depositFromNow(params);
|
|
546
|
-
const expires = (0, moment_1.default)()
|
|
547
|
-
.add(1, 'minutes')
|
|
548
|
-
.toDate();
|
|
549
|
-
const amount = (typeof params.amount.value === 'number') ? params.amount.value : 0;
|
|
550
|
-
const description = (typeof params.description === 'string') ? params.description : params.purpose.typeOf;
|
|
551
|
-
const permitIdentifier = String(params.toLocation.identifier);
|
|
552
|
-
// Permitの存在確認
|
|
553
|
-
const permitService = new (await pecorinoapi.loadPecorino()).service.Permit({
|
|
554
|
-
endpoint: permitServiceCredentials.permitServiceEndpoint,
|
|
555
|
-
auth: await pecorinoapi.auth.ClientCredentials.createInstance({
|
|
556
|
-
domain: permitServiceCredentials.permitServiceAuthorizeServerDomain,
|
|
557
|
-
clientId: permitServiceCredentials.permitServiceClientId,
|
|
558
|
-
clientSecret: permitServiceCredentials.permitServiceClientSecret,
|
|
559
|
-
scopes: [],
|
|
560
|
-
state: ''
|
|
561
|
-
})
|
|
562
|
-
});
|
|
563
|
-
const permit = await permitService.findByIdentifier({
|
|
564
|
-
project: { id: params.project.id },
|
|
565
|
-
identifier: permitIdentifier,
|
|
566
|
-
issuedThrough: { typeOf: factory_1.factory.product.ProductType.PaymentCard }
|
|
567
|
-
});
|
|
568
|
-
await repos.accountTransactionService.start({
|
|
569
|
-
transactionNumber,
|
|
570
|
-
project: { typeOf: params.project.typeOf, id: params.project.id },
|
|
571
|
-
typeOf: factory_1.factory.account.transactionType.Deposit,
|
|
572
|
-
agent,
|
|
573
|
-
expires,
|
|
574
|
-
recipient,
|
|
575
|
-
object: {
|
|
576
|
-
amount: { value: amount },
|
|
577
|
-
description: description,
|
|
578
|
-
// fromLocation: params.fromLocation,
|
|
579
|
-
toLocation: { accountNumber: String(permit.paymentAccount?.accountNumber) }
|
|
580
|
-
},
|
|
581
|
-
// 入金取引に識別子を指定する
|
|
582
|
-
...(typeof accountTransactionIdentifier === 'string') ? { identifier: accountTransactionIdentifier } : undefined
|
|
583
|
-
});
|
|
584
|
-
try {
|
|
585
|
-
await repos.accountTransactionService.confirmSync({ transactionNumber });
|
|
586
|
-
}
|
|
587
|
-
catch (error) {
|
|
588
|
-
await repos.accountTransactionService.cancelSync({ transactionNumber });
|
|
589
|
-
throw error;
|
|
590
|
-
}
|
|
591
|
-
};
|
|
592
|
-
}
|
|
593
|
-
function createAgent4depositFromNow(params) {
|
|
594
|
-
return {
|
|
595
|
-
typeOf: params.agent.typeOf,
|
|
596
|
-
id: String(params.agent.id),
|
|
597
|
-
name: (typeof params.agent.name === 'string')
|
|
598
|
-
? params.agent.name
|
|
599
|
-
: params.fromLocation.typeOf
|
|
600
|
-
};
|
|
601
|
-
}
|
|
602
|
-
function createRecipient4depositFromNow(params) {
|
|
603
|
-
let recipient = {
|
|
604
|
-
typeOf: factory_1.factory.personType.Person,
|
|
605
|
-
id: String(String(params.toLocation.identifier)),
|
|
606
|
-
name: params.toLocation.typeOf
|
|
607
|
-
};
|
|
608
|
-
if (params.recipient?.typeOf === factory_1.factory.organizationType.Corporation) {
|
|
609
|
-
recipient = {
|
|
610
|
-
typeOf: params.recipient.typeOf,
|
|
611
|
-
id: String(params.recipient.id),
|
|
612
|
-
name: (typeof params.recipient.name === 'string')
|
|
613
|
-
? params.recipient.name
|
|
614
|
-
: params.toLocation.typeOf
|
|
615
|
-
};
|
|
616
|
-
}
|
|
617
|
-
else if (typeof params.recipient?.typeOf === 'string') {
|
|
618
|
-
if (params.recipient.typeOf === factory_1.factory.creativeWorkType.SoftwareApplication) {
|
|
619
|
-
throw new factory_1.factory.errors.NotImplemented(`recipient.typeOf [${params.recipient.typeOf}] not implemented`);
|
|
620
|
-
}
|
|
621
|
-
const recipientButSeller = {
|
|
622
|
-
typeOf: params.recipient.typeOf,
|
|
623
|
-
id: String(params.recipient.id),
|
|
624
|
-
name: (typeof params.recipient.name === 'string')
|
|
625
|
-
? params.recipient.name
|
|
626
|
-
: params.toLocation.typeOf
|
|
627
|
-
};
|
|
628
|
-
recipient = recipientButSeller;
|
|
629
|
-
}
|
|
630
|
-
return recipient;
|
|
631
|
-
}
|
|
632
|
-
/**
|
|
633
|
-
* 返金後のアクション
|
|
634
|
-
* @param refundActionAttributes 返金アクション属性
|
|
635
|
-
*/
|
|
636
|
-
// function onRefund(refundActionAttributes: factory.action.trade.refund.IAttributes<factory.paymentMethodType>) {
|
|
637
|
-
// return async (repos: { task: TaskRepo }) => {
|
|
638
|
-
// const potentialActions = refundActionAttributes.potentialActions;
|
|
639
|
-
// const now = new Date();
|
|
640
|
-
// const taskAttributes: factory.task.IAttributes<factory.taskName>[] = [];
|
|
641
|
-
// // tslint:disable-next-line:no-single-line-block-comment
|
|
642
|
-
// /* istanbul ignore else */
|
|
643
|
-
// if (potentialActions !== undefined) {
|
|
644
|
-
// // tslint:disable-next-line:no-single-line-block-comment
|
|
645
|
-
// /* istanbul ignore else */
|
|
646
|
-
// if (Array.isArray(potentialActions.sendEmailMessage)) {
|
|
647
|
-
// potentialActions.sendEmailMessage.forEach((s) => {
|
|
648
|
-
// const sendEmailMessageTask: factory.task.IAttributes<factory.taskName.SendEmailMessage> = {
|
|
649
|
-
// project: s.project,
|
|
650
|
-
// name: factory.taskName.SendEmailMessage,
|
|
651
|
-
// status: factory.taskStatus.Ready,
|
|
652
|
-
// runsAt: now, // なるはやで実行
|
|
653
|
-
// remainingNumberOfTries: 3,
|
|
654
|
-
// numberOfTried: 0,
|
|
655
|
-
// executionResults: [],
|
|
656
|
-
// data: {
|
|
657
|
-
// actionAttributes: s
|
|
658
|
-
// }
|
|
659
|
-
// };
|
|
660
|
-
// taskAttributes.push(sendEmailMessageTask);
|
|
661
|
-
// });
|
|
662
|
-
// }
|
|
663
|
-
// }
|
|
664
|
-
// // タスク保管
|
|
665
|
-
// await Promise.all(taskAttributes.map(async (taskAttribute) => {
|
|
666
|
-
// return repos.task.save(taskAttribute);
|
|
667
|
-
// }));
|
|
668
|
-
// };
|
|
669
|
-
// }
|