PHP library which helps perform an OAuth2 flow for Stripe, which is used when creating and interacting with a Stripe application.
PHP
Switch branches/tags
Nothing to show
Clone or download
Latest commit 6fc3350 Apr 28, 2016
Permalink
Failed to load latest commit information.
LICENSE Create LICENSE Apr 28, 2016
README.md Doc tweaks Oct 9, 2012
StripeOAuth.class.php Minors Sep 6, 2014
StripeOAuth2Client.class.php Minors Sep 6, 2014

README.md

PHP-StripeOAuth

PHP library which helps perform an OAuth2 flow for Stripe, which is used when creating and interacting with a Stripe Application.

Why I made this

While integration the Stripe API (for our new payment flow at Skillshare), I found one thing specifically lacking.
That was, a way to initiate an OAuth flow for a Stripe Application, and to access needed data, in PHP.

While it could be done manually by initiating a curl call (as can be seen in this gist, which was posted fairly recently), I wanted to make use of an established OAuth library to make sure I wasn't recreating the wheel.

Dependencies

Both StripeOAuth.class.php and StripeOAuth2Client.class.php must be loaded.
StripeOAuth2Client.class.php has the class OAuth2Client as a dependency.
For that, please see quizlet's oauth2-php library.

Quick Example

Assuming you've got all your files loaded, you should get pretty far with the following:

<?php

    // redirect to proper application OAuth url
    $oauth = (new StripeOAuth(
        'ca_********************************',
        'sk_*****************************'
    ));
    $url = $oauth->getAuthorizeUri();
    header('Location: ' . ($url));
    exit(0);

    // ...

    // from the callback, after a person has linked their Stripe account with your Stripe application
    $oauth = (new StripeOAuth(
        'ca_********************************',
        'sk_*****************************'
    ));
    $token = $oauth->getAccessToken($_GET['code']);
    $key = $oauth->getPublishableKey($_GET['code']);
    echo 'Access token: ' . ($token) . '<br />Key: ' . ($key);
    exit(0);

The code parameter is accessed from the _GET array, as after a person connects their Stripe account to your Stripe application, this code is passed along in the url. In most conventional applications, this is more-or-less an request token, and we use it to get an access token, and subsequently all the data we want.

More

Will update this page shortly with a few more examples on some of the more advanced workings of the Stripe OAuth flow.