Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

mstdmstd's avatar

Connecting to stripe I got Undefined property: Stripe\Service\CoreServiceFactory::$account error

in my Laravel 8 / with stripe/stripe-php": "^7.75" I try to connect and create account on stripe side and got error :

     Undefined property: Stripe\Service\CoreServiceFactory::$account

with code:

    <?php
    
    namespace App\Http\Controllers;
    
    use Illuminate\Http\Request;
    use Session;
    use Stripe;
    use Stripe\StripeClient;
    use App\Http\Controllers\Controller;
    use Illuminate\Database\DatabaseManager;
    
    use App\Models\Settings;
    use Carbon\Carbon;
    use Illuminate\Support\Arr;
    use App\Models\User;
    use App\Models\StripeToken;
    
    class SellerController extends Controller
    {
    	protected StripeClient $stripeClient;
    	protected DatabaseManager $databaseManager;
    	public function __construct(StripeClient $stripeClient, DatabaseManager $databaseManager)
    	{
    		$this->stripeClient = $stripeClient;
    		$this->databaseManager = $databaseManager;
    	}
    
    	public function redirectToStripe($id)
    	{
    		\Log::info('-1 redirectToStripe $id ::' . print_r($id, true));
    		$seller = User::find($id);
    		if (!$seller) {
    			abort(404);
    		}
    		$appEnv= strtolower(config('app.env'));
    
    		if ($appEnv == 'local' or $appEnv == 'dev') {
    		// In logs I see valid Test key assigned
    			\Log::info('-1 config(app.STRIPE_TEST_KEY)::' . print_r(config('app.STRIPE_TEST_KEY'), true));
    			\Stripe\Stripe::setApiKey(config('app.STRIPE_TEST_KEY')); 
    		}
            if( $appEnv == 'production' ) {
                \Stripe\Stripe::setApiKey( config('app.STRIPE_LIVE_KEY') );
            }
    
    
    		if (!$seller->completed_stripe_onboarding) {
    			$str = \Str::random();
    			$stripeToken = new StripeToken();
    			$stripeToken->token =  $str;
    			$stripeToken->seller_id =  $id;
    			$stripeToken->save();
    		}
    
    		if (!$seller->completed_stripe_onboarding) {
    			// Create a new Stripe Connect Account object.
    			\Log::info('-1 $$this->stripeClient ::' . print_r($this->stripeClient, true));
    			$account = $this->stripeClient->account->create(
    				[
    					'country' => 'US',
    					'type' => 'express',
    					'email' => $seller->email,
    				]
    			);

I check StripeClient object in log :

    [2021-03-21 15:26:18] local.INFO: -1 $$this->stripeClient ::Stripe\StripeClient Object
    (
        [coreServiceFactory:Stripe\StripeClient:private] => 
        [config:Stripe\BaseStripeClient:private] => Array
            (
                [api_key] => 
                [client_id] => 
                [stripe_account] => 
                [stripe_version] => 
                [api_base] => https://api.stripe.com
                [connect_base] => https://connect.stripe.com
                [files_base] => https://files.stripe.com
            )
    
        [defaultOpts:Stripe\BaseStripeClient:private] => Stripe\Util\RequestOptions Object
            (
                [apiKey] => 
                [headers] => Array
                    (
                        [Stripe-Account] => 
                        [Stripe-Version] => 
                    )
    
                [apiBase] => 
            )

How to fix this error ?

Thanks!

0 likes
2 replies
neilstee's avatar
neilstee
Best Answer
Level 34

@mstdmstd and I think account should be accounts?

$account = $this->stripeClient->accounts->create(
    				[
    					'country' => 'US',
    					'type' => 'express',
    					'email' => $seller->email,
    				]
    			);
1 like

Please or to participate in this conversation.