Patreon access is now granted by tier instead of price paid

This commit is contained in:
Stefan Zermatten
2021-01-28 12:20:01 +02:00
parent d99c44fdeb
commit 03b7f1037e

View File

@@ -68,8 +68,8 @@ if (
Authorization: "Bearer " + accessToken, Authorization: "Bearer " + accessToken,
}, },
qs: { qs: {
"include": "memberships", 'include': 'memberships.currently_entitled_tiers',
"fields[member]": "currently_entitled_amount_cents", 'fields[tier]': 'amount_cents,title',
} }
}, callback); }, callback);
}; };
@@ -112,9 +112,18 @@ if (
} }
try { try {
let identity = JSON.parse(body); let identity = JSON.parse(body);
let membership = identity.included[0]; let entitledAmount = 0;
let entitledAmount = membership && membership.attributes if (identity && identity.included){
.currently_entitled_amount_cents || 0; 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; let patreonUserId = identity.data.id;
writeEntitledCentsAndId(userId, entitledAmount, patreonUserId); writeEntitledCentsAndId(userId, entitledAmount, patreonUserId);
if (callback) callback(); if (callback) callback();