UNPKG

@lomray/microservice-payment-stripe

Version:

Stripe payment microservice based on NodeJS & inverted json.

67 lines (63 loc) 2.55 kB
'use strict'; var tslib = require('tslib'); var microserviceHelpers = require('@lomray/microservice-helpers'); var classValidator = require('class-validator'); var classValidatorJsonschema = require('class-validator-jsonschema'); var payoutMethodType = require('../../constants/payout-method-type.js'); var stripe = require('../../services/payment-gateway/stripe.js'); class CreateInstantPayoutInput { } tslib.__decorate([ classValidator.Length(1, 36), classValidator.IsString(), tslib.__metadata("design:type", String) ], CreateInstantPayoutInput.prototype, "userId", void 0); tslib.__decorate([ classValidator.Min(1), classValidator.IsNumber(), tslib.__metadata("design:type", Number) ], CreateInstantPayoutInput.prototype, "amount", void 0); tslib.__decorate([ classValidatorJsonschema.JSONSchema({ description: 'Microservice entity. Your internal microservice payout (withdraw) or any else entity, that implements custom functionality', }), classValidator.Length(1, 36), classValidator.IsString(), microserviceHelpers.IsUndefinable(), tslib.__metadata("design:type", String) ], CreateInstantPayoutInput.prototype, "entityId", void 0); tslib.__decorate([ classValidator.Length(1, 36), classValidator.IsString(), microserviceHelpers.IsUndefinable(), tslib.__metadata("design:type", String) ], CreateInstantPayoutInput.prototype, "payoutMethodId", void 0); tslib.__decorate([ classValidator.IsEnum(payoutMethodType), microserviceHelpers.IsUndefinable(), tslib.__metadata("design:type", String) ], CreateInstantPayoutInput.prototype, "payoutMethodType", void 0); class CreateInstantPayoutOutput { } tslib.__decorate([ classValidator.IsBoolean(), tslib.__metadata("design:type", Boolean) ], CreateInstantPayoutOutput.prototype, "isInstantiated", void 0); /** * Create instant payout */ const instantPayout = microserviceHelpers.Endpoint.custom(() => ({ input: CreateInstantPayoutInput, output: CreateInstantPayoutOutput, description: 'Create instant payout', }), ({ userId, amount, entityId, payoutMethodId, payoutMethodType }) => tslib.__awaiter(void 0, void 0, void 0, function* () { const service = yield stripe.init(); return { isInstantiated: yield service.instantPayout(Object.assign({ userId, amount, entityId }, (payoutMethodId && payoutMethodType ? { payoutMethod: { id: payoutMethodId, method: payoutMethodType } } : {}))), }; })); module.exports = instantPayout;