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