Skip to content

Commit

Permalink
Revert "Add getLodgePrices endpoint to fetch lodge prices (#774)"
Browse files Browse the repository at this point in the history
This reverts commit e2d893e.
  • Loading branch information
jeffplays2005 authored Sep 14, 2024
1 parent e2d893e commit 87b8cbe
Show file tree
Hide file tree
Showing 6 changed files with 2 additions and 236 deletions.
29 changes: 0 additions & 29 deletions client/src/models/__generated__/schema.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 0 additions & 21 deletions server/src/business-layer/services/StripeService.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {
LODGE_PRICING_TYPE_KEY,
MEMBERSHIP_PRODUCT_TYPE_KEY,
ProductTypeValues,
USER_FIREBASE_EMAIL_KEY,
Expand Down Expand Up @@ -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.
Expand Down
44 changes: 0 additions & 44 deletions server/src/middleware/__generated__/routes.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

71 changes: 0 additions & 71 deletions server/src/middleware/__generated__/swagger.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

56 changes: 1 addition & 55 deletions server/src/service-layer/controllers/PaymentController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -28,7 +27,6 @@ import {
} from "service-layer/request-models/UserRequests"
import {
BookingPaymentResponse,
LodgeStripeProductResponse,
MembershipPaymentResponse,
MembershipStripeProductResponse
} from "service-layer/response-models/PaymentResponse"
Expand Down Expand Up @@ -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<LodgeStripeProductResponse> {
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.
Expand Down
17 changes: 1 addition & 16 deletions server/src/service-layer/response-models/PaymentResponse.ts
Original file line number Diff line number Diff line change
@@ -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"

Expand Down Expand Up @@ -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[]
}

0 comments on commit 87b8cbe

Please sign in to comment.