socialiteproviders / paypal-sandbox
Laravel Socialite 的 PayPal Sandbox OAuth2 提供程序
4.3.0
2024-02-07 12:51 UTC
Requires
- php: ^8.0
- ext-json: *
- socialiteproviders/manager: ^4.4
README
composer require socialiteproviders/paypalsandbox
安装与基本使用
请参阅 基本安装指南,然后按照以下特定提供程序的说明进行操作。
在 config/services.php
中添加配置
'paypal_sandbox' => [ 'client_id' => env('PAYPALSANDBOX_CLIENT_ID'), 'client_secret' => env('PAYPALSANDBOX_CLIENT_SECRET'), 'redirect' => env('PAYPALSANDBOX_REDIRECT_URI') ],
添加提供程序事件监听器
Laravel 11+
在 Laravel 11 中,默认的 EventServiceProvider
提供程序已被移除。取而代之,您可以在 AppServiceProvider
的 boot
方法中使用 Event
门面上的 listen
方法添加监听器。
- 注意:除非您使用自己的提供程序覆盖内置的社会化登录提供程序,否则您不需要添加任何内容。
Event::listen(function (\SocialiteProviders\Manager\SocialiteWasCalled $event) { $event->extendSocialite('paypal_sandbox', \SocialiteProviders\PayPalSandbox\Provider::class); });
Laravel 10 或以下
配置包的监听器以监听 `SocialiteWasCalled` 事件。将事件添加到 app/Providers/EventServiceProvider
中的 listen[]
数组。有关详细说明,请参阅 基本安装指南。
protected $listen = [ \SocialiteProviders\Manager\SocialiteWasCalled::class => [ // ... other providers \SocialiteProviders\PayPalSandbox\PayPalSandboxExtendSocialite::class.'@handle', ], ];
使用方法
现在您应该能够像常规使用 Socialite 一样使用此提供程序(假设您已安装了门面)
return Socialite::driver('paypal_sandbox')->redirect();
返回的用户字段
id
name
email