doule6314 2016-03-31 19:31
浏览 184

Laravel PHP Rest API 400错误

Every time I hit a 400 error I get the below screen 400 Error

I am trying to display the errors nicely in an unsuccessful transaction view. However, i can never get past this screen to see if I am parsing $ex correctly.

My code is as follows:

try {
        $payment->create($apiContext);

        $customer = Customer::where('fname', $request->bill_fname)
                        ->where('lname', $request->bill_lname)->first();
        if (!$customer) {
           $customer = Customer::create(['fname' => $request->bill_fname, 'lname' => $request->bill_lname, 'email' => $request->email, 'phone' => $request->phonenum]);
        }

        if(empty($request->cc_token)) {
        $savedcard = CreditCardTable::where('externalCardId', ($request->card_type . substr($request->card_number, -5)))->first();
        if(!$savedcard) {
        $card->create($apiContext);
        $creditcard = CreditCardTable::create(['customer_id' => $customer->id, 'card_id' => $card->id, 'externalCardId' => ($request->card_type . substr($request->card_number, -5))]);
            }
        }

        //dd($payment);
        //store all info in respective tables
        $terminal = Terminal::create(['customer_id' => $customer->id, 'description' => $request->description, 'invoice_id' => $payment->transactions[0]->invoice_number, 'total' => ((($request->amount + $request->shipping_amount) * ($request->tax_rate / 100)) + ($request->amount + $request->shipping_amount)), 'create_time' => $payment->create_time, 'paypal_id' => $payment->id, 'paypal_parent_payment' => $payment->transactions[0]->related_resources[0]->sale->id]);
        $billaddress = BillAddress::where('addrline1', $request->addrline1)
                        ->where('addrline2', $request->addrline2)
                        ->where('zipcode', $request->bill_zip)->first();
        if(!$billaddress) {
            $billaddress = BillAddress::create(['customer_id' => $customer->id, 'addrline1' => $request->addrline1, 'addrline2' => $request->addrline2, 'city' => $request->bill_city, 'state' => $request->bill_state, 'zipcode' => $request->bill_zip]);
        }
        if($request->isSame == 'No') {
        $shipaddress = ShipAddress::where('addrline1', $request->ship_addr_line1)
                        ->where('addrline2', $request->ship_addr_line2)
                        ->where('zipcode', $request->ship_zip)->first();
        if(!$shipaddress) {
            $shipaddress = ShipAddress::create(['customer_id' => $customer->id, 'addrline1' => $request->ship_addr_line1, 'addrline2' => $request->ship_addr_line2, 'city' => $request->ship_bill_city, 'state' => $request->ship_state, 'zipcode' => $request->ship_zip]);
            }
        }
        else {
            //ship address is bill address
            $shipaddress = BillAddress::where('addrline1', $request->addrline1)
                        ->where('addrline2', $request->addrline2)
                        ->where('zipcode', $request->bill_zip)->first();
            if(!$shipaddress) {
            $shipaddress = BillAddress::create(['customer_id' => $customer->id, 'addrline1' => $request->addrline1, 'addrline2' => $request->addrline2, 'city' => $request->bill_city, 'state' => $request->bill_state, 'zipcode' => $request->bill_zip]);
            }
        }
           // dd($payment);
            return view('pages.terminal.success')->with('payment', $payment)->with('fname', $request->bill_fname)->with('lname', $request->bill_lname);
            }
    catch (PayPal\Exception\PayPalConnectionException $ex) {
                return view('errors.unsuccessful')->with('ex', $ex);
                }
    catch (Exception $ex) {
        return view('errors.unsuccessful')->with('ex', $ex);
    }

Errors.Unsuccesful

    @extends('app')

@section('content')
    <div class="alert alert-danger">
      <h4>Oh No!</h4>
      <p>Transaction was not processed processed</p>
    </div>

    <div class="panel panel-danger">
  <div class="panel-heading">
    <h3 class="panel-title">Error</h3>
  </div>
  <div class="panel-body">
    {{ echo $ex->getCode(); // Prints the Error Code
    echo $ex->getData(); // Prints the detailed error message  }}
  </div>
</div>

@endsection

@include('errors.list')

How do I nicely display these errors so I can inform the user of what they are doing wrong?

  • 写回答

1条回答 默认 最新

  • douan3019 2016-04-01 00:02
    关注

    Try resolving the custom exception from the global namespace with a preceding backslash \

    ...
    catch (\PayPal\Exception\PayPalConnectionException $ex) {
    ...
    
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度