2015-10-15 97 views
0

我正在使用PayPal paypal/rest-api-sdk-php作爲我的laravel應用程序的付款網關。Laravel PayPal付款返還400

但是,當鏈接點擊確認,我得到Got Http response code 400 when accessing https://api.sandbox.paypal.com/v1/payments/payment.

以下是我在Laravel 5.1實現的方法和AngularJS:

angular.module('MyApp') 
    .factory('Account', function($http){ 
     return { 

      buyNow: function(pid){ 
       console.log(pid) 
       return $http.put('/api/buynow',pid); 
      } 

     } 
    }); 

    public function buyNowAPI(Request $request) 
     { 
      $pid = $request->input('pid'); 
      $product = Product::find($pid); 
      $baseUrl = url().'/#/app/product?orderId=$pid';  
      $payment = $this->makePaymentUsingPayPal($product->price,'MYR',$product->title,"$baseUrl&success=true", "$baseUrl&success=false"); 

      dd($payment->getLinks()); 
      return response()->json($pid); 
     } 

    public function makePaymentUsingPayPal($total, $currency, $paymentDesc, $returnUrl, $cancelUrl) 
     { 
      $payer = new Payer(); 
      $payer->setPaymentMethod("paypal"); 

      // Specify the payment amount. 
      $amount = new Amount(); 
      $amount->setCurrency($currency); 
      $amount->setTotal($total); 

      $transaction = new Transaction(); 
      $transaction->setAmount($amount); 
      $transaction->setDescription($paymentDesc); 

      $redirectUrls = new RedirectUrls(); 
      $redirectUrls->setReturnUrl($returnUrl); 
      $redirectUrls->setCancelUrl($cancelUrl); 

      $payment = new Payment(); 
      $payment->setRedirectUrls($redirectUrls); 
      $payment->setIntent("sale"); 
      $payment->setPayer($payer); 
      $payment->setTransactions(array($transaction)); 
      $payment->create($this->getApiContext()); 
      return $payment; 
     } 

的laravel代碼的實現是基於實例的可用基於paypal/rest-api-sdk-php的git示例名爲The Pizza Apprest-api-sample-app。 謝謝!

回答