@chevre/domain
Version:
Chevre Domain Library for Node.js
70 lines (69 loc) • 5.1 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.createStartParams = createStartParams;
/**
* 返金取引ファクトリー
*/
const factory = require("../../../factory");
function createStartParams(params) {
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
const { instrument } = params;
const paymentMethodType = (_a = params.object.paymentMethod) === null || _a === void 0 ? void 0 : _a.typeOf;
if (typeof paymentMethodType !== 'string') {
throw new factory.errors.ArgumentNull('object.paymentMethod.typeOf');
}
const paymentMethodId = (_b = params.object.paymentMethod) === null || _b === void 0 ? void 0 : _b.paymentMethodId;
if (typeof paymentMethodId !== 'string') {
throw new factory.errors.ArgumentNull('object.paymentMethod.paymentMethodId');
}
const additionalProperty = (_c = params.object.paymentMethod) === null || _c === void 0 ? void 0 : _c.additionalProperty;
const name = (_d = params.object.paymentMethod) === null || _d === void 0 ? void 0 : _d.name;
// const informPaymentParams = createInformPaymentParams({ paymentService: params.paymentService });
const accountId = (_f = (_e = params.payAction.object[0]) === null || _e === void 0 ? void 0 : _e.paymentMethod) === null || _f === void 0 ? void 0 : _f.accountId;
// 手数料は、CreditCardIFかつカード通貨区分が存在しない場合のみ設定すればよい
let refundFee;
if (((_g = params.paymentService) === null || _g === void 0 ? void 0 : _g.typeOf) === factory.service.paymentService.PaymentServiceType.CreditCard) {
// カード通貨区分の存在する決済サービスを考慮(2023-08-09~)
const invoiceAsServiceOutput = (Array.isArray(params.paymentService.serviceOutput))
? params.paymentService.serviceOutput.find((output) => (output === null || output === void 0 ? void 0 : output.typeOf) === 'Invoice')
: params.paymentService.serviceOutput;
let paymentServiceOutputAmountCurrency;
if ((invoiceAsServiceOutput === null || invoiceAsServiceOutput === void 0 ? void 0 : invoiceAsServiceOutput.typeOf) === 'Invoice') {
paymentServiceOutputAmountCurrency = (_j = (_h = invoiceAsServiceOutput === null || invoiceAsServiceOutput === void 0 ? void 0 : invoiceAsServiceOutput.paymentMethod) === null || _h === void 0 ? void 0 : _h.amount) === null || _j === void 0 ? void 0 : _j.currency;
}
if (typeof paymentServiceOutputAmountCurrency !== 'string') {
if (typeof params.object.refundFee === 'number') {
refundFee = params.object.refundFee;
}
}
}
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({ project: { typeOf: factory.organizationType.Project, id: params.project.id }, transactionNumber: params.transactionNumber, typeOf: factory.assetTransactionType.Refund, agent: params.agent, recipient: params.recipient, object: Object.assign({ accountId: (typeof accountId === 'string') ? accountId : '', paymentMethodId: paymentMethodId, typeOf: params.paymentServiceType, id: (Array.isArray(params.payAction.object) && params.payAction.object.length > 0)
? params.payAction.object[0].id
: '',
// onPaymentStatusChanged: { informPayment: params.informActions }, // discontinue(2025-02-09~)
paymentMethod: Object.assign({ additionalProperty: (Array.isArray(additionalProperty)) ? additionalProperty : [], name: (typeof name === 'string') ? name : paymentMethodType, paymentMethodId: paymentMethodId, typeOf: paymentMethodType }, (Array.isArray(params.payAction.object) && params.payAction.object.length > 0)
? { totalPaymentDue: params.payAction.object[0].paymentMethod.totalPaymentDue }
: undefined) }, (typeof refundFee === 'number') ? { refundFee } : undefined), expires: params.expires, instrument: (Array.isArray(instrument)) ? instrument : [] }, (potentialAction.length > 0) ? { potentialAction } : undefined // add potentialAction(2025-02-05~)
);
}
// function createInformPaymentParams(params: {
// paymentService?: factory.product.IProduct
// | {
// availableChannel?: Pick<factory.service.paymentService.IAvailableChannel, 'onPaymentStatusChanged'>;
// potentialAction?: factory.service.paymentService.IPotentialAction;
// };
// }): factory.product.IInformPayment[] {
// const informPaymentParams: factory.product.IInformPayment[] = [];
// // プロダクト設定を適用
// const informPaymentParamsByProduct = params.paymentService?.availableChannel?.onPaymentStatusChanged?.informPayment;
// if (Array.isArray(informPaymentParamsByProduct)) {
// informPaymentParams.push(...informPaymentParamsByProduct);
// }
// return informPaymentParams;
// }
;