From 03b7f1037efc4e26fbbcd0ac2a91f1f23e8bdea1 Mon Sep 17 00:00:00 2001 From: Stefan Zermatten Date: Thu, 28 Jan 2021 12:20:01 +0200 Subject: [PATCH] Patreon access is now granted by tier instead of price paid --- app/server/patreon/patreon.js | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/app/server/patreon/patreon.js b/app/server/patreon/patreon.js index 27e98522..3044873d 100644 --- a/app/server/patreon/patreon.js +++ b/app/server/patreon/patreon.js @@ -68,8 +68,8 @@ if ( Authorization: "Bearer " + accessToken, }, qs: { - "include": "memberships", - "fields[member]": "currently_entitled_amount_cents", + 'include': 'memberships.currently_entitled_tiers', + 'fields[tier]': 'amount_cents,title', } }, callback); }; @@ -112,9 +112,18 @@ if ( } try { let identity = JSON.parse(body); - let membership = identity.included[0]; - let entitledAmount = membership && membership.attributes - .currently_entitled_amount_cents || 0; + let entitledAmount = 0; + if (identity && identity.included){ + identity.included.forEach(doc => { + if ( + doc.type === 'tier' && + doc.attributes && + doc.attributes.amount_cents > entitledAmount + ){ + entitledAmount = doc.attributes.amount_cents; + } + }); + } let patreonUserId = identity.data.id; writeEntitledCentsAndId(userId, entitledAmount, patreonUserId); if (callback) callback();