@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,42 +0,0 @@
1
- import { factory } from '../../factory';
2
- import type { AccountingReportRepo } from '../../repo/accountingReport';
3
- import type { PayActionRepo } from '../../repo/action/pay';
4
- import type { RefundActionRepo } from '../../repo/action/refund';
5
- import type { AssetTransactionRepo } from '../../repo/assetTransaction';
6
- import type { ProductRepo } from '../../repo/product';
7
- import type { TaskRepo } from '../../repo/task';
8
- import type { TransactionNumberRepo } from '../../repo/transactionNumber';
9
- type IPendingTransaction = Pick<factory.account.transaction.withdraw.ITransaction, 'id' | 'transactionNumber' | 'typeOf'>;
10
- declare function authorize(params: factory.assetTransaction.pay.IStartParamsWithoutDetail, paymentServiceId: string): (repos: {
11
- product: ProductRepo;
12
- }) => Promise<{
13
- pendingTransaction: IPendingTransaction;
14
- currency: string;
15
- accountNumber: string;
16
- }>;
17
- declare function voidTransaction(params: factory.task.voidPayment.IData): (repos: {
18
- product: ProductRepo;
19
- }) => Promise<void>;
20
- declare function payPaymentCard(params: factory.action.trade.pay.IAttributes): (repos: {
21
- action?: never;
22
- actions: {
23
- pay: PayActionRepo;
24
- refund: RefundActionRepo;
25
- };
26
- accountingReport: AccountingReportRepo;
27
- product: ProductRepo;
28
- task: TaskRepo;
29
- }) => Promise<void>;
30
- declare function refundPaymentCard(params: factory.task.refund.IData): (repos: {
31
- action?: never;
32
- actions: {
33
- pay: PayActionRepo;
34
- refund: RefundActionRepo;
35
- };
36
- accountingReport: AccountingReportRepo;
37
- product: ProductRepo;
38
- task: TaskRepo;
39
- assetTransaction: AssetTransactionRepo;
40
- transactionNumber: TransactionNumberRepo;
41
- }) => Promise<void>;
42
- export { authorize, payPaymentCard, refundPaymentCard, voidTransaction };
@@ -1,442 +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.authorize = authorize;
30
- exports.payPaymentCard = payPaymentCard;
31
- exports.refundPaymentCard = refundPaymentCard;
32
- exports.voidTransaction = voidTransaction;
33
- /**
34
- * ペイメントカード決済サービス
35
- */
36
- const moment_timezone_1 = __importDefault(require("moment-timezone"));
37
- const pecorinoapi = __importStar(require("../../pecorinoapi"));
38
- const errorHandler_1 = require("../../errorHandler");
39
- const factory_1 = require("../../factory");
40
- const onPayActionCompleted_1 = require("./any/onPayActionCompleted");
41
- const onRefundActionCompletedOrFailed_1 = require("./any/onRefundActionCompletedOrFailed");
42
- const accountTransactionIdentifier_1 = require("../../factory/accountTransactionIdentifier");
43
- function authorize(params, paymentServiceId) {
44
- return async (repos) => {
45
- const transactionNumber = params.transactionNumber;
46
- if (typeof transactionNumber !== 'string') {
47
- throw new factory_1.factory.errors.ArgumentNull('transactionNumber');
48
- }
49
- // 決済方法検証
50
- const { permit, currency } = await validatePaymentMethod(params, paymentServiceId)(repos);
51
- const accountNumber = permit.paymentAccount?.accountNumber;
52
- if (typeof accountNumber !== 'string') {
53
- throw new factory_1.factory.errors.ArgumentNull('permit.paymentAccount.accountNumber');
54
- }
55
- // 口座取引開始
56
- let pendingTransaction;
57
- try {
58
- const expires = (0, moment_timezone_1.default)(params.expires)
59
- .add(1, 'month')
60
- .toDate();
61
- pendingTransaction = await processAccountTransaction({
62
- transactionNumber,
63
- project: { id: params.project.id, typeOf: factory_1.factory.organizationType.Project },
64
- paymentMethod: params.object.paymentMethod,
65
- agent: params.agent,
66
- recipient: params.recipient,
67
- expires: expires,
68
- accountNumber,
69
- paymentServiceId
70
- })({ product: repos.product });
71
- }
72
- catch (error) {
73
- // PecorinoAPIのエラーをハンドリング
74
- throw (0, errorHandler_1.handlePecorinoError)(error);
75
- }
76
- return { pendingTransaction, currency, accountNumber };
77
- };
78
- }
79
- function validatePaymentMethod(params, paymentServiceId) {
80
- return async (repos) => {
81
- const serviceOutputIdentifier = params.object.paymentMethod?.accountId;
82
- const amount = params.object.paymentMethod?.amount;
83
- const paymentMethodType = params.object.paymentMethod?.identifier;
84
- if (typeof serviceOutputIdentifier !== 'string') {
85
- throw new factory_1.factory.errors.ArgumentNull('object.paymentMethod.accountId');
86
- }
87
- if (typeof amount !== 'number') {
88
- throw new factory_1.factory.errors.ArgumentNull('object.paymentMethod.amount');
89
- }
90
- if (typeof paymentMethodType !== 'string') {
91
- throw new factory_1.factory.errors.ArgumentNull('object.paymentMethod.identifier');
92
- }
93
- // プロダクトから通貨区分を取得
94
- const paymentCatdProduct = (await repos.product.projectFields({
95
- limit: 1,
96
- page: 1,
97
- id: { $eq: paymentServiceId },
98
- typeOf: { $eq: factory_1.factory.product.ProductType.PaymentCard }
99
- }, ['serviceOutput']
100
- // []
101
- )).shift();
102
- const currency = paymentCatdProduct?.serviceOutput?.amount?.currency;
103
- if (typeof currency !== 'string') {
104
- throw new factory_1.factory.errors.NotFound('product.serviceOutput.amount.currency');
105
- }
106
- // プロダクトのavailableChannelを取得する
107
- const availableChannel = await repos.product.findAvailableChannel({
108
- project: { id: params.project.id },
109
- typeOf: factory_1.factory.service.paymentService.PaymentServiceType.PaymentCard,
110
- id: paymentServiceId
111
- });
112
- const permitService = new (await pecorinoapi.loadPecorino()).service.Permit({
113
- endpoint: String(availableChannel.serviceUrl),
114
- auth: await pecorinoapi.auth.ClientCredentials.createInstance({
115
- domain: String(availableChannel.credentials?.authorizeServerDomain),
116
- clientId: String(availableChannel.credentials?.clientId),
117
- clientSecret: String(availableChannel.credentials?.clientSecret),
118
- scopes: [],
119
- state: ''
120
- })
121
- });
122
- // サービスアウトプット存在確認
123
- const serviceOutput = await permitService.findByIdentifier({
124
- project: { id: params.project.id },
125
- identifier: serviceOutputIdentifier,
126
- issuedThrough: { typeOf: factory_1.factory.product.ProductType.PaymentCard }
127
- });
128
- // サービスタイプを確認
129
- if (serviceOutput.issuedThrough?.typeOf !== factory_1.factory.product.ProductType.PaymentCard) {
130
- throw new factory_1.factory.errors.Argument('object.paymentMethod.accountId', 'serviceOutput.issuedThrough?.typeOf must be PaymentCard');
131
- }
132
- if (serviceOutput.issuedThrough?.serviceType?.codeValue !== paymentMethodType) {
133
- throw new factory_1.factory.errors.Argument('object.paymentMethod.accountId', 'paymentMethodType not matched');
134
- }
135
- // 出金金額設定を確認
136
- const paymentAmount = serviceOutput.paymentAmount;
137
- if (typeof paymentAmount?.minValue === 'number') {
138
- if (amount < paymentAmount.minValue) {
139
- throw new factory_1.factory.errors.Argument('object.paymentMethod.amount', `mininum payment amount requirement not satisfied`);
140
- }
141
- }
142
- if (typeof paymentAmount?.maxValue === 'number') {
143
- if (amount > paymentAmount.maxValue) {
144
- throw new factory_1.factory.errors.Argument('object.paymentMethod.amount', `maximum payment amount requirement not satisfied`);
145
- }
146
- }
147
- return { permit: serviceOutput, currency };
148
- };
149
- }
150
- function processAccountTransaction(params) {
151
- return async (repos) => {
152
- const defaultName = `${factory_1.factory.assetTransactionType.Pay} Transaction ${params.transactionNumber}`;
153
- const agent = {
154
- // ...params.agent,
155
- name: (typeof params.agent.name === 'string') ? params.agent.name : defaultName,
156
- typeOf: params.agent.typeOf
157
- };
158
- const recipient = {
159
- // ...params.recipient,
160
- name: (typeof params.recipient.name === 'string')
161
- ? params.recipient.name
162
- : defaultName,
163
- typeOf: params.recipient.typeOf
164
- };
165
- const description = (typeof params.paymentMethod?.description === 'string') ? params.paymentMethod?.description : '';
166
- const accountNumber = params.accountNumber;
167
- const accountTransactionIdentifier = (0, accountTransactionIdentifier_1.createPayIdentifier)({
168
- project: { id: params.project.id },
169
- paymentMethodId: params.transactionNumber
170
- });
171
- // プロダクトのavailableChannelを取得する
172
- const availableChannel = await repos.product.findAvailableChannel({
173
- project: { id: params.project.id },
174
- typeOf: factory_1.factory.service.paymentService.PaymentServiceType.PaymentCard,
175
- id: params.paymentServiceId
176
- });
177
- const accountTransactionService = new (await pecorinoapi.loadPecorino()).service.AccountTransaction({
178
- endpoint: String(availableChannel.serviceUrl),
179
- auth: await pecorinoapi.auth.ClientCredentials.createInstance({
180
- domain: String(availableChannel.credentials?.authorizeServerDomain),
181
- clientId: String(availableChannel.credentials?.clientId),
182
- clientSecret: String(availableChannel.credentials?.clientSecret),
183
- scopes: [],
184
- state: ''
185
- })
186
- });
187
- // ひとまず出金取引に限定
188
- const pendingTransaction = await accountTransactionService.start({
189
- transactionNumber: params.transactionNumber,
190
- project: { typeOf: params.project.typeOf, id: params.project.id },
191
- typeOf: factory_1.factory.account.transactionType.Withdraw,
192
- agent: agent,
193
- expires: params.expires,
194
- recipient: recipient,
195
- object: {
196
- amount: {
197
- value: (typeof params.paymentMethod?.amount === 'number')
198
- ? params.paymentMethod?.amount
199
- : params.paymentMethod?.amount.value
200
- },
201
- description: description,
202
- fromLocation: {
203
- accountNumber: accountNumber
204
- }
205
- },
206
- identifier: accountTransactionIdentifier
207
- });
208
- return pendingTransaction;
209
- };
210
- }
211
- function voidTransaction(params) {
212
- return async (repos) => {
213
- const transaction = params.object;
214
- // const paymentMethodId = transaction.object.paymentMethod?.paymentMethodId;
215
- const paymentMethodId = transaction.object.paymentMethodId;
216
- if (typeof paymentMethodId !== 'string') {
217
- throw new factory_1.factory.errors.ArgumentNull('object.paymentMethodId');
218
- }
219
- const paymentServiceId = String(transaction.object.id);
220
- // アクションステータスに関係なく取消処理実行
221
- // プロダクトのavailableChannelを取得する
222
- const availableChannel = await repos.product.findAvailableChannel({
223
- project: { id: transaction.project.id },
224
- typeOf: factory_1.factory.service.paymentService.PaymentServiceType.PaymentCard,
225
- id: paymentServiceId
226
- });
227
- // 汎用中止サービスを使用(2022-09-27~)
228
- const accountTransactionService = new (await pecorinoapi.loadPecorino()).service.AccountTransaction({
229
- endpoint: String(availableChannel.serviceUrl),
230
- auth: await pecorinoapi.auth.ClientCredentials.createInstance({
231
- domain: String(availableChannel.credentials?.authorizeServerDomain),
232
- clientId: String(availableChannel.credentials?.clientId),
233
- clientSecret: String(availableChannel.credentials?.clientSecret),
234
- scopes: [],
235
- state: ''
236
- })
237
- });
238
- // 取引存在検証(2022-10-26~)
239
- const searchAccountTransactionsResult = await accountTransactionService.search({
240
- limit: 1,
241
- project: { id: { $eq: transaction.project.id } },
242
- transactionNumber: { $eq: paymentMethodId }
243
- });
244
- if (searchAccountTransactionsResult.data.length > 0) {
245
- await accountTransactionService.cancelSync({ transactionNumber: paymentMethodId });
246
- }
247
- };
248
- }
249
- function payPaymentCard(params) {
250
- return async (repos) => {
251
- const payObject = params.object;
252
- const paymentServiceId = payObject[0].id;
253
- const action = await repos.actions.pay.start(params);
254
- try {
255
- const transactionNumber = payObject[0].paymentMethod.paymentMethodId;
256
- const availableChannel = await repos.product.findAvailableChannel({
257
- project: { id: params.project.id },
258
- typeOf: factory_1.factory.service.paymentService.PaymentServiceType.PaymentCard,
259
- id: paymentServiceId
260
- });
261
- const accountTransactionService = new (await pecorinoapi.loadPecorino()).service.AccountTransaction({
262
- endpoint: String(availableChannel.serviceUrl),
263
- auth: await pecorinoapi.auth.ClientCredentials.createInstance({
264
- domain: String(availableChannel.credentials?.authorizeServerDomain),
265
- clientId: String(availableChannel.credentials?.clientId),
266
- clientSecret: String(availableChannel.credentials?.clientSecret),
267
- scopes: [],
268
- state: ''
269
- })
270
- });
271
- await accountTransactionService.confirmSync({ transactionNumber: transactionNumber });
272
- }
273
- catch (error) {
274
- try {
275
- await repos.actions.pay.giveUp({ typeOf: action.typeOf, id: action.id, error });
276
- }
277
- catch (__) {
278
- // no op
279
- }
280
- throw error;
281
- }
282
- const actionResult = {};
283
- await repos.actions.pay.completeWithVoid({ typeOf: action.typeOf, id: action.id, result: actionResult });
284
- await (0, onPayActionCompleted_1.onPayActionCompleted)({
285
- // actionStatus: factory.actionStatusType.CompletedActionStatus,
286
- id: action.id,
287
- object: params.object,
288
- potentialActions: params.potentialActions,
289
- project: params.project,
290
- purpose: params.purpose,
291
- typeOf: action.typeOf
292
- })({
293
- actions: repos.actions,
294
- accountingReport: repos.accountingReport,
295
- task: repos.task
296
- });
297
- // return action;
298
- };
299
- }
300
- function refundPaymentCard(params) {
301
- return async (repos) => {
302
- const paymentMethodId = params.object[0]?.paymentMethod.paymentMethodId;
303
- const paymentServiceId = params.object[0]?.id;
304
- const payTransaction = await repos.assetTransaction.findByTransactionNumber({
305
- typeOf: factory_1.factory.assetTransactionType.Pay,
306
- transactionNumber: paymentMethodId
307
- });
308
- // accountNumberをpendingTransactionから取得する
309
- const accountNumber = payTransaction.object.pendingTransaction?.object.fromLocation?.accountNumber;
310
- if (typeof accountNumber !== 'string') {
311
- throw new factory_1.factory.errors.ArgumentNull('serviceOutput.paymentAccount.accountNumber');
312
- }
313
- const action = await repos.actions.refund.start(params);
314
- let accountTransactionNumber4refund;
315
- try {
316
- const availableChannel = await repos.product.findAvailableChannel({
317
- project: { id: params.project.id },
318
- typeOf: factory_1.factory.service.paymentService.PaymentServiceType.PaymentCard,
319
- id: paymentServiceId
320
- });
321
- const accountTransactionService = new (await pecorinoapi.loadPecorino()).service.AccountTransaction({
322
- endpoint: String(availableChannel.serviceUrl),
323
- auth: await pecorinoapi.auth.ClientCredentials.createInstance({
324
- domain: String(availableChannel.credentials?.authorizeServerDomain),
325
- clientId: String(availableChannel.credentials?.clientId),
326
- clientSecret: String(availableChannel.credentials?.clientSecret),
327
- scopes: [],
328
- state: ''
329
- })
330
- });
331
- // 返金のユニークネスを保証するため識別子を指定する
332
- const accountTransactionIdentifier = (0, accountTransactionIdentifier_1.createRefundIdentifier)({
333
- project: { id: params.project.id },
334
- paymentMethodId
335
- });
336
- // すでに返金済かどうか確認
337
- let confirmedAccountTransactionNumber;
338
- if (typeof accountTransactionIdentifier === 'string') {
339
- // 口座取引で確認する(2022-10-27~)
340
- const searchAccountTransactionsResult = await accountTransactionService.search({
341
- limit: 100,
342
- project: { id: { $eq: params.project.id } },
343
- identifier: { $eq: accountTransactionIdentifier }
344
- });
345
- const existingAccountTransactions = searchAccountTransactionsResult.data;
346
- for (const existingAccountTransaction of existingAccountTransactions) {
347
- if (existingAccountTransaction.status === factory_1.factory.transactionStatusType.Confirmed) {
348
- confirmedAccountTransactionNumber = existingAccountTransaction.transactionNumber;
349
- }
350
- else {
351
- await accountTransactionService.cancelSync({ transactionNumber: existingAccountTransaction.transactionNumber });
352
- }
353
- }
354
- }
355
- if (typeof confirmedAccountTransactionNumber === 'string') {
356
- // 念のためconfirm
357
- await accountTransactionService.confirmSync({ transactionNumber: confirmedAccountTransactionNumber });
358
- accountTransactionNumber4refund = confirmedAccountTransactionNumber;
359
- }
360
- else {
361
- const { transactionNumber } = await repos.transactionNumber.publishByTimestamp({ startDate: new Date() });
362
- const expires = (0, moment_timezone_1.default)()
363
- .add(1, 'minute')
364
- .toDate();
365
- const agent = createAgent4refund(params);
366
- const recipient = createRecipient4refund(params);
367
- await accountTransactionService.start({
368
- transactionNumber: transactionNumber,
369
- project: { typeOf: params.project.typeOf, id: params.project.id },
370
- typeOf: factory_1.factory.account.transactionType.Deposit,
371
- agent: agent,
372
- expires: expires,
373
- recipient: recipient,
374
- object: {
375
- amount: {
376
- value: Number(payTransaction.object?.paymentMethod?.totalPaymentDue?.value)
377
- },
378
- description: `Refund [${payTransaction.object?.paymentMethod?.description}]`,
379
- toLocation: { accountNumber }
380
- },
381
- identifier: accountTransactionIdentifier
382
- });
383
- try {
384
- await accountTransactionService.confirmSync({ transactionNumber });
385
- accountTransactionNumber4refund = transactionNumber;
386
- }
387
- catch (error) {
388
- await accountTransactionService.cancelSync({ transactionNumber });
389
- throw error;
390
- }
391
- }
392
- }
393
- catch (error) {
394
- try {
395
- await repos.actions.refund.giveUp({ typeOf: action.typeOf, id: action.id, error });
396
- }
397
- catch (__) {
398
- // no op
399
- }
400
- throw error;
401
- }
402
- const result = {
403
- accountTransaction: { transactionNumber: accountTransactionNumber4refund }
404
- };
405
- await repos.actions.refund.completeWithVoid({ typeOf: action.typeOf, id: action.id, result });
406
- await (0, onRefundActionCompletedOrFailed_1.onRefundActionCompletedOrFailed)({
407
- actionStatus: factory_1.factory.actionStatusType.CompletedActionStatus,
408
- id: action.id,
409
- object: params.object,
410
- potentialActions: params.potentialActions,
411
- project: params.project,
412
- purpose: params.purpose,
413
- typeOf: action.typeOf
414
- })({
415
- actions: repos.actions,
416
- accountingReport: repos.accountingReport,
417
- task: repos.task
418
- });
419
- // return action;
420
- };
421
- }
422
- function createAgent4refund(params) {
423
- return {
424
- // ...params.agent,
425
- name: (typeof params.agent.name === 'string')
426
- ? params.agent.name
427
- : `${params.agent.typeOf} ${params.agent.id}`,
428
- typeOf: params.agent.typeOf
429
- };
430
- }
431
- function createRecipient4refund(params) {
432
- if (typeof params.recipient?.typeOf !== 'string') {
433
- throw new factory_1.factory.errors.NotFound('recipient.typeOf');
434
- }
435
- return {
436
- // ...<factory.person.IPerson | factory.creativeWork.softwareApplication.webApplication.ICreativeWork>params.recipient,
437
- name: (typeof params.recipient?.name === 'string')
438
- ? params.recipient.name
439
- : `${params.recipient?.typeOf} ${params.recipient?.id}`,
440
- typeOf: params.recipient.typeOf
441
- };
442
- }
@@ -1,6 +0,0 @@
1
- import { factory } from '../../factory';
2
- import type { IOperationExecute } from '../taskHandler';
3
- /**
4
- * タスク実行関数
5
- */
6
- export declare function call(data: factory.task.cancelMoneyTransfer.IData): IOperationExecute<void>;
@@ -1,19 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.call = call;
4
- const assetTransaction_1 = require("../../repo/assetTransaction");
5
- const product_1 = require("../../repo/product");
6
- const moneyTransfer_1 = require("../moneyTransfer");
7
- /**
8
- * タスク実行関数
9
- */
10
- function call(data) {
11
- return async ({ connection }) => {
12
- const assetTransactionRepo = new assetTransaction_1.AssetTransactionRepo(connection);
13
- const productRepo = new product_1.ProductRepo(connection);
14
- await (0, moneyTransfer_1.cancelMoneyTransfer)(data)({
15
- assetTransaction: assetTransactionRepo,
16
- product: productRepo
17
- });
18
- };
19
- }
@@ -1,6 +0,0 @@
1
- import type { IOperationExecute } from '../taskHandler';
2
- import { factory } from '../../factory';
3
- /**
4
- * タスク実行関数
5
- */
6
- export declare function call(data: factory.task.IData<factory.taskName.GivePointAward>): IOperationExecute<void>;
@@ -1,55 +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.call = call;
27
- const factory_1 = require("../../factory");
28
- const action_1 = require("../../repo/action");
29
- const assetTransaction_1 = require("../../repo/assetTransaction");
30
- const product_1 = require("../../repo/product");
31
- const project_1 = require("../../repo/project");
32
- const transactionNumber_1 = require("../../repo/transactionNumber");
33
- const DeliveryService = __importStar(require("../delivery"));
34
- /**
35
- * タスク実行関数
36
- */
37
- function call(data) {
38
- return async ({ redisClient, connection }) => {
39
- if (redisClient === undefined) {
40
- throw new factory_1.factory.errors.Argument('settings', 'redisClient required');
41
- }
42
- const actionRepo = new action_1.ActionRepo(connection);
43
- const assetTransactionRepo = new assetTransaction_1.AssetTransactionRepo(connection);
44
- const productRepo = new product_1.ProductRepo(connection);
45
- const projectRepo = new project_1.ProjectRepo(connection);
46
- const transactionNumberRepo = new transactionNumber_1.TransactionNumberRepo({ connection });
47
- await DeliveryService.givePointAward(data)({
48
- action: actionRepo,
49
- assetTransaction: assetTransactionRepo,
50
- product: productRepo,
51
- project: projectRepo,
52
- transactionNumber: transactionNumberRepo
53
- });
54
- };
55
- }
@@ -1,6 +0,0 @@
1
- import { factory } from '../../factory';
2
- import type { IOperationExecute } from '../taskHandler';
3
- /**
4
- * タスク実行関数
5
- */
6
- export declare function call(data: factory.task.moneyTransfer.IData): IOperationExecute<void>;
@@ -1,49 +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.call = call;
27
- const factory_1 = require("../../factory");
28
- const action_1 = require("../../repo/action");
29
- const product_1 = require("../../repo/product");
30
- const transactionNumber_1 = require("../../repo/transactionNumber");
31
- const MoneyTransferService = __importStar(require("../moneyTransfer"));
32
- /**
33
- * タスク実行関数
34
- */
35
- function call(data) {
36
- return async ({ redisClient, connection }) => {
37
- if (redisClient === undefined) {
38
- throw new factory_1.factory.errors.Argument('settings', 'redisClient required');
39
- }
40
- const actionRepo = new action_1.ActionRepo(connection);
41
- const productRepo = new product_1.ProductRepo(connection);
42
- const transactionNumberRepo = new transactionNumber_1.TransactionNumberRepo({ connection });
43
- await MoneyTransferService.moneyTransfer(data)({
44
- action: actionRepo,
45
- product: productRepo,
46
- transactionNumber: transactionNumberRepo
47
- });
48
- };
49
- }
@@ -1,6 +0,0 @@
1
- import type { IOperationExecute } from '../taskHandler';
2
- import { factory } from '../../factory';
3
- /**
4
- * タスク実行関数
5
- */
6
- export declare function call(data: factory.task.IData<factory.taskName.ReturnPointAward>): IOperationExecute<void>;