Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
- public function connectStandardResponse($state, $code) {
- $paymentHandler = PaymentHandler::where('gateway_state', '=', $state)->first();
- if($paymentHandler != null) {
- // send the token back to stripe to varify
- $stripeRequest = curl_init('https://connect.stripe.com/oauth/token');
- curl_setopt($stripeRequest, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($stripeRequest, CURLOPT_POST, true );
- curl_setopt($stripeRequest, CURLOPT_POSTFIELDS, http_build_query([
- 'grant_type' => 'authorization_code',
- 'client_id' => '',
- 'code' => $code,
- 'client_secret' => config('app.stripe_private_key')
- ]));
- $respCode = curl_getinfo($stripeRequest, CURLINFO_HTTP_CODE);
- $stripeResponse = json_decode(curl_exec($stripeRequest), true);
- curl_close($stripeRequest);
- // validate the response
- if($respCode == 0) {
- if(isset($stripeResponse['stripe_publishable_key'])) {
- // depending on test or live save to appropriate field
- $paymentHandlerField = 'test_published_key';
- if($stripeResponse['livemode'] == true)
- $paymentHandlerField = 'live_published_key';
- // update the payment handler with the external account details
- $paymentHandler->$paymentHandlerField = $stripeResponse['stripe_publishable_key'];
- $paymentHandler->gateway_external_account_key = $stripeResponse['stripe_user_id'];
- $paymentHandler->save();
- // notify the user and redirect
- \SystemMessage::add(trans('app.stripe-connect-account-added'));
- return Redirect('/admin/payment-handlers/edit/'.$paymentHandler->id);
- }
- }
- throw new Exception('Problem connecting to your Stripe account.');
- }
- throw new Exception('Payment handler not found with state.');
- }
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.


