Laravel PayPal payment return 400

I am using PayPal paypal/rest-api-sdk-php for payment gateway for my laravel application.

But when the link is click for confirmation, I get Got Http response code 400 when accessing https://api.sandbox.paypal.com/v1/payments/payment.

Following is my method of implementation in Laravel 5.1 and 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;
        }

The laravel code implementation is based on example that available in git for paypal/rest-api-sdk-php based example called The Pizza App rest-api-sample-app .
Thanks!!

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

You need to follow the instructions mentioned here:

https://github.com/paypal/PayPal-PHP-SDK/wiki/exception-%27PayPal%5CException%5CPayPalConnectionException%27-with-message-%27Got-Http-response-code-400-when-accessing

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


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x