Daan Geurts
7296146aad
|
5 years ago | |
---|---|---|
config | 5 years ago | |
database/migrations | 5 years ago | |
src | 5 years ago | |
tests | 5 years ago | |
.editorconfig | 5 years ago | |
.gitattributes | 5 years ago | |
.gitignore | 5 years ago | |
.scrutinizer.yml | 5 years ago | |
.styleci.yml | 5 years ago | |
.travis.yml | 5 years ago | |
CHANGELOG.md | 5 years ago | |
CONTRIBUTING.md | 5 years ago | |
LICENSE.md | 5 years ago | |
README.md | 5 years ago | |
UPGRADING.md | 5 years ago | |
composer.json | 5 years ago | |
phpunit.xml.dist | 5 years ago |
README.md
Handle Appstore server-to-server notifications for auto-renewable subscriptions
Installation
You can install this package via composer
composer require app-vise/laravel-appstore-server-notifications
The service provider will register itself. You have to publish the config file with:
php artisan vendor:publish --provider="Appvise\AppStoreNotifications\NotificationsServiceProvider" --tag="config"
This is the config that will be published.
return [
/*
* Apple will send the shared secret with the request that should match
* the one you use when validating receipts.
* https://developer.apple.com/documentation/storekit/in-app_purchase/enabling_server-to-server_notifications?language=objc#overview
*/
'shared_secret' => env('APPLE_SHARED_SECRET'),
/*
* 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.apple.com/documentation/storekit/in-app_purchase/enabling_server-to-server_notifications?language=objc#3162176
*/
'jobs' => [
// 'initial_buy' => \App\Jobs\AppstoreNotifications\HandleInitialBuy::class,
// 'cancel' => \App\Jobs\AppstoreNotifications\HandleCancellation::class,
// 'renewal' => \App\Jobs\AppstoreNotifications\HandleRenewal::class,
// 'interactive_renewal' => \App\Jobs\AppstoreNotifications\HandleInteractiveRenewal::class,
// 'did_change_renewal_pref' => \App\Jobs\AppstoreNotifications\HandleDidChangeRenewalPreferences::class,
// 'did_change_renewal_status' => \App\Jobs\AppstoreNotifications\HandleDidChangeRenewalStatus::class,
],
];
The shared secret should match the one you send to the store to validate receipts
This package logs all the incoming requests to the database so these steps are mandatory:
php artisan vendor:publish --provider="Appvise\AppStoreNotifications\NotificationsServiceProvider" --tag="migrations"
You should run migrate next to create the apple_notifications table:
php artisan migrate
This packages registers a POST route (/apple/server/notifications) to the Webhookscontroller of this package
Usage
When there is an change in one of the subscriptions Apple will send a POST request to a configured endpoint. Follow this guide to configure the endpoint:
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 Apple. Apple will retry a couple of times more. The incoming payload is stored in the apple_notifications table.
Handling incoming notifications via Jobs
<?php
namespace App\Jobs\AppstoreNotifications;
use App\Jobs\Job;
use Appvise\AppStoreNotifications\Model\NotificationPayload;
class HandleInitialBuy extends Job
{
public $payload;
public function __construct(NotificationPayload $payload)
{
$this->payload = $payload;
}
/**
* 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 [email protected] 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.