@chevre/domain 24.0.0-alpha.2 → 24.0.0-alpha.21
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/repo/action/acceptCOAOffer.d.ts +23 -0
- package/lib/chevre/repo/action/acceptCOAOffer.js +64 -0
- package/lib/chevre/repo/action/acceptPay.d.ts +8 -0
- package/lib/chevre/repo/action/acceptPay.js +13 -0
- package/lib/chevre/repo/action/actionProcess.d.ts +115 -0
- package/lib/chevre/repo/action/actionProcess.js +293 -0
- package/lib/chevre/repo/action/authorizeOffer.d.ts +21 -0
- package/lib/chevre/repo/action/authorizeOffer.js +85 -0
- package/lib/chevre/repo/action/checkMovieTicket.d.ts +111 -0
- package/lib/chevre/repo/action/checkMovieTicket.js +200 -0
- package/lib/chevre/repo/action/checkThing.d.ts +8 -0
- package/lib/chevre/repo/action/checkThing.js +13 -0
- package/lib/chevre/repo/action.d.ts +9 -249
- package/lib/chevre/repo/action.js +308 -708
- package/lib/chevre/repo/aggregateAction.d.ts +102 -0
- package/lib/chevre/repo/aggregateAction.js +379 -0
- package/lib/chevre/repo/mongoose/schemas/transaction.js +31 -0
- package/lib/chevre/repo/orderInTransaction.d.ts +8 -0
- package/lib/chevre/repo/orderInTransaction.js +16 -2
- package/lib/chevre/repo/orderNumber.d.ts +3 -2
- package/lib/chevre/repo/orderNumber.js +23 -28
- package/lib/chevre/repo/transaction/moneyTransfer.d.ts +61 -0
- package/lib/chevre/repo/transaction/moneyTransfer.js +379 -0
- package/lib/chevre/repo/transaction/placeOrder.d.ts +140 -0
- package/lib/chevre/repo/transaction/placeOrder.js +528 -0
- package/lib/chevre/repo/transaction/returnOrder.d.ts +45 -0
- package/lib/chevre/repo/transaction/returnOrder.js +341 -0
- package/lib/chevre/repo/transaction.d.ts +1 -125
- package/lib/chevre/repo/transaction.js +726 -632
- package/lib/chevre/repository.d.ts +49 -0
- package/lib/chevre/repository.js +107 -2
- package/lib/chevre/service/aggregation/system.d.ts +10 -10
- package/lib/chevre/service/aggregation/system.js +9 -9
- package/lib/chevre/service/assetTransaction/pay/check.d.ts +5 -4
- package/lib/chevre/service/assetTransaction/pay/publishPaymentUrl.d.ts +5 -2
- package/lib/chevre/service/assetTransaction/pay/publishPaymentUrl.js +3 -3
- package/lib/chevre/service/assetTransaction/pay/start/factory.d.ts +51 -3
- package/lib/chevre/service/assetTransaction/pay/start/factory.js +58 -21
- package/lib/chevre/service/assetTransaction/pay/start/preStart/fixPaymentService.d.ts +10 -0
- package/lib/chevre/service/assetTransaction/pay/start/preStart/fixPaymentService.js +88 -0
- package/lib/chevre/service/assetTransaction/pay/start/processAuthorize.d.ts +55 -0
- package/lib/chevre/service/assetTransaction/pay/start/processAuthorize.js +56 -0
- package/lib/chevre/service/assetTransaction/pay/start/processAuthorizeMovieTicket.d.ts +3 -1
- package/lib/chevre/service/assetTransaction/pay/start/processAuthorizeMovieTicket.js +1 -11
- package/lib/chevre/service/assetTransaction/pay/start.d.ts +2 -0
- package/lib/chevre/service/assetTransaction/pay/start.js +8 -132
- package/lib/chevre/service/notification/triggerWebhook.d.ts +7 -6
- package/lib/chevre/service/offer/event/authorize.d.ts +2 -2
- package/lib/chevre/service/offer/event/authorize.js +3 -3
- package/lib/chevre/service/offer/event/issueEventOfferTicket.d.ts +2 -2
- package/lib/chevre/service/offer/event/issueEventOfferTicket.js +1 -1
- package/lib/chevre/service/offer/event/voidTransaction/processVoidTransaction4chevre.d.ts +0 -2
- package/lib/chevre/service/offer/event/voidTransaction/processVoidTransaction4chevre.js +1 -0
- package/lib/chevre/service/offer/event/voidTransaction.d.ts +2 -2
- package/lib/chevre/service/offer/event/voidTransaction.js +2 -2
- package/lib/chevre/service/offer/event/voidTransactionByActionId.d.ts +3 -3
- package/lib/chevre/service/offer/event/voidTransactionByActionId.js +2 -2
- package/lib/chevre/service/offer/eventServiceByCOA/acceptOffer.d.ts +16 -5
- package/lib/chevre/service/offer/eventServiceByCOA/acceptOffer.js +7 -7
- package/lib/chevre/service/offer/eventServiceByCOA/authorize.d.ts +6 -4
- package/lib/chevre/service/offer/eventServiceByCOA/authorize.js +3 -10
- package/lib/chevre/service/offer/eventServiceByCOA/authorizeByAcceptAction.js +21 -13
- package/lib/chevre/service/offer/eventServiceByCOA/changeOffers.js +19 -10
- package/lib/chevre/service/offer/eventServiceByCOA/findAcceptAction.d.ts +2 -2
- package/lib/chevre/service/offer/moneyTransfer/authorize.d.ts +2 -2
- package/lib/chevre/service/offer/moneyTransfer/authorize.js +6 -3
- package/lib/chevre/service/offer/moneyTransfer/voidTransaction.d.ts +2 -2
- package/lib/chevre/service/offer/moneyTransfer/voidTransaction.js +4 -1
- package/lib/chevre/service/offer/product.d.ts +3 -3
- package/lib/chevre/service/offer/product.js +4 -4
- package/lib/chevre/service/order/confirmPayTransaction.d.ts +0 -2
- package/lib/chevre/service/order/confirmPayTransaction.js +1 -0
- package/lib/chevre/service/order/findPlaceOrderTransaction.d.ts +2 -2
- package/lib/chevre/service/order/findPlaceOrderTransaction.js +1 -1
- package/lib/chevre/service/order/onAssetTransactionStatusChanged/isDeliverable.d.ts +16 -0
- package/lib/chevre/service/order/onAssetTransactionStatusChanged/isDeliverable.js +97 -0
- package/lib/chevre/service/order/onAssetTransactionStatusChanged/onPayTransactionCanceled.d.ts +21 -0
- package/lib/chevre/service/order/onAssetTransactionStatusChanged/onPayTransactionCanceled.js +86 -0
- package/lib/chevre/service/order/onAssetTransactionStatusChanged/onPayTransactionConfirmed.d.ts +22 -0
- package/lib/chevre/service/order/onAssetTransactionStatusChanged/onPayTransactionConfirmed.js +112 -0
- package/lib/chevre/service/order/onAssetTransactionStatusChanged/onReserveTransactionConfirmed.d.ts +22 -0
- package/lib/chevre/service/order/onAssetTransactionStatusChanged/onReserveTransactionConfirmed.js +74 -0
- package/lib/chevre/service/order/onAssetTransactionStatusChanged/paymentDue2Processing.d.ts +25 -0
- package/lib/chevre/service/order/onAssetTransactionStatusChanged/paymentDue2Processing.js +111 -0
- package/lib/chevre/service/order/onAssetTransactionStatusChanged/processing2inTransit.d.ts +16 -0
- package/lib/chevre/service/order/onAssetTransactionStatusChanged/processing2inTransit.js +74 -0
- package/lib/chevre/service/order/onAssetTransactionStatusChanged.d.ts +8 -30
- package/lib/chevre/service/order/onAssetTransactionStatusChanged.js +37 -348
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderDelivered.d.ts +6 -7
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderDeliveredPartially.d.ts +6 -5
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderInTransit.d.ts +7 -6
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderInTransit.js +1 -1
- package/lib/chevre/service/order/payOrder.d.ts +2 -2
- package/lib/chevre/service/order/placeOrder/createPlacingOrderFromExistingTransaction.d.ts +2 -2
- package/lib/chevre/service/order/placeOrder/createPlacingOrderFromExistingTransaction.js +1 -1
- package/lib/chevre/service/order/placeOrder.d.ts +13 -12
- package/lib/chevre/service/order/returnOrder.d.ts +2 -2
- package/lib/chevre/service/order/returnOrder.js +1 -1
- package/lib/chevre/service/order/sendOrder.d.ts +6 -6
- package/lib/chevre/service/order/sendOrder.js +10 -8
- package/lib/chevre/service/order.d.ts +3 -6
- package/lib/chevre/service/order.js +3 -9
- package/lib/chevre/service/payment/any/{fixOrderAsNeeded.d.ts → authorize/fixOrderAsNeeded.d.ts} +6 -6
- package/lib/chevre/service/payment/any/{fixOrderAsNeeded.js → authorize/fixOrderAsNeeded.js} +5 -8
- package/lib/chevre/service/payment/any/authorize/fixTransactionNumber.d.ts +3 -3
- package/lib/chevre/service/payment/any/authorize/handlePrePublishedPaymentMethodIdOnAuthorizing.d.ts +3 -3
- package/lib/chevre/service/payment/any/authorize/handlePrePublishedPaymentMethodIdOnAuthorizing.js +1 -1
- package/lib/chevre/service/payment/any/authorize.d.ts +92 -0
- package/lib/chevre/service/payment/any/authorize.js +225 -0
- package/lib/chevre/service/payment/any/findAcceptAction.d.ts +43 -0
- package/lib/chevre/service/payment/any/findAcceptAction.js +94 -0
- package/lib/chevre/service/payment/any/findAuthorizeAction.d.ts +41 -0
- package/lib/chevre/service/payment/any/findAuthorizeAction.js +83 -0
- package/lib/chevre/service/payment/any/findCheckAction.d.ts +45 -0
- package/lib/chevre/service/payment/any/findCheckAction.js +89 -0
- package/lib/chevre/service/payment/any/invalidatePaymentUrl.d.ts +28 -0
- package/lib/chevre/service/payment/any/invalidatePaymentUrl.js +185 -0
- package/lib/chevre/service/payment/any/onPayActionCompleted.d.ts +7 -3
- package/lib/chevre/service/payment/any/onPayActionCompleted.js +3 -0
- package/lib/chevre/service/payment/any/processVoidPayTransaction.d.ts +29 -0
- package/lib/chevre/service/payment/any/processVoidPayTransaction.js +125 -0
- package/lib/chevre/service/payment/any/publishPaymentUrl/fixTransactionNumberOnPublishPaymentUrl.d.ts +2 -2
- package/lib/chevre/service/payment/any/publishPaymentUrl.d.ts +66 -0
- package/lib/chevre/service/payment/any/publishPaymentUrl.js +133 -0
- package/lib/chevre/service/payment/any/voidPayTransaction.d.ts +31 -0
- package/lib/chevre/service/payment/any/voidPayTransaction.js +38 -0
- package/lib/chevre/service/payment/any.d.ts +8 -305
- package/lib/chevre/service/payment/any.js +17 -857
- package/lib/chevre/service/payment/movieTicket/authorize.d.ts +2 -0
- package/lib/chevre/service/payment/movieTicket/checkMovieTicket.d.ts +3 -3
- package/lib/chevre/service/payment/movieTicket/checkMovieTicket.js +3 -3
- package/lib/chevre/service/payment/movieTicket/validation.d.ts +11 -10
- package/lib/chevre/service/payment/movieTicket/validation.js +19 -15
- package/lib/chevre/service/report/telemetry.d.ts +4 -0
- package/lib/chevre/service/report/telemetry.js +7 -12
- package/lib/chevre/service/task/acceptCOAOffer.js +11 -6
- package/lib/chevre/service/task/authorizePayment.js +6 -2
- package/lib/chevre/service/task/checkMovieTicket.js +3 -3
- package/lib/chevre/service/task/checkResource.js +2 -2
- package/lib/chevre/service/task/confirmPayTransaction.js +2 -2
- package/lib/chevre/service/task/deleteTransaction.js +7 -1
- package/lib/chevre/service/task/onAssetTransactionStatusChanged.js +4 -2
- package/lib/chevre/service/task/onOrderPaymentCompleted.js +2 -2
- package/lib/chevre/service/task/payment/payByTask.d.ts +14 -12
- package/lib/chevre/service/task/placeOrder.js +6 -4
- package/lib/chevre/service/task/publishPaymentUrl.js +8 -4
- package/lib/chevre/service/task/returnOrder.js +4 -4
- package/lib/chevre/service/task/returnPayTransaction.js +4 -3
- package/lib/chevre/service/task/sendOrder.js +4 -4
- package/lib/chevre/service/task/voidMoneyTransferTransaction.js +6 -3
- package/lib/chevre/service/task/voidPayTransaction.js +4 -2
- package/lib/chevre/service/task/voidRegisterServiceTransaction.js +3 -3
- package/lib/chevre/service/task/voidReserveTransaction.js +4 -3
- package/lib/chevre/service/transaction/deleteTransaction.d.ts +6 -0
- package/lib/chevre/service/transaction/deleteTransaction.js +56 -14
- package/lib/chevre/service/transaction/moneyTransfer.d.ts +5 -5
- package/lib/chevre/service/transaction/moneyTransfer.js +5 -5
- package/lib/chevre/service/transaction/placeOrder/confirm.d.ts +2 -2
- package/lib/chevre/service/transaction/placeOrder/confirm.js +10 -9
- package/lib/chevre/service/transaction/placeOrder/exportTasksById.d.ts +7 -6
- package/lib/chevre/service/transaction/placeOrder/exportTasksById.js +1 -1
- package/lib/chevre/service/transaction/placeOrder/{publishOrderNumberIfNotExist.d.ts → issueOrderNumberIfNotExist.d.ts} +4 -4
- package/lib/chevre/service/transaction/placeOrder/{publishOrderNumberIfNotExist.js → issueOrderNumberIfNotExist.js} +21 -13
- package/lib/chevre/service/transaction/placeOrder/publishConfirmationNumberIfNotExist.d.ts +2 -2
- package/lib/chevre/service/transaction/placeOrder/publishConfirmationNumberIfNotExist.js +3 -3
- package/lib/chevre/service/transaction/placeOrder/start.d.ts +3 -3
- package/lib/chevre/service/transaction/placeOrder/start.js +2 -2
- package/lib/chevre/service/transaction/placeOrder/updateAgent.d.ts +23 -0
- package/lib/chevre/service/transaction/placeOrder/updateAgent.js +126 -0
- package/lib/chevre/service/transaction/placeOrder.d.ts +2 -1
- package/lib/chevre/service/transaction/placeOrder.js +3 -1
- package/lib/chevre/service/transaction/returnOrder/preStart.d.ts +1 -1
- package/lib/chevre/service/transaction/returnOrder.d.ts +16 -14
- package/lib/chevre/service/transaction/returnOrder.js +4 -4
- package/lib/chevre/service/transaction.d.ts +9 -21
- package/lib/chevre/service/transaction.js +5 -111
- package/package.json +4 -8
|
@@ -1,861 +1,21 @@
|
|
|
1
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
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.
|
|
27
|
-
exports.authorize = authorize;
|
|
28
|
-
exports.findAcceptAction = findAcceptAction;
|
|
29
|
-
exports.findAuthorizeAction = findAuthorizeAction;
|
|
30
|
-
exports.findCheckAction = findCheckAction;
|
|
31
|
-
exports.invalidatePaymentUrl = invalidatePaymentUrl;
|
|
32
|
-
exports.voidPayTransaction = voidPayTransaction;
|
|
33
|
-
exports.processVoidPayTransaction = processVoidPayTransaction;
|
|
34
|
-
exports.publishPaymentUrl = publishPaymentUrl;
|
|
35
|
-
const util = __importStar(require("util"));
|
|
36
|
-
const factory = __importStar(require("../../factory"));
|
|
37
|
-
// import type { TransactionProcessRepo } from '../../repo/transactionProcess';
|
|
38
|
-
const PayTransactionService = __importStar(require("../assetTransaction/pay"));
|
|
39
|
-
const publishOrderNumberIfNotExist_1 = require("../transaction/placeOrder/publishOrderNumberIfNotExist");
|
|
40
|
-
const fixTransactionNumber_1 = require("./any/authorize/fixTransactionNumber");
|
|
41
|
-
const fixTransactionNumberOnPublishPaymentUrl_1 = require("./any/publishPaymentUrl/fixTransactionNumberOnPublishPaymentUrl");
|
|
42
|
-
const factory_1 = require("./any/factory");
|
|
43
|
-
const fixOrderAsNeeded_1 = require("./any/fixOrderAsNeeded");
|
|
3
|
+
exports.publishPaymentUrl = exports.processVoidPayTransaction = exports.voidPayTransaction = exports.findCheckAction = exports.findAuthorizeAction = exports.findAcceptAction = exports.authorize = exports.onPaymentStatusChanged = void 0;
|
|
44
4
|
const onPaymentStatusChanged_1 = require("./any/onPaymentStatusChanged");
|
|
45
5
|
Object.defineProperty(exports, "onPaymentStatusChanged", { enumerable: true, get: function () { return onPaymentStatusChanged_1.onPaymentStatusChanged; } });
|
|
46
|
-
const
|
|
47
|
-
Object.defineProperty(exports, "
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
// typeOf: params.purpose.typeOf,
|
|
63
|
-
// id: params.purpose.id
|
|
64
|
-
// }
|
|
65
|
-
// });
|
|
66
|
-
// authorizeActions = authorizeActions.filter(
|
|
67
|
-
// (a) => a.object.typeOf === factory.action.authorize.paymentMethod.any.ResultType.Payment
|
|
68
|
-
// );
|
|
69
|
-
// // Chevreを使用した承認を取り消し
|
|
70
|
-
// const authorizeActionsWithChevre = authorizeActions.filter((a) => {
|
|
71
|
-
// return a.instrument?.identifier === factory.action.authorize.paymentMethod.any.ServiceIdentifier.Chevre;
|
|
72
|
-
// });
|
|
73
|
-
// if (authorizeActionsWithChevre.length > 0) {
|
|
74
|
-
// await processVoidPayTransaction(params)(repos);
|
|
75
|
-
// }
|
|
76
|
-
await processVoidPayTransaction(params)(repos);
|
|
77
|
-
// 決済URL無効化もここで処理
|
|
78
|
-
await invalidatePaymentUrl(params)(repos);
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
function invalidatePaymentUrl(params) {
|
|
82
|
-
return async (repos
|
|
83
|
-
// settings: Settings
|
|
84
|
-
) => {
|
|
85
|
-
if (params.purpose.typeOf !== factory.transactionType.PlaceOrder) {
|
|
86
|
-
throw new factory.errors.Argument('purpose.typeOf', `must be ${factory.transactionType.PlaceOrder}`);
|
|
87
|
-
}
|
|
88
|
-
const transaction = await repos.transaction.projectFieldsById({
|
|
89
|
-
typeOf: params.purpose.typeOf,
|
|
90
|
-
id: params.purpose.id
|
|
91
|
-
}, ['typeOf', 'status', 'object', 'project', 'seller', 'agent']);
|
|
92
|
-
// const orderCancelled: boolean = params.purpose.result?.order?.orderStatus === factory.orderStatus.OrderCancelled;
|
|
93
|
-
// if (transaction.status === factory.transactionStatusType.Confirmed) {
|
|
94
|
-
// if (!orderCancelled) {
|
|
95
|
-
// // no op
|
|
96
|
-
// return;
|
|
97
|
-
// }
|
|
98
|
-
// }
|
|
99
|
-
// support multiple accept actions(2025-02-25~)
|
|
100
|
-
let acceptPayActions = await repos.action.search({
|
|
101
|
-
project: { id: { $eq: transaction.project.id } },
|
|
102
|
-
typeOf: { $eq: factory.actionType.AcceptAction },
|
|
103
|
-
// actionStatus: { $in: [factory.actionStatusType.CompletedActionStatus] }, // all statuses(2025-02-26~)
|
|
104
|
-
purpose: { id: { $in: [transaction.id] } },
|
|
105
|
-
object: {
|
|
106
|
-
// transactionNumber: { $eq: paymentMethodIdByPaymentUrl },
|
|
107
|
-
typeOf: { $eq: factory.assetTransactionType.Pay }
|
|
108
|
-
}
|
|
109
|
-
}, ['object']);
|
|
110
|
-
switch (transaction.status) {
|
|
111
|
-
case factory.transactionStatusType.InProgress:
|
|
112
|
-
throw new factory.errors.NotImplemented(`${transaction.status} not implemented`);
|
|
113
|
-
case factory.transactionStatusType.Confirmed:
|
|
114
|
-
// support OrderCanceled(2025-02-25~)
|
|
115
|
-
const orderCancelled = params.purpose.result?.order?.orderStatus === factory.orderStatus.OrderCancelled;
|
|
116
|
-
if (!orderCancelled) {
|
|
117
|
-
const paymentMethodIdByPaymentUrl = transaction.object.paymentMethods?.paymentMethodId;
|
|
118
|
-
if (typeof paymentMethodIdByPaymentUrl === 'string') {
|
|
119
|
-
acceptPayActions = acceptPayActions.filter(({ object }) => object.transactionNumber !== paymentMethodIdByPaymentUrl);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
break;
|
|
123
|
-
default:
|
|
124
|
-
// no op
|
|
125
|
-
}
|
|
126
|
-
const invalidatePaymentUrlTasks = [];
|
|
127
|
-
const runsAt = new Date();
|
|
128
|
-
for (const acceptPayAction of acceptPayActions) {
|
|
129
|
-
const paymentMethodIdByPaymentUrl = acceptPayAction.object.transactionNumber;
|
|
130
|
-
const paymentMethodType = acceptPayAction.object.object.paymentMethod.identifier;
|
|
131
|
-
if (typeof paymentMethodType === 'string' && paymentMethodType.length > 0) {
|
|
132
|
-
// create task(2025-02-26~)
|
|
133
|
-
// await PayTransactionService.invalidatePaymentUrl({})(repos, settings);
|
|
134
|
-
const invalidatePaymentUrlData = {
|
|
135
|
-
project: transaction.project,
|
|
136
|
-
typeOf: factory.actionType.RefundAction,
|
|
137
|
-
agent: {
|
|
138
|
-
typeOf: transaction.seller.typeOf,
|
|
139
|
-
name: (typeof transaction.seller.name === 'string')
|
|
140
|
-
? transaction.seller.name
|
|
141
|
-
: String(transaction.seller.name?.ja),
|
|
142
|
-
id: transaction.seller.id
|
|
143
|
-
},
|
|
144
|
-
recipient: {
|
|
145
|
-
typeOf: transaction.agent.typeOf,
|
|
146
|
-
id: transaction.agent.id,
|
|
147
|
-
name: transaction.agent.name
|
|
148
|
-
},
|
|
149
|
-
object: [{
|
|
150
|
-
typeOf: factory.service.paymentService.PaymentServiceType.CreditCard,
|
|
151
|
-
id: acceptPayAction.object.object.id,
|
|
152
|
-
paymentMethod: {
|
|
153
|
-
additionalProperty: [],
|
|
154
|
-
name: paymentMethodType,
|
|
155
|
-
typeOf: paymentMethodType,
|
|
156
|
-
paymentMethodId: paymentMethodIdByPaymentUrl
|
|
157
|
-
},
|
|
158
|
-
refundFee: 0
|
|
159
|
-
}],
|
|
160
|
-
purpose: { typeOf: transaction.typeOf, id: transaction.id },
|
|
161
|
-
instrument: []
|
|
162
|
-
// ...(typeof params.sameAs?.id === 'string') ? { sameAs: params.sameAs } : undefined
|
|
163
|
-
};
|
|
164
|
-
invalidatePaymentUrlTasks.push({
|
|
165
|
-
project: transaction.project,
|
|
166
|
-
name: factory.taskName.InvalidatePaymentUrl,
|
|
167
|
-
status: factory.taskStatus.Ready,
|
|
168
|
-
runsAt,
|
|
169
|
-
remainingNumberOfTries: 10,
|
|
170
|
-
numberOfTried: 0,
|
|
171
|
-
executionResults: [],
|
|
172
|
-
data: invalidatePaymentUrlData
|
|
173
|
-
});
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
if (invalidatePaymentUrlTasks.length > 0) {
|
|
177
|
-
await repos.task.saveMany(invalidatePaymentUrlTasks, { emitImmediately: true });
|
|
178
|
-
}
|
|
179
|
-
// const paymentMethodIdByPaymentUrl = transaction.object.paymentMethods?.paymentMethodId;
|
|
180
|
-
// if (typeof paymentMethodIdByPaymentUrl === 'string' && paymentMethodIdByPaymentUrl.length > 0) {
|
|
181
|
-
// const acceptPayAction = (<Pick<IAcceptPayAction, 'object'>[]>await repos.action.search(
|
|
182
|
-
// {
|
|
183
|
-
// limit: 1,
|
|
184
|
-
// page: 1,
|
|
185
|
-
// project: { id: { $eq: transaction.project.id } },
|
|
186
|
-
// typeOf: { $eq: factory.actionType.AcceptAction },
|
|
187
|
-
// actionStatus: { $in: [factory.actionStatusType.CompletedActionStatus] },
|
|
188
|
-
// purpose: { id: { $in: [transaction.id] } },
|
|
189
|
-
// object: {
|
|
190
|
-
// transactionNumber: { $eq: paymentMethodIdByPaymentUrl },
|
|
191
|
-
// typeOf: { $eq: factory.assetTransactionType.Pay }
|
|
192
|
-
// }
|
|
193
|
-
// },
|
|
194
|
-
// ['object']
|
|
195
|
-
// )).shift();
|
|
196
|
-
// if (acceptPayAction !== undefined) {
|
|
197
|
-
// // const paymentMethodType = transaction.object.paymentMethods?.typeOf;
|
|
198
|
-
// const paymentMethodType = acceptPayAction.object.object.paymentMethod.identifier;
|
|
199
|
-
// if (typeof paymentMethodType === 'string' && paymentMethodType.length > 0) {
|
|
200
|
-
// // chevreで決済URL無効化
|
|
201
|
-
// await PayTransactionService.invalidatePaymentUrl({
|
|
202
|
-
// project: transaction.project,
|
|
203
|
-
// typeOf: factory.actionType.RefundAction,
|
|
204
|
-
// agent: {
|
|
205
|
-
// typeOf: transaction.seller.typeOf,
|
|
206
|
-
// name: (typeof transaction.seller.name === 'string')
|
|
207
|
-
// ? transaction.seller.name
|
|
208
|
-
// : String(transaction.seller.name?.ja),
|
|
209
|
-
// id: transaction.seller.id
|
|
210
|
-
// },
|
|
211
|
-
// recipient: {
|
|
212
|
-
// typeOf: transaction.agent.typeOf,
|
|
213
|
-
// id: transaction.agent.id,
|
|
214
|
-
// name: transaction.agent.name
|
|
215
|
-
// },
|
|
216
|
-
// object: [{
|
|
217
|
-
// typeOf: factory.service.paymentService.PaymentServiceType.CreditCard,
|
|
218
|
-
// id: acceptPayAction.object.object.id,
|
|
219
|
-
// paymentMethod: {
|
|
220
|
-
// additionalProperty: [],
|
|
221
|
-
// name: paymentMethodType,
|
|
222
|
-
// typeOf: paymentMethodType,
|
|
223
|
-
// paymentMethodId: paymentMethodIdByPaymentUrl
|
|
224
|
-
// },
|
|
225
|
-
// refundFee: 0
|
|
226
|
-
// }],
|
|
227
|
-
// purpose: { typeOf: transaction.typeOf, id: transaction.id },
|
|
228
|
-
// instrument: [],
|
|
229
|
-
// ...(typeof params.sameAs?.id === 'string') ? { sameAs: params.sameAs } : undefined
|
|
230
|
-
// })(repos, settings);
|
|
231
|
-
// }
|
|
232
|
-
// }
|
|
233
|
-
// }
|
|
234
|
-
};
|
|
235
|
-
}
|
|
236
|
-
/**
|
|
237
|
-
* 決済承認中止
|
|
238
|
-
* apiもしくはタスクから決済承認を取り消す
|
|
239
|
-
*/
|
|
240
|
-
function processVoidPayTransaction(params) {
|
|
241
|
-
return async (repos) => {
|
|
242
|
-
const cancelAction = {
|
|
243
|
-
startTime: new Date(),
|
|
244
|
-
agent: { id: params.project.id, typeOf: factory.organizationType.Project },
|
|
245
|
-
...(typeof params.sameAs?.id === 'string') ? { sameAs: { id: params.sameAs.id, typeOf: 'Task' } } : undefined
|
|
246
|
-
};
|
|
247
|
-
let transaction;
|
|
248
|
-
// アクションID指定の場合、進行中取引検証(2023-02-24~)
|
|
249
|
-
if (typeof params.id === 'string') {
|
|
250
|
-
transaction = await repos.transaction.projectFieldsInProgressById({ typeOf: params.purpose.typeOf, id: params.purpose.id }, ['typeOf', 'status']);
|
|
251
|
-
}
|
|
252
|
-
else {
|
|
253
|
-
transaction = await repos.transaction.projectFieldsById({ typeOf: params.purpose.typeOf, id: params.purpose.id }, ['typeOf', 'status', 'result']);
|
|
254
|
-
}
|
|
255
|
-
// 承認アクションを取得
|
|
256
|
-
let authorizeActions;
|
|
257
|
-
if (typeof params.id === 'string') {
|
|
258
|
-
const authorizeAction = await repos.action.findById({ typeOf: factory.actionType.AuthorizeAction, id: params.id });
|
|
259
|
-
// 取引内のアクションかどうか確認
|
|
260
|
-
if (authorizeAction.purpose.typeOf !== transaction.typeOf || authorizeAction.purpose.id !== transaction.id) {
|
|
261
|
-
throw new factory.errors.Argument('Transaction', 'Action not found in the transaction');
|
|
262
|
-
}
|
|
263
|
-
authorizeActions = [authorizeAction];
|
|
264
|
-
}
|
|
265
|
-
else {
|
|
266
|
-
authorizeActions = await repos.action.searchByPurpose({
|
|
267
|
-
typeOf: factory.actionType.AuthorizeAction,
|
|
268
|
-
purpose: { typeOf: transaction.typeOf, id: transaction.id },
|
|
269
|
-
object: { typeOf: { $eq: factory.action.authorize.paymentMethod.any.ResultType.Payment } }
|
|
270
|
-
});
|
|
271
|
-
switch (transaction.status) {
|
|
272
|
-
case factory.transactionStatusType.InProgress:
|
|
273
|
-
throw new factory.errors.NotImplemented(`${transaction.status} not implemented`);
|
|
274
|
-
case factory.transactionStatusType.Confirmed:
|
|
275
|
-
// OrderCancelledを考慮(2023-08-30~)
|
|
276
|
-
const orderCancelled = params.purpose.result?.order?.orderStatus === factory.orderStatus.OrderCancelled;
|
|
277
|
-
if (!orderCancelled) {
|
|
278
|
-
// 取り消すべきアクションに絞る
|
|
279
|
-
authorizeActions = authorizeActions.filter(({ actionStatus }) => actionStatus !== factory.actionStatusType.CompletedActionStatus);
|
|
280
|
-
const actionIdsFromTransactionResult = transaction.result?.authorizeActions?.map(({ id }) => id);
|
|
281
|
-
if (!Array.isArray(actionIdsFromTransactionResult)) {
|
|
282
|
-
throw new factory.errors.Argument('Transaction', `${transaction.id} must have result.authorizeActions`);
|
|
283
|
-
}
|
|
284
|
-
authorizeActions = authorizeActions.filter(({ id }) => !actionIdsFromTransactionResult.includes(id));
|
|
285
|
-
// CreditCardIFでは、事前発行のpaymentMethodIdを承認時に指定するケースがある
|
|
286
|
-
// その場合、paymentMethodIdの重複がありうる
|
|
287
|
-
// exclude paymentMethodId in the order(2025-02-25~)
|
|
288
|
-
let authorizedPaymentMethodIds = [];
|
|
289
|
-
authorizedPaymentMethodIds = authorizeActions.filter(({ id }) => actionIdsFromTransactionResult.includes(id))
|
|
290
|
-
.map(({ object }) => object.paymentMethodId);
|
|
291
|
-
authorizedPaymentMethodIds = [...new Set(authorizedPaymentMethodIds)];
|
|
292
|
-
authorizeActions =
|
|
293
|
-
authorizeActions.filter(({ object }) => !authorizedPaymentMethodIds.includes(object.paymentMethodId));
|
|
294
|
-
}
|
|
295
|
-
break;
|
|
296
|
-
default:
|
|
297
|
-
// no op
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
const errors = [];
|
|
301
|
-
for (const action of authorizeActions) {
|
|
302
|
-
// 失敗するケースがあっても、残りが少なくとも処理されるようにエラーハンドリング
|
|
303
|
-
try {
|
|
304
|
-
await repos.action.cancelWithVoid({ typeOf: action.typeOf, id: action.id, cancelAction });
|
|
305
|
-
// 取引が存在すれば中止
|
|
306
|
-
const transactionNumber = action.object.paymentMethodId;
|
|
307
|
-
if (typeof transactionNumber === 'string' && transactionNumber.length > 0) {
|
|
308
|
-
const payTransaction = (await repos.assetTransaction.search({
|
|
309
|
-
limit: 1,
|
|
310
|
-
page: 1,
|
|
311
|
-
project: { id: { $eq: action.project.id } },
|
|
312
|
-
typeOf: factory.assetTransactionType.Pay,
|
|
313
|
-
transactionNumber: { $eq: transactionNumber }
|
|
314
|
-
}, ['_id', 'status'])).shift();
|
|
315
|
-
if (payTransaction !== undefined) {
|
|
316
|
-
// ステータス検証(Expiredから実行される可能性がある)
|
|
317
|
-
if (payTransaction.status !== factory.transactionStatusType.Canceled
|
|
318
|
-
&& payTransaction.status !== factory.transactionStatusType.Expired) {
|
|
319
|
-
await PayTransactionService.cancel({ transactionNumber })(repos);
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
catch (error) {
|
|
325
|
-
errors.push(error);
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
if (errors.length > 0) {
|
|
329
|
-
throw errors[0];
|
|
330
|
-
}
|
|
331
|
-
};
|
|
332
|
-
}
|
|
333
|
-
/**
|
|
334
|
-
* 外部決済ロケーションを発行する
|
|
335
|
-
*/
|
|
336
|
-
function publishPaymentUrl(params) {
|
|
337
|
-
return async (repos, settings) => {
|
|
338
|
-
const { paymentServiceType, purpose, project } = params;
|
|
339
|
-
if (purpose.typeOf !== factory.transactionType.PlaceOrder) {
|
|
340
|
-
throw new factory.errors.NotImplemented(`purpose.typeOf '${purpose.typeOf} not implemented'`);
|
|
341
|
-
}
|
|
342
|
-
try {
|
|
343
|
-
const transaction = await repos.transaction.projectFieldsInProgressById({ typeOf: purpose.typeOf, id: purpose.id }, ['expires', 'seller', 'project']);
|
|
344
|
-
if (project.id !== transaction.project.id) {
|
|
345
|
-
throw new factory.errors.NotFound(factory.transactionType.PlaceOrder);
|
|
346
|
-
}
|
|
347
|
-
// publishOrderNumber(2025-03-11~)
|
|
348
|
-
await (0, publishOrderNumberIfNotExist_1.publishOrderNumberIfNotExist)({
|
|
349
|
-
project: { id: transaction.project.id },
|
|
350
|
-
id: transaction.id,
|
|
351
|
-
object: { orderDate: new Date() }
|
|
352
|
-
})(repos);
|
|
353
|
-
// 取引番号生成
|
|
354
|
-
const { transactionNumber, ticketToken } = await (0, fixTransactionNumberOnPublishPaymentUrl_1.fixTransactionNumberOnPublishPaymentUrl)({
|
|
355
|
-
object: params.object,
|
|
356
|
-
transaction,
|
|
357
|
-
paymentServiceType
|
|
358
|
-
})(repos);
|
|
359
|
-
// let transactionNumber: string | undefined;
|
|
360
|
-
// // support ticketToken(2024-08-21~)
|
|
361
|
-
// const { permitOrInvoice } =
|
|
362
|
-
// await verifyTicketTokenAsNeeded({ project, object: params.object, paymentServiceType, purpose })(repos);
|
|
363
|
-
// if (permitOrInvoice?.typeOf === factory.permit.PermitType.Permit) {
|
|
364
|
-
// const paymentMethodIdByPermit = permitOrInvoice?.identifier;
|
|
365
|
-
// if (typeof paymentMethodIdByPermit === 'string') {
|
|
366
|
-
// transactionNumber = paymentMethodIdByPermit;
|
|
367
|
-
// }
|
|
368
|
-
// }
|
|
369
|
-
// if (typeof transactionNumber !== 'string') {
|
|
370
|
-
// const publishTransactionNumberResult = await repos.transactionNumber.publishByTimestamp({ startDate: new Date() });
|
|
371
|
-
// transactionNumber = publishTransactionNumberResult.transactionNumber;
|
|
372
|
-
// }
|
|
373
|
-
// URL発行
|
|
374
|
-
const authorizeObject = {
|
|
375
|
-
...params.object,
|
|
376
|
-
accountId: '',
|
|
377
|
-
paymentMethodId: transactionNumber,
|
|
378
|
-
typeOf: factory.action.authorize.paymentMethod.any.ResultType.Payment,
|
|
379
|
-
// support referencesOrder(2025-11-24~)
|
|
380
|
-
referencesOrder: (params.object.referencesOrder?.typeOf === factory.order.OrderType.Order)
|
|
381
|
-
? params.object.referencesOrder
|
|
382
|
-
: { typeOf: factory.order.OrderType.Order }
|
|
383
|
-
};
|
|
384
|
-
const startParams = (0, factory_1.creatPublishPaymentUrlParams)({
|
|
385
|
-
object: authorizeObject,
|
|
386
|
-
paymentServiceType,
|
|
387
|
-
transaction: transaction,
|
|
388
|
-
transactionNumber: transactionNumber,
|
|
389
|
-
location: params.location,
|
|
390
|
-
instrument: params.instrument,
|
|
391
|
-
...(typeof params.identifier === 'string') ? { identifier: params.identifier } : undefined,
|
|
392
|
-
...(typeof ticketToken === 'string') ? { ticketToken } : undefined
|
|
393
|
-
});
|
|
394
|
-
const taskId = params.sameAs?.id;
|
|
395
|
-
const result = await PayTransactionService.publishPaymentUrl(startParams, {
|
|
396
|
-
purposeAsTransaction: { id: transaction.id },
|
|
397
|
-
executor: (typeof taskId === 'string') ? { id: taskId } : {} // タスク関連付け(2024-05-22~)
|
|
398
|
-
})(repos, settings);
|
|
399
|
-
// 取引に保管
|
|
400
|
-
const paymentMethodByPaymentUrl = {
|
|
401
|
-
// typeOf: params.object.paymentMethod, // discontinue(2024-06-05~)
|
|
402
|
-
paymentMethodId: result.paymentMethodId
|
|
403
|
-
// paymentUrl: result.paymentUrl, // migrate to recipe(2024-06-05~)
|
|
404
|
-
// issuedThrough: {
|
|
405
|
-
// id: (typeof startParams.object.id === 'string') ? startParams.object.id : ''
|
|
406
|
-
// } // migrate to acceptAction(2024-06-05~)
|
|
407
|
-
// GMO IFを保管(2024-01-01~)
|
|
408
|
-
// entryTranArgs: result.entryTranArgs, // migrate to recipe(2024-06-05~)
|
|
409
|
-
// entryTranResult: result.entryTranResult, // migrate to recipe(2024-06-05~)
|
|
410
|
-
// execTranArgs: result.execTranArgs, // migrate to recipe(2024-06-05~)
|
|
411
|
-
// execTranResult: result.execTranResult, // migrate to recipe(2024-06-05~)
|
|
412
|
-
// paymentMethod: startParams.object.paymentMethod // 拡張(2024-01-04~) // migrate to acceptAction(2024-06-05~)
|
|
413
|
-
};
|
|
414
|
-
await repos.transaction.findByIdAndUpdateInProgress({
|
|
415
|
-
id: transaction.id,
|
|
416
|
-
update: { $set: { 'object.paymentMethods': paymentMethodByPaymentUrl } }
|
|
417
|
-
});
|
|
418
|
-
return {
|
|
419
|
-
paymentMethodId: result.paymentMethodId,
|
|
420
|
-
paymentUrl: result.paymentUrl
|
|
421
|
-
};
|
|
422
|
-
}
|
|
423
|
-
catch (error) {
|
|
424
|
-
// 複数対応(2024-03-27~)
|
|
425
|
-
if (Array.isArray(error)) {
|
|
426
|
-
throw error[0];
|
|
427
|
-
}
|
|
428
|
-
else {
|
|
429
|
-
throw error;
|
|
430
|
-
}
|
|
431
|
-
}
|
|
432
|
-
};
|
|
433
|
-
}
|
|
434
|
-
/**
|
|
435
|
-
* 承認アクションオブジェクトから冗長な属性を排除する
|
|
436
|
-
*/
|
|
437
|
-
function minimizeObjectIncludingPaymentMethodDetails(authorizeObjectIncludingPaymentMethodDetails) {
|
|
438
|
-
const { accountId, paymentMethodId, typeOf } = authorizeObjectIncludingPaymentMethodDetails;
|
|
439
|
-
return { authorizeObject: { accountId, paymentMethodId, typeOf } }; // optimize(2024-06-26~)
|
|
440
|
-
}
|
|
441
|
-
/**
|
|
442
|
-
* 決済承認
|
|
443
|
-
*/
|
|
444
|
-
function authorize(params) {
|
|
445
|
-
return async (repos, settings) => {
|
|
446
|
-
const { paymentServiceType, purpose, project } = params;
|
|
447
|
-
if (purpose.typeOf !== factory.transactionType.PlaceOrder) {
|
|
448
|
-
throw new factory.errors.NotImplemented(`purpose.typeOf '${purpose.typeOf} not implemented'`);
|
|
449
|
-
}
|
|
450
|
-
const transaction = await repos.transaction.projectFieldsInProgressById({ typeOf: purpose.typeOf, id: purpose.id }, ['agent', 'expires', 'typeOf', 'project', 'seller']);
|
|
451
|
-
if (project.id !== transaction.project.id) {
|
|
452
|
-
throw new factory.errors.NotFound(factory.transactionType.PlaceOrder);
|
|
453
|
-
}
|
|
454
|
-
const { confirmationNumber, orderNumber } = await (0, fixOrderAsNeeded_1.fixOrderAsNeeded)({
|
|
455
|
-
project: { id: transaction.project.id },
|
|
456
|
-
purpose
|
|
457
|
-
// paymentServiceType
|
|
458
|
-
})(repos);
|
|
459
|
-
// 取引番号生成
|
|
460
|
-
const fixTransactionNumberResult = await (0, fixTransactionNumber_1.fixTransactionNumber)({
|
|
461
|
-
object: params.object,
|
|
462
|
-
transaction,
|
|
463
|
-
paymentServiceType
|
|
464
|
-
})(repos);
|
|
465
|
-
if (typeof fixTransactionNumberResult.id === 'string') {
|
|
466
|
-
return { id: fixTransactionNumberResult.id };
|
|
467
|
-
}
|
|
468
|
-
const { transactionNumber, pendingPaymentAgencyTransaction, creditCard, invoiceByTicketToken, ticketToken } = fixTransactionNumberResult;
|
|
469
|
-
// let transactionNumber: string | undefined;
|
|
470
|
-
// let pendingPaymentAgencyTransaction: PayTransactionService.IPaymentAgencyTransaction | undefined;
|
|
471
|
-
// let creditCard: factory.action.authorize.paymentMethod.any.ICreditCard | undefined = params.object.creditCard;
|
|
472
|
-
// // ticketTokenを解釈(2024-08-13~)
|
|
473
|
-
// const { permitOrInvoice } =
|
|
474
|
-
// await verifyTicketTokenAsNeeded({ project, object: params.object, paymentServiceType, purpose })(repos);
|
|
475
|
-
// /**
|
|
476
|
-
// * ticketTokenによって指定された決済方法ID
|
|
477
|
-
// */
|
|
478
|
-
// let paymentMethodIdByTicketToken: string | undefined;
|
|
479
|
-
// if (permitOrInvoice?.typeOf === factory.permit.PermitType.Permit) {
|
|
480
|
-
// paymentMethodIdByTicketToken = permitOrInvoice?.identifier;
|
|
481
|
-
// if (typeof paymentMethodIdByTicketToken === 'string') {
|
|
482
|
-
// transactionNumber = paymentMethodIdByTicketToken; // メンバーシップ指定の場合、取引番号に適用(2024-08-13~)
|
|
483
|
-
// }
|
|
484
|
-
// } else if (permitOrInvoice?.typeOf === 'Invoice') {
|
|
485
|
-
// // support paymentServiceType.MovieTicket(2024-11-23~)
|
|
486
|
-
// if (typeof permitOrInvoice?.paymentMethodId === 'string') {
|
|
487
|
-
// paymentMethodIdByTicketToken = permitOrInvoice?.paymentMethodId;
|
|
488
|
-
// if (typeof paymentMethodIdByTicketToken === 'string') {
|
|
489
|
-
// transactionNumber = paymentMethodIdByTicketToken;
|
|
490
|
-
// }
|
|
491
|
-
// }
|
|
492
|
-
// }
|
|
493
|
-
// // リクエストでpaymentMethodIdを指定された場合、取引に保管されたpaymentMethodIdに一致すればそちらを適用(外部サイト決済対応)
|
|
494
|
-
// if (typeof params.object.paymentMethodId === 'string' && params.object.paymentMethodId.length > 0) {
|
|
495
|
-
// if (typeof paymentMethodIdByTicketToken === 'string') {
|
|
496
|
-
// if (paymentMethodIdByTicketToken !== params.object.paymentMethodId) {
|
|
497
|
-
// throw new factory.errors.Argument('ticketToken', 'not matched with paymentMethodId');
|
|
498
|
-
// }
|
|
499
|
-
// }
|
|
500
|
-
// const { authorizeParams, existingCompletedAuthorizeAction } = await handlePrePublishedPaymentMethodIdOnAuthorizing({
|
|
501
|
-
// object: params.object,
|
|
502
|
-
// prePublishedPaymentMethodId: params.object.paymentMethodId,
|
|
503
|
-
// transaction
|
|
504
|
-
// })(repos);
|
|
505
|
-
// if (existingCompletedAuthorizeAction !== undefined) {
|
|
506
|
-
// return { id: existingCompletedAuthorizeAction.id };
|
|
507
|
-
// } else if (authorizeParams !== undefined) {
|
|
508
|
-
// // creditCardを決済URL発行時の情報で上書き(2024-01-08~)
|
|
509
|
-
// // creditCard = authorizeParams.paymentMethodByTransaction.paymentMethod?.creditCard;
|
|
510
|
-
// creditCard = authorizeParams.creditCard;
|
|
511
|
-
// transactionNumber = params.object.paymentMethodId;
|
|
512
|
-
// pendingPaymentAgencyTransaction = authorizeParams.pendingPaymentAgencyTransaction;
|
|
513
|
-
// } else {
|
|
514
|
-
// throw new factory.errors.NotImplemented('pendingPaymentAgencyTransaction requied on paymentMethodId specified');
|
|
515
|
-
// }
|
|
516
|
-
// }
|
|
517
|
-
// // 取引番号発行済でなければ発行
|
|
518
|
-
// if (typeof transactionNumber !== 'string') {
|
|
519
|
-
// const publishTransactionNumberResult = await repos.transactionNumber.publishByTimestamp({ startDate: new Date() });
|
|
520
|
-
// transactionNumber = publishTransactionNumberResult.transactionNumber;
|
|
521
|
-
// }
|
|
522
|
-
const movieTickets = (Array.isArray(params.object.movieTickets)) ? params.object.movieTickets.map(factory_1.createMovieTicket) : undefined;
|
|
523
|
-
const { accountId } = await fixAccountIdIfPossible({
|
|
524
|
-
object: params.object, project: { id: transaction.project.id }
|
|
525
|
-
})();
|
|
526
|
-
const authorizeObjectIncludingPaymentMethodDetails = {
|
|
527
|
-
...params.object,
|
|
528
|
-
accountId,
|
|
529
|
-
paymentMethodId: transactionNumber,
|
|
530
|
-
typeOf: factory.action.authorize.paymentMethod.any.ResultType.Payment,
|
|
531
|
-
// support referencesOrder(2025-11-24~)
|
|
532
|
-
referencesOrder: (params.object.referencesOrder?.typeOf === factory.order.OrderType.Order)
|
|
533
|
-
? params.object.referencesOrder
|
|
534
|
-
: { typeOf: factory.order.OrderType.Order },
|
|
535
|
-
...(creditCard !== undefined) ? { creditCard } : undefined,
|
|
536
|
-
...(Array.isArray(movieTickets)) ? { movieTickets } : undefined
|
|
537
|
-
};
|
|
538
|
-
const { authorizeObject } = minimizeObjectIncludingPaymentMethodDetails(authorizeObjectIncludingPaymentMethodDetails);
|
|
539
|
-
// 承認アクションを開始する
|
|
540
|
-
const taskId = params.sameAs?.id;
|
|
541
|
-
const uniqueActionIdentifier = util.format(`%s:%s:%s`, factory.actionType.AuthorizeAction, factory.action.authorize.paymentMethod.any.ResultType.Payment, authorizeObject.paymentMethodId);
|
|
542
|
-
const actionAttributes = {
|
|
543
|
-
project: transaction.project,
|
|
544
|
-
typeOf: factory.actionType.AuthorizeAction,
|
|
545
|
-
object: authorizeObject,
|
|
546
|
-
agent: {
|
|
547
|
-
typeOf: transaction.agent.typeOf,
|
|
548
|
-
id: transaction.agent.id
|
|
549
|
-
},
|
|
550
|
-
instrument: {
|
|
551
|
-
typeOf: factory.assetTransactionType.Pay, // 資産取引化(2024-03-11~)
|
|
552
|
-
identifier: factory.action.authorize.paymentMethod.any.ServiceIdentifier.Chevre,
|
|
553
|
-
transactionNumber
|
|
554
|
-
},
|
|
555
|
-
recipient: {
|
|
556
|
-
typeOf: transaction.seller.typeOf,
|
|
557
|
-
id: transaction.seller.id,
|
|
558
|
-
name: (typeof transaction.seller.name === 'string')
|
|
559
|
-
? transaction.seller.name
|
|
560
|
-
: String(transaction.seller.name?.ja)
|
|
561
|
-
},
|
|
562
|
-
purpose: { typeOf: transaction.typeOf, id: transaction.id },
|
|
563
|
-
identifier: uniqueActionIdentifier, // add unique identifier(2025-02-25~)
|
|
564
|
-
...(typeof taskId === 'string') ? { sameAs: { id: taskId, typeOf: 'Task' } } : undefined // タスク関連付け(2024-04-22~)
|
|
565
|
-
};
|
|
566
|
-
const action = await repos.action.start(actionAttributes);
|
|
567
|
-
let payTransaction;
|
|
568
|
-
try {
|
|
569
|
-
const startParams = (0, factory_1.creatPayTransactionStartParams)({
|
|
570
|
-
accountId,
|
|
571
|
-
object: authorizeObjectIncludingPaymentMethodDetails,
|
|
572
|
-
paymentServiceType,
|
|
573
|
-
transaction: transaction,
|
|
574
|
-
transactionNumber: transactionNumber,
|
|
575
|
-
location: params.location,
|
|
576
|
-
// confirmationNumber required(2025-02-12~)
|
|
577
|
-
// orderNumber required(2025-02-14~)
|
|
578
|
-
order: { confirmationNumber, orderNumber },
|
|
579
|
-
action: { id: action.id, typeOf: action.typeOf },
|
|
580
|
-
ticketToken,
|
|
581
|
-
instrument: params.instrument
|
|
582
|
-
});
|
|
583
|
-
payTransaction = await PayTransactionService.start(startParams, {
|
|
584
|
-
// useCheckByIdentifierIfNotYet: params.options.useCheckByIdentifierIfNotYet,
|
|
585
|
-
executor: (typeof taskId === 'string') ? { id: taskId } : {}, // タスク関連付け(2024-05-18~)
|
|
586
|
-
purpose: { id: transaction.id },
|
|
587
|
-
checkedAction: params.options.checkedAction,
|
|
588
|
-
...(pendingPaymentAgencyTransaction !== undefined) ? { pendingPaymentAgencyTransaction } : undefined
|
|
589
|
-
})(repos, settings);
|
|
590
|
-
}
|
|
591
|
-
catch (error) {
|
|
592
|
-
try {
|
|
593
|
-
await repos.action.giveUp({ typeOf: action.typeOf, id: action.id, error });
|
|
594
|
-
}
|
|
595
|
-
catch (__) {
|
|
596
|
-
// no op
|
|
597
|
-
}
|
|
598
|
-
// 即時に決済取引を中止するか?(2023-02-03~)
|
|
599
|
-
if (params.options.useCancelPayTransactionOnFailed) {
|
|
600
|
-
// abortエラーの場合は状態不明なので即時中止しない(2023-06-01~)
|
|
601
|
-
// {
|
|
602
|
-
// "type": "aborted",
|
|
603
|
-
// "message": "The user aborted a request.",
|
|
604
|
-
// "name": "AbortError"
|
|
605
|
-
// }
|
|
606
|
-
const rawError = Array.isArray(error) ? error[1] : undefined;
|
|
607
|
-
if (rawError !== undefined && rawError.name !== 'AbortError') {
|
|
608
|
-
await processVoidPayTransaction({
|
|
609
|
-
project: actionAttributes.project,
|
|
610
|
-
id: action.id,
|
|
611
|
-
purpose: actionAttributes.purpose
|
|
612
|
-
})(repos);
|
|
613
|
-
}
|
|
614
|
-
}
|
|
615
|
-
// 複数対応(決済代行IFの場合、0:ChevreError,1:rawError)(2024-03-27~)
|
|
616
|
-
if (Array.isArray(error)) {
|
|
617
|
-
throw error[0];
|
|
618
|
-
}
|
|
619
|
-
else {
|
|
620
|
-
throw error;
|
|
621
|
-
}
|
|
622
|
-
}
|
|
623
|
-
const result = (0, factory_1.createAuthorizeResult)({
|
|
624
|
-
payTransaction,
|
|
625
|
-
object: authorizeObjectIncludingPaymentMethodDetails,
|
|
626
|
-
invoiceByTicketToken
|
|
627
|
-
});
|
|
628
|
-
await repos.action.completeWithVoid({ typeOf: action.typeOf, id: action.id, result: result });
|
|
629
|
-
return { id: action.id };
|
|
630
|
-
};
|
|
631
|
-
}
|
|
632
|
-
/**
|
|
633
|
-
* 承認しようとしているobjectからaccountIdを決定する
|
|
634
|
-
*/
|
|
635
|
-
function fixAccountIdIfPossible(params) {
|
|
636
|
-
return async (
|
|
637
|
-
// repos: {
|
|
638
|
-
// action: ActionRepo;
|
|
639
|
-
// authorization: AuthorizationRepo;
|
|
640
|
-
// ticket: TicketRepo;
|
|
641
|
-
// }
|
|
642
|
-
// credentials: {
|
|
643
|
-
// jwt: JWTCredentials;
|
|
644
|
-
// }
|
|
645
|
-
) => {
|
|
646
|
-
let accountId = '';
|
|
647
|
-
const fromLocation = params.object?.fromLocation;
|
|
648
|
-
const movieTickets = params.object?.movieTickets;
|
|
649
|
-
// discontinue token as fromLocation(ticketTokenへ移行するべき)(2024-12-18~)
|
|
650
|
-
if (typeof fromLocation === 'string') {
|
|
651
|
-
throw new factory.errors.NotImplemented('object.fromLocation as string not implemented');
|
|
652
|
-
// トークン化されたペイメントカード情報でリクエストされた場合、実ペイメントカード情報へ変換する
|
|
653
|
-
// const { authorizedObject } = await verifyToken({
|
|
654
|
-
// project: { id: params.project.id },
|
|
655
|
-
// agent: { id: params.project.id, typeOf: factory.organizationType.Project },
|
|
656
|
-
// token: fromLocation
|
|
657
|
-
// })(repos);
|
|
658
|
-
// const paymentCardOwnershipInfo = authorizedObject;
|
|
659
|
-
// if (Array.isArray(paymentCardOwnershipInfo)) {
|
|
660
|
-
// throw new factory.errors.NotImplemented('fromLocation as an array not implemented');
|
|
661
|
-
// }
|
|
662
|
-
// if (paymentCardOwnershipInfo.typeOf !== 'OwnershipInfo') {
|
|
663
|
-
// throw new factory.errors.Argument('fromLocation', 'must be OwnershipInfo');
|
|
664
|
-
// }
|
|
665
|
-
// if (paymentCardOwnershipInfo.typeOfGood.typeOf !== factory.permit.PermitType.Permit) {
|
|
666
|
-
// throw new factory.errors.Argument('fromLocation', 'must be Permit');
|
|
667
|
-
// }
|
|
668
|
-
// accountId = paymentCardOwnershipInfo.typeOfGood.identifier;
|
|
669
|
-
}
|
|
670
|
-
// 購入番号管理番号をaccountIdにセット(2024-03-24~)
|
|
671
|
-
if (Array.isArray(movieTickets) && movieTickets.length > 0) {
|
|
672
|
-
accountId = movieTickets[0].identifier; // 決済カードidentifierは1つのみ許可の前提
|
|
673
|
-
}
|
|
674
|
-
return { accountId };
|
|
675
|
-
};
|
|
676
|
-
}
|
|
677
|
-
function findAuthorizeAction(params) {
|
|
678
|
-
return async (repos) => {
|
|
679
|
-
// タスク検索
|
|
680
|
-
const task = (await repos.task.projectFields({
|
|
681
|
-
limit: 1,
|
|
682
|
-
page: 1,
|
|
683
|
-
id: { $eq: params.sameAs.id },
|
|
684
|
-
project: { id: { $eq: params.project.id } },
|
|
685
|
-
name: factory.taskName.AuthorizePayment
|
|
686
|
-
}, ['status', 'executionResults'])).shift();
|
|
687
|
-
if (task === undefined) {
|
|
688
|
-
throw new factory.errors.NotFound(factory.taskName.AuthorizePayment);
|
|
689
|
-
}
|
|
690
|
-
const errorByTask = task.executionResults.shift()?.error;
|
|
691
|
-
let defaultActionError;
|
|
692
|
-
if (typeof errorByTask === 'string') {
|
|
693
|
-
defaultActionError = { message: errorByTask };
|
|
694
|
-
}
|
|
695
|
-
else if (typeof errorByTask?.message === 'string') {
|
|
696
|
-
defaultActionError = { message: errorByTask.message, name: errorByTask.name };
|
|
697
|
-
}
|
|
698
|
-
let action = {
|
|
699
|
-
actionStatus: factory.actionStatusType.PotentialActionStatus,
|
|
700
|
-
...(defaultActionError !== undefined) ? { error: defaultActionError } : undefined
|
|
701
|
-
};
|
|
702
|
-
switch (task.status) {
|
|
703
|
-
case factory.taskStatus.Ready:
|
|
704
|
-
break;
|
|
705
|
-
default:
|
|
706
|
-
// タスクがReadyでなければアクション検索
|
|
707
|
-
const authorizeAction = (await repos.action.searchBySameAs({
|
|
708
|
-
sameAs: { id: { $eq: task.id } },
|
|
709
|
-
typeOf: { $eq: factory.actionType.AuthorizeAction }
|
|
710
|
-
// purpose: { id: { $eq: String(params.purpose.id) } }
|
|
711
|
-
})).shift();
|
|
712
|
-
if (authorizeAction !== undefined) {
|
|
713
|
-
// purpose検証
|
|
714
|
-
if (authorizeAction.purpose?.id !== params.purpose.id) {
|
|
715
|
-
throw new factory.errors.NotFound('Action');
|
|
716
|
-
}
|
|
717
|
-
action = {
|
|
718
|
-
id: authorizeAction.id,
|
|
719
|
-
actionStatus: authorizeAction.actionStatus,
|
|
720
|
-
...(authorizeAction.error !== undefined)
|
|
721
|
-
? {
|
|
722
|
-
error: (Array.isArray(authorizeAction.error))
|
|
723
|
-
? authorizeAction.error[0]
|
|
724
|
-
: authorizeAction.error
|
|
725
|
-
}
|
|
726
|
-
: undefined
|
|
727
|
-
};
|
|
728
|
-
}
|
|
729
|
-
}
|
|
730
|
-
return action;
|
|
731
|
-
};
|
|
732
|
-
}
|
|
733
|
-
function findCheckAction(params) {
|
|
734
|
-
return async (repos) => {
|
|
735
|
-
// タスク検索
|
|
736
|
-
const task = (await repos.task.projectFields({
|
|
737
|
-
limit: 1,
|
|
738
|
-
page: 1,
|
|
739
|
-
id: { $eq: params.sameAs.id },
|
|
740
|
-
project: { id: { $eq: params.project.id } },
|
|
741
|
-
name: factory.taskName.CheckMovieTicket
|
|
742
|
-
}, ['status', 'executionResults'])).shift();
|
|
743
|
-
if (task === undefined) {
|
|
744
|
-
throw new factory.errors.NotFound(factory.taskName.CheckMovieTicket);
|
|
745
|
-
}
|
|
746
|
-
const errorByTask = task.executionResults.shift()?.error;
|
|
747
|
-
let defaultActionError;
|
|
748
|
-
if (typeof errorByTask === 'string') {
|
|
749
|
-
defaultActionError = { message: errorByTask };
|
|
750
|
-
}
|
|
751
|
-
else if (typeof errorByTask?.message === 'string') {
|
|
752
|
-
defaultActionError = { message: errorByTask.message, name: errorByTask.name };
|
|
753
|
-
}
|
|
754
|
-
let action = {
|
|
755
|
-
actionStatus: factory.actionStatusType.PotentialActionStatus,
|
|
756
|
-
...(defaultActionError !== undefined) ? { error: defaultActionError } : undefined
|
|
757
|
-
};
|
|
758
|
-
switch (task.status) {
|
|
759
|
-
case factory.taskStatus.Ready:
|
|
760
|
-
break;
|
|
761
|
-
default:
|
|
762
|
-
// タスクがReadyでなければアクション検索
|
|
763
|
-
const authorizeAction = (await repos.action.searchBySameAs({
|
|
764
|
-
sameAs: { id: { $eq: task.id } },
|
|
765
|
-
typeOf: { $eq: factory.actionType.CheckAction }
|
|
766
|
-
// purpose: { id: { $eq: String(params.purpose.id) } }
|
|
767
|
-
})).shift();
|
|
768
|
-
if (authorizeAction !== undefined) {
|
|
769
|
-
// purpose検証
|
|
770
|
-
if (authorizeAction.purpose?.id !== params.purpose.id) {
|
|
771
|
-
throw new factory.errors.NotFound('Action');
|
|
772
|
-
}
|
|
773
|
-
// result from recipe(2024-06-10~)
|
|
774
|
-
const purchaseNumberAuthResult = await repos.action.findIMinimizedPurchaseNumberAuthResultByCheckMovieTicketRecipe({
|
|
775
|
-
project: { id: params.project.id },
|
|
776
|
-
recipeFor: { id: authorizeAction.id }
|
|
777
|
-
});
|
|
778
|
-
action = {
|
|
779
|
-
id: authorizeAction.id,
|
|
780
|
-
actionStatus: authorizeAction.actionStatus,
|
|
781
|
-
...(authorizeAction.error !== undefined)
|
|
782
|
-
? {
|
|
783
|
-
error: (Array.isArray(authorizeAction.error))
|
|
784
|
-
? authorizeAction.error[0]
|
|
785
|
-
: authorizeAction.error
|
|
786
|
-
}
|
|
787
|
-
: undefined,
|
|
788
|
-
...(purchaseNumberAuthResult !== undefined) ? { result: { purchaseNumberAuthResult } } : undefined
|
|
789
|
-
};
|
|
790
|
-
}
|
|
791
|
-
}
|
|
792
|
-
return action;
|
|
793
|
-
};
|
|
794
|
-
}
|
|
795
|
-
function findAcceptAction(params) {
|
|
796
|
-
return async (repos) => {
|
|
797
|
-
// タスク検索
|
|
798
|
-
const task = (await repos.task.projectFields({
|
|
799
|
-
limit: 1,
|
|
800
|
-
page: 1,
|
|
801
|
-
id: { $eq: params.sameAs.id },
|
|
802
|
-
project: { id: { $eq: params.project.id } },
|
|
803
|
-
name: factory.taskName.PublishPaymentUrl
|
|
804
|
-
}, ['status', 'executionResults'])).shift();
|
|
805
|
-
if (task === undefined) {
|
|
806
|
-
throw new factory.errors.NotFound(factory.taskName.PublishPaymentUrl);
|
|
807
|
-
}
|
|
808
|
-
const errorByTask = task.executionResults.shift()?.error;
|
|
809
|
-
let defaultActionError;
|
|
810
|
-
if (typeof errorByTask === 'string') {
|
|
811
|
-
defaultActionError = { message: errorByTask };
|
|
812
|
-
}
|
|
813
|
-
else if (typeof errorByTask?.message === 'string') {
|
|
814
|
-
defaultActionError = { message: errorByTask.message, name: errorByTask.name };
|
|
815
|
-
}
|
|
816
|
-
let action = {
|
|
817
|
-
actionStatus: factory.actionStatusType.PotentialActionStatus,
|
|
818
|
-
...(defaultActionError !== undefined) ? { error: defaultActionError } : undefined
|
|
819
|
-
};
|
|
820
|
-
switch (task.status) {
|
|
821
|
-
case factory.taskStatus.Ready:
|
|
822
|
-
break;
|
|
823
|
-
default:
|
|
824
|
-
// タスクがReadyでなければアクション検索
|
|
825
|
-
const acceptAction = (await repos.action.searchBySameAs({
|
|
826
|
-
sameAs: { id: { $eq: task.id } },
|
|
827
|
-
typeOf: { $eq: factory.actionType.AcceptAction }
|
|
828
|
-
// purpose: { id: { $eq: String(params.purpose.id) } }
|
|
829
|
-
})).shift();
|
|
830
|
-
if (acceptAction !== undefined) {
|
|
831
|
-
// purpose検証
|
|
832
|
-
if (acceptAction.purpose?.id !== params.purpose.id) {
|
|
833
|
-
throw new factory.errors.NotFound('Action');
|
|
834
|
-
}
|
|
835
|
-
const acceptActionWithResult = await repos.action.findById({ id: acceptAction.id, typeOf: factory.actionType.AcceptAction }, ['result', 'object'], []);
|
|
836
|
-
action = {
|
|
837
|
-
id: acceptAction.id,
|
|
838
|
-
actionStatus: acceptAction.actionStatus,
|
|
839
|
-
// add object.transactionNumber(2025-08-26~)
|
|
840
|
-
object: { transactionNumber: acceptActionWithResult.object.transactionNumber },
|
|
841
|
-
...(acceptAction.error !== undefined)
|
|
842
|
-
? {
|
|
843
|
-
error: (Array.isArray(acceptAction.error))
|
|
844
|
-
? acceptAction.error[0]
|
|
845
|
-
: acceptAction.error
|
|
846
|
-
}
|
|
847
|
-
: undefined,
|
|
848
|
-
...(acceptActionWithResult?.result !== undefined)
|
|
849
|
-
? {
|
|
850
|
-
result: {
|
|
851
|
-
paymentMethodId: acceptActionWithResult.result.paymentMethodId,
|
|
852
|
-
paymentUrl: acceptActionWithResult.result.paymentUrl
|
|
853
|
-
}
|
|
854
|
-
}
|
|
855
|
-
: undefined
|
|
856
|
-
};
|
|
857
|
-
}
|
|
858
|
-
}
|
|
859
|
-
return action;
|
|
860
|
-
};
|
|
861
|
-
}
|
|
6
|
+
const authorize_1 = require("./any/authorize");
|
|
7
|
+
Object.defineProperty(exports, "authorize", { enumerable: true, get: function () { return authorize_1.authorize; } });
|
|
8
|
+
const findAcceptAction_1 = require("./any/findAcceptAction");
|
|
9
|
+
Object.defineProperty(exports, "findAcceptAction", { enumerable: true, get: function () { return findAcceptAction_1.findAcceptAction; } });
|
|
10
|
+
const findAuthorizeAction_1 = require("./any/findAuthorizeAction");
|
|
11
|
+
Object.defineProperty(exports, "findAuthorizeAction", { enumerable: true, get: function () { return findAuthorizeAction_1.findAuthorizeAction; } });
|
|
12
|
+
const findCheckAction_1 = require("./any/findCheckAction");
|
|
13
|
+
Object.defineProperty(exports, "findCheckAction", { enumerable: true, get: function () { return findCheckAction_1.findCheckAction; } });
|
|
14
|
+
// import { invalidatePaymentUrl } from './any/invalidatePaymentUrl';
|
|
15
|
+
const voidPayTransaction_1 = require("./any/voidPayTransaction");
|
|
16
|
+
Object.defineProperty(exports, "voidPayTransaction", { enumerable: true, get: function () { return voidPayTransaction_1.voidPayTransaction; } });
|
|
17
|
+
// import { person2username } from './any/person2username';
|
|
18
|
+
const processVoidPayTransaction_1 = require("./any/processVoidPayTransaction");
|
|
19
|
+
Object.defineProperty(exports, "processVoidPayTransaction", { enumerable: true, get: function () { return processVoidPayTransaction_1.processVoidPayTransaction; } });
|
|
20
|
+
const publishPaymentUrl_1 = require("./any/publishPaymentUrl");
|
|
21
|
+
Object.defineProperty(exports, "publishPaymentUrl", { enumerable: true, get: function () { return publishPaymentUrl_1.publishPaymentUrl; } });
|