code
public function ShowPaymentWithPaypal()
{
$payer = new Payer();
$payer->setPaymentMethod('paypal');
$item_1 = new Item();
$item_1->setName('Item 1')
->setCurrency('USD')
->setQuantity(1)
->setPrice(2);
$item_list = new ItemList();
$item_list->setItems(array($item_1));
$amount = new Amount();
$amount->setCurrency('USD')
->setTotal(2);
$transaction = new Transaction();
$transaction->setAmount($amount)
->setItemList($item_list)
->setDescription('Your transaction description');
$redirect_urls = new RedirectUrls();
$redirect_urls->setReturnUrl(\URL::route('ReturnedFromPaypal'))
->setCancelUrl(\URL::route('CancelledPaymentWithPaypal'));
$payment = new Payment();
$payment->setIntent('Sale')
->setPayer($payer)
->setRedirectUrls($redirect_urls)
->setTransactions(array($transaction));
try {
$payment->create($this->_api_context);
} catch (\PayPal\Exception\PPConnectionException $ex) {
dd($ex);
if (\Config::get('app.debug')) {
\Session::put('error','Connection timeout');
return "Error occured";
} else {
\Session::put('error','Some error occur, sorry for inconvenient');
return "Error occured";
}
}
foreach($payment->getLinks() as $link) {
if($link->getRel() == 'approval_url') {
$redirect_url = $link->getHref();
break;
}
}
\Session::put('paypal_payment_id', $payment->getId());
if(isset($redirect_url)) {
return \Redirect::away($redirect_url);
}
\Session::put('error','Unknown error occurred');
return "Last line error";
}
What is the problem?
When I try to login to make a payment using credentials in the form of a sandbox, I get the following error.
We cannot process your payment using your PayPal account. this time. Return to the seller and try a different payment method.
I am following this to set up Paypal in Laravel 5.5
XHR Error Details
Did I miss something?
source
share