A Laravel 5 wrapper for PayPal
- PHP >= 5.5
This package wraps paypal/rest-api-sdk-php package.
Require the package
composer require pulkitjalan/paypal-laravel
Laravel 5.5 uses Package Auto-Discovery, so you don't need to manually add the ServiceProvider.
If you don't use auto-discovery, add the following to the providers
array in your config/app.php
PulkitJalan\PayPal\PayPalServiceProvider::class,
Next add the following to the aliases
array in your config/app.php
. Pick and choose if you want or add all 3.
'PayPal' => PulkitJalan\PayPal\Facades\PayPal::class,
The config is set in config/services.php
'paypal' => [
'client_id' => env('PAYPAL_CLIENT_ID'),
'client_secret' => env('PAYPAL_CLIENT_SECRET'),
'mode' => env('PAYPAL_MODE'), // default is sandbox
// 'log' => [
// 'enabled' => true // default is false
// 'file' => 'paypal.log' // default is laravel.log
// 'level' => 'DEBUG' // default is DEBUG
// ],
],
Main use is to get one of the PayPal api classes.
use PulkitJalan\PayPal\PayPal
class App {
protected $paypal;
public function __construct(PayPal $paypal)
{
$this->paypal = $paypal;
}
public function payout()
{
$payouts = $this->paypal->payout(); // returns PayPal\Api\Payout
$senderBatchHeader = $this->paypal->payoutSenderBatchHeader(); // returns PayPal\Api\PayoutSenderBatchHeader
...
$senderItem = $this->paypal->payoutItem(); // returns PayPal\Api\PayoutItem
...
$payouts->setSenderBatchHeader($senderBatchHeader)
->addItem($senderItem);
...
$payout->create([], $this->paypal->getApiContext());
}
}