Skip to content

Commit

Permalink
Support patreon gifts (#1088)
Browse files Browse the repository at this point in the history
  • Loading branch information
sceuick authored Dec 8, 2024
1 parent b331aac commit 1a751e9
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 3 deletions.
1 change: 1 addition & 0 deletions common/types/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,7 @@ export namespace Patreon {
attributes: {
campaign_lifetime_support_cents: number
campaign_entitled_amount_cents: number
is_gifted: boolean
last_charge_date: string
last_charge_status:
| 'Paid'
Expand Down
3 changes: 2 additions & 1 deletion common/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,7 @@ export function getUserSubscriptionTier(
let manualTier = manualId ? tiers.find((t) => t._id === manualId) : undefined

const nativeExpired = isExpired(user.billing?.validUntil) || user.billing?.status === 'cancelled'
const patronGifted = user.patreon?.member?.attributes?.is_gifted === true
const patronExpired =
isExpired(user.patreon?.member?.attributes.next_charge_date) ||
user.patreon?.member?.attributes.patron_status !== 'active_patron'
Expand All @@ -388,7 +389,7 @@ export function getUserSubscriptionTier(
nativeTier = undefined
}

if (patronExpired) {
if (patronExpired && !patronGifted) {
patronTier = undefined
}

Expand Down
5 changes: 4 additions & 1 deletion srv/api/user/patreon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ async function authorize(code: string, refresh?: boolean) {
const memberProps = [
'patron_status',
'last_charge_date',
'is_gifted',
'last_charge_status',
'next_charge_date',
'currently_entitled_amount_cents',
Expand Down Expand Up @@ -95,7 +96,9 @@ async function identity(token: string) {
return match
})

const contrib = tier.attributes.amount_cents
let contrib = tier.attributes.amount_cents
if (!contrib) {
}
const sub = getPatreonEntitledTierByCost(contrib, getCachedTiers())

return { tier, sub, user, member }
Expand Down
2 changes: 1 addition & 1 deletion srv/db/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export async function connect(verbose = false) {

cli.on('connectionPoolCleared', onClose('connectionPoolCleared'))

logger.info({ uri }, 'Connected to MongoDB')
logger.info('Connected to MongoDB')
connected = true
return database
} catch (ex) {
Expand Down

0 comments on commit 1a751e9

Please sign in to comment.