I used this https://github.com/thephpleague/omnipay (popular payment package). I used both the API and the express checkout on PayPal.
PayPal on Laravel 5.2.22
Heya guys, does anyone know how to integrate PayPal payements on Laravel 5.2.22 ?
Thanks for your answers.
Heya bashy, thanks for you answer ! Can you give me some example code ? Omnipay for paypal is poorly documentend :/
There's a couple of examples around. https://solidmarkup.com/blog/using-omnipay-paypal-with-laravel is one I looked at to get a feel of it. Read the code in the src folder and you can understand what is needed.
- Basically you have a form with a submit button, send that to Laravel and read/save the package they choose into the session.
- After saving to session, request it to PayPal using the methods in the package.
- redirect to PayPal.
- listen for ACK response for payment success etc.
Tried with omnipay, but the example you give me is really outdated, and don't really work :/ (i'm certainly don't doing it right) Thanks for trying by the way, i'm loosing my hope haha. If you have any advice, don't hesitate !
The latest version of cashier supports paypal out of the box via briantree. It's marked as a beta feature, but might work for what you want to do :-)
@Maddox Well, it's not totally right but 90% of it still works on the latest. It's a starting point and you should be able to work out the rest by looking in the code of omnipay. Have you still got the code you tried? What didn't work?
Gonna take a look about this @ohffs Did you already used it ? :)
@bashy Last try i did was with http://packalyst.com/packages/package/netshell/paypal, after installation, tried the "ExampleController" and got this error changing these lines;
$redirectUrls->setReturnUrl(action('ThisController@getDone')); $redirectUrls->setCancelUrl(action('ThisController@getCancel'));
Replacing the name of the Controller by mine, and got this error.
1/1 InvalidArgumentException in UrlGenerator.php line 603: Action App\Http\Controllers\PaymentController@getDone not defined.
@Maddox That's not the omnipay package though. I used omnipay/paypal in composer and made the calls manually in two methods on a payment controller.
@Maddox no - thankfully I don't have to deal with billing stuff these days :-)
I don't think Omnipay v 2 is even compatible with Larvel version 5.2 due to Symfony 3 not being supported by Omnipay at present.
Anyone know a solution that does work for Laravel 5.2? I need to be able to integrate multiple payment gateways - ie Paypal, Sage, Stripe etc etc.
ich stehe vor dem gleichen Problem .. Jede Idee ist hilfreich.
I actually made it work with Omnypay on Laravel 5.2 (for paypal) Can give the code if you want some help.
that would be awesome! Thank you so much @Maddox !
Hi Maddox
If you have any code that illustrates how you got Ominpay working on Laravel 5.2, I'm sure there are several here who would be very grateful (including myself) :o)
- You need to add to your composer.json, on require-dev section:
"ignited/laravel-omnipay": "2.*",
"omnipay/omnipay": "*"
- Update your composer, and add the aliase and the service provider on config/app.php
Service provider
'Ignited\LaravelOmnipay\LaravelOmnipayServiceProvider',
Aliase
'Omnipay' => 'Ignited\LaravelOmnipay\Facades\OmnipayFacade',
Now you are ready to use my PaymentController ! (commentend in french sorry, ask me if you want me to translate)
<?php
/**
* Site web de vente - Commerxio
* @author Micaël Cid
* @version 1.0
*
* Controlleur permettant de gérer le paiement.
*/
namespace App\Http\Controllers;
use Omnipay\Omnipay;;
use Session;
use Gloudemans\Shoppingcart\Facades\Cart;
/**
* Class PaymentController
* @package App\Http\Controllers
*/
class PaymentController extends Controller
{
/**
* Fonction me permettant de tout préparer pour envoyer la requête de paiement.
*
* @todo Compléter la fonction, notamment au niveau du traitement de $response
* Permet de mettre tous les paramètres nécessaires au paiement dans la session de l'utilisateur.
* L'url d'annulation.
* L'url de retour en cas de succès.
* Le montant total.
* La devise.
* Le contenue de tous les articles de mon chariots.
*/
public function postPayment()
{
$items = array();
foreach(Cart::content() as $item)
{
$items[] = array('name' => $item->name, 'quantity' => $item->qty, 'price' => $item->price);
}
$params = array(
'cancelUrl'=>'http://commerxio.dev/payment/cancel',
'returnUrl'=>'http://commerxio.dev/payment/sucess',
'amount' => Cart::total(),
'currency' => 'CHF'
);
Session::put('params', $params);
Session::save();
$gateway = Omnipay::create('PayPal_Express');
$gateway->setUsername('SanboxEmail');
$gateway->setPassword('SanboxPassword');
$gateway->setSignature('SanboxSignature');
$gateway->setTestMode(true);
$response = $gateway->purchase($params)->setItems($items)->send();
if ($response->isSuccessful()) {
// payment was successful: update database
print_r($response);
} elseif ($response->isRedirect()) {
// redirect to offsite payment gateway
$response->redirect();
} else {
// payment failed: display message to customer
echo $response->getMessage();
}
}
/**
* Fonction permettant de completer la requête de paiement, ainsi que de traiter la réponse de PayPal.
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
*
*/
public function getSuccessPayment()
{
$gateway = Omnipay::create('PayPal_Express');
$gateway->setUsername('SandBoxUsername');
$gateway->setPassword('SandboxPassword');
$gateway->setSignature('SandboxSignature');
$gateway->setTestMode(true);
$params = Session::get('params');
$response = $gateway->completePurchase($params)->send();
$paypalResponse = $response->getData(); // this is the raw response object
if(isset($paypalResponse['PAYMENTINFO_0_ACK']) && $paypalResponse['PAYMENTINFO_0_ACK'] === 'Success') {
return view('payment.sucess');
} else {
//Failed transaction
}
}
}
Thanks for your code.
Is this definitely working in Laravel 5.2 ?
did you not get these errors (due to Laravel 5.2 running Symphony 3 as a component)
installation request for ignited/laravel-omnipay ^2.1 -> satisfiable by ignited/laravel-omnipay[2.1.0].
Conclusion: remove symfony/http-foundation v3.0.2
Conclusion: don't install symfony/http-foundation v3.0.2
ignited/laravel-omnipay 2.1.0 requires omnipay/common 2.3.* -> satisfiable by omnipay/common[2.3.2, v2.3.0, v2.3.1, v2.3.3, v2.3.4]. .............
Can only install one of: symfony/http-foundation[v2.6.9, v3.0.2].
Can only install one of: symfony/http-foundation[v2.7.0, v3.0.2].
Can only install one of: symfony/http-foundation[v2.7.1, v3.0.2].
Can only install one of: symfony/http-foundation[v2.7.2, v3.0.2].
Can only install one of: symfony/http-foundation[v2.7.3, v3.0.2].
Can only install one of: symfony/http-foundation[v2.7.4, v3.0.2].
Can only install one of: symfony/http-foundation[v2.7.5, v3.0.2].
Can only install one of: symfony/http-foundation[v2.7.6, v3.0.2].
Can only install one of: symfony/http-foundation[v2.7.7, v3.0.2].
Can only install one of: symfony/http-foundation[v2.7.8, v3.0.2].
Can only install one of: symfony/http-foundation[v2.7.9, v3.0.2].
Installation request for symfony/http-foundation == 3.0.2.0 -> satisfiable by symfony/http-foundation[v3.0.2]. `
Yeah, sorry, it's because you need to add:
"omnipay/omnipay": "*"
to your composer.json first, then update it, and finally add:
"ignited/laravel-omnipay": "2.*",
and re-update !
Many thanks again.
I created a new fresh install of Laravel 5.2 and have managed to install Omnipay. No idea why I got the errors I did previously!
Off to try a few code tests. This is going to be so much easier than writing all my own implementation.. The in code comments in the official Omipay gateways are fantastic.
Take a look at these comments for the REST Paypal Auth request. Beautiful comments :0)
https://github.com/thephpleague/omnipay-paypal/blob/master/src/Message/RestAuthorizeRequest.php
Really nice one ! Didn't found this one :3
Hope your code is working now :)
I lost a day yesterday on this. I manged to crack it with this:
First in terminal run:
composer require symfony/event-dispatcher:^2.8
after that run
composer require omnipay/paypal:"2.6.3"
after that run
composer require ignited/laravel-omnipay:"2.3.0"
Note: Of course you can use what ever version you prefer, I just prefer putting the exact ones in.
Please or to participate in this conversation.