laulamanapps/google-wallet
Composer 安装命令:
composer require laulamanapps/google-wallet
包简介
Generate Google Wallet passes from PHP
README 文档
README
Generate Google Wallet passes from PHP. The Google counterpart of laulamanapps/apple-passbook.
Passes are distributed via "Add to Google Wallet" links: an RS256-signed JWT whose payload
embeds the pass classes and objects (a so-called "fat JWT"). Because the classes and objects
travel inside the JWT, no Google Wallet REST API call is needed — the only dependency is
ext-openssl for signing.
Installation
composer require laulamanapps/google-wallet
Or use one of the framework integrations, which wire the service account and save-URL factory from configuration:
- Symfony: laulamanapps/google-wallet-symfony
- Laravel: laulamanapps/google-wallet-laravel
Service account setup
- Sign up for a Google Wallet issuer account in the Google Pay & Wallet Console and note your issuer id.
- Create a Google Cloud service account with the Wallet Object Issuer role and download its JSON key file.
- Link the service account to your issuer account in the console.
Quickstart
use LauLamanApps\GoogleWallet\Object\Barcode; use LauLamanApps\GoogleWallet\Object\BarcodeType; use LauLamanApps\GoogleWallet\Object\GenericClass; use LauLamanApps\GoogleWallet\Object\GenericObject; use LauLamanApps\GoogleWallet\Object\Image; use LauLamanApps\GoogleWallet\Object\TextModule; use LauLamanApps\GoogleWallet\PassPayload; use LauLamanApps\GoogleWallet\SaveUrlFactory; use LauLamanApps\GoogleWallet\ServiceAccount; $serviceAccount = ServiceAccount::fromJsonFile('/path/to/service-account.json'); // Ids are '<issuerId>.<identifier>' $object = new GenericObject('3388000000012345678.member-0001', '3388000000012345678.membership'); $object->setCardTitle('ACME Membership'); $object->setHeader('John Doe'); $object->setSubheader('Gold member'); $object->setHexBackgroundColor('#4285f4'); $object->setLogo(Image::fromUri('https://example.com/logo.png', 'ACME logo')); $object->setBarcode(new Barcode(BarcodeType::QrCode, 'member-0001')); $object->addTextModule(new TextModule('Member since', '2020')); $payload = new PassPayload(); $payload->addGenericClass(new GenericClass('3388000000012345678.membership')); $payload->addGenericObject($object); $factory = new SaveUrlFactory($serviceAccount, ['https://example.com']); $saveUrl = $factory->create($payload); // https://pay.google.com/gp/v/save/eyJhbGciOiJSUzI1NiIs...
Render the url as an Add to Google Wallet button and you are done.
Pass types
Next to GenericClass/GenericObject the same pattern is available for:
EventTicketClass/EventTicketObjectOfferClass/OfferObjectLoyaltyClass/LoyaltyObjectTransitClass/TransitObject
Add them to the PassPayload with the matching add*Class()/add*Object() methods.
Signing a JWT yourself
SaveUrlFactory covers the common case. If you need the raw JWT, use JwtSigner directly:
use LauLamanApps\GoogleWallet\JwtSigner; $signer = new JwtSigner($serviceAccount); $jwt = $signer->sign([ 'iss' => $serviceAccount->getClientEmail(), 'aud' => 'google', 'typ' => 'savetowallet', 'iat' => time(), 'origins' => ['https://example.com'], 'payload' => $payload->toArray(), ]);
Credits
License
The MIT License (MIT). Please see License File for more information.
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 5
- 推荐数: 3
其他信息
- 授权协议: MIT
- 更新时间: 2026-07-08