Skip to content

Commit

Permalink
668 backend create endpoint to fetch lodge prices (#777)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
jeffplays2005 authored Sep 15, 2024
1 parent e2d893e commit f0ebbe0
Showing 1 changed file with 9 additions and 17 deletions.
26 changes: 9 additions & 17 deletions server/src/service-layer/controllers/PaymentController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
})
Expand Down

0 comments on commit f0ebbe0

Please sign in to comment.