@chevre/domain 25.2.0-alpha.0 → 25.2.0-alpha.10
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/actionProcess.js +62 -72
- package/lib/chevre/repo/action.d.ts +4 -1
- package/lib/chevre/repo/action.js +3 -2
- package/lib/chevre/repo/assetTransaction.d.ts +1 -1
- package/lib/chevre/repo/assetTransaction.js +1 -1
- package/lib/chevre/repo/mongoose/schemas/action.js +67 -66
- package/lib/chevre/service/offer/event/authorize/factory.d.ts +2 -1
- package/lib/chevre/service/offer/event/authorize/factory.js +13 -25
- package/lib/chevre/service/offer/event/authorize.d.ts +4 -0
- package/lib/chevre/service/offer/event/authorize.js +2 -6
- package/lib/chevre/service/offer/event/voidTransaction/processVoidTransaction4coa.js +1 -1
- package/lib/chevre/service/offer/eventServiceByCOA/authorize/factory.d.ts +2 -0
- package/lib/chevre/service/offer/eventServiceByCOA/authorize/factory.js +6 -13
- package/lib/chevre/service/offer/eventServiceByCOA/authorize.d.ts +5 -1
- package/lib/chevre/service/offer/eventServiceByCOA/authorize.js +5 -10
- package/lib/chevre/service/offer/eventServiceByCOA/authorizeByAcceptAction.d.ts +5 -0
- package/lib/chevre/service/offer/eventServiceByCOA/authorizeByAcceptAction.js +3 -32
- package/lib/chevre/service/offer/eventServiceByCOA/changeOffers.d.ts +0 -1
- package/lib/chevre/service/offer/eventServiceByCOA/changeOffers.js +1 -2
- package/lib/chevre/service/payment/any/authorize.js +6 -32
- package/lib/chevre/service/payment/any/factory.js +1 -1
- package/lib/chevre/service/transaction/placeOrder/confirm/prepareUnitPriceOfferConditions.d.ts +22 -0
- package/lib/chevre/service/transaction/placeOrder/confirm/prepareUnitPriceOfferConditions.js +120 -0
- package/lib/chevre/service/transaction/placeOrder/confirm/validation.d.ts +9 -1
- package/lib/chevre/service/transaction/placeOrder/confirm/validation.js +109 -93
- package/lib/chevre/service/transaction/placeOrder/confirm.d.ts +7 -0
- package/lib/chevre/service/transaction/placeOrder/confirm.js +17 -42
- package/package.json +2 -2
|
@@ -26,6 +26,11 @@ export declare function authorizeByAcceptAction(params: {
|
|
|
26
26
|
*/
|
|
27
27
|
id: string;
|
|
28
28
|
};
|
|
29
|
+
}, options: {
|
|
30
|
+
/**
|
|
31
|
+
* 2026-07-04~
|
|
32
|
+
*/
|
|
33
|
+
useLegacyAuthorizeOfferObject: boolean;
|
|
29
34
|
}): IAuthorizeOperation<Pick<IAuthorizeOfferAction, 'id' | 'instrument'> & {
|
|
30
35
|
result: IAuthorizeOfferAction['result'];
|
|
31
36
|
}>;
|
|
@@ -7,23 +7,8 @@ const factory_1 = require("../../../factory");
|
|
|
7
7
|
/**
|
|
8
8
|
* 採用アクションからCOA興行オファー承認
|
|
9
9
|
*/
|
|
10
|
-
function authorizeByAcceptAction(params) {
|
|
10
|
+
function authorizeByAcceptAction(params, options) {
|
|
11
11
|
return async (repos) => {
|
|
12
|
-
// const acceptAction = (<IAcceptAction[]>await repos.action.search(
|
|
13
|
-
// {
|
|
14
|
-
// limit: 1,
|
|
15
|
-
// page: 1,
|
|
16
|
-
// project: { id: { $eq: params.project.id } },
|
|
17
|
-
// id: { $in: [params.object.id] },
|
|
18
|
-
// typeOf: { $eq: factory.actionType.AcceptAction },
|
|
19
|
-
// purpose: { id: { $in: [params.purpose.id] } },
|
|
20
|
-
// actionStatus: { $in: [factory.actionStatusType.CompletedActionStatus] }
|
|
21
|
-
// },
|
|
22
|
-
// ['result', 'object', 'potentialActions']
|
|
23
|
-
// )).shift();
|
|
24
|
-
// if (acceptAction === undefined) {
|
|
25
|
-
// throw new factory.errors.NotFound(factory.actionType.AcceptAction);
|
|
26
|
-
// }
|
|
27
12
|
const acceptAction = await repos.accpetCOAOfferAction.findCompletedById({
|
|
28
13
|
project: { id: params.project.id },
|
|
29
14
|
id: params.object.id,
|
|
@@ -44,9 +29,6 @@ function authorizeByAcceptAction(params) {
|
|
|
44
29
|
agent: { id: params.agent.id },
|
|
45
30
|
transaction: { id: params.purpose.id },
|
|
46
31
|
id: acceptAction.potentialActions.id,
|
|
47
|
-
options: {
|
|
48
|
-
// useCreateOrderOnOfferAccepted: USE_CREATE_ORDER_ON_OFFER_ACCEPTED // discontinue(2024-05-28~)
|
|
49
|
-
}
|
|
50
32
|
};
|
|
51
33
|
action = await (0, changeOffers_1.changeOffers)(changeOfferParams)(repos);
|
|
52
34
|
}
|
|
@@ -64,14 +46,6 @@ function authorizeByAcceptAction(params) {
|
|
|
64
46
|
if (responseBody === undefined) {
|
|
65
47
|
throw new factory_1.factory.errors.NotFound('afterMedia by recipe');
|
|
66
48
|
}
|
|
67
|
-
// const requestBody = acceptAction.instrument.requestBody;
|
|
68
|
-
// if (requestBody === undefined) {
|
|
69
|
-
// throw new chevre.factory.errors.NotFound(`${chevre.factory.actionType.AcceptAction}.result.requestBody`);
|
|
70
|
-
// }
|
|
71
|
-
// const responseBody = acceptResult.result?.responseBody;
|
|
72
|
-
// if (responseBody === undefined) {
|
|
73
|
-
// throw new chevre.factory.errors.NotFound(`${chevre.factory.actionType.AcceptAction}.result.responseBody`);
|
|
74
|
-
// }
|
|
75
49
|
const authorizeParams = {
|
|
76
50
|
object: {
|
|
77
51
|
acceptAction: { id: params.object.id },
|
|
@@ -81,12 +55,9 @@ function authorizeByAcceptAction(params) {
|
|
|
81
55
|
agent: { id: params.agent.id },
|
|
82
56
|
transaction: { id: params.purpose.id },
|
|
83
57
|
store: { id: params.store.id },
|
|
84
|
-
result: { requestBody, responseBody }
|
|
85
|
-
options: {
|
|
86
|
-
// useCreateOrderOnOfferAccepted: USE_CREATE_ORDER_ON_OFFER_ACCEPTED // discontinue(2024-05-28~)
|
|
87
|
-
}
|
|
58
|
+
result: { requestBody, responseBody }
|
|
88
59
|
};
|
|
89
|
-
action = await (0, authorize_1.authorize)(authorizeParams)(repos);
|
|
60
|
+
action = await (0, authorize_1.authorize)(authorizeParams, options)(repos);
|
|
90
61
|
}
|
|
91
62
|
return action;
|
|
92
63
|
};
|
|
@@ -9,7 +9,6 @@ const any_1 = require("../any");
|
|
|
9
9
|
const factory_1 = require("./authorize/factory");
|
|
10
10
|
const validateAcceptedOffers_1 = require("./authorize/validateAcceptedOffers");
|
|
11
11
|
const factory_2 = require("../../../factory");
|
|
12
|
-
// type IAcceptAction = Pick<factory.action.accept.coaOffer.IAction, 'result'>;
|
|
13
12
|
/**
|
|
14
13
|
* COA興行オファー承認のオファーを変更
|
|
15
14
|
*/
|
|
@@ -134,7 +133,7 @@ function changeOffers(params) {
|
|
|
134
133
|
const actionResult = {
|
|
135
134
|
...authorizeAction.result,
|
|
136
135
|
price: price,
|
|
137
|
-
amount: []
|
|
136
|
+
// amount: [] // discontinue(2026-07-06~)
|
|
138
137
|
};
|
|
139
138
|
// ActiveActionStatus->CompletedActionStatusで再実装(2024-01-15~)
|
|
140
139
|
await repos.action.reStart({ id: authorizeAction.id, typeOf: authorizeAction.typeOf });
|
|
@@ -209,40 +209,14 @@ function authorize(params) {
|
|
|
209
209
|
* 承認しようとしているobjectからaccountIdを決定する
|
|
210
210
|
*/
|
|
211
211
|
function fixAccountIdIfPossible(params) {
|
|
212
|
-
return async (
|
|
213
|
-
// repos: {
|
|
214
|
-
// action: ActionRepo;
|
|
215
|
-
// authorization: AuthorizationRepo;
|
|
216
|
-
// ticket: TicketRepo;
|
|
217
|
-
// }
|
|
218
|
-
// credentials: {
|
|
219
|
-
// jwt: JWTCredentials;
|
|
220
|
-
// }
|
|
221
|
-
) => {
|
|
212
|
+
return async () => {
|
|
222
213
|
let accountId = '';
|
|
223
|
-
const fromLocation = params.object?.fromLocation;
|
|
214
|
+
// const fromLocation = params.object?.fromLocation;
|
|
224
215
|
const movieTickets = params.object?.movieTickets;
|
|
225
|
-
// discontinue token as fromLocation(ticketTokenへ移行するべき)(2024-12-18~)
|
|
226
|
-
if (typeof fromLocation === 'string') {
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
// const { authorizedObject } = await verifyToken({
|
|
230
|
-
// project: { id: params.project.id },
|
|
231
|
-
// agent: { id: params.project.id, typeOf: factory.organizationType.Project },
|
|
232
|
-
// token: fromLocation
|
|
233
|
-
// })(repos);
|
|
234
|
-
// const paymentCardOwnershipInfo = authorizedObject;
|
|
235
|
-
// if (Array.isArray(paymentCardOwnershipInfo)) {
|
|
236
|
-
// throw new factory.errors.NotImplemented('fromLocation as an array not implemented');
|
|
237
|
-
// }
|
|
238
|
-
// if (paymentCardOwnershipInfo.typeOf !== 'OwnershipInfo') {
|
|
239
|
-
// throw new factory.errors.Argument('fromLocation', 'must be OwnershipInfo');
|
|
240
|
-
// }
|
|
241
|
-
// if (paymentCardOwnershipInfo.typeOfGood.typeOf !== factory.permit.PermitType.Permit) {
|
|
242
|
-
// throw new factory.errors.Argument('fromLocation', 'must be Permit');
|
|
243
|
-
// }
|
|
244
|
-
// accountId = paymentCardOwnershipInfo.typeOfGood.identifier;
|
|
245
|
-
}
|
|
216
|
+
// // discontinue token as fromLocation(ticketTokenへ移行するべき)(2024-12-18~)
|
|
217
|
+
// if (typeof fromLocation === 'string') {
|
|
218
|
+
// throw new factory.errors.NotImplemented('object.fromLocation as string not implemented');
|
|
219
|
+
// }
|
|
246
220
|
// 購入番号管理番号をaccountIdにセット(2024-03-24~)
|
|
247
221
|
if (Array.isArray(movieTickets) && movieTickets.length > 0) {
|
|
248
222
|
accountId = movieTickets[0].identifier; // 決済カードidentifierは1つのみ許可の前提
|
|
@@ -140,7 +140,7 @@ function creatPayTransactionStartParams(params) {
|
|
|
140
140
|
...(typeof params.object.name === 'string') ? { name: params.object.name } : undefined,
|
|
141
141
|
...(typeof accountId === 'string') ? { accountId } : undefined,
|
|
142
142
|
...(typeof params.object.description === 'string') ? { description: params.object.description } : undefined,
|
|
143
|
-
...(typeof params.object.fromLocation === 'string') ? { fromLocation: params.object.fromLocation } : undefined,
|
|
143
|
+
// ...(typeof params.object.fromLocation === 'string') ? { fromLocation: params.object.fromLocation } : undefined, // discontinue(2026-07-08~)
|
|
144
144
|
...(params.object.creditCard !== undefined) ? { creditCard: params.object.creditCard } : undefined,
|
|
145
145
|
...(Array.isArray(movieTickets)) ? { movieTickets } : undefined
|
|
146
146
|
},
|
package/lib/chevre/service/transaction/placeOrder/confirm/prepareUnitPriceOfferConditions.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { OfferRepo } from '../../../../repo/offer/unitPriceInCatalog';
|
|
2
|
+
import { factory } from '../../../../factory';
|
|
3
|
+
export type IAuthorizeEventServiceOffer = factory.action.authorize.offer.eventService.IAction;
|
|
4
|
+
type IOrderAcceptedOffer = Pick<factory.order.IAcceptedOffer, 'itemOffered' | 'offeredThrough' | 'serialNumber' | 'priceSpecification' | 'id'>;
|
|
5
|
+
export declare function createAuthorizeOfferResultsExpected(params: {
|
|
6
|
+
authorizeEventServiceOfferActions: Pick<IAuthorizeEventServiceOffer, 'id' | 'result'>[];
|
|
7
|
+
}): Pick<IAuthorizeEventServiceOffer, 'id' | 'result'>[];
|
|
8
|
+
/**
|
|
9
|
+
* 注文ドキュメントと予約取引ドキュメントを参照することによって生成した、単価オファー検証条件
|
|
10
|
+
* 元々オファー承認アクションのresultに保管されていた
|
|
11
|
+
*/
|
|
12
|
+
type IPreparedUnitPriceOfferConditions = Pick<IAuthorizeEventServiceOffer, 'id' | 'result'>;
|
|
13
|
+
declare function prepareUnitPriceOfferConditions(params: {
|
|
14
|
+
project: {
|
|
15
|
+
id: string;
|
|
16
|
+
};
|
|
17
|
+
acceptedOffers: IOrderAcceptedOffer[];
|
|
18
|
+
authorizeEventServiceOfferActions: IAuthorizeEventServiceOffer[];
|
|
19
|
+
}): (repos: {
|
|
20
|
+
offer: OfferRepo;
|
|
21
|
+
}) => Promise<IPreparedUnitPriceOfferConditions[]>;
|
|
22
|
+
export { IPreparedUnitPriceOfferConditions, prepareUnitPriceOfferConditions };
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.createAuthorizeOfferResultsExpected = createAuthorizeOfferResultsExpected;
|
|
7
|
+
exports.prepareUnitPriceOfferConditions = prepareUnitPriceOfferConditions;
|
|
8
|
+
const debug_1 = __importDefault(require("debug"));
|
|
9
|
+
const factory_1 = require("../../../../factory");
|
|
10
|
+
const debug = (0, debug_1.default)('chevre-domain:service:transaction:placeOrder:confirm:prepareUnitPriceOfferConditions');
|
|
11
|
+
function acceptedOffers2authorizeResult(params) {
|
|
12
|
+
const { acceptedOffers4result, unitPriceOffers } = params;
|
|
13
|
+
const programMembershipUsed = acceptedOffers2programMembershipUsed({ acceptedOffers: acceptedOffers4result });
|
|
14
|
+
// オファーIDごとに集計
|
|
15
|
+
const offerIds = [...new Set(acceptedOffers4result.map((o) => String(o.id)))];
|
|
16
|
+
const offers = offerIds.map((offerId) => {
|
|
17
|
+
const acceptedOffer = unitPriceOffers.find(({ id }) => id === offerId);
|
|
18
|
+
if (acceptedOffer === undefined) {
|
|
19
|
+
throw new factory_1.factory.errors.Internal(`acceptedOffer not found [id:${offerId}]`);
|
|
20
|
+
}
|
|
21
|
+
const amountOfThisGood = acceptedOffers4result.filter(({ id }) => id === offerId).length;
|
|
22
|
+
const { acceptedPaymentMethod, priceSpecification } = acceptedOffer;
|
|
23
|
+
const unitPriceSpec = priceSpecification;
|
|
24
|
+
if (unitPriceSpec === undefined) {
|
|
25
|
+
throw new factory_1.factory.errors.Internal(`unitPriceSpec not found [id:${offerId}]`);
|
|
26
|
+
}
|
|
27
|
+
const { eligibleQuantity } = unitPriceSpec;
|
|
28
|
+
return {
|
|
29
|
+
id: offerId,
|
|
30
|
+
includesObject: { amountOfThisGood },
|
|
31
|
+
typeOf: factory_1.factory.offerType.Offer,
|
|
32
|
+
priceSpecification: {
|
|
33
|
+
...(eligibleQuantity !== undefined) ? { eligibleQuantity } : undefined,
|
|
34
|
+
},
|
|
35
|
+
...(acceptedPaymentMethod !== undefined) ? { acceptedPaymentMethod } : undefined
|
|
36
|
+
};
|
|
37
|
+
});
|
|
38
|
+
return {
|
|
39
|
+
// amount: [], // discontinue(2026-07-06~)
|
|
40
|
+
itemOffered: {
|
|
41
|
+
serviceOutput: { programMembershipUsed } // add programMembershipUsed required(2024-08-15~)
|
|
42
|
+
},
|
|
43
|
+
offers
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
function acceptedOffers2programMembershipUsed(params) {
|
|
47
|
+
const programMembershipUsed = [];
|
|
48
|
+
const permitIdentifiers = [];
|
|
49
|
+
params.acceptedOffers.forEach(({ itemOffered }) => {
|
|
50
|
+
if (itemOffered.programMembershipUsed?.typeOf === factory_1.factory.programMembership.ProgramMembershipType.ProgramMembership) {
|
|
51
|
+
// メンバーシップコードに対してユニークに集計
|
|
52
|
+
if (!permitIdentifiers.includes(itemOffered.programMembershipUsed.identifier)) {
|
|
53
|
+
permitIdentifiers.push(itemOffered.programMembershipUsed.identifier);
|
|
54
|
+
const issuedThroughTypeOf = itemOffered.programMembershipUsed.issuedThrough.typeOf;
|
|
55
|
+
if (issuedThroughTypeOf === factory_1.factory.service.paymentService.PaymentServiceType.FaceToFace) {
|
|
56
|
+
programMembershipUsed.push({
|
|
57
|
+
typeOf: factory_1.factory.permit.PermitType.Permit,
|
|
58
|
+
identifier: itemOffered.programMembershipUsed.identifier,
|
|
59
|
+
issuedThrough: { typeOf: issuedThroughTypeOf }
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
programMembershipUsed.push({
|
|
64
|
+
typeOf: factory_1.factory.permit.PermitType.Permit,
|
|
65
|
+
identifier: itemOffered.programMembershipUsed.identifier,
|
|
66
|
+
issuedThrough: { typeOf: issuedThroughTypeOf, id: itemOffered.programMembershipUsed.issuedThrough.id }
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
return programMembershipUsed;
|
|
73
|
+
}
|
|
74
|
+
function createAuthorizeOfferResultsExpected(params) {
|
|
75
|
+
return params.authorizeEventServiceOfferActions.map((a) => {
|
|
76
|
+
return {
|
|
77
|
+
id: a.id,
|
|
78
|
+
result: a.result
|
|
79
|
+
};
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
function prepareUnitPriceOfferConditions(params) {
|
|
83
|
+
return async (repos) => {
|
|
84
|
+
// COAの場合は単価オファーを参照せずにそのまま返す
|
|
85
|
+
const isCOA = params.authorizeEventServiceOfferActions.some((action) => action.instrument.typeOf === factory_1.factory.assetTransactionType.COAReserveTransaction);
|
|
86
|
+
if (isCOA) {
|
|
87
|
+
return params.authorizeEventServiceOfferActions.map(({ id, result }) => ({ id, result }));
|
|
88
|
+
}
|
|
89
|
+
const conditions = [];
|
|
90
|
+
const offerIds = [...new Set(params.acceptedOffers.map((o) => String(o.id)))];
|
|
91
|
+
const unitPriceOffers = await repos.offer.search({
|
|
92
|
+
id: { $in: offerIds }
|
|
93
|
+
}, {
|
|
94
|
+
acceptedPaymentMethod: 1,
|
|
95
|
+
priceSpecification: 1,
|
|
96
|
+
});
|
|
97
|
+
debug('unitPriceOffers:', unitPriceOffers);
|
|
98
|
+
for (const authorizeEventServiceOfferAction of params.authorizeEventServiceOfferActions) {
|
|
99
|
+
if (authorizeEventServiceOfferAction.result === undefined) {
|
|
100
|
+
throw new Error('authorizeEventServiceOfferAction.result should exist');
|
|
101
|
+
}
|
|
102
|
+
const acceptedOffers4action = params.acceptedOffers.filter(((offer) => {
|
|
103
|
+
return offer.serialNumber === authorizeEventServiceOfferAction.instrument.transactionNumber;
|
|
104
|
+
}));
|
|
105
|
+
conditions.push({
|
|
106
|
+
id: authorizeEventServiceOfferAction.id,
|
|
107
|
+
result: {
|
|
108
|
+
typeOf: authorizeEventServiceOfferAction.result.typeOf,
|
|
109
|
+
// priceCurrency: authorizeEventServiceOfferAction.result.priceCurrency,
|
|
110
|
+
price: authorizeEventServiceOfferAction.result.price,
|
|
111
|
+
...acceptedOffers2authorizeResult({
|
|
112
|
+
acceptedOffers4result: acceptedOffers4action,
|
|
113
|
+
unitPriceOffers
|
|
114
|
+
})
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
return conditions;
|
|
119
|
+
};
|
|
120
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { factory } from '../../../../factory';
|
|
2
2
|
import { PlaceOrderFactory } from '../../../../factory/transaction';
|
|
3
|
+
import { IPreparedUnitPriceOfferConditions } from './prepareUnitPriceOfferConditions';
|
|
3
4
|
import { IAcceptPayAction, IAuthorizeEventServiceOffer, IAuthorizePaymentAction, IPayTransaction } from './validation/factory';
|
|
4
5
|
export { IAcceptPayAction, IAuthorizeEventServiceOffer, IAuthorizePaymentAction, IPayTransaction };
|
|
5
6
|
/**
|
|
@@ -35,9 +36,16 @@ export declare function validatePaymentMethods(params: {
|
|
|
35
36
|
* 興行オファー適用条件確認
|
|
36
37
|
*/
|
|
37
38
|
export declare function validateEventOffers(params: {
|
|
39
|
+
project: {
|
|
40
|
+
id: string;
|
|
41
|
+
};
|
|
38
42
|
order: {
|
|
39
43
|
price: number;
|
|
40
44
|
};
|
|
41
45
|
paymentMethods: factory.order.IReferencedInvoice[];
|
|
42
|
-
|
|
46
|
+
/**
|
|
47
|
+
* 承認アクションのresultに条件が保管されているはず(2026-07-06時点で)
|
|
48
|
+
*/
|
|
49
|
+
authorizeOfferActions: Pick<IAuthorizeEventServiceOffer, 'id' | 'result'>[];
|
|
50
|
+
unitPriceOfferConditions?: IPreparedUnitPriceOfferConditions[];
|
|
43
51
|
}): void;
|
|
@@ -17,23 +17,20 @@ const factory_1 = require("../../../../factory");
|
|
|
17
17
|
const validateInvoiceReferencesOrder_1 = require("./validation/validateInvoiceReferencesOrder");
|
|
18
18
|
const validateMovieTicket_1 = require("./validation/validateMovieTicket");
|
|
19
19
|
const validatePrice_1 = require("./validation/validatePrice");
|
|
20
|
-
const debug = (0, debug_1.default)('chevre-domain:service:transaction');
|
|
20
|
+
const debug = (0, debug_1.default)('chevre-domain:service:transaction:placeOrder:confirm:validation');
|
|
21
21
|
/**
|
|
22
22
|
* 取引が確定可能な状態かどうかをチェックする
|
|
23
23
|
*/
|
|
24
|
-
function validateTransaction(transaction, acceptPayActions, authorizePaymentActions, authorizeEventServiceOfferActions,
|
|
25
|
-
// authorizeProductOfferActions: Pick<IAuthorizeProductOffer, 'id' | 'result'>[],
|
|
26
|
-
eventReservationAcceptedOffers, payTransactions, customer) {
|
|
24
|
+
function validateTransaction(transaction, acceptPayActions, authorizePaymentActions, authorizeEventServiceOfferActions, eventReservationAcceptedOffers, payTransactions, customer) {
|
|
27
25
|
// validateProfile(transaction);
|
|
28
26
|
validateProfile({ customer });
|
|
29
27
|
(0, validatePrice_1.validatePrice)(authorizePaymentActions, authorizeEventServiceOfferActions);
|
|
30
28
|
// 請求のreferencesOrder検証(2025-11-23~)
|
|
31
29
|
(0, validateInvoiceReferencesOrder_1.validateInvoiceReferencesOrder)(authorizePaymentActions, eventReservationAcceptedOffers);
|
|
32
|
-
// 利用可能な通貨単位に対して取引検証
|
|
33
|
-
validateMonetaryAmount(authorizePaymentActions, authorizeEventServiceOfferActions);
|
|
30
|
+
// // 利用可能な通貨単位に対して取引検証
|
|
31
|
+
// validateMonetaryAmount(authorizePaymentActions, authorizeEventServiceOfferActions); // discontinue(2026-07-06~)
|
|
34
32
|
// 利用可能なMovieTicketIF決済方法タイプに対して動的にコーディング
|
|
35
33
|
const movieTicketPaymentMethodTypes = findMovieTicketPaymentMethodTypesFromTransaction(authorizePaymentActions, eventReservationAcceptedOffers);
|
|
36
|
-
debug('processing validateMovieTicket... movieTicketPaymentMethodTypes:', movieTicketPaymentMethodTypes);
|
|
37
34
|
if (Array.isArray(movieTicketPaymentMethodTypes) && movieTicketPaymentMethodTypes.length > 0) {
|
|
38
35
|
movieTicketPaymentMethodTypes.forEach((paymentMethodType) => {
|
|
39
36
|
const authorizeMovieTicketActions = authorizePaymentActions.filter((a) => {
|
|
@@ -59,7 +56,6 @@ eventReservationAcceptedOffers, payTransactions, customer) {
|
|
|
59
56
|
authorizedMovieTickets.push(...object.paymentMethod.movieTickets);
|
|
60
57
|
}
|
|
61
58
|
});
|
|
62
|
-
debug(authorizedMovieTickets.length, 'movie tickets authorized', 'transaction:', transaction.id);
|
|
63
59
|
// validateMovieTicket(paymentMethodType, { id: transaction.id }, authorizePaymentActions, eventReservationAcceptedOffers);
|
|
64
60
|
(0, validateMovieTicket_1.validateMovieTicket)(paymentMethodType, { id: transaction.id }, authorizedMovieTickets, eventReservationAcceptedOffers);
|
|
65
61
|
});
|
|
@@ -95,18 +91,6 @@ function findMovieTicketPaymentMethodTypesFromTransaction(authorizePaymentAction
|
|
|
95
91
|
// ];
|
|
96
92
|
return [...new Set(paymentMethodTypes)];
|
|
97
93
|
}
|
|
98
|
-
// function validateProfile(transaction: Pick<factory.transaction.placeOrder.ITransaction, 'object'>) {
|
|
99
|
-
// // object.customerで検証(2022-05-26~)
|
|
100
|
-
// const profile = transaction.object.customer;
|
|
101
|
-
// const profileSatisfied = typeof profile?.typeOf === 'string' && profile.typeOf.length > 0
|
|
102
|
-
// && typeof profile.email === 'string' && profile.email.length > 0
|
|
103
|
-
// && typeof profile.familyName === 'string' && profile.familyName.length > 0
|
|
104
|
-
// && typeof profile.givenName === 'string' && profile.givenName.length > 0
|
|
105
|
-
// && typeof profile.telephone === 'string' && profile.telephone.length > 0;
|
|
106
|
-
// if (!profileSatisfied) {
|
|
107
|
-
// throw new factory.errors.Argument('Transaction', 'Customer Profile Required');
|
|
108
|
-
// }
|
|
109
|
-
// }
|
|
110
94
|
function validateProfile(params) {
|
|
111
95
|
const profile = params.customer;
|
|
112
96
|
const profileSatisfied = typeof profile?.typeOf === 'string' && profile.typeOf.length > 0
|
|
@@ -148,63 +132,63 @@ function validatePaymentUrl(transaction, acceptPayActions, authorizePaymentActio
|
|
|
148
132
|
}
|
|
149
133
|
}
|
|
150
134
|
}
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
}
|
|
135
|
+
// JPY以外の通貨決済はひとまず廃止(2026-07-06~)
|
|
136
|
+
// /**
|
|
137
|
+
// * JPY以外の通貨について取引を検証する
|
|
138
|
+
// */
|
|
139
|
+
// function validateMonetaryAmount(
|
|
140
|
+
// _authorizePaymentActions: IAuthorizePaymentAction[],
|
|
141
|
+
// authorizeEventServiceOfferActions: Pick<IAuthorizeEventServiceOffer, 'result'>[]
|
|
142
|
+
// ) {
|
|
143
|
+
// // PaymentCard決済を廃止したので、JPY以外の通貨に対しての承認はありえない(2026-04-18~)
|
|
144
|
+
// const authorizeMonetaryAmountActions: IAuthorizePaymentAction[] = [];
|
|
145
|
+
// const requiredMonetaryAmountByCurrencyType: {
|
|
146
|
+
// currency: string;
|
|
147
|
+
// value: number;
|
|
148
|
+
// }[] = [];
|
|
149
|
+
// authorizeEventServiceOfferActions.forEach(
|
|
150
|
+
// (a) => {
|
|
151
|
+
// const amount = a.result?.amount;
|
|
152
|
+
// if (Array.isArray(amount)) {
|
|
153
|
+
// amount.forEach((monetaryAmount) => {
|
|
154
|
+
// if (typeof monetaryAmount.value === 'number') {
|
|
155
|
+
// requiredMonetaryAmountByCurrencyType.push({ currency: monetaryAmount.currency, value: monetaryAmount.value });
|
|
156
|
+
// }
|
|
157
|
+
// });
|
|
158
|
+
// }
|
|
159
|
+
// },
|
|
160
|
+
// 0
|
|
161
|
+
// );
|
|
162
|
+
// const requiredCurrencyTypes = [...new Set(requiredMonetaryAmountByCurrencyType.map((m) => m.currency))];
|
|
163
|
+
// const authorizedCurrencyTypes = [...new Set(authorizeMonetaryAmountActions.map(({ result }) => {
|
|
164
|
+
// const resultAsInvoice = (Array.isArray(result))
|
|
165
|
+
// ? result[0]
|
|
166
|
+
// : undefined;
|
|
167
|
+
// return resultAsInvoice?.totalPaymentDue?.currency as string;
|
|
168
|
+
// }
|
|
169
|
+
// ))];
|
|
170
|
+
// if (requiredCurrencyTypes.length !== authorizedCurrencyTypes.length) {
|
|
171
|
+
// throw new factory.errors.Argument('Transaction', 'MonetaryAmount account types not matched');
|
|
172
|
+
// }
|
|
173
|
+
// const requireMonetaryAmountSatisfied = requiredCurrencyTypes.every((currencyType) => {
|
|
174
|
+
// const requiredMonetaryAmount = requiredMonetaryAmountByCurrencyType
|
|
175
|
+
// .filter((m) => m.currency === currencyType)
|
|
176
|
+
// .reduce((a, b) => a + b.value, 0);
|
|
177
|
+
// let authorizedMonetaryAmount = 0;
|
|
178
|
+
// authorizeMonetaryAmountActions.forEach(({ result }) => {
|
|
179
|
+
// const resultAsInvoice = (Array.isArray(result))
|
|
180
|
+
// ? result[0]
|
|
181
|
+
// : undefined;
|
|
182
|
+
// if (resultAsInvoice?.totalPaymentDue?.currency === currencyType) {
|
|
183
|
+
// authorizedMonetaryAmount += resultAsInvoice.totalPaymentDue.value;
|
|
184
|
+
// }
|
|
185
|
+
// });
|
|
186
|
+
// return requiredMonetaryAmount === authorizedMonetaryAmount;
|
|
187
|
+
// });
|
|
188
|
+
// if (!requireMonetaryAmountSatisfied) {
|
|
189
|
+
// throw new factory.errors.Argument('Transaction', 'Required MonetaryAmount not satisfied');
|
|
190
|
+
// }
|
|
191
|
+
// }
|
|
208
192
|
/**
|
|
209
193
|
* 注文オファー数検証
|
|
210
194
|
*/
|
|
@@ -257,7 +241,6 @@ function validateAcceptedOffers(params) {
|
|
|
257
241
|
});
|
|
258
242
|
if (ticketIdentifiers.length > 0) {
|
|
259
243
|
ticketIdentifiers = [...new Set(ticketIdentifiers)];
|
|
260
|
-
debug('ticketIdentifiers unique?', ticketIdentifiers.join(' '), 'numAcceptedOffers:', numAcceptedOffers);
|
|
261
244
|
// チケット識別子が注文内ユニークなので、注文オファー数に一致するはず
|
|
262
245
|
if (ticketIdentifiers.length !== numAcceptedOffers) {
|
|
263
246
|
throw new factory_1.factory.errors.Argument('Transaction', 'ticketIdentifiers must be unique');
|
|
@@ -274,7 +257,6 @@ function validateAcceptedOffers(params) {
|
|
|
274
257
|
});
|
|
275
258
|
if (ticketNumbers.length > 0) {
|
|
276
259
|
ticketNumbers = [...new Set(ticketNumbers)];
|
|
277
|
-
debug('ticketNumbers unique?', ticketNumbers.join(' '), 'numAcceptedOffers:', numAcceptedOffers);
|
|
278
260
|
// チケット識別子が注文内ユニークなので、注文オファー数に一致するはず
|
|
279
261
|
if (ticketNumbers.length !== numAcceptedOffers) {
|
|
280
262
|
throw new factory_1.factory.errors.Argument('Transaction', 'ticketNumbers must be unique');
|
|
@@ -313,6 +295,34 @@ function validatePaymentMethods(params, options) {
|
|
|
313
295
|
* 興行オファー適用条件確認
|
|
314
296
|
*/
|
|
315
297
|
function validateEventOffers(params) {
|
|
298
|
+
const { unitPriceOfferConditions } = params;
|
|
299
|
+
/**
|
|
300
|
+
* 以下処理で検証に使用するアクション結果リスト
|
|
301
|
+
*/
|
|
302
|
+
let validatingAuthorizeOfferActions;
|
|
303
|
+
// 承認アクションと比較する
|
|
304
|
+
if (Array.isArray(unitPriceOfferConditions)) {
|
|
305
|
+
const everyActionsMatched = unitPriceOfferConditions.length === params.authorizeOfferActions.length
|
|
306
|
+
&& params.authorizeOfferActions.every((authorizeEventServiceOfferAction) => {
|
|
307
|
+
const conditionExpected = unitPriceOfferConditions.find(({ id }) => id === authorizeEventServiceOfferAction.id);
|
|
308
|
+
const resultMatched = (0, util_1.isDeepStrictEqual)(conditionExpected?.result, authorizeEventServiceOfferAction.result);
|
|
309
|
+
debug('validateEventOffers: unitPriceOfferConditions: resultMatched?', resultMatched, params.project.id, authorizeEventServiceOfferAction.id);
|
|
310
|
+
if (!resultMatched) {
|
|
311
|
+
console.error('validateEventOffers: unitPriceOfferConditions not matched!', params.project.id, authorizeEventServiceOfferAction.id, conditionExpected?.result, authorizeEventServiceOfferAction.result);
|
|
312
|
+
}
|
|
313
|
+
return resultMatched;
|
|
314
|
+
});
|
|
315
|
+
// 全アクションについて結果が一致していればunitPriceOfferConditionsを採用する(2026-07-07~)
|
|
316
|
+
if (everyActionsMatched) {
|
|
317
|
+
validatingAuthorizeOfferActions = [...unitPriceOfferConditions];
|
|
318
|
+
}
|
|
319
|
+
else {
|
|
320
|
+
validatingAuthorizeOfferActions = [...params.authorizeOfferActions];
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
else {
|
|
324
|
+
validatingAuthorizeOfferActions = [...params.authorizeOfferActions];
|
|
325
|
+
}
|
|
316
326
|
const { paymentMethods } = params;
|
|
317
327
|
const firstCreditCardPaymentMethodIdentifier = paymentMethods.find((referenceInvoice) => {
|
|
318
328
|
return referenceInvoice.issuedThrough.typeOf === factory_1.factory.service.paymentService.PaymentServiceType.CreditCard
|
|
@@ -322,37 +332,44 @@ function validateEventOffers(params) {
|
|
|
322
332
|
return referenceInvoice.issuedThrough.typeOf === factory_1.factory.service.paymentService.PaymentServiceType.CreditCard
|
|
323
333
|
|| referenceInvoice.issuedThrough.typeOf === factory_1.factory.service.paymentService.PaymentServiceType.FaceToFace;
|
|
324
334
|
}).length;
|
|
325
|
-
|
|
335
|
+
validatingAuthorizeOfferActions.forEach((a) => {
|
|
326
336
|
// support result.offers(2024-06-18~)
|
|
327
337
|
const acceptedOffersInResult = a.result?.offers;
|
|
328
338
|
if (Array.isArray(acceptedOffersInResult) && acceptedOffersInResult.length > 0) {
|
|
329
339
|
acceptedOffersInResult.forEach((acceptedOfferInResult) => {
|
|
330
340
|
const offerId = acceptedOfferInResult.id;
|
|
331
341
|
const unitPriceSpec = acceptedOfferInResult.priceSpecification;
|
|
332
|
-
//
|
|
333
|
-
|
|
334
|
-
const
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
342
|
+
// 適用金額要件は廃止(2026-07-05~)
|
|
343
|
+
// // 適用金額要件を満たしていなければエラー
|
|
344
|
+
// const eligibleTransactionVolumePrice = unitPriceSpec?.eligibleTransactionVolume?.price;
|
|
345
|
+
// const eligibleTransactionVolumePriceCurrency = unitPriceSpec?.eligibleTransactionVolume?.priceCurrency;
|
|
346
|
+
// if (typeof eligibleTransactionVolumePrice === 'number') {
|
|
347
|
+
// if (params.order.price < eligibleTransactionVolumePrice) {
|
|
348
|
+
// throw new factory.errors.Argument(
|
|
349
|
+
// 'Transaction',
|
|
350
|
+
// format(
|
|
351
|
+
// 'Transaction volume must be more than or equal to %s %s for offer:%s',
|
|
352
|
+
// eligibleTransactionVolumePrice,
|
|
353
|
+
// eligibleTransactionVolumePriceCurrency,
|
|
354
|
+
// offerId
|
|
355
|
+
// )
|
|
356
|
+
// );
|
|
357
|
+
// }
|
|
358
|
+
// }
|
|
340
359
|
// 適用数量検証(全興行オファー承認アクションについて)(2023-11-15~)
|
|
341
360
|
// 適用数量要件を満たしていなければエラー
|
|
342
|
-
const numAcceptedOffersByOfferId =
|
|
361
|
+
const numAcceptedOffersByOfferId = validatingAuthorizeOfferActions.reduce((previousNumOffer, { result }) => {
|
|
343
362
|
const numOfferOnCurrentAction = result?.offers?.find(({ id }) => id === offerId)?.includesObject.amountOfThisGood;
|
|
344
363
|
return previousNumOffer + ((typeof numOfferOnCurrentAction === 'number') ? numOfferOnCurrentAction : 0);
|
|
345
364
|
}, 0);
|
|
346
365
|
const eligibleQuantityMaxValue = unitPriceSpec?.eligibleQuantity?.maxValue;
|
|
347
366
|
if (typeof eligibleQuantityMaxValue === 'number') {
|
|
348
|
-
debug('validateEventOffers: numAcceptedOffersByOfferId > eligibleQuantityMaxValue?', numAcceptedOffersByOfferId, eligibleQuantityMaxValue);
|
|
349
367
|
if (numAcceptedOffersByOfferId > eligibleQuantityMaxValue) {
|
|
350
368
|
throw new factory_1.factory.errors.Argument('Transaction', `Number of offer:${offerId} must be less than or equal to ${eligibleQuantityMaxValue}`);
|
|
351
369
|
}
|
|
352
370
|
}
|
|
353
371
|
const eligibleQuantityMinValue = unitPriceSpec?.eligibleQuantity?.minValue;
|
|
354
372
|
if (typeof eligibleQuantityMinValue === 'number') {
|
|
355
|
-
debug('validateEventOffers: numAcceptedOffersByOfferId < eligibleQuantityMinValue?', numAcceptedOffersByOfferId, eligibleQuantityMinValue);
|
|
356
373
|
if (numAcceptedOffersByOfferId < eligibleQuantityMinValue) {
|
|
357
374
|
throw new factory_1.factory.errors.Argument('Transaction', `Number of offer:${offerId} must be more than or equal to ${eligibleQuantityMinValue}`);
|
|
358
375
|
}
|
|
@@ -363,7 +380,6 @@ function validateEventOffers(params) {
|
|
|
363
380
|
const satisfyAcceptedPaymentMethod = numCreditCardOrFaceToFacePaymentMethod === 1
|
|
364
381
|
&& typeof firstCreditCardPaymentMethodIdentifier === 'string'
|
|
365
382
|
&& acceptedPaymentMethodTypes.includes(firstCreditCardPaymentMethodIdentifier);
|
|
366
|
-
debug('validateEventOffers: satisfyAcceptedPaymentMethod?', JSON.stringify(acceptedPaymentMethodTypes));
|
|
367
383
|
if (!satisfyAcceptedPaymentMethod) {
|
|
368
384
|
throw new factory_1.factory.errors.Argument('Transaction', `acceptedPaymentMethod requirement not satisfied`);
|
|
369
385
|
}
|
|
@@ -372,7 +388,7 @@ function validateEventOffers(params) {
|
|
|
372
388
|
}
|
|
373
389
|
});
|
|
374
390
|
// check programMembershipUsed(2024-08-15~)
|
|
375
|
-
const programMembershipRequired =
|
|
391
|
+
const programMembershipRequired = validatingAuthorizeOfferActions.reduce((a, b) => {
|
|
376
392
|
const programMembershipUsedfromResult = b.result?.itemOffered?.serviceOutput.programMembershipUsed;
|
|
377
393
|
if (Array.isArray(programMembershipUsedfromResult)) {
|
|
378
394
|
a.push(...programMembershipUsedfromResult);
|