VerifyCsrfToken.php 第 67 行中的 TokenMismatchException:将 paytm 与 laravel 5.3 集成时
TokenMismatchException in VerifyCsrfToken.php line 67: while integrating paytm with laravel 5.3
token mismatch exception in verifyCsrfToken
我通过将“https://github.com/anandsiddharth/laravel-paytm-wallet”与 laravel 5.3 联系起来集成了 paytm,在付款时它重定向到 paytm 网站,当它重定向回我的网站时它给出错误 "TokenMismatchException in VerifyCsrfToken.php line 67"
View.php
<form action="{{action('OrderController@order')}}" method="post" name="payuForm" >
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<input type="hidden" name="firstname" id="firstname" value="{{$data1->first_name}}" />
<input type="hidden" name="email" id="email" value="{{$data1->email}}" />
<input type="text" name="amount" value="<?php echo $data[0]->cost?>" readonly/>
<input type="text" name="productinfo" value="<?php echo $data[0]->mid?>" readonly />
<input type="text" name="phone" value="{{$data1->mobile}}" readonly/>
<center><button class="btn btn-colored btn-theme-colored text-uppercase pay">Pay</button></center>
</form>
Controller.php
<?php
namespace App\Http\Controllers;
use PaytmWallet;
use Illuminate\Http\Request;
use App\EventRegistration;
use Session;
use DB;
class OrderController extends Controller
{
/**
* Redirect the user to the Payment Gateway.
*
* @return Response
*/
public function register()
{
return view('register');
}
/**
* Redirect the user to the Payment Gateway.
*
* @return Response
*/
public function order(Request $request)
{
$input = $request->all();
//pri($input); die();
$input['order_id'] = str_random(16);
$input['fee'] = $input['amount'];
Session::put('packid', $input['productinfo']);
EventRegistration::create($input);
$payment = PaytmWallet::with('receive');
$payment->prepare([
'order' => $input['order_id'],
'user' => $input['firstname'],
'mobile_number' => $input['phone'],
'email' => $input['email'],
'amount' => $input['fee'],
'callback_url' => url('payment/status')
]);
//pri($payment);exit;
return $payment->receive();
}
/**
* Obtain the payment information.
*
* @return Object
*/
public function paymentCallback()
{
$transaction = PaytmWallet::with('receive');
$response = $transaction->response();
$order_id = $transaction->getOrderId();
if($transaction->isSuccessful()){
dd('payment Done');
}else if($transaction->isFailed()){
dd('payment Failed');
}
}
}
Routes.php
Route::get('event-registration', 'OrderController@register');
Route::post('payment', 'OrderController@order');
Route::post('payment/status', 'OrderController@paymentCallback');
添加 /
以不通过现有 url
追加 url
Route::get('/event-registration', 'OrderController@register');
Route::post('/payment', 'OrderController@order');
Route::post('/payment/status', 'OrderController@paymentCallback');
并使用 /payment
作为表单标记中的操作,因为您已经为此 'OrderController@order'
创建了路由并且没有使用任何命名路由。
<form action="/payment" method="post" name="payuForm" >
还要检查你在路由中请求数据
Route::post('payment', function(Illuminate\Http\Request $request){
return dd($request->all());
});
我也遇到这个错误,不过我已经解决了问题。
php artisan cache:clear.
清除缓存和 cookie 浏览器。
使用私人浏览器 (Mozilla)/隐身 Window (Chrome)
打开您的 form/page 然后提交。
希望这对你有用。
嘿@Deepak Patel 我搜索了很多与您的相关信息 question.i 找到了适合您的解决方案。
版本 5.1 Laravel 的 VerifyCsrfToken 中间件允许 routes.you 需要将路由添加到 App\Http\MiddlewareVerifyCsrfToken class:
中的 $except 数组
<?php namespace App\Http\Middleware;
use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as BaseVerifier;
class VerifyCsrfToken extends BaseVerifier
{
protected $except = [
'your-route-name/*',
];
}
它在 laravel 中禁用 csrf 用于特定 route.Hope 它的工作。
token mismatch exception in verifyCsrfToken
我通过将“https://github.com/anandsiddharth/laravel-paytm-wallet”与 laravel 5.3 联系起来集成了 paytm,在付款时它重定向到 paytm 网站,当它重定向回我的网站时它给出错误 "TokenMismatchException in VerifyCsrfToken.php line 67"
View.php
<form action="{{action('OrderController@order')}}" method="post" name="payuForm" >
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<input type="hidden" name="firstname" id="firstname" value="{{$data1->first_name}}" />
<input type="hidden" name="email" id="email" value="{{$data1->email}}" />
<input type="text" name="amount" value="<?php echo $data[0]->cost?>" readonly/>
<input type="text" name="productinfo" value="<?php echo $data[0]->mid?>" readonly />
<input type="text" name="phone" value="{{$data1->mobile}}" readonly/>
<center><button class="btn btn-colored btn-theme-colored text-uppercase pay">Pay</button></center>
</form>
Controller.php
<?php
namespace App\Http\Controllers;
use PaytmWallet;
use Illuminate\Http\Request;
use App\EventRegistration;
use Session;
use DB;
class OrderController extends Controller
{
/**
* Redirect the user to the Payment Gateway.
*
* @return Response
*/
public function register()
{
return view('register');
}
/**
* Redirect the user to the Payment Gateway.
*
* @return Response
*/
public function order(Request $request)
{
$input = $request->all();
//pri($input); die();
$input['order_id'] = str_random(16);
$input['fee'] = $input['amount'];
Session::put('packid', $input['productinfo']);
EventRegistration::create($input);
$payment = PaytmWallet::with('receive');
$payment->prepare([
'order' => $input['order_id'],
'user' => $input['firstname'],
'mobile_number' => $input['phone'],
'email' => $input['email'],
'amount' => $input['fee'],
'callback_url' => url('payment/status')
]);
//pri($payment);exit;
return $payment->receive();
}
/**
* Obtain the payment information.
*
* @return Object
*/
public function paymentCallback()
{
$transaction = PaytmWallet::with('receive');
$response = $transaction->response();
$order_id = $transaction->getOrderId();
if($transaction->isSuccessful()){
dd('payment Done');
}else if($transaction->isFailed()){
dd('payment Failed');
}
}
}
Routes.php
Route::get('event-registration', 'OrderController@register');
Route::post('payment', 'OrderController@order');
Route::post('payment/status', 'OrderController@paymentCallback');
添加 /
以不通过现有 url
Route::get('/event-registration', 'OrderController@register');
Route::post('/payment', 'OrderController@order');
Route::post('/payment/status', 'OrderController@paymentCallback');
并使用 /payment
作为表单标记中的操作,因为您已经为此 'OrderController@order'
创建了路由并且没有使用任何命名路由。
<form action="/payment" method="post" name="payuForm" >
还要检查你在路由中请求数据
Route::post('payment', function(Illuminate\Http\Request $request){
return dd($request->all());
});
我也遇到这个错误,不过我已经解决了问题。
php artisan cache:clear.
清除缓存和 cookie 浏览器。
使用私人浏览器 (Mozilla)/隐身 Window (Chrome)
打开您的 form/page 然后提交。
希望这对你有用。
嘿@Deepak Patel 我搜索了很多与您的相关信息 question.i 找到了适合您的解决方案。 版本 5.1 Laravel 的 VerifyCsrfToken 中间件允许 routes.you 需要将路由添加到 App\Http\MiddlewareVerifyCsrfToken class:
中的 $except 数组<?php namespace App\Http\Middleware;
use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as BaseVerifier;
class VerifyCsrfToken extends BaseVerifier
{
protected $except = [
'your-route-name/*',
];
}
它在 laravel 中禁用 csrf 用于特定 route.Hope 它的工作。