PHP code example of laulamanapps / google-wallet-symfony

1. Go to this page and download the library: Download laulamanapps/google-wallet-symfony library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

laulamanapps / google-wallet-symfony example snippets


// config/bundles.php

return [
    // ...
    LauLamanApps\GoogleWalletBundle\GoogleWalletBundle::class => ['all' => true],
];

namespace App\Controller;

use LauLamanApps\GoogleWallet\PassPayload;
use LauLamanApps\GoogleWallet\SaveUrlFactory;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Response;

class WalletController
{
    public function __construct(
        private readonly SaveUrlFactory $saveUrlFactory,
    ) {
    }

    public function save(): Response
    {
        $payload = new PassPayload();
        // ... build your pass, see the laulamanapps/google-wallet README

        return new RedirectResponse($this->saveUrlFactory->create($payload));
    }
}

// config/routes/google_wallet.php

use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;

return function (RoutingConfigurator $routes): void {
    $routes->import('@GoogleWalletBundle/Resources/config/callback_routes.php');
};

$class = new GenericClass('3388000000012345678.membership');
$class->setCallbackUrl('https://example.com/google-wallet/callback');

namespace App\EventListener;

use LauLamanApps\GoogleWalletBundle\Event\PassDeletedEvent;
use LauLamanApps\GoogleWalletBundle\Event\PassSavedEvent;
use Symfony\Component\EventDispatcher\Attribute\AsEventListener;

final class WalletPassListener
{
    #[AsEventListener]
    public function onPassSaved(PassSavedEvent $event): void
    {
        $event->getObjectId(); // '3388000000012345678.member-0001'
        $event->getClassId();  // '3388000000012345678.membership'
    }

    #[AsEventListener]
    public function onPassDeleted(PassDeletedEvent $event): void
    {
        // e.g. mark the pass as removed in your database
    }
}
yaml
# config/routes/google_wallet.yaml
googlewallet:
    resource: '@GoogleWalletBundle/Resources/config/callback_routes.php'