@chevre/domain 24.0.0-alpha.73 → 24.0.0-alpha.75

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 (86) hide show
  1. package/lib/chevre/credentials.js +3 -26
  2. package/lib/chevre/errorHandler.js +15 -38
  3. package/lib/chevre/eventEmitter.js +17 -7
  4. package/lib/chevre/index.d.ts +0 -2
  5. package/lib/chevre/index.js +17 -29
  6. package/lib/chevre/repo/aggregateOffer.js +3 -26
  7. package/lib/chevre/repo/event.js +17 -7
  8. package/lib/chevre/repo/eventSeries.js +1 -24
  9. package/lib/chevre/repo/offerCatalog.js +3 -26
  10. package/lib/chevre/repository.js +103 -126
  11. package/lib/chevre/service/accountTransaction.js +17 -7
  12. package/lib/chevre/service/aggregation.js +17 -7
  13. package/lib/chevre/service/assetTransaction/pay/check.js +17 -7
  14. package/lib/chevre/service/assetTransaction/pay/publishPaymentUrl.js +17 -7
  15. package/lib/chevre/service/assetTransaction/pay/searchGMOTrade.js +17 -7
  16. package/lib/chevre/service/assetTransaction/pay/start/processAuthorize.js +5 -5
  17. package/lib/chevre/service/assetTransaction/pay/start/processAuthorizeCreditCard.js +17 -7
  18. package/lib/chevre/service/assetTransaction/pay/start/processAuthorizeMovieTicket.js +17 -7
  19. package/lib/chevre/service/assetTransaction/registerService/potentialActions.js +0 -1
  20. package/lib/chevre/service/assetTransaction/registerService.d.ts +3 -0
  21. package/lib/chevre/service/assetTransaction/registerService.js +19 -62
  22. package/lib/chevre/service/assetTransaction/reserve/start/createSubReservations.js +52 -76
  23. package/lib/chevre/service/assetTransaction/reserve/start.js +18 -75
  24. package/lib/chevre/service/assetTransaction.d.ts +0 -2
  25. package/lib/chevre/service/assetTransaction.js +18 -17
  26. package/lib/chevre/service/notification/notifyByEmail.js +1 -1
  27. package/lib/chevre/service/notification/sendEmailMessage.js +1 -1
  28. package/lib/chevre/service/notification/triggerWebhook.js +22 -12
  29. package/lib/chevre/service/offer/event/authorize/processStartReserve4chevre.js +17 -7
  30. package/lib/chevre/service/offer/eventServiceByCOA/acceptOffer/authorize.js +2 -2
  31. package/lib/chevre/service/offer/product.js +17 -7
  32. package/lib/chevre/service/offer.js +17 -7
  33. package/lib/chevre/service/order/confirmPayTransaction.js +17 -7
  34. package/lib/chevre/service/payment/any/authorize.js +17 -7
  35. package/lib/chevre/service/payment/any/processVoidPayTransaction.js +17 -7
  36. package/lib/chevre/service/payment/any/publishPaymentUrl.js +17 -7
  37. package/lib/chevre/service/payment/creditCard/authorize/handleAuthorizeError.js +1 -1
  38. package/lib/chevre/service/payment/movieTicket/payMovieTicket/processSeatInfoSync.js +1 -1
  39. package/lib/chevre/service/payment/movieTicket/refundMovieTicket/processSeatInfoSync.js +4 -4
  40. package/lib/chevre/service/payment/movieTicket/refundMovieTicket/processSeatInfoSyncCancel.js +1 -1
  41. package/lib/chevre/service/permit.js +17 -7
  42. package/lib/chevre/service/reserveCOA/cancelReservation.js +1 -1
  43. package/lib/chevre/service/task/aggregateScreeningEvent.js +17 -7
  44. package/lib/chevre/service/task/deletePerson.js +2 -25
  45. package/lib/chevre/service/task/deleteTransaction.js +17 -7
  46. package/lib/chevre/service/task/importEventCapacitiesFromCOA.js +17 -7
  47. package/lib/chevre/service/task/importEventsFromCOA.js +17 -7
  48. package/lib/chevre/service/task/importOffersFromCOA.js +17 -7
  49. package/lib/chevre/service/task/payment/invalidatePaymentUrlByTask.js +17 -7
  50. package/lib/chevre/service/task/payment/payByTask.js +21 -11
  51. package/lib/chevre/service/task/payment/refundByTask.js +21 -11
  52. package/lib/chevre/service/task/payment/voidPaymentByTask.js +21 -11
  53. package/lib/chevre/service/task/returnPayTransaction.js +17 -7
  54. package/lib/chevre/service/task/returnReserveTransaction.js +17 -7
  55. package/lib/chevre/service/task.js +2 -25
  56. package/lib/chevre/service/taskHandler.js +3 -26
  57. package/lib/chevre/service/transaction/returnOrder/preStart/getReturnPolicyByProject.js +5 -5
  58. package/lib/chevre/service/transaction.js +17 -7
  59. package/lib/chevre/service.d.ts +0 -4
  60. package/lib/chevre/service.js +33 -43
  61. package/lib/index.js +17 -7
  62. package/package.json +9 -14
  63. package/lib/chevre/pecorinoapi.d.ts +0 -5
  64. package/lib/chevre/pecorinoapi.js +0 -9
  65. package/lib/chevre/service/assetTransaction/moneyTransfer/potentialActions.d.ts +0 -7
  66. package/lib/chevre/service/assetTransaction/moneyTransfer/potentialActions.js +0 -104
  67. package/lib/chevre/service/assetTransaction/moneyTransfer.d.ts +0 -51
  68. package/lib/chevre/service/assetTransaction/moneyTransfer.js +0 -434
  69. package/lib/chevre/service/assetTransaction/pay/start/account/validation.d.ts +0 -8
  70. package/lib/chevre/service/assetTransaction/pay/start/account/validation.js +0 -43
  71. package/lib/chevre/service/assetTransaction/pay/start/processAuthorizeAccount.d.ts +0 -13
  72. package/lib/chevre/service/assetTransaction/pay/start/processAuthorizeAccount.js +0 -62
  73. package/lib/chevre/service/delivery.d.ts +0 -27
  74. package/lib/chevre/service/delivery.js +0 -305
  75. package/lib/chevre/service/moneyTransfer.d.ts +0 -76
  76. package/lib/chevre/service/moneyTransfer.js +0 -659
  77. package/lib/chevre/service/payment/paymentCard.d.ts +0 -42
  78. package/lib/chevre/service/payment/paymentCard.js +0 -442
  79. package/lib/chevre/service/task/cancelMoneyTransfer.d.ts +0 -6
  80. package/lib/chevre/service/task/cancelMoneyTransfer.js +0 -19
  81. package/lib/chevre/service/task/givePointAward.d.ts +0 -6
  82. package/lib/chevre/service/task/givePointAward.js +0 -55
  83. package/lib/chevre/service/task/moneyTransfer.d.ts +0 -6
  84. package/lib/chevre/service/task/moneyTransfer.js +0 -49
  85. package/lib/chevre/service/task/returnPointAward.d.ts +0 -6
  86. package/lib/chevre/service/task/returnPointAward.js +0 -55
