mirror of
https://github.com/supabase/supabase.git
synced 2026-07-06 22:34:54 +08:00
27 lines
823 B
TypeScript
27 lines
823 B
TypeScript
export const getProductPrice = (product: any) => {
|
|
const defaultPriceId = product.metadata?.default_price_id
|
|
const price =
|
|
defaultPriceId !== undefined
|
|
? product.prices.find((price: any) => price.id === defaultPriceId)
|
|
: product.prices[0]
|
|
return price
|
|
}
|
|
|
|
export const formSubscriptionUpdatePayload = (
|
|
selectedTier: any,
|
|
selectedComputeSize: any,
|
|
selectedPaymentMethod: string,
|
|
region: string
|
|
) => {
|
|
const defaultPrice = selectedTier ? getProductPrice(selectedTier) : undefined
|
|
const addons =
|
|
region === 'af-south-1' || !selectedComputeSize.id ? [] : [selectedComputeSize.prices[0].id]
|
|
const proration_date = Math.floor(Date.now() / 1000)
|
|
return {
|
|
...(defaultPrice && { tier: defaultPrice.id }),
|
|
addons,
|
|
proration_date,
|
|
payment_method: selectedPaymentMethod,
|
|
}
|
|
}
|