-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add base endpoints for Stripe integration [DEV-3671] (#500)
* Add base endpoints for Stripe integration * Add swagger docs and make it as separate swagger for admin and api * - Add Stripe webhook handling - Add subscription entity - Add chekout API guarding * Add auth routes to admin * Lint and format * swagger changes * Get rid of /admin/checkout and move it to /admin/subscriptions * Change endpoint in swagger * Fix swagger generation and add API routes * Fix swagger request body for subscription update * Fix stripeSync function * Get permissions from the M2M token * Sync updated and small clean-ups * Clean-ups * Add trial period days to subscription creation * Get also trilaing subsriptions * Get rd of Stripe naming * Small cleeanups and refactoring * Make swagger changes * Resolve review comments * Overall format + lockfile --------- Co-authored-by: Tasos Derisiotis <[email protected]>
- Loading branch information
1 parent
e20d83d
commit 99792c7
Showing
78 changed files
with
7,025 additions
and
4,253 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import * as dotenv from 'dotenv'; | ||
import type { Request, Response } from 'express'; | ||
import { check } from 'express-validator'; | ||
import { validationResult } from '../validator'; | ||
import type { PortalCustomerGetUnsuccessfulResponseBody } from '../../types/portal.js'; | ||
|
||
dotenv.config(); | ||
|
||
export class PortalCustomerController { | ||
static portalCustomerGetValidator = [ | ||
check('logToUserId').optional().isString().withMessage('logToUserId should be a string').bail(), | ||
]; | ||
|
||
async get(request: Request, response: Response) { | ||
const result = validationResult(request); | ||
// handle error | ||
if (!result.isEmpty()) { | ||
return response.status(400).json({ | ||
error: result.array().pop()?.msg, | ||
} satisfies PortalCustomerGetUnsuccessfulResponseBody); | ||
} | ||
|
||
return response.status(500).json({ | ||
error: 'Not implemented yet', | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import type { Stripe } from 'stripe'; | ||
import type { Request, Response } from 'express'; | ||
import * as dotenv from 'dotenv'; | ||
import type { PriceListResponseBody, PriceListUnsuccessfulResponseBody } from '../../types/portal.js'; | ||
import { StatusCodes } from 'http-status-codes'; | ||
import { check } from '../validator/index.js'; | ||
import { validate } from '../validator/decorator.js'; | ||
|
||
dotenv.config(); | ||
|
||
export class PriceController { | ||
static priceListValidator = [ | ||
check('productId').optional().isString().withMessage('productId should be a string').bail(), | ||
]; | ||
|
||
/** | ||
* @openapi | ||
* | ||
* /admin/price/list: | ||
* get: | ||
* summary: Get a list of prices | ||
* description: Get a list of prices | ||
* tags: [Price] | ||
* parameters: | ||
* - in: query | ||
* name: productId | ||
* schema: | ||
* type: string | ||
* description: The product id. If passed - returns filtered by this product list of prices. | ||
* required: false | ||
* responses: | ||
* 200: | ||
* description: A list of prices | ||
* content: | ||
* application/json: | ||
* schema: | ||
* $ref: '#/components/schemas/PriceListResponseBody' | ||
* 400: | ||
* $ref: '#/components/schemas/InvalidRequest' | ||
* 401: | ||
* $ref: '#/components/schemas/UnauthorizedError' | ||
* 500: | ||
* $ref: '#/components/schemas/InternalError' | ||
* 404: | ||
* $ref: '#/components/schemas/NotFoundError' | ||
*/ | ||
@validate | ||
async getListPrices(request: Request, response: Response) { | ||
const stripe = response.locals.stripe as Stripe; | ||
// Get query parameters | ||
const productId = request.query.productId; | ||
|
||
try { | ||
// Fetch the list of prices | ||
const prices = productId | ||
? await stripe.prices.list({ | ||
product: productId as string, | ||
active: true, | ||
}) | ||
: await stripe.prices.list({ | ||
active: true, | ||
}); | ||
|
||
return response.status(StatusCodes.OK).json({ | ||
prices: prices, | ||
} satisfies PriceListResponseBody); | ||
} catch (error) { | ||
return response.status(500).json({ | ||
error: `Internal error: ${(error as Error)?.message || error}`, | ||
} satisfies PriceListUnsuccessfulResponseBody); | ||
} | ||
} | ||
} |
Oops, something went wrong.