From f0ebbe0e0d14ce1b77e902afc1124988719fb5b5 Mon Sep 17 00:00:00 2001 From: Jeffery <61447509+jeffplays2005@users.noreply.github.com> Date: Sun, 15 Sep 2024 13:03:46 +1200 Subject: [PATCH] 668 backend create endpoint to fetch lodge prices (#777) * Add getLodgePrices endpoint to fetch lodge prices * Update endpoint to use correct methods and update stripeservice for correct variable names Used the wrong method for endpoint so fixed that. * Add doc to each field and simplify `name` field logic --- .../controllers/PaymentController.ts | 26 +++++++------------ 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/server/src/service-layer/controllers/PaymentController.ts b/server/src/service-layer/controllers/PaymentController.ts index 9d2bf758..e4634fde 100644 --- a/server/src/service-layer/controllers/PaymentController.ts +++ b/server/src/service-layer/controllers/PaymentController.ts @@ -118,37 +118,29 @@ export class PaymentController extends Controller { const stripeService = new StripeService() try { const lodgeProducts = await stripeService.getActiveLodgeProducts() - // Maps the products to the required response type MembershipStripeProductResponse in PaymentResponse - + // Maps the products to the required response type LodgeStripeProductResponse in PaymentResponse const productsValues = lodgeProducts.map((product) => { - // Checks the membership type of the product + // Checks the lodge 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 { + // The stripe product id productId: product.id, - name, + // The lodge booking type + name: lodgeType, + // The product description description: product.description, + // A boolean value if there is a lodge booking discount discount: product.metadata.discount === "true", + // The price of the lodge booking displayPrice: ( Number( (product.default_price as Stripe.Price).unit_amount_decimal ) / 100 ).toString(), + // The original price of the lodge booking originalPrice: product.metadata.original_price } })