@chevre/domain
Version:
Chevre Domain Library for Node.js
166 lines (165 loc) • 10.6 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.createPayObjectServiceOutput = createPayObjectServiceOutput;
const factory = require("../../../factory");
/**
* PayAction.object.serviceOutputを作成する
* 決済カード決済の場合のみ、対象予約情報をserviceOutputに持つ決済カード情報として存在する
*/
function createPayObjectServiceOutput(params) {
const transaction = params.transaction;
const paymentMethod = transaction.object.paymentMethod;
const order = params.order;
let paymentServiceOutput;
switch (transaction.object.typeOf) {
case factory.service.paymentService.PaymentServiceType.FaceToFace:
case factory.service.paymentService.PaymentServiceType.PaymentCard:
case factory.service.paymentService.PaymentServiceType.CreditCard:
break;
case factory.service.paymentService.PaymentServiceType.MovieTicket:
const paymentMethodType = paymentMethod === null || paymentMethod === void 0 ? void 0 : paymentMethod.identifier;
const movieTickets = paymentMethod === null || paymentMethod === void 0 ? void 0 : paymentMethod.movieTickets;
if (Array.isArray(movieTickets)) {
paymentServiceOutput = movieTickets.map((movieTicket) => {
var _a;
const { amount, additionalProperty } = checkResult2movieTicket(movieTicket, params.checkResult);
const reservation4invoice = movieTicket2reservation4invoice(movieTicket, order, String(paymentMethodType), transaction.transactionNumber);
return Object.assign(Object.assign({ identifier: movieTicket.identifier, additionalProperty }, (typeof (amount === null || amount === void 0 ? void 0 : amount.value) === 'number') ? { amount } : undefined), (typeof ((_a = reservation4invoice.priceSpecification) === null || _a === void 0 ? void 0 : _a.typeOf) === 'string')
? { serviceOutput: reservation4invoice }
: undefined);
});
}
break;
default:
throw new factory.errors.NotImplemented(`Payment service "${transaction.object.typeOf}" not implemented.`);
}
return paymentServiceOutput;
}
function checkResult2movieTicket(
// transaction: Pick<factory.assetTransaction.ITransaction<factory.assetTransactionType.Pay>, 'object'>,
movieTicket, checkResult) {
var _a, _b;
const additionalProperty = [];
let amount;
// accountsReceivablesByServiceTypeへの依存をactionRecipeへ移行(2024-12-16~)
const purchaseNumberInfo = (_a = checkResult === null || checkResult === void 0 ? void 0 : checkResult.purchaseNumberAuthResult.knyknrNoInfoOut) === null || _a === void 0 ? void 0 : _a.find(({ knyknrNo }) => knyknrNo === movieTicket.identifier);
const ykknInfoOfServiceType = (_b = purchaseNumberInfo === null || purchaseNumberInfo === void 0 ? void 0 : purchaseNumberInfo.ykknInfo) === null || _b === void 0 ? void 0 : _b.find((ykknInfo) => ykknInfo.ykknshTyp === movieTicket.serviceType);
const kijUnip = ykknInfoOfServiceType === null || ykknInfoOfServiceType === void 0 ? void 0 : ykknInfoOfServiceType.kijUnip;
if (typeof kijUnip === 'string') {
amount = {
typeOf: 'MonetaryAmount',
value: Number(kijUnip)
};
}
additionalProperty.push(...(typeof kijUnip === 'string') ? [{ name: 'kijUnip', value: kijUnip }] : [], ...(typeof (purchaseNumberInfo === null || purchaseNumberInfo === void 0 ? void 0 : purchaseNumberInfo.dnshKmTyp) === 'string') ? [{ name: 'dnshKmTyp', value: purchaseNumberInfo.dnshKmTyp }] : []
// ...(typeof purchaseNumberInfo?.znkkkytsknGkjknTyp === 'string')
// ? [{ name: 'znkkkytsknGkjknTyp', value: purchaseNumberInfo.znkkkytsknGkjknTyp }]
// : []
);
// const accountsReceivables = transaction.object.accountsReceivablesByServiceType;
// if (Array.isArray(accountsReceivables)) {
// const accountsReceivable = accountsReceivables.find((a) => a.serviceType === movieTicket.serviceType)?.accountsReceivable;
// if (typeof accountsReceivable === 'number') {
// amount = {
// typeOf: 'MonetaryAmount',
// value: accountsReceivable
// };
// }
// }
return { additionalProperty, amount };
}
function reservationPriceComponent2invoicePriceComponent(component) {
var _a;
const accounting = (typeof ((_a = component.accounting) === null || _a === void 0 ? void 0 : _a.accountsReceivable) === 'number')
? { accountsReceivable: component.accounting.accountsReceivable }
: undefined;
let minimizedUnitPriceSpec;
let minimizedMovieTicketTypeChargeSpec;
let minimizedCategoryCodeChargeSpec;
if (component.typeOf === factory.priceSpecificationType.UnitPriceSpecification) {
const appliesToAddOn = (Array.isArray(component.appliesToAddOn))
? component.appliesToAddOn.map((addOn) => {
return { typeOf: addOn.typeOf };
})
: undefined;
minimizedUnitPriceSpec = Object.assign(Object.assign({ typeOf: component.typeOf, price: component.price, referenceQuantity: component.referenceQuantity }, (Array.isArray(appliesToAddOn)) ? { appliesToAddOn } : undefined), (typeof (accounting === null || accounting === void 0 ? void 0 : accounting.accountsReceivable) === 'number') ? { accounting } : undefined);
}
else if (component.typeOf === factory.priceSpecificationType.MovieTicketTypeChargeSpecification) {
minimizedMovieTicketTypeChargeSpec = Object.assign({ typeOf: component.typeOf, price: component.price,
// 適用決済方法区分を追加(2023-03-29~)
appliesToMovieTicket: {
serviceOutput: {
typeOf: component.appliesToMovieTicket.serviceOutput.typeOf
}
} }, (typeof (accounting === null || accounting === void 0 ? void 0 : accounting.accountsReceivable) === 'number') ? { accounting } : undefined);
}
else {
minimizedCategoryCodeChargeSpec = Object.assign({ typeOf: component.typeOf, price: component.price }, (typeof (accounting === null || accounting === void 0 ? void 0 : accounting.accountsReceivable) === 'number') ? { accounting } : undefined);
}
if (minimizedUnitPriceSpec !== undefined) {
return minimizedUnitPriceSpec;
}
else if (minimizedMovieTicketTypeChargeSpec !== undefined) {
return minimizedMovieTicketTypeChargeSpec;
}
else if (minimizedCategoryCodeChargeSpec !== undefined) {
return minimizedCategoryCodeChargeSpec;
}
else {
throw new factory.errors.NotImplemented(`unexpected priceComponent: ${component.typeOf}`);
}
}
/**
* 決済カードの対象予約情報を作成する
*/
function movieTicket2reservation4invoice(movieTicket, order, paymentMethodType, payTransactionNumber) {
var _a;
// Orderから対象予約を取得
const reservationOffer = order.acceptedOffersMovieTicketUsed.find(({ itemOffered, priceSpecification }) => {
var _a, _b;
let mvtkUnitPriceSpec;
// MovieTicket適用単価オファーからidentifierを取り出す
if ((priceSpecification === null || priceSpecification === void 0 ? void 0 : priceSpecification.typeOf) === factory.priceSpecificationType.CompoundPriceSpecification) {
// 適用購入管理番号が一致、かつ、決済方法区分が一致、の単価仕様を検索
mvtkUnitPriceSpec = (_a = priceSpecification === null || priceSpecification === void 0 ? void 0 : priceSpecification.priceComponent) === null || _a === void 0 ? void 0 : _a.find((p) => {
return p.typeOf === factory.priceSpecificationType.UnitPriceSpecification
&& Array.isArray(p.appliesToMovieTicket)
&& p.appliesToMovieTicket.some((appliesToMovieTicket) => {
return appliesToMovieTicket.identifier === movieTicket.identifier
&& appliesToMovieTicket.serviceOutput.typeOf === paymentMethodType;
});
});
}
let isMovieTicketServiceOutput = mvtkUnitPriceSpec !== undefined
&& itemOffered.reservationFor.id === movieTicket.serviceOutput.reservationFor.id
&& ((_b = itemOffered.reservedTicket.ticketedSeat) === null || _b === void 0 ? void 0 : _b.seatNumber) === movieTicket.serviceOutput.reservedTicket.ticketedSeat.seatNumber
&& itemOffered.reservedTicket.ticketedSeat.seatSection === movieTicket.serviceOutput.reservedTicket.ticketedSeat.seatSection;
// チケット識別子で照合(2024-04-17~)
isMovieTicketServiceOutput = isMovieTicketServiceOutput
&& typeof itemOffered.reservedTicket.identifier === 'string'
&& itemOffered.reservedTicket.identifier === movieTicket.serviceOutput.reservedTicket.identifier;
return isMovieTicketServiceOutput;
});
// 対象予約は存在必須(2024-04-17~)
if (reservationOffer === undefined) {
throw new factory.errors.NotFound(factory.offerType.Offer, `acceptedOffer for the movieTicket not found at movieTicket2reservation4invoice. [movieTicket.identifier:${movieTicket.identifier} movieTicket.serviceType:${movieTicket.serviceType} paymentMethodType:${paymentMethodType} payTransactionNumber:${payTransactionNumber}]`);
}
/**
* COAの場合のみ予約のチケットトークンが存在
*/
let ticketToken;
const ticketTokenByReservationOffer = reservationOffer.itemOffered.reservedTicket.ticketToken;
if (typeof ticketTokenByReservationOffer === 'string' && ticketTokenByReservationOffer.length > 0) {
ticketToken = ticketTokenByReservationOffer;
}
const reservationNumber = reservationOffer.itemOffered.reservationNumber;
let priceComponents4invoice = [];
const priceComponent = (_a = reservationOffer.priceSpecification) === null || _a === void 0 ? void 0 : _a.priceComponent;
if (Array.isArray(priceComponent)) {
priceComponents4invoice = priceComponent.map(reservationPriceComponent2invoicePriceComponent);
}
return Object.assign({ priceSpecification: {
typeOf: factory.priceSpecificationType.CompoundPriceSpecification,
priceComponent: priceComponents4invoice
}, reservationNumber }, (typeof ticketToken === 'string') ? { reservedTicket: { ticketToken } } : undefined);
}
;