Giter VIP home page Giter VIP 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

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

php-stripeoauth's Issues

Updates per oauth2-server-php changes

https://github.com/bshaffer/oauth2-server-php implements the final draft of OAuth 2.0. I'm noticing issues particularly in https://github.com/nerdfiles/stripe-market/blob/master/includes/stripe-functions.php#L96-L974 when double usage of $_GET['code'] for the purposes of crafting tokens and public keys โ€” specifically keys.

When it comes to Stripe, I'm attempting to Connect Accounts via OAuth2.0 authorization_codes โ€” accounts are being connected by it seems a double registration then queues up the deletion of that account. I have a feeling the culpable code exists here in the glue between oauth2-server-php and stripe-php itself.

Getting Test Access Token After Live Access Token

Love this! I couldn't figure out a way using your StripeOAuth classes to generate a test access token after getting a connected user's live access token, refresh token, publishable key, etc. I wondered if you had a way to accomplish this that I'm not seeing. I tried adjusting your code a bit using the getTokens method and setting refresh to true, requiring the code within the getTokens method to be run and creating a new StripeOAuth2Client instance with the new secret key but I didn't have any luck. I currently just created a curl call in my script to handle this but if I could clean up my code and use your classes that would be ideal.

The call to accomplish this is below (using the live refresh token and the test api key associated with my platform):
curl https://connect.stripe.com/oauth/token
-d client_secret=sk_test_asdfasdfasdfasdfasdfasdfdsaf
-d refresh_token=REFRESH_TOKEN
-d grant_type=refresh_token

Declaration should be compatible

I get this error in StripeOAuth2Client.class.php:

Unhandled Exception

Message:

Declaration of StripeOAuth2Client::makeRequest() should be compatible with OAuth2Client::makeRequest($path, $method = 'GET', $params = Array, $ch = NULL)

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.