Paypal沙盒api在付款登录页面的奇怪问题

时间:2017-11-10 07:05:46

标签: php laravel-5.4 paypal-sandbox

Reference

代码

public function ShowPaymentWithPaypal()
{
    $payer = new Payer();
    $payer->setPaymentMethod('paypal');
    $item_1 = new Item();
    $item_1->setName('Item 1') /** item name **/
        ->setCurrency('USD')
        ->setQuantity(1)
        ->setPrice(2); /** unit price **/

    $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')) /** Specify return URL **/
        ->setCancelUrl(\URL::route('CancelledPaymentWithPaypal'));

    $payment = new Payment();
    $payment->setIntent('Sale')
        ->setPayer($payer)
        ->setRedirectUrls($redirect_urls)
        ->setTransactions(array($transaction));
        /** dd($payment->create($this->_api_context));exit; **/

    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";
            /** echo "Exception: " . $ex->getMessage() . PHP_EOL; **/
            /** $err_data = json_decode($ex->getData(), true); **/
            /** exit; **/
        } else {
            \Session::put('error','Some error occur, sorry for inconvenient');
            return "Error occured";
            /** die('Some error occur, sorry for inconvenient'); **/
        }
    }
    foreach($payment->getLinks() as $link) {
        if($link->getRel() == 'approval_url') {
            $redirect_url = $link->getHref();
            break;
        }
    }
    /** add payment ID to session **/
    \Session::put('paypal_payment_id', $payment->getId());
    if(isset($redirect_url)) {
        /** redirect to paypal **/
        return \Redirect::away($redirect_url);
    }
    \Session::put('error','Unknown error occurred');
    return "Last line error";
}

有什么问题?

当我尝试使用沙箱凭据进行付款登录时,我收到以下错误。

  

我们无法使用您的PayPal帐户处理您的付款   这次。请回到商家并尝试使用其他商品   付款方式。

I am following this to configure Paypal in Laravel 5.5

XHR错误详情

enter image description here 我错过了什么吗?

0 个答案:

没有答案