@lomray/microservice-payment-stripe
Version:
Stripe payment microservice based on NodeJS & inverted json.
99 lines (95 loc) • 3.52 kB
JavaScript
;
var tslib = require('tslib');
var microserviceHelpers = require('@lomray/microservice-helpers');
var classValidator = require('class-validator');
var transactionRole = require('../../constants/transaction-role.js');
var stripe = require('../../services/payment-gateway/stripe.js');
class PaymentIntentInput {
}
tslib.__decorate([
classValidator.Length(1, 36),
classValidator.IsString(),
tslib.__metadata("design:type", String)
], PaymentIntentInput.prototype, "userId", void 0);
tslib.__decorate([
classValidator.Length(1, 36),
classValidator.IsString(),
tslib.__metadata("design:type", String)
], PaymentIntentInput.prototype, "receiverId", void 0);
tslib.__decorate([
classValidator.IsNumber(),
tslib.__metadata("design:type", Number)
], PaymentIntentInput.prototype, "entityCost", void 0);
tslib.__decorate([
classValidator.IsNumber(),
microserviceHelpers.IsUndefinable(),
tslib.__metadata("design:type", Number)
], PaymentIntentInput.prototype, "applicationPaymentPercent", void 0);
tslib.__decorate([
classValidator.IsString(),
microserviceHelpers.IsUndefinable(),
tslib.__metadata("design:type", String)
], PaymentIntentInput.prototype, "title", void 0);
tslib.__decorate([
classValidator.IsString(),
microserviceHelpers.IsUndefinable(),
tslib.__metadata("design:type", String)
], PaymentIntentInput.prototype, "cardId", void 0);
tslib.__decorate([
classValidator.IsString(),
microserviceHelpers.IsUndefinable(),
tslib.__metadata("design:type", String)
], PaymentIntentInput.prototype, "entityId", void 0);
tslib.__decorate([
classValidator.IsEnum(transactionRole),
microserviceHelpers.IsUndefinable(),
tslib.__metadata("design:type", String)
], PaymentIntentInput.prototype, "feesPayer", void 0);
tslib.__decorate([
classValidator.IsObject(),
microserviceHelpers.IsUndefinable(),
tslib.__metadata("design:type", Object)
], PaymentIntentInput.prototype, "additionalFeesPercent", void 0);
tslib.__decorate([
classValidator.IsNumber(),
microserviceHelpers.IsUndefinable(),
tslib.__metadata("design:type", Number)
], PaymentIntentInput.prototype, "extraReceiverRevenuePercent", void 0);
tslib.__decorate([
classValidator.IsBoolean(),
microserviceHelpers.IsUndefinable(),
tslib.__metadata("design:type", Boolean)
], PaymentIntentInput.prototype, "withTax", void 0);
class PaymentIntentOutput {
}
tslib.__decorate([
classValidator.IsObject(),
tslib.__metadata("design:type", Array)
], PaymentIntentOutput.prototype, "transaction", void 0);
/**
* Create PaymentIntent
* @description Must be called from API
*/
const connectAccount = microserviceHelpers.Endpoint.custom(() => ({
input: PaymentIntentInput,
output: PaymentIntentOutput,
description: 'Create new PaymentIntent',
}), ({ userId, entityCost, receiverId, applicationPaymentPercent, cardId, title, entityId, feesPayer, additionalFeesPercent, extraReceiverRevenuePercent, withTax, }) => tslib.__awaiter(void 0, void 0, void 0, function* () {
const service = yield stripe.init();
return {
transaction: yield service.createPaymentIntent({
userId,
entityId,
entityCost,
receiverId,
cardId,
title,
applicationPaymentPercent,
feesPayer,
additionalFeesPercent,
extraReceiverRevenuePercent,
withTax,
}),
};
}));
module.exports = connectAccount;