2017 © Pedro Peláez
 

library laravel-paypal

A Paypal bridge for Laravel

image

sger/laravel-paypal

A Paypal bridge for Laravel

  • Saturday, July 9, 2016
  • by sger
  • Repository
  • 1 Watchers
  • 5 Stars
  • 140 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 1 Open issues
  • 2 Versions
  • 4 % Grown

The README.md

Laravel Paypal

Build Status Code Climate Test Coverage Issue Count, (*1)

Laravel Paypal is a bridge for Laravel 5 using the PHP SDK for PayPal RESTful APIs Package.This package is inspired by https://github.com/vinkla/vimeo., (*2)

Installation

Require this package, with Composer, in the root directory of your project., (*3)

composer require sger/laravel-paypal

Add the service provider to config/app.php in the providers array., (*4)

Sger\Paypal\PaypalServiceProvider::class
'Paypal' => Sger\Paypal\Facades\Paypal::class

Configuration

php artisan vendor:publish

This will create a config/paypal.php file in your app which contains two types of connection 'sandbox' and 'live'., (*5)

Usage

In your routes.php create for example:, (*6)

Route::resource('payments', 'PaymentsController');

next in your controller in your store method add the following code:, (*7)

$payer = new Payer;
$payer->setPaymentMethod("paypal");

$item1 = new Item();
$item1->setName('test')
    ->setCurrency('EUR')
    ->setQuantity(1)
    ->setPrice(10);

$itemList = new ItemList();
$itemList->setItems(array($item1));

$amount = new Amount();
$amount->setCurrency('EUR')
    ->setTotal(10);

$transaction = new Transaction();
$transaction->setAmount($amount)
    ->setItemList($itemList)
    ->setDescription("Payment description")
    ->setInvoiceNumber(uniqid());

$baseUrl = \URL::to('/');

$redirectUrls = new RedirectUrls();
$redirectUrls->setReturnUrl("$baseUrl/execute-payment?success=true")
->setCancelUrl("$baseUrl/execute-payment?success=false");

$payment = new Payment();

$payment->setIntent("sale")
    ->setPayer($payer)
    ->setRedirectUrls($redirectUrls)
    ->setTransactions(array($transaction));

try {
    $payment->create(\Paypal::connection('sandbox'));
} catch (\PPConnectionException $ex) {
    return  "Exception: " . $ex->getMessage() . PHP_EOL;
    exit(1);
}

$approvalUrl = $payment->getApprovalLink();
// redirect user to the $approvalUrl

License

Laravel Paypal is licensed under The MIT License (MIT)., (*8)

The Versions