diff --git a/docs/.vitepress/theme/components/sponsor/SponsorAmountPicker.vue b/docs/.vitepress/theme/components/sponsor/SponsorAmountPicker.vue index ef140c791..0e297042b 100644 --- a/docs/.vitepress/theme/components/sponsor/SponsorAmountPicker.vue +++ b/docs/.vitepress/theme/components/sponsor/SponsorAmountPicker.vue @@ -5,9 +5,15 @@ import Icon from '@lucide/vue/src/Icon'; import { check } from '../../../data/iconNodes'; import SponsorSection from './SponsorSection.vue'; import SponsorSectionHeader from './SponsorSectionHeader.vue'; -import { TIERS, formatEuro, getPreviousTier, getTierForAmount, getTierLinks } from './tiers'; - -type Frequency = 'monthly' | 'once'; +import { + TIERS, + formatEuro, + getAmountLinks, + getPreviousTier, + getTierForAmount, + getTierLinks, + type Frequency, +} from './tiers'; const frequencies: { id: Frequency; label: string }[] = [ { id: 'monthly', label: 'Monthly' }, @@ -29,8 +35,16 @@ const total = computed(() => { const tier = computed(() => (isMonthly.value ? getTierForAmount(total.value) : null)); -// Only a monthly preset matches a tier's checkout, other amounts go to the general pages. -const links = computed(() => getTierLinks(customAmount.value === '' ? tier.value?.id : undefined)); +// A monthly preset opens its tier's checkout, other amounts open a checkout prefilled with +// the amount. The platforms expect whole amounts, so decimals are rounded. +const links = computed(() => { + const value = Math.round(total.value); + + if (customAmount.value === '' && tier.value) return getTierLinks(tier.value.id); + if (value > 0) return getAmountLinks(value, frequency.value); + + return getTierLinks(); +}); const amountText = computed(() => formatEuro(total.value)); diff --git a/docs/.vitepress/theme/components/sponsor/tiers.ts b/docs/.vitepress/theme/components/sponsor/tiers.ts index d2b3fab04..14831bd33 100644 --- a/docs/.vitepress/theme/components/sponsor/tiers.ts +++ b/docs/.vitepress/theme/components/sponsor/tiers.ts @@ -101,4 +101,26 @@ export function getTierLinks(id?: TierId) { }; } +export type Frequency = 'monthly' | 'once'; + +/** Checkout links prefilled with a custom amount and frequency. */ +export function getAmountLinks(amount: number, frequency: Frequency) { + const isMonthly = frequency === 'monthly'; + + const openCollectiveParams = new URLSearchParams({ + interval: isMonthly ? 'month' : 'oneTime', + amount: String(amount), + contributeAs: 'me', + }); + const githubSponsorsParams = new URLSearchParams({ + frequency: isMonthly ? 'recurring' : 'one-time', + amount: String(amount), + }); + + return { + openCollective: `${OPEN_COLLECTIVE_URL}/donate?${openCollectiveParams}`, + githubSponsors: `${GITHUB_SPONSORS_URL}/sponsorships?${githubSponsorsParams}`, + }; +} + export const formatEuro = (amount: number) => `€${amount.toLocaleString('en-US')}`;