epmnzava / paypal-laravel
This is a laravel package for intergration with paypal
Requires
- php: ^7.1|^7.2|^7.3|^7.4|^8.0
- illuminate/support: ^5.5.44|^6.0|^7.0|^8.0|^9.0|^10.0
README
This package is meant to help laravel developers to easily integrate their server side web application or web service with Paypal
Installation
Version Matrix
You can install the package via composer:
composer require epmnzava/paypal-laravel
Update your config (for Laravel 5.4 and below)
Add the service provider to the providers array in config/app.php:
"Epmnzava\PaypalLaravel\PaypalLaravelServiceProvider"::class
Add the facade to the aliases array in config/app.php:
'Paypal'=>Epmnzava\PaypalLaravel\PaypalLaravelFacade::class,
Publish the package configuration (for Laravel 5.4 and below)
Publish the configuration file and migrations by running the provided console command:
php artisan vendor:publish --provider="Epmnzava\PaypalLaravel\PaypalLaravelServiceProvider"
Environmental Variables
PAYPAL_CLIENT_ID your provided paypal client id
PAYPAL_CLIENT_SECRET your provided paypal client secret
PAYPAL_REDIRECT_URL your redirect url
PAYPAL_CANCEL_URL your cancel url
PAYPAL_ENVIRONMENT your environment either test or production
PAYPAL_CURRENCY_CODE currency put TZS for Tanzanian Shillings
PAYPAL_ORG_NAME your organization name
Usage
<?php> namespace App\Http\Controllers; use Illuminate\Http\Request; use Epmnzava\PaypalLaravel\PaypalLaravel as Paypal; class TestController extends Controller { public function payments(Request $request){ $paypal_payments=new paypal; $response=$paypal_payments->CreatePayment(int $amount, $tax, $shipping, $handling_fee, $description); // You will need the order_id to reference the transaction hence save it from here. $payment_id=$response["order_id"]; //the checkout link will lead the user you to paypal where he/she can approve the payment. return redirect($response["checkout_link"]); }
After payment approval the user will be redirected back to your application on PAYPAL_REDIRECT_URL which you have set on your .env
<?php namespace App\Http\Controllers; use Illuminate\Http\Request; use Epmnzava\PaypalLaravel\PaypalLaravel as Paypal; class TestController extends Controller { public function paypal_redirect(Request $request){ $paypal=new Paypal; // This will execute the approved payment notice that the redirected url comes back with PayerID which we reuse it $response=$paypal->executePayment($request->paymentId,$request->PayerID); if(json_decode($response)->state=="approved"){ // update your database and share the success message to the user. } }
Testing
composer test
Changelog
Please see CHANGELOG for more information what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email epmnzava@gmail.com instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.