UNPKG

@dbbs/strapi-stripe-payment

Version:
43 lines (42 loc) 1.61 kB
"use strict"; /** * controller */ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const strapi_1 = require("@strapi/strapi"); const http_errors_1 = __importDefault(require("http-errors")); const helpers_1 = require("../helpers"); const validationSchemas_1 = require("../validationSchemas"); exports.default = strapi_1.factories.createCoreController('plugin::stripe-payment.purchase', ({ strapi }) => ({ async createCheckoutSession(ctx) { const { quantity, planId, organizationName, organizationId } = ctx.request.body; const { user } = ctx.state; const validatedParams = await (0, helpers_1.validateWithYupSchema)(validationSchemas_1.createCheckoutSessionSchema, { quantity, planId, organizationName, organizationId }); const checkoutSessionLink = await strapi .plugin('stripe-payment') .service('purchase') .createCheckoutSession({ userId: user.id, ...validatedParams }); ctx.send({ url: checkoutSessionLink }); }, async getAllPurchases(ctx) { const { id } = ctx.params; const purchases = await strapi.plugin('stripe-payment').service('purchase').getAllPurchases({ organizationId: id }); if (!purchases) { throw new http_errors_1.default.NotFound(`Purchases are not found`); } ctx.send(purchases); } }));