daily pastebin goal
6%
SHARE
TWEET

dfdsfsd

Culkus Oct 2nd, 2017 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     public function connectStandardResponse($state, $code) {
  2.        
  3.         $paymentHandler = PaymentHandler::where('gateway_state', '=', $state)->first();
  4.         if($paymentHandler != null) {
  5.      
  6.             // send the token back to stripe to varify
  7.             $stripeRequest = curl_init('https://connect.stripe.com/oauth/token');
  8.             curl_setopt($stripeRequest, CURLOPT_RETURNTRANSFER, true);
  9.             curl_setopt($stripeRequest, CURLOPT_POST, true );
  10.             curl_setopt($stripeRequest, CURLOPT_POSTFIELDS, http_build_query([
  11.                 'grant_type' => 'authorization_code',
  12.                 'client_id' => '',
  13.                 'code' => $code,
  14.                 'client_secret' => config('app.stripe_private_key')
  15.             ]));
  16.             $respCode = curl_getinfo($stripeRequest, CURLINFO_HTTP_CODE);
  17.             $stripeResponse = json_decode(curl_exec($stripeRequest), true);
  18.             curl_close($stripeRequest);  
  19.            
  20.             // validate the response
  21.             if($respCode == 0) {
  22.                 if(isset($stripeResponse['stripe_publishable_key'])) {
  23.                    
  24.                     // depending on test or live save to appropriate field
  25.                     $paymentHandlerField = 'test_published_key';
  26.                     if($stripeResponse['livemode'] == true)
  27.                         $paymentHandlerField = 'live_published_key';
  28.                    
  29.                     // update the payment handler with the external account details
  30.                     $paymentHandler->$paymentHandlerField = $stripeResponse['stripe_publishable_key'];
  31.                     $paymentHandler->gateway_external_account_key = $stripeResponse['stripe_user_id'];
  32.                     $paymentHandler->save();      
  33.                    
  34.                     // notify the user and redirect
  35.                     \SystemMessage::add(trans('app.stripe-connect-account-added'));
  36.                     return Redirect('/admin/payment-handlers/edit/'.$paymentHandler->id);              
  37.                 }
  38.             }
  39.             throw new Exception('Problem connecting to your Stripe account.');
  40.         }
  41.         throw new Exception('Payment handler not found with state.');
  42.     }
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