UNPKG

@lomray/microservice-payment-stripe

Version:

Stripe payment microservice based on NodeJS & inverted json.

87 lines (83 loc) 3.08 kB
'use strict'; var tslib = require('tslib'); var microserviceHelpers = require('@lomray/microservice-helpers'); var classValidator = require('class-validator'); var stripe = require('../../services/payment-gateway/stripe.js'); class CreateCartCheckoutInput { } tslib.__decorate([ classValidator.IsString(), tslib.__metadata("design:type", String) ], CreateCartCheckoutInput.prototype, "cartId", void 0); tslib.__decorate([ classValidator.Length(1, 36), classValidator.IsString(), tslib.__metadata("design:type", String) ], CreateCartCheckoutInput.prototype, "userId", void 0); tslib.__decorate([ classValidator.IsString(), classValidator.ValidateIf((input) => !input.isEmbeddedMode), tslib.__metadata("design:type", String) ], CreateCartCheckoutInput.prototype, "successUrl", void 0); tslib.__decorate([ classValidator.IsString(), classValidator.ValidateIf((input) => !input.isEmbeddedMode), tslib.__metadata("design:type", String) ], CreateCartCheckoutInput.prototype, "cancelUrl", void 0); tslib.__decorate([ classValidator.IsString(), microserviceHelpers.IsUndefinable(), microserviceHelpers.IsNullable(), classValidator.ValidateIf((input) => input.isEmbeddedMode), tslib.__metadata("design:type", Object) ], CreateCartCheckoutInput.prototype, "returnUrl", void 0); tslib.__decorate([ classValidator.Length(1, 40), classValidator.IsString(), microserviceHelpers.IsUndefinable(), tslib.__metadata("design:type", String) ], CreateCartCheckoutInput.prototype, "customerEmail", void 0); tslib.__decorate([ classValidator.IsBoolean(), microserviceHelpers.IsUndefinable(), tslib.__metadata("design:type", Boolean) ], CreateCartCheckoutInput.prototype, "isEmbeddedMode", void 0); class CreateCartCheckoutOutput { } tslib.__decorate([ microserviceHelpers.IsNullable(), classValidator.IsString(), tslib.__metadata("design:type", Object) ], CreateCartCheckoutOutput.prototype, "redirectUrl", void 0); tslib.__decorate([ microserviceHelpers.IsNullable(), classValidator.IsString(), tslib.__metadata("design:type", Object) ], CreateCartCheckoutOutput.prototype, "clientSecret", void 0); /** * Creates checkout session and return redirect url to stripe checkout */ const createCartCheckout = microserviceHelpers.Endpoint.custom(() => ({ input: CreateCartCheckoutInput, output: CreateCartCheckoutOutput, description: 'Setup intent and return client secret key', }), ({ cartId, successUrl, cancelUrl, userId, customerEmail, returnUrl, isEmbeddedMode = false, }) => tslib.__awaiter(void 0, void 0, void 0, function* () { const service = yield stripe.init(); return service.createCartCheckout(isEmbeddedMode ? { isEmbeddedMode, cartId, userId, returnUrl, customerEmail, } : { isEmbeddedMode, cartId, userId, successUrl, cancelUrl, customerEmail, }); })); module.exports = createCartCheckout;