1. Go to this page and download the library: Download hypnodev/larapal library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
hypnodev / larapal example snippets
namespace App;
use hypnodev\Larapal\Traits\BillableWithPaypal;
// ...
class User extends Authenticatable
{
use Notifiable, BillableWithPaypal;
// ...
}
auth()->user()->chargeWithPaypal('Charge description', [ // Array of items
['name' => 'pkg base', 'description' => 'base package', 'price' => 10.00, 'tax' => 2]
]);
// If your charge has shipping, you need to add an extra param with name and amount
auth()->user()->chargeWithPaypal('Charge description', [ // Array of items
['name' => 'pkg base', 'description' => 'base package', 'price' => 10.00, 'tax' => 2]
], [ // Shipping
'name' => 'Courier name',
'amount' => 100.50,
'address' => [ // Optional, you can skip this key
'address' => '4178 Libby Street',
'city' => 'Hermosa Beach',
'state' => 'CA',
'postal_code' => '90254',
'country' => 'USA'
]
]);
auth()->user()->subscribeWithPaypal('Plan id');
namespace App;
use hypnodev\Larapal\Traits\BillableWithPaypal;
// ...
class User extends Authenticatable
{
use Notifiable, BillableWithPaypal;
// ...
/**
* @inheritDoc
*/
protected function getPaypalCurrency(): string
{
return 'USD';
}
}
namespace App;
use hypnodev\Larapal\Traits\BillableWithPaypal;
// ...
class User extends Authenticatable
{
use Notifiable, BillableWithPaypal;
// ...
/**
* @inheritDoc
*/
protected function getShippingFields(): array
{
return [
'address' => $this->shipping_address,
'city' => $this->shipping_city,
'state' => $this->shipping_state,
'postal_code' => $this->shipping_postal_code,
'country' => $this->shipping_country
];
}
}