@dbbs/strapi-stripe-payment
Version:
Strapi integration plugin for Stripe payment system
50 lines (49 loc) • 2.2 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const http_errors_1 = __importDefault(require("http-errors"));
const strapi_1 = require("@strapi/strapi");
const validationSchemas_1 = require("../validationSchemas");
const helpers_1 = require("../helpers");
exports.default = strapi_1.factories.createCoreController('plugin::stripe-payment.plan', ({ strapi }) => ({
async create(ctx) {
const { price, interval, productId, type, currency } = ctx.request.body;
const validatedParams = await (0, helpers_1.validateWithYupSchema)(validationSchemas_1.createPlanSchema, {
price,
interval,
productId,
type,
currency
});
const plan = await strapi.plugin('stripe-payment').service('plan').create(validatedParams);
ctx.send(plan);
},
async getPlanById(ctx) {
const { id } = ctx.params;
const validatedParams = await (0, helpers_1.validateWithYupSchema)(validationSchemas_1.getPlanByIdSchema, { id });
const plan = await strapi.plugin('stripe-payment').service('plan').getPlanById(validatedParams);
if (!plan) {
throw new http_errors_1.default.NotFound(`Plan with ID ${id} not found`);
}
ctx.send(plan);
},
async getPlans(ctx) {
const products = await strapi.plugin('stripe-payment').service('plan').getPlans();
ctx.send(products);
},
async delete(ctx) {
const { id } = ctx.params;
const validatedParams = await (0, helpers_1.validateWithYupSchema)(validationSchemas_1.deletePlanSchema, { id });
const result = await strapi.plugin('stripe-payment').service('plan').delete(validatedParams);
if (!result) {
throw new http_errors_1.default.NotFound(`Plan with ID ${id} not found`);
}
ctx.send(result);
},
async getCurrencies(ctx) {
const currencies = await strapi.plugin('stripe-payment').service('plan').getUniqueCurrencies();
ctx.send(currencies);
}
}));