Skip to content

dbrax/paypal-laravel

Repository files navigation

Paypal Server Intergration With Laravel

Latest Version on Packagist Build Status Total Downloads Emmanuel Mnzava

This package is meant to help laravel developers to easily integrate their server side web application or web service with Paypal

alt text

Installation

Version Matrix

Version Laravel PHP Version
1.5 8.0 >= 8.0
1.3 8.0 >= 7.3
1.2 7.0 >= 7.2.5

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.

Any questions or comments hit me up on