app-vise/laravel-google-server-notifications

Handling Google play server to server notifications

dev-development 2019-11-20 09:39 UTC

This package is auto-updated.

Last update: 2024-03-21 21:06:44 UTC


README

Latest Version on Packagist Build Status StyleCI Scrutinizer Code Quality Total Downloads

Installation

You can install this package via composer

composer require app-vise/laravel-google-server-notifications 

The service provider will register itself. You have to publish the config file with:

php artisan vendor:publish --provider="Appvise\GooglePlayNotifications\NotificationsServiceProvider" --tag="config" 

This is the config that will be published.

return [
    /*
     * All the events that should be handeled by your application.
     * Typically you should uncomment all jobs
     *
     * You can find a list of all notification types here:
     * https://developer.android.com/google/play/billing/realtime_developer_notifications
     */
    'jobs' => [
        // 'subscription_recovered' => \App\Jobs\PlayStore\HandleRecovered::class,
        // 'subscription_renewed' => \App\Jobs\PlayStore\HandleRenewed::class,
        // 'subscription_canceled' =>  \App\Jobs\PlayStore\HandleCanceled::class,
        // 'subscription_purchased' => \App\Jobs\PlayStore\HandlePurchased::class,
        // 'subscription_on_hold' => \App\Jobs\PlayStore\HandleOnHold::class,
        // 'subscription_in_grace_period' => \App\Jobs\PlayStore\HandleInGracePeriod::class,
        // 'subscription_restarted' => \App\Jobs\PlayStore\HandleRestarted::class,
        // 'subscription_price_change_confirmed' => \App\Jobs\PlayStore\HandlePriceChangeConfirmed::class,
        // 'subscription_deferred' => \App\Jobs\PlayStore\HandleDeferred::class,
        // 'subscription_paused' => \App\Jobs\PlayStore\HandlePaused::class,
        // 'subscription_pause_schedule_changed' => \App\Jobs\PlayStore\HandlePauseScheduleChanged::class,
        // 'subscription_revoked' => \App\Jobs\PlayStore\HandleRevoked::class,
        // 'subscription_expired' => \App\Jobs\PlayStore\HandleExpired::class
    ],
];

This package logs all the incoming requests to the database so these steps are mandatory:

php artisan vendor:publish --provider="Appvise\GooglePlayNotifications\NotificationsServiceProvider" --tag="migrations"

You should run migrate next to create the google_notifications table:

php artisan migrate

This packages registers a POST route (/google/server/notifications) to the Webhookscontroller of this package

Usage

When there is an change in one of the subscriptions Google will send a realtime notification via POST request to a configured endpoint. Follow this guide to setup Pub/Sub:

This package will send a 200 response if you configured the right Job for the right Notification Type otherwise it will send a 500 back to Google. Google will retry a couple of times more. The incoming payload is stored in the google_notifications table.

Handling incoming notifications via Jobs

<?php

namespace App\Jobs\GooglePlayNotifications;

use App\Jobs\Job;

class HandleRecovered extends Job
{
    public $notification;

    public function __construct(array $notification)
    {
        $this->notification = $notification;
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        // Do something that matches your business logic with $this->payload
    }
}

Changelog

Please see CHANGELOG for more information about what has changed recently.

Testing

composer test

Security

If you discover any security related issues, please email daan@app-vise.nl instead of using the issue tracker.

Credits

A big thanks to Spatie's laravel-stripe-webhooks which was a huge inspiration and starting point for this package

License

The MIT License (MIT). Please see License File for more information.