An example of implementing the Patreon PHP library to create a website that displays all of the Patrons of a Patreon Campaign and automatically updates when a Pledge is created, updated or deleted.
You can find a live version of this example at patreon.1f991.com where you can pledge to the test Campaign to see yourself added in realtime, and you can follow the tutorial below to set up this example with your own Campaign.
- A Web Server (such as Wamp or MAMP if you're developing on your own computer)
- PHP >=7.2.0
- Composer
- A Patreon Campaign
First you will need to create a Patreon API Client to obtain a Patreon
Creator's Access Token
.
- Visit
Clients & API Keys
in the Patreon Platform Portal - Click
Create Client
- Fill out the fields and save — you don't need to enter real data
- After your client is created you'll find your
Creator's Access Token
by clicking the arrow next to your Client
- Open your terminal
- Clone this project from GitHub into a directory called
patreon
:
git clone https://github.com/1f991/patreon-php-example patreon
- Change into the
patreon
directory:
cd patreon
- Install the dependencies with Composer:
composer install
- Open the newly created
.env
file and add yourCreator's Access Token
:
PATREON_ACCESS_TOKEN="your-creators-access-token-here"
You're now ready to visit your new Patreon PHP example website!
You will need your Patreon API Client's Client ID
, Client Secret
and a
Redirect URI to enable OAuth log ins.
- Return to
Clients & API Keys
in the Patreon Platform Portal - Click "Edit Client" and in
Redirect URIs
add the address to your Patreon PHP example website with/login.php
at the end. For example if your website ispatreon.localhost
you would enterhttp://patreon.localhost/login.php
- Click "Update Client"
- Copy and paste the
Client ID
,Client Secret
andRedirect URI
values into your.env
file, for example:
PATREON_ACCESS_TOKEN="your-creators-access-token-here"
PATREON_WEBHOOK_SECRET=""
PATREON_CLIENT_ID="your-client-id-here"
PATREON_CLIENT_SECRET="your-client-secret-here"
PATREON_REDIRECT_URI="http://patreon.localhost/login.php"
⚠ Do not log in to your Patreon PHP website with your creator account. You must create a new account for testing. If you log in with your creator account then your
Creator's Access Token
will be reset and all requests will fail. When that happens you will need to repeat step 4 again. via patreondevelopers.com.
Visit your Patreon PHP example website again and click "log in if you're already a patron →" to confirm everything is working as expected.
Your website will need to be accessible online for this step. You can use ngrok to expose a local website to the open internet during development.
- Visit Register Webhooks in the Patreon Platform Portal.
- Paste the URL to your Patreon PHP website and append
/webhook.php
, e.g:
https://patreon.1f991.com/webhook.php
- Copy the Secret that is generated by Patreon
- Open
.env
and add yourPATREON_WEBHOOK_SECRET
:
PATREON_ACCESS_TOKEN="your-creators-access-token-here"
PATREON_WEBHOOK_SECRET="your-patreon-webhook-secret"
You're all set! Patreon will now notify your website every time there's a new pledge, a pledge is deleted or a pledge is updated, and your website will update the local database.
You can test out your webhook integration with the helpful Patreon event tests.
- Next to the
Create Pledge
event clickSend test
- Click
Send Test
again — you should see Patreon displayTest Response --- Status code: 200
- Visit your website again, you should see a new pledge!
- Next to the
Delete Pledge
event clickSend Test
(and thenSend Test
again) - Visit your website again, the test pledge is gone!
Please visit the Patreon Developers forum for any support.
Please reach out to Samuel Ryan via email (sryan@1f991.com) to report any security concerns you may have with this example project. Although this project is intended as an example, it is probable some of the code will be copy and pasted into production, therefore it is important the example code be free of vulnerabilities. Acknowledgement will be provided within 24 hours.