@chevre/domain 25.2.0-alpha.2 → 25.2.0-alpha.3
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/transaction/placeOrder/confirm/prepareUnitPriceOfferConditions.d.ts +17 -0
- package/lib/chevre/service/transaction/placeOrder/confirm/prepareUnitPriceOfferConditions.js +116 -0
- package/lib/chevre/service/transaction/placeOrder/confirm/validation.d.ts +4 -1
- package/lib/chevre/service/transaction/placeOrder/confirm.d.ts +2 -0
- package/lib/chevre/service/transaction/placeOrder/confirm.js +9 -0
- package/package.json +1 -1
package/lib/chevre/service/transaction/placeOrder/confirm/prepareUnitPriceOfferConditions.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
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
|
+
declare function prepareUnitPriceOfferConditions(params: {
|
|
9
|
+
project: {
|
|
10
|
+
id: string;
|
|
11
|
+
};
|
|
12
|
+
acceptedOffers: IOrderAcceptedOffer[];
|
|
13
|
+
authorizeEventServiceOfferActions: IAuthorizeEventServiceOffer[];
|
|
14
|
+
}): (repos: {
|
|
15
|
+
offer: OfferRepo;
|
|
16
|
+
}) => Promise<Pick<IAuthorizeEventServiceOffer, "id" | "result">[]>;
|
|
17
|
+
export { prepareUnitPriceOfferConditions };
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createAuthorizeOfferResultsExpected = createAuthorizeOfferResultsExpected;
|
|
4
|
+
exports.prepareUnitPriceOfferConditions = prepareUnitPriceOfferConditions;
|
|
5
|
+
const util_1 = require("util");
|
|
6
|
+
const factory_1 = require("../../../../factory");
|
|
7
|
+
function acceptedOffers2authorizeResult(params) {
|
|
8
|
+
const { acceptedOffers4result, unitPriceOffers } = params;
|
|
9
|
+
const programMembershipUsed = acceptedOffers2programMembershipUsed({ acceptedOffers: acceptedOffers4result });
|
|
10
|
+
// オファーIDごとに集計
|
|
11
|
+
const offerIds = [...new Set(acceptedOffers4result.map((o) => String(o.id)))];
|
|
12
|
+
const offers = offerIds.map((offerId) => {
|
|
13
|
+
const acceptedOffer = unitPriceOffers.find(({ id }) => id === offerId);
|
|
14
|
+
if (acceptedOffer === undefined) {
|
|
15
|
+
throw new factory_1.factory.errors.Internal(`acceptedOffer not found [id:${offerId}]`);
|
|
16
|
+
}
|
|
17
|
+
const amountOfThisGood = acceptedOffers4result.filter(({ id }) => id === offerId).length;
|
|
18
|
+
const { acceptedPaymentMethod, priceSpecification } = acceptedOffer;
|
|
19
|
+
const unitPriceSpec = priceSpecification;
|
|
20
|
+
if (unitPriceSpec === undefined) {
|
|
21
|
+
throw new factory_1.factory.errors.Internal(`unitPriceSpec not found [id:${offerId}]`);
|
|
22
|
+
}
|
|
23
|
+
const { eligibleQuantity } = unitPriceSpec;
|
|
24
|
+
return {
|
|
25
|
+
id: offerId,
|
|
26
|
+
includesObject: { amountOfThisGood },
|
|
27
|
+
typeOf: factory_1.factory.offerType.Offer,
|
|
28
|
+
priceSpecification: {
|
|
29
|
+
...(eligibleQuantity !== undefined) ? { eligibleQuantity } : undefined,
|
|
30
|
+
},
|
|
31
|
+
...(acceptedPaymentMethod !== undefined) ? { acceptedPaymentMethod } : undefined
|
|
32
|
+
};
|
|
33
|
+
});
|
|
34
|
+
return {
|
|
35
|
+
amount: [],
|
|
36
|
+
itemOffered: {
|
|
37
|
+
serviceOutput: { programMembershipUsed } // add programMembershipUsed required(2024-08-15~)
|
|
38
|
+
},
|
|
39
|
+
offers
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
function acceptedOffers2programMembershipUsed(params) {
|
|
43
|
+
const programMembershipUsed = [];
|
|
44
|
+
const permitIdentifiers = [];
|
|
45
|
+
params.acceptedOffers.forEach(({ itemOffered }) => {
|
|
46
|
+
if (itemOffered.programMembershipUsed?.typeOf === factory_1.factory.programMembership.ProgramMembershipType.ProgramMembership) {
|
|
47
|
+
// メンバーシップコードに対してユニークに集計
|
|
48
|
+
if (!permitIdentifiers.includes(itemOffered.programMembershipUsed.identifier)) {
|
|
49
|
+
permitIdentifiers.push(itemOffered.programMembershipUsed.identifier);
|
|
50
|
+
const issuedThroughTypeOf = itemOffered.programMembershipUsed.issuedThrough.typeOf;
|
|
51
|
+
if (issuedThroughTypeOf === factory_1.factory.service.paymentService.PaymentServiceType.FaceToFace) {
|
|
52
|
+
programMembershipUsed.push({
|
|
53
|
+
typeOf: factory_1.factory.permit.PermitType.Permit,
|
|
54
|
+
identifier: itemOffered.programMembershipUsed.identifier,
|
|
55
|
+
issuedThrough: { typeOf: issuedThroughTypeOf }
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
programMembershipUsed.push({
|
|
60
|
+
typeOf: factory_1.factory.permit.PermitType.Permit,
|
|
61
|
+
identifier: itemOffered.programMembershipUsed.identifier,
|
|
62
|
+
issuedThrough: { typeOf: issuedThroughTypeOf, id: itemOffered.programMembershipUsed.issuedThrough.id }
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
return programMembershipUsed;
|
|
69
|
+
}
|
|
70
|
+
function createAuthorizeOfferResultsExpected(params) {
|
|
71
|
+
return params.authorizeEventServiceOfferActions.map((a) => {
|
|
72
|
+
return {
|
|
73
|
+
id: a.id,
|
|
74
|
+
result: a.result
|
|
75
|
+
};
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
function prepareUnitPriceOfferConditions(params) {
|
|
79
|
+
return async (repos) => {
|
|
80
|
+
const conditions = [];
|
|
81
|
+
const offerIds = [...new Set(params.acceptedOffers.map((o) => String(o.id)))];
|
|
82
|
+
const unitPriceOffers = await repos.offer.search({
|
|
83
|
+
id: { $in: offerIds }
|
|
84
|
+
});
|
|
85
|
+
for (const authorizeEventServiceOfferAction of params.authorizeEventServiceOfferActions) {
|
|
86
|
+
if (authorizeEventServiceOfferAction.result === undefined) {
|
|
87
|
+
throw new Error('authorizeEventServiceOfferAction.result should exist');
|
|
88
|
+
}
|
|
89
|
+
const acceptedOffers4action = params.acceptedOffers.filter(((offer) => {
|
|
90
|
+
return offer.serialNumber === authorizeEventServiceOfferAction.instrument.transactionNumber;
|
|
91
|
+
}));
|
|
92
|
+
conditions.push({
|
|
93
|
+
id: authorizeEventServiceOfferAction.id,
|
|
94
|
+
result: {
|
|
95
|
+
typeOf: authorizeEventServiceOfferAction.result.typeOf,
|
|
96
|
+
priceCurrency: authorizeEventServiceOfferAction.result.priceCurrency,
|
|
97
|
+
price: authorizeEventServiceOfferAction.result.price,
|
|
98
|
+
...acceptedOffers2authorizeResult({
|
|
99
|
+
acceptedOffers4result: acceptedOffers4action,
|
|
100
|
+
unitPriceOffers
|
|
101
|
+
})
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
// 承認アクションと比較する
|
|
106
|
+
for (const authorizeEventServiceOfferAction of params.authorizeEventServiceOfferActions) {
|
|
107
|
+
const conditionExpected = conditions.find(({ id }) => id === authorizeEventServiceOfferAction.id);
|
|
108
|
+
const resultMatched = (0, util_1.isDeepStrictEqual)(conditionExpected?.result, authorizeEventServiceOfferAction.result);
|
|
109
|
+
console.log('resultMatched?', resultMatched, authorizeEventServiceOfferAction.id, authorizeEventServiceOfferAction.instrument.transactionNumber);
|
|
110
|
+
if (!resultMatched) {
|
|
111
|
+
console.log(conditionExpected?.result, authorizeEventServiceOfferAction.result);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
return conditions;
|
|
115
|
+
};
|
|
116
|
+
}
|
|
@@ -39,5 +39,8 @@ export declare function validateEventOffers(params: {
|
|
|
39
39
|
price: number;
|
|
40
40
|
};
|
|
41
41
|
paymentMethods: factory.order.IReferencedInvoice[];
|
|
42
|
-
|
|
42
|
+
/**
|
|
43
|
+
* 承認アクションのresultに条件が保管されているはず(2026-07-06時点で)
|
|
44
|
+
*/
|
|
45
|
+
authorizeEventServiceOfferActions: Pick<IAuthorizeEventServiceOffer, 'id' | 'result'>[];
|
|
43
46
|
}): void;
|
|
@@ -5,6 +5,7 @@ import type { AssetTransactionRepo } from '../../../repo/assetTransaction';
|
|
|
5
5
|
import type { AuthorizationRepo } from '../../../repo/authorization';
|
|
6
6
|
import type { ConfirmationNumberRepo } from '../../../repo/confirmationNumber';
|
|
7
7
|
import type { MessageRepo } from '../../../repo/message';
|
|
8
|
+
import type { OfferRepo } from '../../../repo/offer/unitPriceInCatalog';
|
|
8
9
|
import type { OrderInTransactionRepo } from '../../../repo/orderInTransaction';
|
|
9
10
|
import type { ProjectRepo } from '../../../repo/project';
|
|
10
11
|
import type { SettingRepo } from '../../../repo/setting';
|
|
@@ -19,6 +20,7 @@ interface IConfirmOperationRepos {
|
|
|
19
20
|
assetTransaction: AssetTransactionRepo;
|
|
20
21
|
authorization: AuthorizationRepo;
|
|
21
22
|
message: MessageRepo;
|
|
23
|
+
offer: OfferRepo;
|
|
22
24
|
project: ProjectRepo;
|
|
23
25
|
placeOrder: PlaceOrderRepo;
|
|
24
26
|
orderInTransaction: OrderInTransactionRepo;
|
|
@@ -12,6 +12,7 @@ const factory_2 = require("../../order/placeOrder/factory");
|
|
|
12
12
|
const orderedItem_1 = require("../../order/placeOrder/factory/orderedItem");
|
|
13
13
|
const result_1 = require("./confirm/factory/result");
|
|
14
14
|
const potentialActions_1 = require("./confirm/potentialActions");
|
|
15
|
+
const prepareUnitPriceOfferConditions_1 = require("./confirm/prepareUnitPriceOfferConditions");
|
|
15
16
|
const publishCode_1 = require("./confirm/publishCode");
|
|
16
17
|
const validation_1 = require("./confirm/validation");
|
|
17
18
|
const publishConfirmationNumberIfNotExist_1 = require("./publishConfirmationNumberIfNotExist");
|
|
@@ -114,6 +115,14 @@ function confirm(params, options) {
|
|
|
114
115
|
project: { id: transaction.project.id }
|
|
115
116
|
}))
|
|
116
117
|
.filter(({ serialNumber }) => typeof serialNumber === 'string' && serialNumbers.includes(serialNumber));
|
|
118
|
+
// 単価オファーの全適用条件を検証するために、単価オファーを参照(2026-07-06~)
|
|
119
|
+
if (transaction.project.id === 'cinerino') {
|
|
120
|
+
await (0, prepareUnitPriceOfferConditions_1.prepareUnitPriceOfferConditions)({
|
|
121
|
+
project: { id: transaction.project.id, },
|
|
122
|
+
acceptedOffers,
|
|
123
|
+
authorizeEventServiceOfferActions
|
|
124
|
+
})({ offer: repos.offer });
|
|
125
|
+
}
|
|
117
126
|
// authorizePaymentActionsからpayTransactionsを参照(2024-06-20~)
|
|
118
127
|
let payTransactions = [];
|
|
119
128
|
// 決済承認アクションのinstrument依存をobject依存へ変更(2025-12-14~)
|
package/package.json
CHANGED