@chevre/domain 21.2.0-alpha.28 → 21.2.0-alpha.29
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.
|
@@ -273,10 +273,29 @@ class MongoRepository {
|
|
|
273
273
|
*/
|
|
274
274
|
findById(params) {
|
|
275
275
|
return __awaiter(this, void 0, void 0, function* () {
|
|
276
|
+
let projection = {};
|
|
277
|
+
if (Array.isArray(params.inclusion) && params.inclusion.length > 0) {
|
|
278
|
+
params.inclusion.forEach((field) => {
|
|
279
|
+
projection[field] = 1;
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
else {
|
|
283
|
+
projection = {
|
|
284
|
+
__v: 0,
|
|
285
|
+
createdAt: 0,
|
|
286
|
+
updatedAt: 0
|
|
287
|
+
};
|
|
288
|
+
if (Array.isArray(params.exclusion) && params.exclusion.length > 0) {
|
|
289
|
+
params.exclusion.forEach((field) => {
|
|
290
|
+
projection[field] = 0;
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
}
|
|
276
294
|
const doc = yield this.transactionModel.findOne({
|
|
277
295
|
_id: { $eq: params.id },
|
|
278
296
|
typeOf: { $eq: params.typeOf }
|
|
279
297
|
})
|
|
298
|
+
.select(projection)
|
|
280
299
|
.exec();
|
|
281
300
|
if (doc === null) {
|
|
282
301
|
throw new factory.errors.NotFound(this.transactionModel.modelName);
|
|
@@ -52,10 +52,18 @@ exports.voidPayTransaction = voidPayTransaction;
|
|
|
52
52
|
function invalidatePaymentUrl(params) {
|
|
53
53
|
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
54
54
|
var _a, _b, _c, _d, _e;
|
|
55
|
+
if (params.purpose.typeOf !== factory.transactionType.PlaceOrder) {
|
|
56
|
+
throw new factory.errors.Argument('purpose.typeOf', `must be ${factory.transactionType.PlaceOrder}`);
|
|
57
|
+
}
|
|
55
58
|
const transaction = yield repos.transaction.findById({
|
|
56
59
|
typeOf: params.purpose.typeOf,
|
|
57
60
|
id: params.purpose.id
|
|
58
61
|
});
|
|
62
|
+
// 確定取引に対応(2023-05-03~)
|
|
63
|
+
if (transaction.status === factory.transactionStatusType.Confirmed) {
|
|
64
|
+
// no op
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
59
67
|
const paymentMethodIdByPaymentUrl = (_a = transaction.object.paymentMethods) === null || _a === void 0 ? void 0 : _a.paymentMethodId;
|
|
60
68
|
const paymentMethodType = (_b = transaction.object.paymentMethods) === null || _b === void 0 ? void 0 : _b.typeOf;
|
|
61
69
|
if (typeof paymentMethodIdByPaymentUrl === 'string' && paymentMethodIdByPaymentUrl.length > 0
|
|
@@ -70,12 +78,10 @@ function invalidatePaymentUrl(params) {
|
|
|
70
78
|
? transaction.seller.name
|
|
71
79
|
: String((_c = transaction.seller.name) === null || _c === void 0 ? void 0 : _c.ja),
|
|
72
80
|
id: transaction.seller.id
|
|
73
|
-
// project: transaction.seller.project
|
|
74
81
|
},
|
|
75
82
|
recipient: { typeOf: transaction.agent.typeOf, name: transaction.agent.name },
|
|
76
83
|
object: [{
|
|
77
84
|
typeOf: factory.service.paymentService.PaymentServiceType.CreditCard,
|
|
78
|
-
// tslint:disable-next-line:max-line-length
|
|
79
85
|
id: (_e = (_d = transaction.object.paymentMethods) === null || _d === void 0 ? void 0 : _d.issuedThrough) === null || _e === void 0 ? void 0 : _e.id,
|
|
80
86
|
paymentMethod: {
|
|
81
87
|
additionalProperty: [],
|
|
@@ -103,10 +109,11 @@ function processVoidPayTransaction(params) {
|
|
|
103
109
|
transaction = yield repos.transaction.findInProgressById({ typeOf: params.purpose.typeOf, id: params.purpose.id });
|
|
104
110
|
}
|
|
105
111
|
else {
|
|
106
|
-
transaction = yield repos.transaction.findById({
|
|
112
|
+
transaction = (yield repos.transaction.findById({
|
|
107
113
|
typeOf: params.purpose.typeOf,
|
|
108
|
-
id: params.purpose.id
|
|
109
|
-
|
|
114
|
+
id: params.purpose.id,
|
|
115
|
+
inclusion: ['id', 'typeOf', 'status']
|
|
116
|
+
}));
|
|
110
117
|
}
|
|
111
118
|
// 承認アクションを取得
|
|
112
119
|
let authorizeActions;
|
|
@@ -122,7 +129,7 @@ function processVoidPayTransaction(params) {
|
|
|
122
129
|
const authorizeActionsOnTransaction = yield repos.action.searchByPurpose({
|
|
123
130
|
typeOf: factory.actionType.AuthorizeAction,
|
|
124
131
|
purpose: {
|
|
125
|
-
typeOf:
|
|
132
|
+
typeOf: transaction.typeOf,
|
|
126
133
|
id: transaction.id
|
|
127
134
|
}
|
|
128
135
|
});
|
|
@@ -131,12 +138,20 @@ function processVoidPayTransaction(params) {
|
|
|
131
138
|
return ((_a = a.object) === null || _a === void 0 ? void 0 : _a.typeOf) === factory.action.authorize.paymentMethod.any.ResultType.Payment
|
|
132
139
|
&& ((_b = a.instrument) === null || _b === void 0 ? void 0 : _b.identifier) === factory.action.authorize.paymentMethod.any.ServiceIdentifier.Chevre;
|
|
133
140
|
});
|
|
141
|
+
switch (transaction.status) {
|
|
142
|
+
case factory.transactionStatusType.InProgress:
|
|
143
|
+
throw new factory.errors.NotImplemented(`${transaction.status} not implemented`);
|
|
144
|
+
// 確定取引に対応(2023-05-03~)
|
|
145
|
+
case factory.transactionStatusType.Confirmed:
|
|
146
|
+
// アクションステータスを検証する
|
|
147
|
+
authorizeActions = authorizeActions.filter((a) => a.actionStatus !== factory.actionStatusType.CompletedActionStatus);
|
|
148
|
+
break;
|
|
149
|
+
default:
|
|
150
|
+
// no op
|
|
151
|
+
}
|
|
134
152
|
}
|
|
135
153
|
const errors = [];
|
|
136
154
|
for (const action of authorizeActions) {
|
|
137
|
-
// 直列にゆっくり処理する場合↓
|
|
138
|
-
// tslint:disable-next-line:no-magic-numbers
|
|
139
|
-
// await new Promise((resolve) => setTimeout(() => { resolve(); }, 1000));
|
|
140
155
|
// 失敗するケースがあっても、残りが少なくとも処理されるようにエラーハンドリング
|
|
141
156
|
try {
|
|
142
157
|
// 取引が存在すれば中止
|
|
@@ -78,7 +78,21 @@ function createTasks(params) {
|
|
|
78
78
|
object: transaction
|
|
79
79
|
}
|
|
80
80
|
};
|
|
81
|
-
|
|
81
|
+
// 確定取引にも決済承認中止タスクを追加(2023-05-03~)
|
|
82
|
+
const voidPaymentTaskAttributes = {
|
|
83
|
+
project: transaction.project,
|
|
84
|
+
name: factory.taskName.VoidPayTransaction,
|
|
85
|
+
status: factory.taskStatus.Ready,
|
|
86
|
+
runsAt: taskRunsAt,
|
|
87
|
+
remainingNumberOfTries: 10,
|
|
88
|
+
numberOfTried: 0,
|
|
89
|
+
executionResults: [],
|
|
90
|
+
data: {
|
|
91
|
+
project: transaction.project,
|
|
92
|
+
purpose: { typeOf: transaction.typeOf, id: transaction.id }
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
taskAttributes.push(...triggerWebhookTaskAttributes, deleteTransactionTask, voidPaymentTaskAttributes);
|
|
82
96
|
switch (transaction.status) {
|
|
83
97
|
case factory.transactionStatusType.Confirmed:
|
|
84
98
|
const potentialActions = transaction.potentialActions;
|
|
@@ -107,7 +121,6 @@ function createTasks(params) {
|
|
|
107
121
|
};
|
|
108
122
|
taskAttributes.push(placeOrderTaskAttributes);
|
|
109
123
|
break;
|
|
110
|
-
// 期限切れor中止の場合は、タスクリストを作成する
|
|
111
124
|
case factory.transactionStatusType.Canceled:
|
|
112
125
|
case factory.transactionStatusType.Expired:
|
|
113
126
|
const voidReserveTaskAttributes = {
|
|
@@ -136,19 +149,6 @@ function createTasks(params) {
|
|
|
136
149
|
purpose: { typeOf: transaction.typeOf, id: transaction.id }
|
|
137
150
|
}
|
|
138
151
|
};
|
|
139
|
-
const voidPaymentTaskAttributes = {
|
|
140
|
-
project: transaction.project,
|
|
141
|
-
name: factory.taskName.VoidPayTransaction,
|
|
142
|
-
status: factory.taskStatus.Ready,
|
|
143
|
-
runsAt: taskRunsAt,
|
|
144
|
-
remainingNumberOfTries: 10,
|
|
145
|
-
numberOfTried: 0,
|
|
146
|
-
executionResults: [],
|
|
147
|
-
data: {
|
|
148
|
-
project: transaction.project,
|
|
149
|
-
purpose: { typeOf: transaction.typeOf, id: transaction.id }
|
|
150
|
-
}
|
|
151
|
-
};
|
|
152
152
|
const voidMoneyTransferTaskAttributes = {
|
|
153
153
|
project: transaction.project,
|
|
154
154
|
name: factory.taskName.VoidMoneyTransferTransaction,
|
|
@@ -162,7 +162,7 @@ function createTasks(params) {
|
|
|
162
162
|
purpose: { typeOf: transaction.typeOf, id: transaction.id }
|
|
163
163
|
}
|
|
164
164
|
};
|
|
165
|
-
taskAttributes.push(voidReserveTaskAttributes, voidRegisterServiceTaskAttributes,
|
|
165
|
+
taskAttributes.push(voidReserveTaskAttributes, voidRegisterServiceTaskAttributes, voidMoneyTransferTaskAttributes);
|
|
166
166
|
break;
|
|
167
167
|
default:
|
|
168
168
|
throw new factory.errors.NotImplemented(`Transaction status "${transaction.status}" not implemented.`);
|
package/package.json
CHANGED