mercredi 15 février 2017

Laravel 5.3 - Omnipay Paypal Express not returning success message

I'm new to Laravel. I've been struggling to implement Paypal Express Checkout in my website for a couple days in order to enable donations to a non-profit organization. Thanks to these explanations I've been able to install Omnipay, let the user input the amount (s)he wants to donate and go to Paypal. But, when I try to end the transaction (Pay), I'm not redirected to my succes message. My sandbox account does not show any transactions either, so it seems the payment is not completed correctly. I'm guessing there's something wrong with my "getSuccessPayment" function, but I can't figure out what it is...

Here's my Controller so far :

<?php namespace App\Http\Controllers;
use Omnipay\Omnipay;
use Session;
use App\Http\Requests\PaymentRequest;

class PaymentController extends Controller {

    public function postPayment(PaymentRequest $request)
    {
        $price = $request->get('price');

        $items[] = array('name' => 'Don', 'quantity' => 1, 'price' => $price);

        $params = array(
            'cancelUrl'=>url('/donner'),
            'returnUrl'=>url('/donner'),
            'amount' =>  $price,
            'currency' => 'EUR'
        );

        Session::put('params', $params);
        Session::save();

        $gateway = Omnipay::create('PayPal_Express');
        $gateway->setUsername('my sandbox email'); 
        $gateway->setPassword('my sandbox password');  
        $gateway->setSignature('my sandbox signature');
        $gateway->setTestMode(true);

       $response = $gateway->purchase($params)->setItems($items)->send();

        if ($response->isSuccessful()) {
            print_r($response);
        } elseif ($response->isRedirect()) {
            $response->redirect();
        } else {
            echo $response->getMessage();
        }
    }

     public function getSuccessPayment()
    {

        $gateway = Omnipay::create('PayPal_Express');
        $gateway->setUsername('my sandbox email'); 
        $gateway->setPassword('my sandbox password');  
        $gateway->setSignature('my sandbox signature');
        $gateway->setTestMode(true);

        $params = Session::get('params');
        $response = $gateway->completePurchase($params)->send();
        $paypalResponse = $response->getData(); 

        if(isset($paypalResponse['PAYMENTINFO_0_ACK']) && $paypalResponse['PAYMENTINFO_0_ACK'] === 'Success') {
            return redirect('/paypal_success');

        } else {
            //payment fails

        }
    }
}
?>

And my Routes :

Route::post('donner',
    ['as' => 'payment', 'uses' => 'PaymentController@postPayment']);

Route::get('payment_success', 'PaymentController@getSuccessPayment');



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2kwtHHj
via IFTTT

Aucun commentaire:

Enregistrer un commentaire