Google Wallet Ticket Creation
August 7, 2025 · AI Conversations
—
### ✅ Add Class Creation Logic (only once per event)
Here’s how to **create the EventTicketClass** before issuing the ticket:
—
### 🔁 1. Add this class creation block **before `$passObject` definition**
Update this part in your existing code to create the class dynamically *if not already created*:
use GoogleClient;
use GoogleServiceWalletobjectsEventTicketClass;
// Initialize Google Client
$client = new GoogleClient();
$client->setAuthConfig($serviceAccountPath);
$client->addScope('https://www.googleapis.com/auth/wallet_object.issuer');
$client->setSubject($clientEmail);
$walletobjectsService = new GoogleServiceWalletobjects($client);
// Check if class exists
try {
$walletobjectsService->eventTicketclass->get($fullClassId);
} catch (GoogleServiceException $e) {
if ($e->getCode() === 404) {
// Create class since it doesn't exist
$eventClass = new GoogleServiceWalletobjectsEventTicketClass([
'id' => $fullClassId,
'issuerName' => 'Fossetts Circus',
'eventName' => [
'defaultValue' => [
'language' => 'en-US',
'value' => $order['event_name'] ?? $order['event_venue']
]
],
'venue' => [
'name' => [
'defaultValue' => [
'language' => 'en-US',
'value' => $order['event_venue']
]
],
'address' => [
'defaultValue' => [
'language' => 'en-US',
'value' => $venue_address
]
]
]
]);
try {
$walletobjectsService->eventTicketclass->insert($eventClass);
} catch (Exception $ex) {
http_response_code(500);
exit('Class creation failed: ' . htmlspecialchars($ex->getMessage()));
}
} else {
http_response_code(500);
exit('Failed to check class: ' . htmlspecialchars($e->getMessage()));
}
}
—
### ✅ Final Notes:
– This logic ensures the class is created only once per event (based on `$event_id` or venue).
– You may customize the `$classId` further to include event ID or date for uniqueness:
$classId = 'live_fossetts_ticket_' . $order['event_id'];
– Then update:
$objectId = $issuerId . '.' . $classId . '_' . $order_code;
$fullClassId = $issuerId . '.' . $classId;
—
Let me know if you want to store a flag in DB to prevent class creation per event manually or need full CRUD for classes.
—
### ✅ Modify the EventTicketClass creation to include the logo
In the class creation block (`$eventClass = new EventTicketClass([…])`), add the `logo` parameter like this:
$eventClass = new GoogleServiceWalletobjectsEventTicketClass([
'id' => $fullClassId,
'issuerName' => 'Fossetts Circus',
'eventName' => [
'defaultValue' => [
'language' => 'en-US',
'value' => $order['event_name'] ?? $order['event_venue']
]
],
'venue' => [
'name' => [
'defaultValue' => [
'language' => 'en-US',
'value' => $order['event_venue']
]
],
'address' => [
'defaultValue' => [
'language' => 'en-US',
'value' => $venue_address
]
]
],
'logo' => [
'sourceUri' => [
'uri' => 'https://yourdomain.com/path/to/logo.png',
'description' => 'Fossetts Circus Logo'
]
]
]);
—
### 🔐 Logo Requirements:
| Requirement | Value |
|——————–|——————————-|
| Protocol | HTTPS |
| Format | PNG or JPG |
| Recommended Size | 660×660 px |
| File Size | < 100KB |
| Hosting | Must be publicly accessible |
—
### ✅ If your logo is hosted locally:
Upload it to your server or a CDN like:
https://fossettscircus.com/assets/logo.png
Then replace this line:
'uri' => 'https://yourdomain.com/path/to/logo.png',
—
Let me know if you also want to add **hero image**, **background color**, or **event thumbnail** – these are also supported in the class.
Fatal error: Uncaught Error: Class "GoogleClient" not found
means that the **Google API Client Library** is not installed or not autoloaded properly in your project.
—
### ✅ Solution: Install the Google API Client via Composer
Run the following command in your project directory:
composer require google/apiclient:^2.0
This will install the required package and make the `GoogleClient` class available.
—
### ✅ Ensure Autoloading is Set
Make sure this line is present at the top of your script and correctly points to your `vendor/autoload.php` file:
require_once __DIR__ . '/vendor/autoload.php';
If your directory structure is different, adjust the path accordingly.
—
### 🔁 After installing, your `composer.json` should include:
"require": {
"firebase/php-jwt": "^6.0",
"google/apiclient": "^2.0"
}
—
### ✅ Final Check
After installing, verify the class works by placing a small test snippet:
require_once __DIR__ . '/vendor/autoload.php';
$client = new GoogleClient();
echo 'Google Client loaded successfully.';
—
Let me know if you’re on a shared hosting and can’t use Composer directly — I can guide you through downloading the libraries manually.