2 回答
TA贡献1744条经验 获得超4个赞
由于付款是公共方法并且它会重定向,因此很可能是通过路由调用的。在这种情况下,您可以在付款中注入请求实例,如下所示:
public function payment(Request $request) {
$data = $this->projectData($request);
$provider = new ExpressCheckout;
$response = $provider->setExpressCheckout($data);
dd($response);
// $response = $provider->setExpressCheckout($data, true);
return redirect($response['paypal_link']);
}
TA贡献1891条经验 获得超3个赞
private function projectData(){
$request=request();
// dd($request->all());
// $item = [];
// $datat = array_map(function($item){
// return [
// 'name'=>$request->project_id,
// 'price'=>$request->budget,
// 'desc'=>'Deposit',
// 'qty'=>1
// ];
// }, $item);
$data = [
'items'=>[
'name'=>'Project No.'.$request->project_id
],
'invoice_id' => uniqid(),
'invoice_description' => "Payment for Project No.".$request->project_id." Amount ".$request->budget,
'return_url' => route('payment.success'),
'cancel_url' => route('payment.cancel'),
'total' => $request->budget
];
// dd($data);
return $data;
}
/**
* Responds with a welcome message with instructions
*
* @return \Illuminate\Http\Response
*/
public function payment() {
$data = $this->projectData();
$provider = new ExpressCheckout;
$response = $provider->setExpressCheckout($data);
dd($response);
// $response = $provider->setExpressCheckout($data, true);
return redirect($response['paypal_link']);
}
仅当您来自请求时,而不是从请求的函数调用另一个函数时,才可以使用依赖项注入,如果您要这样做,请尝试我的方法,或者将您的请求添加到处理此请求的主控制器并传递给其他方法。
- 2 回答
- 0 关注
- 78 浏览
添加回答
举报