我是Laravel新手。我一直在努力在我的网站上实施Paypal Express Checkout几天,以便为非营利组织捐款。感谢these explanations我已经能够安装Omnipay,让用户输入他想要捐赠的金额并转到Paypal。 但是,当我尝试结束交易(付款)时,我没有重定向到我的成功消息。我的沙箱帐户也没有显示任何交易,所以看起来付款没有正确完成。我猜有什么毛病我的“getSuccessPayment”的功能,但我无法弄清楚它是什么......Laravel 5.3 - Omnipay Paypal Express不回复成功消息
这里是我的控制器至今:
<?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('/payment_success'),
'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('/payment_success');
} else {
//payment fails
return redirect('/payment_failure');
}
}
}
?>
我的路线:
Route::post('donner',
['as' => 'payment', 'uses' => '[email protected]']);
Route::get('payment_success', '[email protected]');
Route::get('payment_failure', '[email protected]');
嗨@mefimefi谢谢你。我花了整整一天的时间尝试做一些他们说在我的版本的laravel 5.3.30上安装omnipay/paypal很困难的事情。我终于设法今天破解它。首先在你的终端中运行:'composer需要symfony/event-dispatcher:^ 2.8'。之后在终端运行:'composer require omnipay/paypal:“2.6.3”'。当然,我的贝宝版本是当前版本(你也可以把作曲家需要omnipay/paypal:*)。希望这有助于某人。 :) – Matija
我忘了最后一个:'作曲家需要点燃/ laravel-omnipay:“2.3.0”'那就应该这样做。之后你需要服务提供者:''Ignited \ LaravelOmnipay \ LaravelOmnipayServiceProvider','和别名:''Omnipay'=>'Ignited \ LaravelOmnipay \ Facades \ OmnipayFacade','in * config/app.php * – Matija