libern / laravel-appstore-server-notifications
处理 Appstore 服务器之间的通知
v0.0.5
2020-11-11 12:44 UTC
Requires
- php: ^7.1
- bensampo/laravel-enum: ^1.0
- illuminate/support: ^5.5|^5.6|^5.7|^5.8|^6.0|^7.0
Requires (Dev)
- orchestra/testbench: ~3.7.0|^4.0
- phpunit/phpunit: ^8.2
README
安装
您可以通过 composer 安装此包
composer require libern/laravel-appstore-server-notifications
服务提供程序将自动注册。您必须使用以下命令发布配置文件:
php artisan vendor:publish --provider="Appvise\AppStoreNotifications\NotificationsServiceProvider" --tag="config"
以下是将要发布的配置。
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, ], ];
共享密钥应与您发送给商店以验证收据的密钥相匹配
此包将所有传入请求记录到数据库中,因此这些步骤是强制性的
php artisan vendor:publish --provider="Appvise\AppStoreNotifications\NotificationsServiceProvider" --tag="migrations"
您应该运行迁移来创建 apple_notifications 表
php artisan migrate
此包将一个 POST 路由 (/apple/server/notifications) 注册到该包的 Webhookscontroller
用法
当订阅之一发生变化时,Apple 会将 POST 请求发送到配置的端点。 遵循此指南配置端点:
如果您为正确的通知类型配置了正确的作业,此包将发送 200 响应;否则,它将向 Apple 发送 500 响应。Apple 将重试几次。传入的有效负载存储在 apple_notifications 表中。
通过作业处理传入的通知
<?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 了解最近更改的更多信息。
测试
composer test
安全
如果您发现任何安全相关的问题,请通过电子邮件 daan@app-vise.nl 而不是使用问题跟踪器。
鸣谢
非常感谢 Spatie's laravel-stripe-webhooks,它为这个包提供了巨大的灵感和起点
许可证
MIT 许可证 (MIT)。有关更多信息,请参阅 许可证文件。