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!!
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