@@ -1,434 +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 (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- var __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
27
- };
28
- Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.start = start;
30
- exports.confirm = confirm;
31
- exports.cancel = cancel;
32
- exports.exportTasksById = exportTasksById;
33
- /**
34
- * 通貨転送取引サービス
35
- */
36
- const moment_1 = __importDefault(require("moment"));
37
- const factory_1 = require("../../factory");
38
- const pecorinoapi = __importStar(require("../../pecorinoapi"));
39
- // import type { TransactionNumberRepo } from '../../repo/transactionNumber';
40
- const MoneyTransferService = __importStar(require("../moneyTransfer"));
41
- const potentialActions_1 = require("./moneyTransfer/potentialActions");
42
- /**
43
- * 取引開始
44
- * Pecorinoサービスを利用して口座取引を開始する
45
- */
46
- function start(params) {
47
- return async (repos) => {
48
- const issuedThroughId = fixIssuedThroughId(params);
49
- // location.issuedThroughIdからプロダクトをfixする
50
- const products = await repos.product.projectFields({
51
- limit: 1,
52
- page: 1,
53
- project: { id: { $eq: params.project.id } },
54
- typeOf: { $eq: factory_1.factory.product.ProductType.PaymentCard },
55
- id: { $eq: issuedThroughId }
56
- }, ['availableChannel', 'serviceOutput']
57
- // []
58
- );
59
- const product = products.shift();
60
- if (product === undefined) {
61
- throw new factory_1.factory.errors.NotFound('Product');
62
- }
63
- // fromとtoをfix
64
- const { fromLocation } = await fixFromLocation(params, product)({});
65
- const { toLocation } = await fixToLocation(params, product)({});
66
- const amount = fixMonetaryAmount(params, product);
67
- // 自動発行廃止(2022-05-17~)
68
- const transactionNumber = params.transactionNumber;
69
- if (typeof transactionNumber !== 'string' || transactionNumber.length === 0) {
70
- throw new factory_1.factory.errors.ArgumentNull('transactionNumber');
71
- }
72
- const transactionType = params.object.pendingTransaction?.typeOf;
73
- if (typeof transactionType !== 'string') {
74
- throw new factory_1.factory.errors.ArgumentNull('object.pendingTransaction.typeOf');
75
- }
76
- // 取引開始
77
- const startParams = {
78
- project: params.project,
79
- transactionNumber: transactionNumber,
80
- typeOf: factory_1.factory.assetTransactionType.MoneyTransfer,
81
- agent: params.agent,
82
- recipient: params.recipient,
83
- object: {
84
- amount,
85
- fromLocation,
86
- toLocation,
87
- pendingTransaction: {
88
- typeOf: transactionType,
89
- transactionNumber: transactionNumber,
90
- ...(typeof params.identifier === 'string') ? { identifier: params.identifier } : undefined
91
- },
92
- ...(typeof params.object.description === 'string') ? { description: params.object.description } : {},
93
- force: params.object.force === true
94
- },
95
- expires: params.expires
96
- };
97
- // 取引開始
98
- const transaction = await repos.assetTransaction.start(startParams);
99
- await authorizeAccount({ transaction })(repos);
100
- return transaction;
101
- };
102
- }
103
- function fixIssuedThroughId(params) {
104
- let issuedThroughId;
105
- const pendingTransactionType = params.object.pendingTransaction?.typeOf;
106
- switch (pendingTransactionType) {
107
- case factory_1.factory.account.transactionType.Deposit:
108
- issuedThroughId = String(params.object.toLocation.issuedThrough?.id);
109
- break;
110
- case factory_1.factory.account.transactionType.Transfer:
111
- case factory_1.factory.account.transactionType.Withdraw:
112
- issuedThroughId = String(params.object.fromLocation.issuedThrough?.id);
113
- break;
114
- default:
115
- throw new factory_1.factory.errors.Argument('AccountTransactionType', `invalid type: ${params.typeOf}`);
116
- }
117
- if (typeof issuedThroughId !== 'string' || issuedThroughId.length === 0) {
118
- throw new factory_1.factory.errors.ArgumentNull('location.issuedThrough.id');
119
- }
120
- return issuedThroughId;
121
- }
122
- function authorizeAccount(params) {
123
- return async (repos) => {
124
- const transaction = params.transaction;
125
- const fromLocation = transaction.object.fromLocation;
126
- const toLocation = transaction.object.toLocation;
127
- if (typeof transaction.object.pendingTransaction?.typeOf !== 'string') {
128
- throw new factory_1.factory.errors.NotFound('transaction.object.pendingTransaction.typeOf');
129
- }
130
- await MoneyTransferService.authorize({
131
- typeOf: transaction.object.pendingTransaction.typeOf,
132
- identifier: transaction.object.pendingTransaction.identifier,
133
- transactionNumber: transaction.object.pendingTransaction.transactionNumber,
134
- project: { typeOf: transaction.project.typeOf, id: transaction.project.id },
135
- agent: transaction.agent,
136
- object: {
137
- force: transaction.object.force === true,
138
- amount: transaction.object.amount.value,
139
- fromLocation: {
140
- ...(typeof fromLocation.identifier === 'string')
141
- ? {
142
- identifier: fromLocation.identifier,
143
- hasNoPermit: fromLocation.hasNoPermit === true,
144
- issuedThrough: { id: fromLocation.issuedThrough?.id }
145
- }
146
- : undefined
147
- },
148
- toLocation: {
149
- ...(typeof toLocation.identifier === 'string')
150
- ? {
151
- identifier: toLocation.identifier,
152
- hasNoPermit: toLocation.hasNoPermit === true,
153
- issuedThrough: { id: toLocation.issuedThrough?.id }
154
- }
155
- : undefined
156
- },
157
- ...(typeof transaction.object.description === 'string')
158
- ? { description: transaction.object.description }
159
- : undefined
160
- },
161
- recipient: transaction.recipient,
162
- purpose: { typeOf: transaction.typeOf, id: transaction.id }
163
- })(repos);
164
- // return pendingTransaction;
165
- };
166
- }
167
- function fixMonetaryAmount(params, product) {
168
- // currencyはプロダクトから自動取得
169
- const currency = product.serviceOutput?.amount?.currency;
170
- if (typeof currency !== 'string') {
171
- throw new factory_1.factory.errors.Argument('amount', 'currency unknown');
172
- }
173
- // 金額をfix
174
- const amountValue = params.object?.amount?.value;
175
- if (typeof amountValue !== 'number') {
176
- throw new factory_1.factory.errors.ArgumentNull('amount.value');
177
- }
178
- return {
179
- typeOf: 'MonetaryAmount',
180
- currency,
181
- value: amountValue
182
- };
183
- }
184
- function fixFromLocation(params, product) {
185
- return async (__) => {
186
- const amount = params.object.amount;
187
- if (typeof amount?.value !== 'number') {
188
- throw new factory_1.factory.errors.ArgumentNull('amount.value');
189
- }
190
- const { permitServiceEndpoint, permitServiceAuthorizeServerDomain, permitServiceClientId, permitServiceClientSecret } = createPermitServiceCredentials({ product });
191
- const permitService = new (await pecorinoapi.loadPecorino()).service.Permit({
192
- endpoint: permitServiceEndpoint,
193
- auth: await pecorinoapi.auth.ClientCredentials.createInstance({
194
- domain: permitServiceAuthorizeServerDomain,
195
- clientId: permitServiceClientId,
196
- clientSecret: permitServiceClientSecret,
197
- scopes: [],
198
- state: ''
199
- })
200
- });
201
- let fromLocation = params.object.fromLocation;
202
- const transactionType = params.object.pendingTransaction?.typeOf;
203
- switch (transactionType) {
204
- case factory_1.factory.account.transactionType.Withdraw:
205
- case factory_1.factory.account.transactionType.Transfer: {
206
- const fromLocationObject = fromLocation;
207
- // Permitの存在しない注文口座に対応する
208
- const hasNoPermit = fromLocationObject.hasNoPermit === true;
209
- let serviceOutput;
210
- if (!hasNoPermit) {
211
- // サービスアウトプット存在確認
212
- serviceOutput = await permitService.findByIdentifier({
213
- project: { id: params.project.id },
214
- identifier: fromLocationObject.identifier,
215
- issuedThrough: { typeOf: factory_1.factory.product.ProductType.PaymentCard }
216
- });
217
- // 出金金額設定を確認
218
- const paymentAmount = serviceOutput.paymentAmount;
219
- if (typeof paymentAmount?.minValue === 'number') {
220
- if (amount.value < paymentAmount.minValue) {
221
- throw new factory_1.factory.errors.Argument('fromLocation', `mininum payment amount requirement not satisfied`);
222
- }
223
- }
224
- if (typeof paymentAmount?.maxValue === 'number') {
225
- if (amount.value > paymentAmount.maxValue) {
226
- throw new factory_1.factory.errors.Argument('fromLocation', `maximum payment amount requirement not satisfied`);
227
- }
228
- }
229
- }
230
- const accountNumber = (serviceOutput !== undefined)
231
- ? String(serviceOutput.paymentAccount?.accountNumber)
232
- : fromLocationObject.identifier;
233
- fromLocation = {
234
- typeOf: (serviceOutput !== undefined) ? serviceOutput.typeOf : factory_1.factory.permit.PermitType.Permit,
235
- identifier: (serviceOutput !== undefined) ? serviceOutput.identifier : accountNumber,
236
- ...(hasNoPermit) ? { hasNoPermit } : undefined,
237
- issuedThrough: { id: fromLocationObject.issuedThrough?.id }
238
- };
239
- break;
240
- }
241
- default:
242
- // no op
243
- }
244
- return { fromLocation };
245
- };
246
- }
247
- function fixToLocation(params, product) {
248
- return async (__) => {
249
- let toLocation = params.object.toLocation;
250
- const amount = params.object.amount;
251
- if (typeof amount?.value !== 'number') {
252
- throw new factory_1.factory.errors.ArgumentNull('amount.value');
253
- }
254
- const { permitServiceEndpoint, permitServiceAuthorizeServerDomain, permitServiceClientId, permitServiceClientSecret } = createPermitServiceCredentials({ product });
255
- const permitService = new (await pecorinoapi.loadPecorino()).service.Permit({
256
- endpoint: permitServiceEndpoint,
257
- auth: await pecorinoapi.auth.ClientCredentials.createInstance({
258
- domain: permitServiceAuthorizeServerDomain,
259
- clientId: permitServiceClientId,
260
- clientSecret: permitServiceClientSecret,
261
- scopes: [],
262
- state: ''
263
- })
264
- });
265
- const transactionType = params.object.pendingTransaction?.typeOf;
266
- switch (transactionType) {
267
- case factory_1.factory.account.transactionType.Deposit:
268
- case factory_1.factory.account.transactionType.Transfer: {
269
- const toLocationObject = toLocation;
270
- // Permitの存在しない注文口座に対応する
271
- const hasNoPermit = toLocationObject.hasNoPermit === true;
272
- let serviceOutput;
273
- if (!hasNoPermit) {
274
- // サービスアウトプット存在確認
275
- serviceOutput = await permitService.findByIdentifier({
276
- project: { id: params.project.id },
277
- identifier: toLocationObject.identifier,
278
- issuedThrough: { typeOf: factory_1.factory.product.ProductType.PaymentCard }
279
- });
280
- // 入金金額設定を確認
281
- const depositAmount = serviceOutput.depositAmount;
282
- if (typeof depositAmount?.minValue === 'number') {
283
- if (amount.value < depositAmount.minValue) {
284
- throw new factory_1.factory.errors.Argument('toLocation', `mininum deposit amount requirement not satisfied`);
285
- }
286
- }
287
- if (typeof depositAmount?.maxValue === 'number') {
288
- if (amount.value > depositAmount.maxValue) {
289
- throw new factory_1.factory.errors.Argument('toLocation', `maximum deposit amount requirement not satisfied`);
290
- }
291
- }
292
- }
293
- const accountNumber = (serviceOutput !== undefined)
294
- ? String(serviceOutput.paymentAccount?.accountNumber)
295
- : toLocationObject.identifier;
296
- toLocation = {
297
- typeOf: (serviceOutput !== undefined) ? serviceOutput.typeOf : factory_1.factory.permit.PermitType.Permit,
298
- identifier: (serviceOutput !== undefined) ? serviceOutput.identifier : accountNumber,
299
- ...(hasNoPermit) ? { hasNoPermit } : undefined,
300
- issuedThrough: { id: toLocationObject.issuedThrough?.id }
301
- };
302
- break;
303
- }
304
- default:
305
- // no op
306
- }
307
- return { toLocation };
308
- };
309
- }
310
- function createPermitServiceCredentials(params) {
311
- const permitServiceEndpoint = params.product.availableChannel?.serviceUrl;
312
- const permitServiceAuthorizeServerDomain = params.product.availableChannel?.credentials?.authorizeServerDomain;
313
- const permitServiceClientId = params.product.availableChannel?.credentials?.clientId;
314
- const permitServiceClientSecret = params.product.availableChannel?.credentials?.clientSecret;
315
- if (typeof permitServiceEndpoint !== 'string' || permitServiceEndpoint.length === 0
316
- || typeof permitServiceAuthorizeServerDomain !== 'string' || permitServiceAuthorizeServerDomain.length === 0
317
- || typeof permitServiceClientId !== 'string' || permitServiceClientId.length === 0
318
- || typeof permitServiceClientSecret !== 'string' || permitServiceClientSecret.length === 0) {
319
- throw new factory_1.factory.errors.Internal('membershipService availableChannel invalid');
320
- }
321
- return {
322
- permitServiceEndpoint,
323
- permitServiceAuthorizeServerDomain,
324
- permitServiceClientId,
325
- permitServiceClientSecret
326
- };
327
- }
328
- /**
329
- * 取引確定
330
- */
331
- function confirm(params) {
332
- return async (repos) => {
333
- let transaction;
334
- // 取引存在確認
335
- if (typeof params.id === 'string') {
336
- transaction = await repos.assetTransaction.findById({
337
- typeOf: factory_1.factory.assetTransactionType.MoneyTransfer,
338
- id: params.id
339
- });
340
- }
341
- else if (typeof params.transactionNumber === 'string') {
342
- transaction = await repos.assetTransaction.findByTransactionNumber({
343
- typeOf: factory_1.factory.assetTransactionType.MoneyTransfer,
344
- transactionNumber: params.transactionNumber
345
- });
346
- }
347
- else {
348
- throw new factory_1.factory.errors.ArgumentNull('Transaction ID or Transaction Number');
349
- }
350
- const potentialActions = await (0, potentialActions_1.createPotentialActions)({
351
- transaction: transaction
352
- });
353
- await repos.assetTransaction.confirm({
354
- typeOf: factory_1.factory.assetTransactionType.MoneyTransfer,
355
- id: transaction.id,
356
- result: {},
357
- potentialActions: potentialActions
358
- });
359
- };
360
- }
361
- /**
362
- * 取引中止
363
- */
364
- function cancel(params) {
365
- return async (repos) => {
366
- await repos.assetTransaction.cancel({
367
- typeOf: factory_1.factory.assetTransactionType.MoneyTransfer,
368
- id: params.id,
369
- transactionNumber: params.transactionNumber
370
- });
371
- };
372
- }
373
- /**
374
- * 取引のタスク出力
375
- */
376
- function exportTasksById(params) {
377
- return async (repos) => {
378
- const transaction = await repos.assetTransaction.findById({
379
- typeOf: factory_1.factory.assetTransactionType.MoneyTransfer,
380
- id: params.id
381
- });
382
- const potentialActions = transaction.potentialActions;
383
- const taskAttributes = [];
384
- // タスク実行日時バッファの指定があれば調整
385
- let taskRunsAt = new Date();
386
- if (typeof params.runsTasksAfterInSeconds === 'number') {
387
- taskRunsAt = (0, moment_1.default)(taskRunsAt)
388
- .add(params.runsTasksAfterInSeconds, 'seconds')
389
- .toDate();
390
- }
391
- switch (transaction.status) {
392
- case factory_1.factory.transactionStatusType.Confirmed:
393
- /* istanbul ignore else */
394
- if (potentialActions !== undefined) {
395
- /* istanbul ignore else */
396
- if (potentialActions.moneyTransfer !== undefined) {
397
- taskAttributes.push(...potentialActions.moneyTransfer.map((a) => {
398
- return {
399
- project: transaction.project,
400
- name: factory_1.factory.taskName.MoneyTransfer,
401
- status: factory_1.factory.taskStatus.Ready,
402
- runsAt: taskRunsAt,
403
- remainingNumberOfTries: 10,
404
- numberOfTried: 0,
405
- executionResults: [],
406
- data: a
407
- };
408
- }));
409
- }
410
- }
411
- break;
412
- case factory_1.factory.transactionStatusType.Canceled:
413
- case factory_1.factory.transactionStatusType.Expired: {
414
- const cancelMoneyTransferTaskAttributes = {
415
- project: { typeOf: transaction.project.typeOf, id: transaction.project.id },
416
- name: factory_1.factory.taskName.CancelMoneyTransfer,
417
- status: factory_1.factory.taskStatus.Ready,
418
- runsAt: taskRunsAt,
419
- remainingNumberOfTries: 10,
420
- numberOfTried: 0,
421
- executionResults: [],
422
- data: {
423
- purpose: { typeOf: transaction.typeOf, id: transaction.id }
424
- }
425
- };
426
- taskAttributes.push(cancelMoneyTransferTaskAttributes);
427
- break;
428
- }
429
- default:
430
- throw new factory_1.factory.errors.NotImplemented(`Transaction status "${transaction.status}" not implemented.`);
431
- }
432
- return repos.task.saveMany(taskAttributes, { emitImmediately: true });
433
- };
434
- }
@@ -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>;
@@ -1,43 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.validateAccount = validateAccount;
4
- const factory_1 = require("../../../../../factory");
5
- function validateAccount(params) {
6
- return async (repos) => {
7
- // 引き出し口座の存在を確認する
8
- const paymentMethodType = params.object.paymentMethod?.identifier;
9
- if (typeof paymentMethodType !== 'string') {
10
- throw new factory_1.factory.errors.ArgumentNull('object.paymentMethod.identifier');
11
- }
12
- const accountNumber = params.object.paymentMethod?.accountId;
13
- if (typeof accountNumber !== 'string') {
14
- throw new factory_1.factory.errors.ArgumentNull('object.paymentMethod.accountId');
15
- }
16
- // 販売者から決済情報取得
17
- const sellerId = params.recipient?.id;
18
- if (typeof sellerId !== 'string') {
19
- throw new factory_1.factory.errors.ArgumentNull('recipient.id');
20
- }
21
- // const sellers = <Pick<factory.seller.ISeller, 'paymentAccepted'>[]>await repos.seller.search(
22
- // {
23
- // limit: 1,
24
- // page: 1,
25
- // id: { $eq: sellerId }
26
- // },
27
- // ['paymentAccepted'],
28
- // []
29
- // );
30
- // const seller = sellers.shift();
31
- // if (seller === undefined) {
32
- // throw new factory.errors.NotFound(factory.organizationType.Corporation);
33
- // }
34
- // const paymentAccepted = seller.paymentAccepted?.some((a) => a.paymentMethodType === paymentMethodType);
35
- const paymentAccepted = await repos.paymentAccepted.isAcceptedBySeller({
36
- seller: { id: sellerId },
37
- codeValue: paymentMethodType
38
- });
39
- if (paymentAccepted !== true) {
40
- throw new factory_1.factory.errors.Argument('recipient', `payment not accepted [${paymentMethodType}]`);
41
- }
42
- };
43
- }
@@ -1,13 +0,0 @@
1
- import { factory } from '../../../../factory';
2
- import type { AssetTransactionRepo } from '../../../../repo/assetTransaction';
3
- import type { EventRepo } from '../../../../repo/event';
4
- import type { ProductRepo } from '../../../../repo/product';
5
- import type { SellerPaymentAcceptedRepo } from '../../../../repo/sellerPaymentAccepted';
6
- export declare function processAuthorizeAccount(params: factory.assetTransaction.pay.IStartParamsWithoutDetail, transaction: {
7
- id: string;
8
- }, paymentServiceId: string): (repos: {
9
- event: EventRepo;
10
- paymentAccepted: SellerPaymentAcceptedRepo;
11
- product: ProductRepo;
12
- assetTransaction: AssetTransactionRepo;
13
- }) => Promise<factory.assetTransaction.pay.ITransaction>;
@@ -1,62 +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 (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.processAuthorizeAccount = processAuthorizeAccount;
27
- const factory_1 = require("../../../../factory");
28
- const PaymentCardPayment = __importStar(require("../../../payment/paymentCard"));
29
- const validation_1 = require("./account/validation");
30
- function processAuthorizeAccount(params, transaction, paymentServiceId) {
31
- return async (repos) => {
32
- const amount = params.object.paymentMethod?.amount;
33
- if (typeof amount !== 'number') {
34
- throw new factory_1.factory.errors.ArgumentNull('object.paymentMethod?.amount');
35
- }
36
- await (0, validation_1.validateAccount)(params)(repos);
37
- const { pendingTransaction, currency, accountNumber } = await PaymentCardPayment.authorize(params, paymentServiceId)(repos);
38
- const totalPaymentDue = {
39
- typeOf: 'MonetaryAmount',
40
- currency,
41
- value: amount
42
- };
43
- const savingPendingTransaction = {
44
- typeOf: pendingTransaction.typeOf,
45
- id: pendingTransaction.id,
46
- transactionNumber: pendingTransaction.transactionNumber,
47
- object: { fromLocation: { accountNumber } }
48
- };
49
- return saveAuthorizeResult({
50
- id: transaction.id,
51
- update: {
52
- 'object.paymentMethod.totalPaymentDue': totalPaymentDue,
53
- 'object.pendingTransaction': savingPendingTransaction
54
- }
55
- })(repos);
56
- };
57
- }
58
- function saveAuthorizeResult(params) {
59
- return async (repos) => {
60
- return repos.assetTransaction.findByIdAndUpdateInProgress(params);
61
- };
62
- }
@@ -1,27 +0,0 @@
1
- import { factory } from '../factory';
2
- import type { ActionRepo } from '../repo/action';
3
- import type { AssetTransactionRepo } from '../repo/assetTransaction';
4
- import type { ProductRepo } from '../repo/product';
5
- import type { ProjectRepo } from '../repo/project';
6
- import type { TransactionNumberRepo } from '../repo/transactionNumber';
7
- /**
8
- * 特典付与
9
- */
10
- declare function givePointAward(params: factory.task.IData<factory.taskName.GivePointAward>): (repos: {
11
- action: ActionRepo;
12
- assetTransaction: AssetTransactionRepo;
13
- product: ProductRepo;
14
- project: ProjectRepo;
15
- transactionNumber: TransactionNumberRepo;
16
- }) => Promise<void>;
17
- /**
18
- * 特典返却
19
- */
20
- declare function returnPointAward(params: factory.task.IData<factory.taskName.ReturnPointAward>): (repos: {
21
- action: ActionRepo;
22
- assetTransaction: AssetTransactionRepo;
23
- product: ProductRepo;
24
- project: ProjectRepo;
25
- transactionNumber: TransactionNumberRepo;
26
- }) => Promise<void>;
27
- export { givePointAward, returnPointAward };