@lomray/microservice-payment-stripe
Version:
Stripe payment microservice based on NodeJS & inverted json.
60 lines (56 loc) • 1.99 kB
JavaScript
;
var tslib = require('tslib');
var microserviceHelpers = require('@lomray/microservice-helpers');
var classValidator = require('class-validator');
var stripe = require('../../services/payment-gateway/stripe.js');
class CreateCheckoutInput {
}
tslib.__decorate([
classValidator.Length(1, 36),
classValidator.IsString(),
tslib.__metadata("design:type", String)
], CreateCheckoutInput.prototype, "userId", void 0);
tslib.__decorate([
classValidator.IsString(),
tslib.__metadata("design:type", String)
], CreateCheckoutInput.prototype, "priceId", void 0);
tslib.__decorate([
classValidator.IsString(),
tslib.__metadata("design:type", String)
], CreateCheckoutInput.prototype, "successUrl", void 0);
tslib.__decorate([
classValidator.IsString(),
tslib.__metadata("design:type", String)
], CreateCheckoutInput.prototype, "cancelUrl", void 0);
tslib.__decorate([
classValidator.IsBoolean(),
microserviceHelpers.IsUndefinable(),
tslib.__metadata("design:type", Boolean)
], CreateCheckoutInput.prototype, "isAllowPromoCode", void 0);
class CreateCheckoutOutput {
}
tslib.__decorate([
microserviceHelpers.IsNullable(),
classValidator.IsString(),
tslib.__metadata("design:type", Object)
], CreateCheckoutOutput.prototype, "redirectUrl", void 0);
/**
* Creates checkout session and return redirect url to stripe checkout
*/
const createCheckout = microserviceHelpers.Endpoint.custom(() => ({
input: CreateCheckoutInput,
output: CreateCheckoutOutput,
description: 'Setup intent and return client secret key',
}), ({ priceId, successUrl, cancelUrl, userId, isAllowPromoCode }) => tslib.__awaiter(void 0, void 0, void 0, function* () {
const service = yield stripe.init();
return {
redirectUrl: yield service.createCheckout({
priceId,
userId,
successUrl,
cancelUrl,
isAllowPromoCode,
}),
};
}));
module.exports = createCheckout;