As of January 2019 this library is archived and will no longer receive any updates and/or fixes. This library is not compatible with the new Patreon API.
Due to lack of use this should be not impactful, however if anybody is using the library and wishes to take over maintenance please let me know. The post that follows is the original post, please note that some links may no longer work.
Hi!
I have put together a new library for PHP developers working with the Patreon Platform. Patreon PHP is designed to make integrating Patreon into your modern PHP application very easy.
Features
- Modern PHP (7.2)
- Ready-to-use example project available (visit it at patreon.1f991.com)
- Accept Webhooks from Patreon — secure signature verification included!
- Retrieve all pledges (the library handles pagination for you)
- Determine entity state with helper methods, e.g:
$user->hasActivePledge()
,$reward->isAvailableToChoose()
,$campaign->getAvailableRewards()
,$goal->hasBeenCompleted()
(and many more) - Simple Patreon OAuth client
Also…
- Full documentation
- Unit tested
- MIT licensed
- Follows Semantic Versioning
- Maintained
You can find the source and documentation on GitHub and the example project is available on GitHub too. The following are a couple of quick examples to show how easy this library is to use.
Output the name of every patron of your campaign:
use Squid\Patreon\Patreon;
$patreon = new Patreon('creators-access-token');
$campaign = $patreon->campaigns()->getMyCampaignWithPledges();
$campaign->pledges->each(function ($pledge) {
echo $pledge->patron->name;
});
Output a link to each of your available rewards:
use Squid\Patreon\Patreon;
$patreon = new Patreon('creators-access-token');
$campaign = $patreon->campaigns()->getMyCampaign();
$campaign->rewards->filter(function ($reward) {
return $reward->isAvailableToChoose();
})->each(function ($reward) {
echo "<a href='{$reward->getPledgeUrl()}'>{$reward->title}</a>";
});
Determine if the user who just logged in via OAuth is an active patron:
use Squid\Patreon\Patreon;
$patreon = new Patreon('visitors-access-token');
$me = $patreon->me()->get();
if ($me->hasActivePledge()) {
echo 'You are an active patron, welcome to my website.';
} else {
echo 'You must be an active patron to access this website.';
}
All feedback, ideas and contributions are gratefully received and welcomed. Please let me know if you have any questions about using the library, happy to provide guidance
Thanks!