@chevre/domain 21.8.0-alpha.1 → 21.8.0-alpha.2
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/service/order/confirmPayTransaction.d.ts +26 -0
- package/lib/chevre/service/order/confirmPayTransaction.js +109 -0
- package/lib/chevre/service/order/placeOrder.d.ts +3 -1
- package/lib/chevre/service/order/placeOrder.js +13 -0
- package/lib/chevre/service/order.d.ts +2 -2
- package/lib/chevre/service/order.js +4 -3
- package/lib/chevre/service/task/confirmPayTransaction.js +13 -101
- package/lib/chevre/service/task/returnOrder.js +2 -2
- package/package.json +1 -1
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import * as factory from '../../factory';
|
|
2
|
+
import { MongoRepository as AccountingReportRepo } from '../../repo/accountingReport';
|
|
3
|
+
import { MongoRepository as ActionRepo } from '../../repo/action';
|
|
4
|
+
import { RedisRepository as RegisterServiceInProgressRepo } from '../../repo/action/registerServiceInProgress';
|
|
5
|
+
import { MongoRepository as AssetTransactionRepo } from '../../repo/assetTransaction';
|
|
6
|
+
import { MongoRepository as EventRepo } from '../../repo/event';
|
|
7
|
+
import { MongoRepository as OrderRepo } from '../../repo/order';
|
|
8
|
+
import { MongoRepository as ProductRepo } from '../../repo/product';
|
|
9
|
+
import { MongoRepository as ProjectRepo } from '../../repo/project';
|
|
10
|
+
import { MongoRepository as SellerRepo } from '../../repo/seller';
|
|
11
|
+
import { MongoRepository as TaskRepo } from '../../repo/task';
|
|
12
|
+
import { MongoRepository as TransactionRepo } from '../../repo/transaction';
|
|
13
|
+
declare function confirmPayTransaction(data: factory.task.IData<factory.taskName.ConfirmPayTransaction>): (repos: {
|
|
14
|
+
action: ActionRepo;
|
|
15
|
+
assetTransaction: AssetTransactionRepo;
|
|
16
|
+
order: OrderRepo;
|
|
17
|
+
accountingReport: AccountingReportRepo;
|
|
18
|
+
event: EventRepo;
|
|
19
|
+
product: ProductRepo;
|
|
20
|
+
project: ProjectRepo;
|
|
21
|
+
seller: SellerRepo;
|
|
22
|
+
task: TaskRepo;
|
|
23
|
+
transaction: TransactionRepo;
|
|
24
|
+
registerServiceInProgress: RegisterServiceInProgressRepo;
|
|
25
|
+
}) => Promise<void>;
|
|
26
|
+
export { confirmPayTransaction };
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.confirmPayTransaction = void 0;
|
|
13
|
+
const factory = require("../../factory");
|
|
14
|
+
const PayTransactionService = require("../assetTransaction/pay");
|
|
15
|
+
const payOrder_1 = require("../order/payOrder");
|
|
16
|
+
function confirmPayTransaction(data) {
|
|
17
|
+
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
18
|
+
// アクション開始
|
|
19
|
+
const action = yield repos.action.start(data);
|
|
20
|
+
try {
|
|
21
|
+
for (const confirmingTransaction of data.object) {
|
|
22
|
+
yield PayTransactionService.confirm({
|
|
23
|
+
transactionNumber: confirmingTransaction.transactionNumber,
|
|
24
|
+
potentialActions: {
|
|
25
|
+
pay: {
|
|
26
|
+
purpose: {
|
|
27
|
+
typeOf: data.purpose.typeOf,
|
|
28
|
+
confirmationNumber: data.purpose.confirmationNumber,
|
|
29
|
+
orderNumber: data.purpose.orderNumber
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
})({
|
|
34
|
+
action: repos.action,
|
|
35
|
+
accountingReport: repos.accountingReport,
|
|
36
|
+
assetTransaction: repos.assetTransaction,
|
|
37
|
+
event: repos.event,
|
|
38
|
+
order: repos.order,
|
|
39
|
+
product: repos.product,
|
|
40
|
+
project: repos.project,
|
|
41
|
+
seller: repos.seller,
|
|
42
|
+
task: repos.task
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
// actionにエラー結果を追加
|
|
48
|
+
try {
|
|
49
|
+
const actionError = Object.assign(Object.assign({}, error), { message: error.message, name: error.name });
|
|
50
|
+
yield repos.action.giveUp({ typeOf: action.typeOf, id: action.id, error: actionError });
|
|
51
|
+
}
|
|
52
|
+
catch (__) {
|
|
53
|
+
// 失敗したら仕方ない
|
|
54
|
+
}
|
|
55
|
+
throw error;
|
|
56
|
+
}
|
|
57
|
+
// アクション完了
|
|
58
|
+
const actionResult = {};
|
|
59
|
+
yield repos.action.complete({ typeOf: action.typeOf, id: action.id, result: actionResult });
|
|
60
|
+
// processOrder連携(2023-08-23~)
|
|
61
|
+
yield onConfirmed(data)({
|
|
62
|
+
assetTransaction: repos.assetTransaction,
|
|
63
|
+
order: repos.order,
|
|
64
|
+
registerActionInProgress: repos.registerServiceInProgress,
|
|
65
|
+
task: repos.task,
|
|
66
|
+
transaction: repos.transaction
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
exports.confirmPayTransaction = confirmPayTransaction;
|
|
71
|
+
function onConfirmed(params) {
|
|
72
|
+
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
73
|
+
if (params.processOrder === true) {
|
|
74
|
+
// 注文のpaymentMethodIdを取得
|
|
75
|
+
const order = yield repos.order.findByOrderNumber({
|
|
76
|
+
orderNumber: params.purpose.orderNumber,
|
|
77
|
+
project: { id: params.project.id },
|
|
78
|
+
inclusion: ['paymentMethods'],
|
|
79
|
+
exclusion: []
|
|
80
|
+
});
|
|
81
|
+
// PayTransactionのステータス検証
|
|
82
|
+
let allPayTransactionConfirmed = false;
|
|
83
|
+
const paymentMethodIds = order.paymentMethods.filter((invoice) => typeof invoice.paymentMethodId === 'string' && invoice.paymentMethodId.length > 0)
|
|
84
|
+
.map((invoice) => invoice.paymentMethodId);
|
|
85
|
+
if (paymentMethodIds.length > 0) {
|
|
86
|
+
const referencedPayTransactions = yield repos.assetTransaction.search({
|
|
87
|
+
project: { id: { $eq: params.project.id } },
|
|
88
|
+
typeOf: factory.assetTransactionType.Pay,
|
|
89
|
+
transactionNumber: { $in: paymentMethodIds }
|
|
90
|
+
}, ['status']);
|
|
91
|
+
allPayTransactionConfirmed =
|
|
92
|
+
referencedPayTransactions.every((payTransation) => payTransation.status === factory.transactionStatusType.Confirmed);
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
allPayTransactionConfirmed = true;
|
|
96
|
+
}
|
|
97
|
+
if (allPayTransactionConfirmed) {
|
|
98
|
+
yield (0, payOrder_1.payOrder)({
|
|
99
|
+
project: { id: params.project.id },
|
|
100
|
+
object: {
|
|
101
|
+
confirmationNumber: params.purpose.confirmationNumber,
|
|
102
|
+
orderNumber: params.purpose.orderNumber
|
|
103
|
+
},
|
|
104
|
+
useOnOrderStatusChanged: params.useOnOrderStatusChanged === true
|
|
105
|
+
})(repos);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
}
|
|
@@ -42,5 +42,7 @@ declare function placeOrder(params: {
|
|
|
42
42
|
registerActionInProgress: RegisterServiceInProgressRepo;
|
|
43
43
|
task: TaskRepo;
|
|
44
44
|
transaction: TransactionRepo;
|
|
45
|
-
}) => Promise<
|
|
45
|
+
}) => Promise<{
|
|
46
|
+
order: factory.order.IOrder;
|
|
47
|
+
}>;
|
|
46
48
|
export { placeOrder, placeOrderWithoutTransaction };
|
|
@@ -232,7 +232,16 @@ function placeOrder(params) {
|
|
|
232
232
|
});
|
|
233
233
|
}
|
|
234
234
|
else if (order.orderStatus === factory.orderStatus.OrderProcessing) {
|
|
235
|
+
// OrderPaymentDueに対する処理をまず強制的に実行する(2023-08-24~)
|
|
236
|
+
yield (0, onOrderStatusChanged_1.onOrderStatusChanged)({
|
|
237
|
+
order: Object.assign(Object.assign({}, order), { orderStatus: factory.orderStatus.OrderPaymentDue }),
|
|
238
|
+
placeOrderTransaction
|
|
239
|
+
})({
|
|
240
|
+
registerActionInProgress: repos.registerActionInProgress,
|
|
241
|
+
task: repos.task
|
|
242
|
+
});
|
|
235
243
|
// OrderPaymentDueをスキップしてOrderProcessingから開始する場合(2023-08-23~)
|
|
244
|
+
// paymentMethods.length: 0の場合に、confirmPayTransactionは実行されないので、ここで強制的にpayOrderを実行する必要がある
|
|
236
245
|
yield (0, payOrder_1.payOrder)({
|
|
237
246
|
project: { id: order.project.id },
|
|
238
247
|
object: {
|
|
@@ -242,12 +251,16 @@ function placeOrder(params) {
|
|
|
242
251
|
useOnOrderStatusChanged: params.useOnOrderStatusChanged
|
|
243
252
|
})(repos);
|
|
244
253
|
}
|
|
254
|
+
else {
|
|
255
|
+
throw new factory.errors.NotImplemented(`placing an order on the status '${order.orderStatus}' not implemented`);
|
|
256
|
+
}
|
|
245
257
|
}
|
|
246
258
|
// onOrderStatusChangedへ移行(2023-08-17~)
|
|
247
259
|
// await onPlaceOrder({
|
|
248
260
|
// object: order,
|
|
249
261
|
// potentialActions: params.potentialActions
|
|
250
262
|
// })(repos);
|
|
263
|
+
return { order };
|
|
251
264
|
});
|
|
252
265
|
}
|
|
253
266
|
exports.placeOrder = placeOrder;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* 注文サービス
|
|
3
3
|
*/
|
|
4
|
+
import { confirmPayTransaction } from './order/confirmPayTransaction';
|
|
4
5
|
import { deleteOrder } from './order/deleteOrder';
|
|
5
6
|
import { onOrderStatusChanged } from './order/onOrderStatusChanged';
|
|
6
7
|
import { onOrderUpdated } from './order/onOrderUpdated';
|
|
7
8
|
import { placeOrder, placeOrderWithoutTransaction } from './order/placeOrder';
|
|
8
|
-
import { returnOrder } from './order/returnOrder';
|
|
9
9
|
import { sendOrder } from './order/sendOrder';
|
|
10
|
-
export { deleteOrder, onOrderStatusChanged, onOrderUpdated, placeOrder, placeOrderWithoutTransaction,
|
|
10
|
+
export { confirmPayTransaction, deleteOrder, onOrderStatusChanged, onOrderUpdated, placeOrder, placeOrderWithoutTransaction, sendOrder };
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.sendOrder = exports.
|
|
3
|
+
exports.sendOrder = exports.placeOrderWithoutTransaction = exports.placeOrder = exports.onOrderUpdated = exports.onOrderStatusChanged = exports.deleteOrder = exports.confirmPayTransaction = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* 注文サービス
|
|
6
6
|
*/
|
|
7
|
+
const confirmPayTransaction_1 = require("./order/confirmPayTransaction");
|
|
8
|
+
Object.defineProperty(exports, "confirmPayTransaction", { enumerable: true, get: function () { return confirmPayTransaction_1.confirmPayTransaction; } });
|
|
7
9
|
const deleteOrder_1 = require("./order/deleteOrder");
|
|
8
10
|
Object.defineProperty(exports, "deleteOrder", { enumerable: true, get: function () { return deleteOrder_1.deleteOrder; } });
|
|
9
11
|
const onOrderStatusChanged_1 = require("./order/onOrderStatusChanged");
|
|
@@ -13,7 +15,6 @@ Object.defineProperty(exports, "onOrderUpdated", { enumerable: true, get: functi
|
|
|
13
15
|
const placeOrder_1 = require("./order/placeOrder");
|
|
14
16
|
Object.defineProperty(exports, "placeOrder", { enumerable: true, get: function () { return placeOrder_1.placeOrder; } });
|
|
15
17
|
Object.defineProperty(exports, "placeOrderWithoutTransaction", { enumerable: true, get: function () { return placeOrder_1.placeOrderWithoutTransaction; } });
|
|
16
|
-
|
|
17
|
-
Object.defineProperty(exports, "returnOrder", { enumerable: true, get: function () { return returnOrder_1.returnOrder; } });
|
|
18
|
+
// import { returnOrder } from './order/returnOrder';
|
|
18
19
|
const sendOrder_1 = require("./order/sendOrder");
|
|
19
20
|
Object.defineProperty(exports, "sendOrder", { enumerable: true, get: function () { return sendOrder_1.sendOrder; } });
|
|
@@ -22,8 +22,7 @@ const project_1 = require("../../repo/project");
|
|
|
22
22
|
const seller_1 = require("../../repo/seller");
|
|
23
23
|
const task_1 = require("../../repo/task");
|
|
24
24
|
const transaction_1 = require("../../repo/transaction");
|
|
25
|
-
const
|
|
26
|
-
const payOrder_1 = require("../order/payOrder");
|
|
25
|
+
const confirmPayTransaction_1 = require("../order/confirmPayTransaction");
|
|
27
26
|
/**
|
|
28
27
|
* タスク実行関数
|
|
29
28
|
*/
|
|
@@ -32,106 +31,19 @@ function call(data) {
|
|
|
32
31
|
if (settings.redisClient === undefined) {
|
|
33
32
|
throw new factory.errors.Argument('settings', 'redisClient required');
|
|
34
33
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
const action = yield actionRepo.start(data);
|
|
48
|
-
try {
|
|
49
|
-
for (const confirmingTransaction of data.object) {
|
|
50
|
-
yield PayTransactionService.confirm({
|
|
51
|
-
transactionNumber: confirmingTransaction.transactionNumber,
|
|
52
|
-
potentialActions: {
|
|
53
|
-
pay: {
|
|
54
|
-
purpose: {
|
|
55
|
-
typeOf: data.purpose.typeOf,
|
|
56
|
-
confirmationNumber: data.purpose.confirmationNumber,
|
|
57
|
-
orderNumber: data.purpose.orderNumber
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
})({
|
|
62
|
-
action: actionRepo,
|
|
63
|
-
accountingReport: accountingReportRepo,
|
|
64
|
-
assetTransaction: assetTransactionRepo,
|
|
65
|
-
event: eventRepo,
|
|
66
|
-
order: orderRepo,
|
|
67
|
-
product: productRepo,
|
|
68
|
-
project: projectRepo,
|
|
69
|
-
seller: sellerRepo,
|
|
70
|
-
task: taskRepo
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
catch (error) {
|
|
75
|
-
// actionにエラー結果を追加
|
|
76
|
-
try {
|
|
77
|
-
const actionError = Object.assign(Object.assign({}, error), { message: error.message, name: error.name });
|
|
78
|
-
yield actionRepo.giveUp({ typeOf: action.typeOf, id: action.id, error: actionError });
|
|
79
|
-
}
|
|
80
|
-
catch (__) {
|
|
81
|
-
// 失敗したら仕方ない
|
|
82
|
-
}
|
|
83
|
-
throw error;
|
|
84
|
-
}
|
|
85
|
-
// アクション完了
|
|
86
|
-
const actionResult = {};
|
|
87
|
-
yield actionRepo.complete({ typeOf: action.typeOf, id: action.id, result: actionResult });
|
|
88
|
-
// processOrder連携(2023-08-23~)
|
|
89
|
-
yield onConfirmed(data)({
|
|
90
|
-
assetTransaction: assetTransactionRepo,
|
|
91
|
-
order: orderRepo,
|
|
92
|
-
registerActionInProgress: registerServiceInProgressRepo,
|
|
93
|
-
task: taskRepo,
|
|
94
|
-
transaction: transactionRepo
|
|
34
|
+
yield (0, confirmPayTransaction_1.confirmPayTransaction)(data)({
|
|
35
|
+
action: new action_1.MongoRepository(settings.connection),
|
|
36
|
+
assetTransaction: new assetTransaction_1.MongoRepository(settings.connection),
|
|
37
|
+
order: new order_1.MongoRepository(settings.connection),
|
|
38
|
+
accountingReport: new accountingReport_1.MongoRepository(settings.connection),
|
|
39
|
+
event: new event_1.MongoRepository(settings.connection),
|
|
40
|
+
product: new product_1.MongoRepository(settings.connection),
|
|
41
|
+
project: new project_1.MongoRepository(settings.connection),
|
|
42
|
+
seller: new seller_1.MongoRepository(settings.connection),
|
|
43
|
+
task: new task_1.MongoRepository(settings.connection),
|
|
44
|
+
transaction: new transaction_1.MongoRepository(settings.connection),
|
|
45
|
+
registerServiceInProgress: new registerServiceInProgress_1.RedisRepository(settings.redisClient)
|
|
95
46
|
});
|
|
96
47
|
});
|
|
97
48
|
}
|
|
98
49
|
exports.call = call;
|
|
99
|
-
function onConfirmed(params) {
|
|
100
|
-
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
101
|
-
if (params.processOrder === true) {
|
|
102
|
-
// 注文のpaymentMethodIdを取得
|
|
103
|
-
const order = yield repos.order.findByOrderNumber({
|
|
104
|
-
orderNumber: params.purpose.orderNumber,
|
|
105
|
-
project: { id: params.project.id },
|
|
106
|
-
inclusion: ['paymentMethods'],
|
|
107
|
-
exclusion: []
|
|
108
|
-
});
|
|
109
|
-
// PayTransactionのステータス検証
|
|
110
|
-
let allPayTransactionConfirmed = false;
|
|
111
|
-
const paymentMethodIds = order.paymentMethods.filter((invoice) => typeof invoice.paymentMethodId === 'string' && invoice.paymentMethodId.length > 0)
|
|
112
|
-
.map((invoice) => invoice.paymentMethodId);
|
|
113
|
-
if (paymentMethodIds.length > 0) {
|
|
114
|
-
const referencedPayTransactions = yield repos.assetTransaction.search({
|
|
115
|
-
project: { id: { $eq: params.project.id } },
|
|
116
|
-
typeOf: factory.assetTransactionType.Pay,
|
|
117
|
-
transactionNumber: { $in: paymentMethodIds }
|
|
118
|
-
}, ['status']);
|
|
119
|
-
allPayTransactionConfirmed =
|
|
120
|
-
referencedPayTransactions.every((payTransation) => payTransation.status === factory.transactionStatusType.Confirmed);
|
|
121
|
-
}
|
|
122
|
-
else {
|
|
123
|
-
allPayTransactionConfirmed = true;
|
|
124
|
-
}
|
|
125
|
-
if (allPayTransactionConfirmed) {
|
|
126
|
-
yield (0, payOrder_1.payOrder)({
|
|
127
|
-
project: { id: params.project.id },
|
|
128
|
-
object: {
|
|
129
|
-
confirmationNumber: params.purpose.confirmationNumber,
|
|
130
|
-
orderNumber: params.purpose.orderNumber
|
|
131
|
-
},
|
|
132
|
-
useOnOrderStatusChanged: params.useOnOrderStatusChanged === true
|
|
133
|
-
})(repos);
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
});
|
|
137
|
-
}
|
|
@@ -17,7 +17,7 @@ const order_1 = require("../../repo/order");
|
|
|
17
17
|
const ownershipInfo_1 = require("../../repo/ownershipInfo");
|
|
18
18
|
const task_1 = require("../../repo/task");
|
|
19
19
|
const transaction_1 = require("../../repo/transaction");
|
|
20
|
-
const
|
|
20
|
+
const returnOrder_1 = require("../order/returnOrder");
|
|
21
21
|
/**
|
|
22
22
|
* タスク実行関数
|
|
23
23
|
*/
|
|
@@ -32,7 +32,7 @@ function call(data) {
|
|
|
32
32
|
const taskRepo = new task_1.MongoRepository(settings.connection);
|
|
33
33
|
const transactionRepo = new transaction_1.MongoRepository(settings.connection);
|
|
34
34
|
const registerServiceInProgressRepo = new registerServiceInProgress_1.RedisRepository(settings.redisClient);
|
|
35
|
-
yield
|
|
35
|
+
yield (0, returnOrder_1.returnOrder)(Object.assign(Object.assign({}, data), { useOnOrderStatusChanged: true }))({
|
|
36
36
|
action: actionRepo,
|
|
37
37
|
order: orderRepo,
|
|
38
38
|
ownershipInfo: ownershipInfoRepo,
|
package/package.json
CHANGED