From 87b8cbe35baca28c8ee3b105165b642ef95d8fa4 Mon Sep 17 00:00:00 2001 From: Jeffery <61447509+jeffplays2005@users.noreply.github.com> Date: Sat, 14 Sep 2024 23:53:47 +1200 Subject: [PATCH] Revert "Add getLodgePrices endpoint to fetch lodge prices (#774)" This reverts commit e2d893e585c497e4226d570debc7ac70aa1f73d5. --- client/src/models/__generated__/schema.d.ts | 29 -------- .../business-layer/services/StripeService.ts | 21 ------ server/src/middleware/__generated__/routes.ts | 44 ------------ .../src/middleware/__generated__/swagger.json | 71 ------------------- .../controllers/PaymentController.ts | 56 +-------------- .../response-models/PaymentResponse.ts | 17 +---- 6 files changed, 2 insertions(+), 236 deletions(-) diff --git a/client/src/models/__generated__/schema.d.ts b/client/src/models/__generated__/schema.d.ts index 9b305014b..1568af09d 100644 --- a/client/src/models/__generated__/schema.d.ts +++ b/client/src/models/__generated__/schema.d.ts @@ -32,10 +32,6 @@ export interface paths { /** @description Fetches the prices of the membership products from Stripe. */ get: operations["GetMembershipPrices"]; }; - "/payment/lodge_prices": { - /** @description Fetches the prices of the lodge products from Stripe. */ - get: operations["GetLodgePrices"]; - }; "/payment/checkout_status": { /** @description Fetches the details of a checkout session based on a stripe checkout session id. */ get: operations["GetCheckoutSessionDetails"]; @@ -250,20 +246,6 @@ export interface components { }[]; }; /** @enum {string} */ - LodgePricingTypeValues: "single_friday_or_saturday" | "normal"; - LodgeStripeProductResponse: { - error?: string; - message?: string; - data?: { - originalPrice?: string; - displayPrice: string; - discount: boolean; - description?: string; - name: components["schemas"]["LodgePricingTypeValues"]; - productId: string; - }[]; - }; - /** @enum {string} */ "stripe.Stripe.Checkout.Session.Status": "complete" | "expired" | "open"; /** @description Set of key-value pairs that you can attach to an object. This can be useful for storing additional information about the object in a structured format. */ "stripe.Stripe.Metadata": { @@ -759,17 +741,6 @@ export interface operations { }; }; }; - /** @description Fetches the prices of the lodge products from Stripe. */ - GetLodgePrices: { - responses: { - /** @description The prices of the lodge products. */ - 200: { - content: { - "application/json": components["schemas"]["LodgeStripeProductResponse"]; - }; - }; - }; - }; /** @description Fetches the details of a checkout session based on a stripe checkout session id. */ GetCheckoutSessionDetails: { parameters: { diff --git a/server/src/business-layer/services/StripeService.ts b/server/src/business-layer/services/StripeService.ts index 20f065e81..8f7e9c504 100644 --- a/server/src/business-layer/services/StripeService.ts +++ b/server/src/business-layer/services/StripeService.ts @@ -1,5 +1,4 @@ import { - LODGE_PRICING_TYPE_KEY, MEMBERSHIP_PRODUCT_TYPE_KEY, ProductTypeValues, USER_FIREBASE_EMAIL_KEY, @@ -378,26 +377,6 @@ export default class StripeService { } } - /** Fetch all active products from Stripe - * @returns lodgeProducts - An array of active lodge products from Stripe - */ - public async getActiveLodgeProducts() { - try { - const products = await stripe.products.list({ - active: true, - expand: ["data.default_price"] - }) - // Filter products with the required metadata - const lodgeProducts = products.data.filter((product) => - Object.keys(product.metadata).includes(LODGE_PRICING_TYPE_KEY) - ) - return lodgeProducts - } catch (error) { - console.error("Error fetching Stripe products:", error) - throw error - } - } - /** * Promotes a user from guest to member status. * @param uid The user ID to promote to a member. diff --git a/server/src/middleware/__generated__/routes.ts b/server/src/middleware/__generated__/routes.ts index d46b6ddd2..75dd6b398 100644 --- a/server/src/middleware/__generated__/routes.ts +++ b/server/src/middleware/__generated__/routes.ts @@ -115,21 +115,6 @@ const models: TsoaRoute.Models = { "additionalProperties": false, }, // WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa - "LodgePricingTypeValues": { - "dataType": "refEnum", - "enums": ["single_friday_or_saturday","normal"], - }, - // WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa - "LodgeStripeProductResponse": { - "dataType": "refObject", - "properties": { - "error": {"dataType":"string"}, - "message": {"dataType":"string"}, - "data": {"dataType":"array","array":{"dataType":"nestedObjectLiteral","nestedProperties":{"originalPrice":{"dataType":"string"},"displayPrice":{"dataType":"string","required":true},"discount":{"dataType":"boolean","required":true},"description":{"dataType":"string"},"name":{"ref":"LodgePricingTypeValues","required":true},"productId":{"dataType":"string","required":true}}}}, - }, - "additionalProperties": false, - }, - // WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa "stripe.Stripe.Checkout.Session.Status": { "dataType": "refAlias", "type": {"dataType":"union","subSchemas":[{"dataType":"enum","enums":["complete"]},{"dataType":"enum","enums":["expired"]},{"dataType":"enum","enums":["open"]}],"validators":{}}, @@ -725,35 +710,6 @@ export function RegisterRoutes(app: Router) { } }); // WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa - app.get('/payment/lodge_prices', - ...(fetchMiddlewares(PaymentController)), - ...(fetchMiddlewares(PaymentController.prototype.getLodgePrices)), - - function PaymentController_getLodgePrices(request: ExRequest, response: ExResponse, next: any) { - const args: Record = { - }; - - // WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa - - let validatedArgs: any[] = []; - try { - validatedArgs = templateService.getValidatedArgs({ args, request, response }); - - const controller = new PaymentController(); - - templateService.apiHandler({ - methodName: 'getLodgePrices', - controller, - response, - next, - validatedArgs, - successStatus: undefined, - }); - } catch (err) { - return next(err); - } - }); - // WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa app.get('/payment/checkout_status', authenticateMiddleware([{"jwt":[]}]), ...(fetchMiddlewares(PaymentController)), diff --git a/server/src/middleware/__generated__/swagger.json b/server/src/middleware/__generated__/swagger.json index 353b3488c..27405b340 100644 --- a/server/src/middleware/__generated__/swagger.json +++ b/server/src/middleware/__generated__/swagger.json @@ -272,57 +272,6 @@ "type": "object", "additionalProperties": false }, - "LodgePricingTypeValues": { - "enum": [ - "single_friday_or_saturday", - "normal" - ], - "type": "string" - }, - "LodgeStripeProductResponse": { - "properties": { - "error": { - "type": "string" - }, - "message": { - "type": "string" - }, - "data": { - "items": { - "properties": { - "originalPrice": { - "type": "string" - }, - "displayPrice": { - "type": "string" - }, - "discount": { - "type": "boolean" - }, - "description": { - "type": "string" - }, - "name": { - "$ref": "#/components/schemas/LodgePricingTypeValues" - }, - "productId": { - "type": "string" - } - }, - "required": [ - "displayPrice", - "discount", - "name", - "productId" - ], - "type": "object" - }, - "type": "array" - } - }, - "type": "object", - "additionalProperties": false - }, "stripe.Stripe.Checkout.Session.Status": { "type": "string", "enum": [ @@ -1567,26 +1516,6 @@ "parameters": [] } }, - "/payment/lodge_prices": { - "get": { - "operationId": "GetLodgePrices", - "responses": { - "200": { - "description": "The prices of the lodge products.", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/LodgeStripeProductResponse" - } - } - } - } - }, - "description": "Fetches the prices of the lodge products from Stripe.", - "security": [], - "parameters": [] - } - }, "/payment/checkout_status": { "get": { "operationId": "GetCheckoutSessionDetails", diff --git a/server/src/service-layer/controllers/PaymentController.ts b/server/src/service-layer/controllers/PaymentController.ts index 9d2bf758c..9b81acdf8 100644 --- a/server/src/service-layer/controllers/PaymentController.ts +++ b/server/src/service-layer/controllers/PaymentController.ts @@ -10,8 +10,7 @@ import { import { MembershipTypeValues, MEMBERSHIP_TYPE_KEY, - LODGE_PRICING_TYPE_KEY, - LodgePricingTypeValues + LODGE_PRICING_TYPE_KEY } from "business-layer/utils/StripeProductMetadata" import { UTCDateToDdMmYyyy, @@ -28,7 +27,6 @@ import { } from "service-layer/request-models/UserRequests" import { BookingPaymentResponse, - LodgeStripeProductResponse, MembershipPaymentResponse, MembershipStripeProductResponse } from "service-layer/response-models/PaymentResponse" @@ -109,58 +107,6 @@ export class PaymentController extends Controller { } } - /** - * Fetches the prices of the lodge products from Stripe. - * @returns The prices of the lodge products. - */ - @Get("lodge_prices") - public async getLodgePrices(): Promise { - const stripeService = new StripeService() - try { - const lodgeProducts = await stripeService.getActiveLodgeProducts() - // Maps the products to the required response type MembershipStripeProductResponse in PaymentResponse - - const productsValues = lodgeProducts.map((product) => { - // Checks the membership type of the product - const lodgeType = product.metadata[ - LODGE_PRICING_TYPE_KEY - ] as LodgePricingTypeValues - - let name: LodgePricingTypeValues - - switch (lodgeType) { - case LodgePricingTypeValues.SingleFridayOrSaturday: { - name = LodgePricingTypeValues.SingleFridayOrSaturday - break - } - case LodgePricingTypeValues.Normal: { - name = LodgePricingTypeValues.Normal - break - } - } - - return { - productId: product.id, - name, - description: product.description, - discount: product.metadata.discount === "true", - displayPrice: ( - Number( - (product.default_price as Stripe.Price).unit_amount_decimal - ) / 100 - ).toString(), - originalPrice: product.metadata.original_price - } - }) - this.setStatus(200) - return { data: productsValues } - } catch (error) { - console.error(error) - this.setStatus(500) - return { error: "Error fetching active Stripe products" } - } - } - /** * Fetches the details of a checkout session based on a stripe checkout session id. * @param sessionId The id of the stripe checkout session to fetch. diff --git a/server/src/service-layer/response-models/PaymentResponse.ts b/server/src/service-layer/response-models/PaymentResponse.ts index b7a9aad11..7b083e7e3 100644 --- a/server/src/service-layer/response-models/PaymentResponse.ts +++ b/server/src/service-layer/response-models/PaymentResponse.ts @@ -1,7 +1,4 @@ -import { - LodgePricingTypeValues, - MembershipTypeValues -} from "business-layer/utils/StripeProductMetadata" +import { MembershipTypeValues } from "business-layer/utils/StripeProductMetadata" import { CommonResponse } from "./CommonResponse" import { Timestamp } from "firebase-admin/firestore" @@ -34,18 +31,6 @@ export interface MembershipStripeProductResponse extends CommonResponse { }[] } -// Make a data shape matching to the expected response from Stripe API -export interface LodgeStripeProductResponse extends CommonResponse { - data?: { - productId: string - name: LodgePricingTypeValues - description?: string - discount: boolean - displayPrice: string - originalPrice?: string - }[] -} - export interface AvailableDatesResponse extends CommonResponse { data?: AvailableDates[] }