accessToken || $this->tokenExpires->lessThan(Carbon::now()) ) { $clientId = config('services.paypal.client_id'); $secret = config('services.paypal.secret'); $response = Http::withBasicAuth($clientId, $secret) ->throw() ->asForm() ->post("$baseUrl/oauth2/token", [ 'grant_type' => 'client_credentials', ]); if (!$response->successful()) { $response->throw(); } $this->accessToken = $response['access_token']; $this->tokenExpires = Carbon::now()->addSeconds( $response['expires_in'], ); } return Http::withToken($this->accessToken)->baseUrl($baseUrl); } }