Git Product home page Git Product logo

php-stripeoauth's Introduction

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.

php-stripeoauth's People

Contributors

onassar avatar

Watchers

 avatar  avatar

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.