Git Product home page Git Product logo

patreon-php-example's Introduction

Patreon PHP Example

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.

Requirements

  • A Web Server (such as Wamp or MAMP if you're developing on your own computer)
  • PHP >=7.2.0
  • Composer
  • A Patreon Campaign

Getting Started

Patreon Client

First you will need to create a Patreon API Client to obtain a Patreon Creator's Access Token.

  1. Visit Clients & API Keys in the Patreon Platform Portal
  2. Click Create Client
  3. Fill out the fields and save — you don't need to enter real data
  4. After your client is created you'll find your Creator's Access Token by clicking the arrow next to your Client

Install Example Project

  1. Open your terminal
  2. Clone this project from GitHub into a directory called patreon:
git clone https://github.com/1f991/patreon-php-example patreon
  1. Change into the patreon directory:
cd patreon
  1. Install the dependencies with Composer:
composer install
  1. Open the newly created .env file and add your Creator's Access Token:
PATREON_ACCESS_TOKEN="your-creators-access-token-here"

Cloning Demo

You're now ready to visit your new Patreon PHP example website!

Accepting Logins

You will need your Patreon API Client's Client ID, Client Secret and a Redirect URI to enable OAuth log ins.

  1. Return to Clients & API Keys in the Patreon Platform Portal
  2. 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 is patreon.localhost you would enter http://patreon.localhost/login.php
  3. Click "Update Client"
  4. Copy and paste the Client ID, Client Secret and Redirect 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.

Setting up Webhooks

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.

  1. Visit Register Webhooks in the Patreon Platform Portal.
  2. Paste the URL to your Patreon PHP website and append /webhook.php, e.g:
https://patreon.1f991.com/webhook.php
  1. Copy the Secret that is generated by Patreon
  2. Open .env and add your PATREON_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.

  1. Next to the Create Pledge event click Send test
  2. Click Send Test again — you should see Patreon display Test Response --- Status code: 200
  3. Visit your website again, you should see a new pledge!
  4. Next to the Delete Pledge event click Send Test (and then Send Test again)
  5. Visit your website again, the test pledge is gone!

Help

Please visit the Patreon Developers forum for any support.

Security Vulnerabilities

Please reach out to Samuel Ryan via email ([email protected]) 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.

patreon-php-example's People

Contributors

shrink avatar

Stargazers

 avatar

Watchers

 avatar  avatar

patreon-php-example's Issues

Should handle refreshing Creator's Access Token

Creator Access Token's expire: a user should be encouraged to set the Access Token and Refresh Token in their .env and then when the Access Token expires the Refresh Token should be used to attempt to obtain a new Access Token. Without this change, anybody using the example as-is will encounter it "randomly" failing a few weeks after they deploy it -- or any time they accidentally log in with their creator account.

Question: should we rewrite the value in the .env?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.