Skip to content

Commit 1a751e9

Browse files
authored
Support patreon gifts (#1088)
1 parent b331aac commit 1a751e9

File tree

4 files changed

+8
-3
lines changed

4 files changed

+8
-3
lines changed

common/types/schema.ts

+1
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,7 @@ export namespace Patreon {
445445
attributes: {
446446
campaign_lifetime_support_cents: number
447447
campaign_entitled_amount_cents: number
448+
is_gifted: boolean
448449
last_charge_date: string
449450
last_charge_status:
450451
| 'Paid'

common/util.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,7 @@ export function getUserSubscriptionTier(
380380
let manualTier = manualId ? tiers.find((t) => t._id === manualId) : undefined
381381

382382
const nativeExpired = isExpired(user.billing?.validUntil) || user.billing?.status === 'cancelled'
383+
const patronGifted = user.patreon?.member?.attributes?.is_gifted === true
383384
const patronExpired =
384385
isExpired(user.patreon?.member?.attributes.next_charge_date) ||
385386
user.patreon?.member?.attributes.patron_status !== 'active_patron'
@@ -388,7 +389,7 @@ export function getUserSubscriptionTier(
388389
nativeTier = undefined
389390
}
390391

391-
if (patronExpired) {
392+
if (patronExpired && !patronGifted) {
392393
patronTier = undefined
393394
}
394395

srv/api/user/patreon.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ async function authorize(code: string, refresh?: boolean) {
4545
const memberProps = [
4646
'patron_status',
4747
'last_charge_date',
48+
'is_gifted',
4849
'last_charge_status',
4950
'next_charge_date',
5051
'currently_entitled_amount_cents',
@@ -95,7 +96,9 @@ async function identity(token: string) {
9596
return match
9697
})
9798

98-
const contrib = tier.attributes.amount_cents
99+
let contrib = tier.attributes.amount_cents
100+
if (!contrib) {
101+
}
99102
const sub = getPatreonEntitledTierByCost(contrib, getCachedTiers())
100103

101104
return { tier, sub, user, member }

srv/db/client.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export async function connect(verbose = false) {
3434

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

37-
logger.info({ uri }, 'Connected to MongoDB')
37+
logger.info('Connected to MongoDB')
3838
connected = true
3939
return database
4040
} catch (ex) {

0 commit comments

Comments
 (0)