I am trying to build some sort of a point system in my wordpress website using my-cred linked with patreon.
Like , If a user pledged 5 dollars for the first month , he would get 500 points in my website , and every month I would need to increase the current points based on the type of pledge he makes .
So is there a way I can access monthly payments made and credit accordingly in my website? Any help would greatly appreciated and also if there’s a better solution to this would be happy to hear.
The total_historical_amount_cents property would be ideal for your use case, as it provides a value equal to the amount the user has paid towards your campaign throughout the life of their pledge, which includes refunds, i.e if someone spends $10 and then $5 is refunded their total_historical_amount_cents will equal 500.
Your implementation could simply sync your points system with the value of total_historical_amount_cents.
And we have a multiplier associated with each level , that is points for level 1 is 5$ * 100 , for level 2 is 10$ * 200 , level 3 - $15 * 300 and so on.
First month , user takes level 1, so he gets 500 points credited , and next month he takes up level 2, which is 2000 points + 500 points (prev month) = 2500 points (total points).
In this case historical_amount_cents would be equal to 15$ , but I need to give the first 5 dollar 500 points and then the next 10$ - 2000 points , total points 2500.
For new Patron’s you can simply keep track of the Reward resource on their Pledge, i.e every successful billing cycle you check which Reward they have and then award them the appropriate points – you would keep an association between Reward ID and level in your local database.
Edit: I forgot to mention, you’ll need to account for campaigns which charge upfront, as in an is_charged_immediately campaign the patron is immediately charged the difference between their current pledge and their new pledge or in the case of decreasing their pledge they are charged only the difference next month (source). You could do this with something like, “if campaign is_charged_immediately and reward_id is not equal to the previous reward_id, recalculate points considering the previous month to have been at the new reward level”.
You cannot access historical data at the moment beyond total_historical_amount_cents, therefore, if your system was set up after a campaign had started you wouldn’t be able to determine an existing patron’s points exactly but you could determine it reasonably well based on knowledge of the pledge start date, the current amount and our understanding of average user behaviour.
For example:
Pledge started 6 months ago
total_historical_amount_cents is 4000
The campaign has 2 reward levels, $5 and $10
The current pledge amount_cents is 1000
From this information, we can determine that they probably upgraded from the $5 to $10 pledge 2 months ago, and award the appropriate 6000 points (4 x 500, 2 x 2000).
A Patreon employee stated that they intend to expose more payment information, that’s on their roadmap for the next quarter, so there’s hope it’ll get easier in future.