Laravel PayPal
Documentation
The documentation for the package can be viewed by clicking the following link:
https://srmklive.github.io/laravel-paypal/docs.html
Usage
Following are some ways through which you can access the paypal provider:
// Import the class namespaces first, before using it directly
use Srmklive\PayPal\Services\PayPal as PayPalClient;
$provider = new PayPalClient;
// Through facade. No need to import namespaces
$provider = PayPal::setProvider();
Override PayPal API Configuration
You can override PayPal API configuration by calling setApiCredentials
method:
$provider->setApiCredentials($config);
Get Access Token
After setting the PayPal API configuration by calling setApiCredentials
method. You need to get access token before performing any API calls
$provider->getAccessToken();
Set Currency
By default the currency used is USD
. If you wish to change it, you may call setCurrency
method to set a different currency before calling any respective API methods:
$provider->setCurrency('EUR');
Initiating an order for Checkout
Use the createOrder method to initiate an order
$provider->createOrder([
"intent"=> "CAPTURE",
"purchase_units"=> [
0 => [
"amount"=> [
"currency_code"=> "USD",
"value"=> "100.00"
]
]
]
]);
The response from this will include an order ID which you will need to retail, and a links collection so you can redirect the user to Paypal to complete the order with their payment details
When the user returns to the notifcation url you can capture the order payment with
$provider->capturePaymentOrder($order_id); //order id from the createOrder step
Support
This version supports Laravel 6 or greater.
- In case of any issues, kindly create one on the Issues section.
- If you would like to contribute:
- Fork this repository.
- Implement your features.
- Generate pull request.