Last active
June 27, 2018 10:28
-
-
Save studio-fars-company/db632fbcacaa37dbbec1f80f7f13d168 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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