From fc03097ed8377e486cc3b322d62e036e8346c067 Mon Sep 17 00:00:00 2001 From: Stefan Zermatten Date: Thu, 28 Jan 2021 12:15:45 +0200 Subject: [PATCH] Patreon access is now given by tier instead of by price paid --- .../api/users/patreon/updatePatreonDetails.js | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/app/imports/api/users/patreon/updatePatreonDetails.js b/app/imports/api/users/patreon/updatePatreonDetails.js index 58661764..1a63ea14 100644 --- a/app/imports/api/users/patreon/updatePatreonDetails.js +++ b/app/imports/api/users/patreon/updatePatreonDetails.js @@ -9,8 +9,8 @@ const getIdentity = function(accessToken, callback){ Authorization: 'Bearer ' + accessToken, }, qs: { - 'include': 'memberships', - 'fields[member]': 'currently_entitled_amount_cents', + 'include': 'memberships.currently_entitled_tiers', + 'fields[tier]': 'amount_cents,title', } }, callback); }; @@ -61,9 +61,18 @@ const updateIdentity = Meteor.wrapAsync(function(accessToken, userId, callback){ } try { let identity = JSON.parse(body); - let membership = identity.included && 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; + } + }); + } writeEntitledCents(userId, entitledAmount); if (callback) callback(); } catch(error) {