2016-11-18 13 views
-1

私は最近私のサイトにPayPal支払いを追加しました(一般的にLaravelを使用しています)。したがって、私はthis pluginを使用しています。PayPal支払いがもう動作しません - Laravel Paypal

私が使用している完全なコードは次のとおりです。

public function getCheckout(Request $request) 
    { 
     $userInfo = \App\User::where('id', '=', \Auth::user()->id) 
      ->first(); 

     if ($userInfo->street == "") { 
      $request->session()->flash('alert-info', 'Vor der ersten Bestellung müssen Sie erst Ihre Daten vervollständigen'); 
      return redirect('/editData'); 
     } 

     $cart = Cart::where('user_id', \Auth::user()->id)->first(); 
     $items = $cart->cartItems; 
     $total = 0; 
     foreach ($items as $item) { 
      $total += $item->product->price; 
     } 

     $itemList = PayPal::itemList(); 

     foreach ($items as $item) { 
      $product = Product::where('id', '=', $item->product->id)->first(); 
      $itemName = $product->name; 
      $itemPrice = $product->price; 
      $payPalItem = PayPal::item(); 
      $payPalItem->setName($itemName) 
       ->setDescription($itemName) 
       ->setCurrency('EUR') 
       ->setQuantity(1) 
       ->setPrice($itemPrice); 
      $itemList->addItem($payPalItem); 
     } 

     $payer = PayPal::Payer(); 
     $payer->setPaymentMethod('paypal'); 

     $details = PayPal::details(); 
     $details->setShipping("2.50") 
      ->setSubtotal($total); 

     $amount = PayPal:: Amount(); 
     $amount->setCurrency('EUR'); 
     $amount->setTotal(($total + 2.5)); 
     $amount->setDetails($details); 

     $transaction = PayPal::Transaction(); 
     $transaction->setAmount($amount); 
     $transaction->setItemList($itemList); 
     $transaction->setDescription('Ihr Warenkorb'); 

     $redirectUrls = PayPal:: RedirectUrls(); 
     $redirectUrls->setReturnUrl(action('[email protected]')); 
     $redirectUrls->setCancelUrl(action('[email protected]')); 

     $payment = PayPal::Payment(); 
     $payment->setIntent('sale'); 
     $payment->setPayer($payer); 
     $payment->setRedirectUrls($redirectUrls); 
     $payment->setTransactions(array($transaction)); 

     try { 
      $response = $payment->create($this->_apiContext); 
     } catch (PayPalConnectionException $ex) { 
      echo $ex->getCode(); // Prints the Error Code 
      echo $ex->getData(); // Prints the detailed error message 
      die($ex); 
     } 

     $redirectUrl = $response->links[1]->href; 

     return Redirect::to($redirectUrl); 
    } 

    public function getDone(Request $request) 
    { 
     $cart = Cart::where('user_id', \Auth::user()->id)->first(); 
     $items = $cart->cartItems; 
     $total = 0; 
     foreach ($items as $item) { 
      $total += $item->product->price; 
     } 

     $order = new Order(); 
     $order->total_paid = $total + 2.5; 
     $order->user_id = \Auth::user()->id; 
     $order->save(); 

     foreach ($items as $item) { 
      $orderItem = new OrderItem(); 
      $orderItem->order_id = $order->id; 
      $orderItem->product_id = $item->product->id; 
      $orderItem->save(); 
      $product = $item->product; 
      if ($product->stockCount != "") { 
       $product->stockCount--; 
      } 
      $product->save(); 
      CartItem::destroy($item->id); 
     } 

     $id = $request->get('paymentId'); 
     $token = $request->get('token'); 
     $payer_id = $request->get('PayerID'); 

     $payment = PayPal::getById($id, $this->_apiContext); 

     $paymentExecution = PayPal::PaymentExecution(); 

     $paymentExecution->setPayerId($payer_id); 

     try { 
      $payment->create($this->_apiContext); 
     } catch (PayPalConnectionException $ex) { 
      echo $ex->getCode(); // Prints the Error Code 
      echo $ex->getData(); // Prints the detailed error message 
      die($ex); 
     } 
     try { 

      $payment->execute($paymentExecution, $this->_apiContext); 
     } catch (PayPalConnectionException $ex) { 
      echo $ex->getCode(); 
      echo $ex->getData(); 
      die($ex); 
     } 

     // Clear the shopping cart, write to database, send notifications, etc. 

     // Thank the user for the purchase 

     $userInfo = \App\User::where('id', '=', \Auth::user()->id) 
      ->first(); 

     $userMail = $userInfo->email; 

     $orderItems = OrderItem::where('order_id', '=', $order->id)->get(); 

     Mail::to($userMail)->send(new orderFinished($order)); 

     $sellerArray = []; 

     foreach ($orderItems as $orderItem) { 
      $product = $orderItem->product; 
      $seller = User::where('id', '=', $product->user_id)->first(); 
      $buyer = User::where('id', '=', $order->user_id)->first(); 
      if (!in_array($seller, $sellerArray)) { 
       Mail::to($seller->email)->send(new newOrderMail($order, $seller, $buyer)); 
       array_push($sellerArray, $seller); 
      } 
     } 

     return view('checkout.done'); 
    } 

