comsa/google-business-client-bundle
Installation
composer require comsa/google-business-client-bundle
Add the bundle to config/bundles.php:
return [
// ...
Comsa\GoogleBusinessClientBundle\ComsaGoogleBusinessClientBundle::class => ['all' => true],
];
Configuration Publish the default config:
php bin/console config:dump-reference Comsa\GoogleBusinessClientBundle\Configuration
Update .env with your Google API credentials:
GOOGLE_BUSINESS_API_KEY=your_api_key
GOOGLE_BUSINESS_CLIENT_ID=your_client_id
GOOGLE_BUSINESS_CLIENT_SECRET=your_client_secret
GOOGLE_BUSINESS_REDIRECT_URI=your_redirect_uri
First Use Case: Fetching Business Profile Inject the client into a service/controller:
use Comsa\GoogleBusinessClientBundle\Service\GoogleBusinessClient;
class BusinessController extends Controller
{
public function __construct(private GoogleBusinessClient $client) {}
public function showProfile()
{
$businessAccountId = 'your_business_account_id';
$profile = $this->client->getBusinessProfile($businessAccountId);
return response()->json($profile);
}
}
Authentication Flow
OAuth2 service for user authentication:
$authUrl = $this->client->getAuthUrl();
// Redirect user to $authUrl
$token = $this->client->handleAuthCallback($request);
$this->client->setAccessToken($token);
CRUD Operations
$location = [
'name' => 'Main Store',
'address' => '123 Main St',
'phoneNumber' => '+1234567890',
];
$this->client->createLocation($businessAccountId, $location);
$profile = $this->client->getBusinessProfile($businessAccountId);
$this->client->updateBusinessProfile($businessAccountId, ['hours' => [...]]);
Event-Driven Updates
$this->client->subscribeToWebhook($businessAccountId, $webhookUrl, ['LOCATION_UPDATED']);
event(new BusinessProfileUpdated($businessAccountId, $profile));
UpdateLocationsJob::dispatch($businessAccountId, $locations)->onQueue('google-business');
$response = $this->client->withRetry()->getBusinessProfile($businessAccountId);
Token Expiry
refreshToken() method or implement a token refresh listener:
$this->client->setRefreshToken($refreshToken);
$this->client->refreshToken();
Business Account ID Mismatch
$businessAccountId matches the Google Business Profile ID. Verify via:
$this->client->listBusinessAccounts();
API Quotas
$this->client->withRetry(3, 1000)->createLocation($businessAccountId, $location);
$this->client->setDebug(true); // Logs requests/responses to storage/logs/google_business.log
Custom Services Extend the base client for domain-specific logic:
class CustomBusinessClient extends GoogleBusinessClient
{
public function syncInventory($businessAccountId, array $items)
{
// Custom logic
}
}
Event Listeners
Listen for Google Business events (e.g., BusinessProfileUpdated):
public function handle(BusinessProfileUpdated $event)
{
// Sync with CRM, update UI, etc.
}
Configuration Overrides
Override default config in config/packages/comsa_google_business_client.php:
return [
'api_version' => 'v1',
'default_business_account' => '123456789',
];
batchCreateLocations() for bulk updates.$this->client->validateWebhook($request, $secret);
How can I help you explore Laravel packages today?