daily pastebin goal
6%
SHARE
TWEET

php stripe stand alone account

a guest Jul 1st, 2015 4 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.   define('CLIENT_ID', 'ca_');
  3.   define('API_KEY', 'sk_test_');
  4.  
  5.   define('TOKEN_URI', 'https://connect.stripe.com/oauth/token');
  6.   define('AUTHORIZE_URI', 'https://connect.stripe.com/oauth/authorize');
  7.  
  8.   if (isset($_GET['code'])) { // Redirect w/ code
  9.     $code = $_GET['code'];
  10.  
  11.     $token_request_body = array(
  12.       'client_secret' => API_KEY,
  13.       'grant_type' => 'authorization_code',
  14.       'client_id' => CLIENT_ID,
  15.       'code' => $code,
  16.     );
  17.  
  18.     $req = curl_init(TOKEN_URI);
  19.     curl_setopt($req, CURLOPT_RETURNTRANSFER, true);
  20.     curl_setopt($req, CURLOPT_POST, true );
  21.     curl_setopt($req, CURLOPT_POSTFIELDS, http_build_query($token_request_body));
  22.  
  23.     // TODO: Additional error handling
  24.     $respCode = curl_getinfo($req, CURLINFO_HTTP_CODE);
  25.     $resp = json_decode(curl_exec($req), true);
  26.     curl_close($req);
  27.  
  28.     echo $resp['access_token'];
  29.   } else if (isset($_GET['error'])) { // Error
  30.     echo $_GET['error_description'];
  31.   } else { // Show OAuth link
  32.     $authorize_request_body = array(
  33.       'response_type' => 'code',
  34.       'scope' => 'read_write',
  35.       'client_id' => CLIENT_ID
  36.     );
  37.  
  38.     $url = AUTHORIZE_URI . '?' . http_build_query($authorize_request_body);
  39.   echo "<a href='$url'><img src=\"blue-on-light.png\"></a>";
  40.   }
  41. ?>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top