それは前に働いていたと私は私は何も変更しなかったが、突然、それはもう動作しませんかなり確信している... アイムこのエラーを取得:

400 { "名": "MALFORMED_REQUEST"、 "メッセージ": "5c8663496f505": "https://developer.paypal.com/webapps/developer/docs/api/#MALFORMED_REQUEST"、 "debug_id":、 "information_link" を "着信JSONリクエストは、APIリクエストにマップされません"} PayPal \ Exception \ PayPalConnectionException:アクセス時にHTTP応答コード400を取得しましたhttps://api.sandbox.paypal.com/v1/payments/payment

これはなぜ起こる可能性があるのですか?言って、(私はそれが働いていたことを確認したところ)最新のリビジョンに戻した後、私は別のエラーを取得:

PayPalConnectionException in PayPalHttpConnection.php line 174: 
Got Http response code 500 when accessing https://api.sandbox.paypal.com/v1/payments/payment/PAY-1DS60820MW1392725LAYAB6A/execute. 
in PayPalHttpConnection.php line 174 
at PayPalHttpConnection->execute('{"payer_id":"J922HVAQ2RHAW"}') in PayPalRestCall.php line 74 
at PayPalRestCall->execute(array('PayPal\Handler\RestHandler'), '/v1/payments/payment/PAY-1DS60820MW1392725LAYAB6A/execute', 'POST', '{"payer_id":"J922HVAQ2RHAW"}', array()) in PayPalResourceModel.php line 102 
at PayPalResourceModel::executeCall('/v1/payments/payment/PAY-1DS60820MW1392725LAYAB6A/execute', 'POST', '{"payer_id":"J922HVAQ2RHAW"}', null, object(ApiContext), object(PayPalRestCall)) in Payment.php line 650 
at Payment->execute(object(PaymentExecution), object(ApiContext)) in PayPalController.php line 142 
at PayPalController->getDone(object(Request)) 
at call_user_func_array(array(object(PayPalController), 'getDone'), array(object(Request))) in Controller.php line 55 
at Controller->callAction('getDone', array(object(Request))) in ControllerDispatcher.php line 44 
at ControllerDispatcher->dispatch(object(Route), object(PayPalController), 'getDone') in Route.php line 189 

しかし:私は本当に何のアイデア....

編集を持っていません。このdoesnのをいくつかの命令はうまくいく、いくつかの命令はうまくいく、いくつかの命令は動作しない、あるいは他の言葉を使って言う:時には動作する、時には... ...私が疑問に思うのは、なぜエラーが発生するのかだけでなく、私が言ったように、私がした唯一の事はファイルを最新のリビジョンに戻すことです(GITを使って)。私のローカルバージョンから最新のリビジョンに変更されたのは、書式設定のもの((の前のスペース)とstockCountだけです。これは単に製品のカウンタです。あなたがコードで見ることができます)

+0

送信するJSONの書式をAPIの書類で確認すると、それのどの部分が問題を引き起こしているのか。 –

+0

@Dontfeedthecodeそれは問題ないのですが、問題はありません。完全なコードを提供しましたが、機能を破壊する可能性のあるものは表示されません。 – nameless

+0

@Dontfeedthecodeは大丈夫です。新しい情報のために私の質問を編集します – nameless

答えて

0

こんにちは親愛なるごめんなさい。私はpaypalに送られた合計金額が正しく計算されていないと思います。 詳細内に小計を設定すると、この式を使用して小計が計算されていることを確認できます
小計=合計((項目1価格*数量)+ ...(項目2価格*数量)) 次に、この数式を使用して計算されます 合計=小計+送料 PayPalに送信された金額が正しく計算されていることを確認してください

関連する問題