Skip to content

Instantly share code, notes, and snippets.

@studio-fars-company
Last active June 27, 2018 10:28
Show Gist options
  • Save studio-fars-company/db632fbcacaa37dbbec1f80f7f13d168 to your computer and use it in GitHub Desktop.
Save studio-fars-company/db632fbcacaa37dbbec1f80f7f13d168 to your computer and use it in GitHub Desktop.
public function connect(){//子ユーザーコネクト作成
define('CLIENT_ID', 'クライアントID');//connectの設置ページにある
define('TOKEN_URI', 'https://connect.stripe.com/oauth/token');
define('AUTHORIZE_URI', 'https://connect.stripe.com/oauth/authorize');
if (isset($_GET['code'])) { // Redirect/ code
$code = $_GET['code'];
$token_request_body = array(
'client_secret' => env('STRIPE_SECRET'),
'grant_type' => 'authorization_code',
'client_id' => CLIENT_ID,
'code' => $code,
);
$req = curl_init(TOKEN_URI);
curl_setopt($req, CURLOPT_RETURNTRANSFER, true);
curl_setopt($req, CURLOPT_POST, true );
curl_setopt($req, CURLOPT_POSTFIELDS, http_build_query($token_request_body));
// TODO: Additional error handling
$respCode = curl_getinfo($req, CURLINFO_HTTP_CODE);
$resp = json_decode(curl_exec($req), true);
curl_close($req);
$id = Auth::id();//user_id取得
\App\User::where('id', $id)->update(['stripe_user_id' => $resp['stripe_user_id']]);
return redirect()->back();
} else if (isset($_GET['error'])) { // Error
echo $_GET['error_description'];
} else { // Show OAuth link
$authorize_request_body = array(
'response_type' => 'code',
'scope' => 'read_write',
'client_id' => CLIENT_ID,
);
$url = AUTHORIZE_URI . '?' . http_build_query($authorize_request_body);
return view('connect')->with('url',$url);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment