金额参数是必需的 - Omnipay paypal laravel
The amount parameter is required - Omnipay paypal with laravel
您好,我一直在尝试使用带有 Laravel 4 的 Omnipay paypal 将 paypal 与我网站的购物车集成。到目前为止,我主要使用 THIS 教程。
我仍处于初始阶段,但遇到了障碍。当我尝试结帐时,我收到一条错误消息 "The amount parameter is required"。
我有点菜鸟,所以我可能会做一些愚蠢的事情,但如果我对数量进行硬编码(即:'price' => 25.00,)那么它应该可以正常工作。描述和货币也都从数据库中提取并发送到贝宝页面。我在这里发现的问题似乎没有人将数据动态地拉到他们的控制器所以也许我做错了什么?
这是我的控制器的相关部分:
<?php
use Omnipay\Omnipay;
class PaymentController extends Controller {
public function postPayment() {
$params = array(
'cancelUrl' => 'http://localhost/cancel_order',
'returnUrl' => 'http://localhost/payment_success',
'name' => Input::get('name'),
'description' => Input::get('description'),
'price' => Input::get('price'),
'currency' => Input::get('currency') );
Session::put('params', $params);
Session::save();
$gateway = Omnipay::create('PayPal_Express');
$gateway->setUsername('my username');
$gateway->setPassword('my pass');
$gateway->setSignature('my signature');
$gateway->setTestMode(true);
$response = $gateway->purchase($params)->send();
这是我的购物车结帐按钮:
{{ Form::open([ 'url' => 'pay_via_paypal', 'method' => 'post' ]) }}
{{Form::hidden('product',Product::find($productID)->name)}}
{{Form::hidden('description',Product::find($productID)->description)}}
{{Form::hidden('amount',Product::find($productID)->price)}}
{{Form::hidden('currency',Product::find($productID)->currency)}}
{{Form::submit('CHECKOUT')}}
{{Form::close()}}
表单可能看起来有点混乱,但在我提交之前,表单上的所有值都显示正常。
感谢您的帮助。
如果你仔细查看教程,你会看到有一个 index()
函数负责生成表单。以及处理表单提交的 postPayment()
函数。
在 index() 函数中(在教程中)
在hello.blade.php
中有一个参数叫做price
<input type="hidden" value="{{ $price }}" name="price" />
你的情况
{{ Form::hidden('amount',Product::find($productID)->price) }}
应替换为
{{ Form::hidden('price',Product::find($productID)->price) }}
然后当你提交表单时它会路由到 postPayment()
函数,在这里,所以 Route::post('pay_via_paypal', 'PaymentController@postPayment');
这个路由应该在你的 route
文件中
在postPayment()
函数中,
$params = array(
'cancelUrl' => 'http://localhost/cancel_order',
'returnUrl' => 'http://localhost/payment_success',
'name' => Input::get('name'),
'description' => Input::get('description'),
// you dont need this price parameter ('price' => Input::get('price'),)
'amount' => Input::get('price'), // add amount parameter which is required in paypal.
'currency' => Input::get('currency') );
仅作说明,
you are repeatedly use Product::find($productID)
which is not a good practice, If you get that product into a Object variable then, You can use that object without repeating Product::find($productID)
.
要做到这一点,您可以将 object
从控制器传递到 blade 视图,
喜欢,
$product = Product::find($productId);
return View::make('hello')->with(Array("product" => $product));
在 blade 视图中,
....
{{ Form::hidden('product',$product->name) }}
{{ Form::hidden('description',$product->description) }}
....
..等等
您好,我一直在尝试使用带有 Laravel 4 的 Omnipay paypal 将 paypal 与我网站的购物车集成。到目前为止,我主要使用 THIS 教程。
我仍处于初始阶段,但遇到了障碍。当我尝试结帐时,我收到一条错误消息 "The amount parameter is required"。
我有点菜鸟,所以我可能会做一些愚蠢的事情,但如果我对数量进行硬编码(即:'price' => 25.00,)那么它应该可以正常工作。描述和货币也都从数据库中提取并发送到贝宝页面。我在这里发现的问题似乎没有人将数据动态地拉到他们的控制器所以也许我做错了什么?
这是我的控制器的相关部分:
<?php
use Omnipay\Omnipay;
class PaymentController extends Controller {
public function postPayment() {
$params = array(
'cancelUrl' => 'http://localhost/cancel_order',
'returnUrl' => 'http://localhost/payment_success',
'name' => Input::get('name'),
'description' => Input::get('description'),
'price' => Input::get('price'),
'currency' => Input::get('currency') );
Session::put('params', $params);
Session::save();
$gateway = Omnipay::create('PayPal_Express');
$gateway->setUsername('my username');
$gateway->setPassword('my pass');
$gateway->setSignature('my signature');
$gateway->setTestMode(true);
$response = $gateway->purchase($params)->send();
这是我的购物车结帐按钮:
{{ Form::open([ 'url' => 'pay_via_paypal', 'method' => 'post' ]) }}
{{Form::hidden('product',Product::find($productID)->name)}}
{{Form::hidden('description',Product::find($productID)->description)}}
{{Form::hidden('amount',Product::find($productID)->price)}}
{{Form::hidden('currency',Product::find($productID)->currency)}}
{{Form::submit('CHECKOUT')}}
{{Form::close()}}
表单可能看起来有点混乱,但在我提交之前,表单上的所有值都显示正常。
感谢您的帮助。
如果你仔细查看教程,你会看到有一个 index()
函数负责生成表单。以及处理表单提交的 postPayment()
函数。
在 index() 函数中(在教程中)
在hello.blade.php
中有一个参数叫做price
<input type="hidden" value="{{ $price }}" name="price" />
你的情况
{{ Form::hidden('amount',Product::find($productID)->price) }}
应替换为
{{ Form::hidden('price',Product::find($productID)->price) }}
然后当你提交表单时它会路由到 postPayment()
函数,在这里,所以 Route::post('pay_via_paypal', 'PaymentController@postPayment');
这个路由应该在你的 route
文件中
在postPayment()
函数中,
$params = array(
'cancelUrl' => 'http://localhost/cancel_order',
'returnUrl' => 'http://localhost/payment_success',
'name' => Input::get('name'),
'description' => Input::get('description'),
// you dont need this price parameter ('price' => Input::get('price'),)
'amount' => Input::get('price'), // add amount parameter which is required in paypal.
'currency' => Input::get('currency') );
仅作说明,
you are repeatedly use
Product::find($productID)
which is not a good practice, If you get that product into a Object variable then, You can use that object without repeatingProduct::find($productID)
.
要做到这一点,您可以将 object
从控制器传递到 blade 视图,
喜欢,
$product = Product::find($productId);
return View::make('hello')->with(Array("product" => $product));
在 blade 视图中,
....
{{ Form::hidden('product',$product->name) }}
{{ Form::hidden('description',$product->description) }}
....
..等等