如何解决InvalidArgumentException 空号无效 laravel omnipay paypal 集成
使用 omnipay 将 paypal 集成到我的 Web 应用程序,我遇到此错误 invalidargumentexception Empty number is invalid 当我尝试将 project_id 保存在付款表中时出现错误。
下面是我的代码。对于 paypal 正在使用的两个函数。请任何人帮助我一直坚持使用此代码一周,我想将 project_id 保存在付款表中,以便我可以使用它来创建之间的关系两个表既是付款表又是项目表
这是我的 PaymentController
当我在 payment_success 函数中添加这部分 'items' => array( array( 'project_id' => $project->project_id ),),
时,出现上述错误。
public function charge(Request $request,$id)
{
$project = Project::findOrFail($request->id);
if($request->input('submit'))
{
//$project = new Project();
$project = Project::findOrFail($request->id);
$project->update(['user_name' => (Auth::user()->name)]);
$project->update(['invoice_id' => (null)]);
$project->update(['payment_status' => ('initialised')]);
$project->save();
try {
$response = $this->gateway->purchase(array(
'amount' => $project->amount,'items' => array(
array(
'project_id' => $project->project_id
),'project_id' => $project->project_id,'currency' => env('PAYPAL_CURRENCY'),'returnUrl' => url('paymentsuccess'),'cancelUrl' => url('paymenterror'),))->send();
if ($response->isRedirect()) {
$response->redirect(); // this will automatically forward the customer
} else {
// not successful
return $response->getMessage();
}
} catch(Exception $e) {
return $e->getMessage();
}
}
}
public function payment_success(Request $request)
{
$project = Session::get('id');
$paymentId = Session::get('paypalPaymentId');
// Once the transaction has been approved,we need to complete it.
if ($request->input('paymentId') && $request->input('PayerID'))
{
$transaction = $this->gateway->completePurchase(array(
'payer_id' => $request->input('PayerID'),'transactionReference' => $request->input('paymentId'),));
$response = $transaction->send();
# Payment is processing but may still fail due e.g to insufficient funds
//$project = Project::find($id);
if ($response->isSuccessful())
{
// The customer has successfully paid.
$arr_body = $response->getData();
// Insert transaction data into the database
$isPaymentExist = Payment::where('payment_id',$arr_body['id'])->first();
if(!$isPaymentExist)
{
$payment = new Payment;
$payment->payment_id = $arr_body['id'];
$payment->user_name = Auth::user()->name;
$payment->session_id = Auth::user()->session_id;
$payment->project_id = $arr_body['project_id'];
$payment->payer_id = $arr_body['payer']['payer_info']['payer_id'];
$payment->payer_email = $arr_body['payer']['payer_info']['email'];
$payment->amount = $arr_body['transactions'][0]['amount']['total'];
$payment->currency = env('PAYPAL_CURRENCY');
$payment->payment_status = $arr_body['state'];
$payment->save();
}
return redirect('/client/projects')->with('success','Payment is successful. Your transaction id is: '. $arr_body['id']);
} else {
//return $response->getMessage();
return Redirect::to('/client/projects')->$response->getMessage();
}
} else {
//return 'Transaction is declined';
return redirect('/client/projects')->with('success','Transaction is declined');
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。