UNPKG

@chevre/domain

Version:

Chevre Domain Library for Node.js

137 lines (136 loc) 9.62 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.createStartParams = createStartParams; /** * 決済取引ファクトリー */ const factory = require("../../../factory"); // tslint:disable-next-line:cyclomatic-complexity max-func-body-length function createStartParams(params, options) { var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0; const { instrument } = params; const paymentServiceId = (params.paymentService !== undefined) ? String(params.paymentService.id) : ''; const paymentMethodType = (params.paymentService !== undefined) // FaceToFace以外は、プロダクトから決済方法タイプを自動取得 ? (_a = params.paymentService.serviceType) === null || _a === void 0 ? void 0 : _a.codeValue : (_b = params.object.paymentMethod) === null || _b === void 0 ? void 0 : _b.identifier; if (typeof paymentMethodType !== 'string') { throw new factory.errors.ArgumentNull('object.paymentMethod.identifier'); } let totalPaymentDue; let accountId = (_c = params.object.paymentMethod) === null || _c === void 0 ? void 0 : _c.accountId; switch (params.paymentServiceType) { case factory.service.paymentService.PaymentServiceType.FaceToFace: // 対面決済ではとりあえず問答無用にJPY totalPaymentDue = { typeOf: 'MonetaryAmount', currency: factory.priceCurrency.JPY, value: params.amount }; break; case factory.service.paymentService.PaymentServiceType.CreditCard: totalPaymentDue = { typeOf: 'MonetaryAmount', currency: factory.priceCurrency.JPY, value: params.amount }; accountId = ''; // 強制的に空文字化(2024-06-14~) break; case factory.service.paymentService.PaymentServiceType.MovieTicket: const specifiedMovieTickets = (_d = params.object.paymentMethod) === null || _d === void 0 ? void 0 : _d.movieTickets; totalPaymentDue = { typeOf: 'MonetaryAmount', currency: factory.unitCode.C62, value: (Array.isArray(specifiedMovieTickets)) ? specifiedMovieTickets.length : 0 }; // MovieTicketIFの決済取引において最大同時着券数を設定可能にする(2023-03-27~) const totalPaymentDueMaxValue = (_g = (_f = (_e = params.paymentService) === null || _e === void 0 ? void 0 : _e.availableChannel) === null || _f === void 0 ? void 0 : _f.totalPaymentDue) === null || _g === void 0 ? void 0 : _g.maxValue; const totalPaymentDueValue = totalPaymentDue.value; if (typeof totalPaymentDueValue === 'number' && typeof totalPaymentDueMaxValue === 'number') { if (totalPaymentDueValue > totalPaymentDueMaxValue) { throw new factory.errors.Argument('paymentMethod.movieTickets', `Number of movieTickets must be less than or equal to ${totalPaymentDueMaxValue}`); } } // 強制的にidentifierで上書き(2024-06-14~) accountId = (Array.isArray(specifiedMovieTickets) && specifiedMovieTickets.length > 0) ? specifiedMovieTickets[0].identifier // 決済カードidentifierは1つのみ許可の前提 : ''; break; default: // no op } // const informPaymentParams = createInformPaymentParams({ // paymentService: <factory.service.paymentService.IService | undefined>params.paymentService // }); // currencyはデフォルトでJPY let paymentMethodCurrency = factory.priceCurrency.JPY; if (params.paymentServiceType === factory.service.paymentService.PaymentServiceType.PaymentCard) { const paymentCardServiceOutputCurrency = (_k = (_j = (_h = params.paymentService) === null || _h === void 0 ? void 0 : _h.serviceOutput) === null || _j === void 0 ? void 0 : _j.amount) === null || _k === void 0 ? void 0 : _k.currency; if (typeof paymentCardServiceOutputCurrency === 'string') { paymentMethodCurrency = paymentCardServiceOutputCurrency; } } else if (params.paymentServiceType === factory.service.paymentService.PaymentServiceType.CreditCard) { const creditCardPaymentServiceOutput = (_l = params.paymentService) === null || _l === void 0 ? void 0 : _l.serviceOutput; const invoiceAsServiceOutput = (Array.isArray(creditCardPaymentServiceOutput)) ? creditCardPaymentServiceOutput.find((output) => (output === null || output === void 0 ? void 0 : output.typeOf) === 'Invoice') : creditCardPaymentServiceOutput; // カード通貨区分が存在すれば適用 if ((invoiceAsServiceOutput === null || invoiceAsServiceOutput === void 0 ? void 0 : invoiceAsServiceOutput.typeOf) === 'Invoice') { const creditCardAsPaymentServiceOutputCurrency = (_o = (_m = invoiceAsServiceOutput.paymentMethod) === null || _m === void 0 ? void 0 : _m.amount) === null || _o === void 0 ? void 0 : _o.currency; if (typeof creditCardAsPaymentServiceOutputCurrency === 'string') { paymentMethodCurrency = creditCardAsPaymentServiceOutputCurrency; } } } const paymentMethodAmount = { typeOf: 'MonetaryAmount', currency: paymentMethodCurrency, value: params.amount }; const paymentMethod = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ additionalProperty: (Array.isArray((_p = params.object.paymentMethod) === null || _p === void 0 ? void 0 : _p.additionalProperty)) ? (_q = params.object.paymentMethod) === null || _q === void 0 ? void 0 : _q.additionalProperty : [], name: (typeof ((_r = params.object.paymentMethod) === null || _r === void 0 ? void 0 : _r.name) === 'string') ? params.object.paymentMethod.name : paymentMethodType, amount: paymentMethodAmount, identifier: paymentMethodType }, (typeof ((_s = params.object.paymentMethod) === null || _s === void 0 ? void 0 : _s.description) === 'string') ? { description: (_t = params.object.paymentMethod) === null || _t === void 0 ? void 0 : _t.description } : undefined), (totalPaymentDue !== undefined) ? { totalPaymentDue: totalPaymentDue } : undefined), (typeof accountId === 'string') ? { accountId: accountId } : undefined), (typeof ((_u = params.object.paymentMethod) === null || _u === void 0 ? void 0 : _u.method) === 'string') ? { method: (_v = params.object.paymentMethod) === null || _v === void 0 ? void 0 : _v.method } : undefined), (((_w = params.object.paymentMethod) === null || _w === void 0 ? void 0 : _w.creditCard) !== undefined) ? { creditCard: (_x = params.object.paymentMethod) === null || _x === void 0 ? void 0 : _x.creditCard } : undefined), (Array.isArray((_y = params.object.paymentMethod) === null || _y === void 0 ? void 0 : _y.movieTickets)) ? { movieTickets: (_z = params.object.paymentMethod) === null || _z === void 0 ? void 0 : _z.movieTickets } : undefined), (params.paymentServiceType === factory.service.paymentService.PaymentServiceType.CreditCard) ? { paymentMethodId: params.transactionNumber } // 必要ないはずだが互換性維持対応(2024-06-14~) : undefined); const object = Object.assign({ accountId: (typeof accountId === 'string') ? accountId : '', paymentMethodId: params.transactionNumber, typeOf: params.paymentServiceType, id: paymentServiceId, // onPaymentStatusChanged: { informPayment: params.informActions }, // discontinue(2025-02-09~) paymentMethod }, (params.paymentServiceType === factory.service.paymentService.PaymentServiceType.MovieTicket) ? { checkedAction: { id: options.checkedAction.id } } // add checkedAction(2024-12-13~) : undefined); const potentialAction = []; params.informActions.forEach((informAction) => { if (typeof informAction.id === 'string' && informAction.id !== '') { potentialAction.push({ id: informAction.id, typeOf: factory.actionType.InformAction }); } }); return Object.assign(Object.assign({ project: { typeOf: factory.organizationType.Project, id: params.project.id }, transactionNumber: params.transactionNumber, typeOf: factory.assetTransactionType.Pay, agent: params.agent, recipient: params.recipient, object, expires: params.expires, instrument: (Array.isArray(instrument)) ? instrument : [] }, (typeof ((_0 = params.location) === null || _0 === void 0 ? void 0 : _0.typeOf) === 'string') ? { location: params.location } : undefined), (potentialAction.length > 0) ? { potentialAction } : undefined // add potentialAction(2025-02-05~) ); } // function createInformPaymentParams(params: { // paymentService?: Pick<factory.service.paymentService.IService, 'availableChannel' | 'potentialAction'>; // }): factory.product.IInformPayment[] { // const informPaymentParams: factory.product.IInformPayment[] = []; // // プロダクト設定を適用 // const informPaymentParamsByProduct = params.paymentService?.availableChannel?.onPaymentStatusChanged?.informPayment; // if (Array.isArray(informPaymentParamsByProduct)) { // informPaymentParams.push(...informPaymentParamsByProduct); // } // return informPaymentParams; // }