@lomray/microservice-payment-stripe
Version:
Stripe payment microservice based on NodeJS & inverted json.
113 lines (109 loc) • 4.63 kB
JavaScript
;
var tslib = require('tslib');
var microserviceHelpers = require('@lomray/microservice-helpers');
var fromSmallestUnit = require('@lomray/microservices-client-api/helpers/parsers/from-smallest-unit');
var toSmallestUnit = require('@lomray/microservices-client-api/helpers/parsers/to-smallest-unit');
var classValidator = require('class-validator');
var classValidatorJsonschema = require('class-validator-jsonschema');
var transactionRole = require('../../constants/transaction-role.js');
var calculation = require('../../services/common/calculation.js');
class PaymentIntentFeesInput {
}
tslib.__decorate([
classValidator.IsNumber(),
tslib.__metadata("design:type", Number)
], PaymentIntentFeesInput.prototype, "entityCost", void 0);
tslib.__decorate([
classValidator.IsEnum(transactionRole),
microserviceHelpers.IsUndefinable(),
tslib.__metadata("design:type", String)
], PaymentIntentFeesInput.prototype, "feesPayer", void 0);
tslib.__decorate([
classValidator.IsNumber(),
microserviceHelpers.IsUndefinable(),
tslib.__metadata("design:type", Number)
], PaymentIntentFeesInput.prototype, "applicationPaymentPercent", void 0);
tslib.__decorate([
classValidator.IsNumber(),
microserviceHelpers.IsUndefinable(),
tslib.__metadata("design:type", Object)
], PaymentIntentFeesInput.prototype, "additionalFeesPercent", void 0);
tslib.__decorate([
classValidator.IsNumber(),
microserviceHelpers.IsUndefinable(),
tslib.__metadata("design:type", Number)
], PaymentIntentFeesInput.prototype, "extraReceiverRevenuePercent", void 0);
tslib.__decorate([
classValidatorJsonschema.JSONSchema({
description: 'Should calculate and include estimated tax for transaction',
}),
classValidator.IsBoolean(),
microserviceHelpers.IsUndefinable(),
tslib.__metadata("design:type", Boolean)
], PaymentIntentFeesInput.prototype, "shouldEstimateTax", void 0);
tslib.__decorate([
classValidatorJsonschema.JSONSchema({
description: 'Should include stripe fee in calculation result',
}),
classValidator.IsBoolean(),
microserviceHelpers.IsUndefinable(),
tslib.__metadata("design:type", Boolean)
], PaymentIntentFeesInput.prototype, "withStripeFee", void 0);
class PaymentIntentFeesOutput {
}
tslib.__decorate([
classValidator.IsNumber(),
tslib.__metadata("design:type", Number)
], PaymentIntentFeesOutput.prototype, "stripeFee", void 0);
tslib.__decorate([
classValidator.IsNumber(),
tslib.__metadata("design:type", Number)
], PaymentIntentFeesOutput.prototype, "platformFee", void 0);
tslib.__decorate([
classValidator.IsNumber(),
tslib.__metadata("design:type", Number)
], PaymentIntentFeesOutput.prototype, "userAmount", void 0);
tslib.__decorate([
classValidator.IsNumber(),
tslib.__metadata("design:type", Number)
], PaymentIntentFeesOutput.prototype, "receiverRevenue", void 0);
tslib.__decorate([
classValidator.IsNumber(),
microserviceHelpers.IsUndefinable(),
tslib.__metadata("design:type", Number)
], PaymentIntentFeesOutput.prototype, "estimatedTaxPercent", void 0);
tslib.__decorate([
classValidator.IsNumber(),
microserviceHelpers.IsUndefinable(),
tslib.__metadata("design:type", Number)
], PaymentIntentFeesOutput.prototype, "estimatedTax", void 0);
tslib.__decorate([
classValidator.IsNumber(),
microserviceHelpers.IsUndefinable(),
tslib.__metadata("design:type", Number)
], PaymentIntentFeesOutput.prototype, "taxFee", void 0);
/**
* Returns calculated fees for payment intent
* @description Call from frontend for buy entity fees calculation
*/
const paymentIntentFees = microserviceHelpers.Endpoint.custom(() => ({
input: PaymentIntentFeesInput,
output: PaymentIntentFeesOutput,
description: 'Returns calculated fees for payment intent',
}), ({ entityCost, extraReceiverRevenuePercent, applicationPaymentPercent, additionalFeesPercent, feesPayer, shouldEstimateTax, withStripeFee, }) => tslib.__awaiter(void 0, void 0, void 0, function* () {
const entityUnitCost = toSmallestUnit(entityCost);
const unitFees = yield calculation.getPaymentIntentFees({
entityUnitCost,
extraReceiverRevenuePercent,
feesPayer,
additionalFeesPercent,
applicationPaymentPercent,
shouldEstimateTax,
withStripeFee,
});
return Object.fromEntries(Object.entries(unitFees).map(([title, amount]) => {
const newKey = title.replace('Unit', '');
return [newKey, !newKey.includes('Percent') ? fromSmallestUnit(amount) : amount];
}));
}));
module.exports = paymentIntentFees;