sger / laravel-paypal by sger

A Paypal bridge for Laravel
169
6
3
Package Data
Maintainer Username: sger
Maintainer Contact: spiros.gerokostas@gmail.com (Spiros Gerokostas)
Package Create Date: 2016-07-08
Package Last Update: 2016-07-09
Home Page:
Language: PHP
License: MIT
Last Refreshed: 2024-11-22 03:09:54
Package Statistics
Total Downloads: 169
Monthly Downloads: 3
Daily Downloads: 0
Total Stars: 6
Total Watchers: 3
Total Forks: 1
Total Open Issues: 1

Laravel Paypal

Build Status Code Climate Test Coverage Issue Count

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.

Installation

Require this package, with Composer, in the root directory of your project.

composer require sger/laravel-paypal

Add the service provider to config/app.php in the providers array.

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'.

Usage

In your routes.php create for example:

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

next in your controller in your store method add the following code:

$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).