From 5f7b1d415169d72bf6086b953364ec5056894443 Mon Sep 17 00:00:00 2001 From: Olivier Bellone Date: Thu, 29 Jun 2017 16:57:20 +0200 Subject: [PATCH] Added example for OAuth --- examples/oauth.php | 55 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 examples/oauth.php diff --git a/examples/oauth.php b/examples/oauth.php new file mode 100644 index 000000000..5018a633d --- /dev/null +++ b/examples/oauth.php @@ -0,0 +1,55 @@ + 'authorization_code', + 'code' => $code, + )); + } catch (\Stripe\Error\OAuth\OAuthBase $e) { + exit("Error: " . $e->getMessage()); + } + + $accountId = $resp->stripe_user_id; + + echo "

Success! Account $accountId is connected.

\n"; + echo "

Click here to disconnect the account.

\n"; + +} elseif (isset($_GET['error'])) { + // The user was redirect back from the OAuth form with an error. + $error = $_GET['error']; + $error_description = $_GET['error_description']; + + echo "

Error: code=$error, description=$error_description

\n"; + echo "

Click here to restart the OAuth flow.

\n"; + +} elseif (isset($_GET['deauth'])) { + // Deauthorization request + $accountId = $_GET['deauth']; + + try { + \Stripe\OAuth::deauthorize(array( + 'stripe_user_id' => $accountId, + )); + } catch (\Stripe\Error\OAuth\OAuthBase $e) { + exit("Error: " . $e->getMessage()); + } + + echo "

Success! Account $accountId is disonnected.

\n"; + echo "

Click here to restart the OAuth flow.

\n"; + +} else { + $url = \Stripe\OAuth::authorizeUrl(array( + 'scope' => 'read_only', + )); + echo "Connect with Stripe\n"; +}