laravel应用程序中的贝宝中的504服务不可用错误

问题描述 投票:0回答:1

我在贝宝付款中遇到错误,我可以成功创建付款,但是在拒绝付款或接受付款后,我收到错误消息“ Http响应代码504”

我从这里使用了示例:https://github.com/avinashn/paypal-payment-gateway-integration-laravel

创建付款:

        function payWithpaypal($amount1)
{

    $payer = new Payer();
    $payer->setPaymentMethod('paypal');

    $item_1 = new Item();

    $item_1->setName('Item 1') /** item name **/
        ->setCurrency('USD')
        ->setQuantity(1)
        ->setPrice($amount1); /** unit price **/

    $item_list = new ItemList();
    $item_list->setItems(array($item_1));

    $amount = new Amount();
    $amount->setCurrency('USD')
        ->setTotal($amount1);

    $transaction = new Transaction();
    $transaction->setAmount($amount)
        ->setItemList($item_list)
        ->setDescription('Your transaction description');

    $redirect_urls = new RedirectUrls();
    $redirect_urls->setReturnUrl(URL::to('status')) /** Specify return URL **/
        ->setCancelUrl(URL::to('status'));

    $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) {
        var_dump(json_decode($ex->getData()));
        exit(1);
        if (\Config::get('app.debug')) {

            \Session::put('error', 'Connection timeout');
            return Redirect::to('/');

        } else {

            \Session::put('error', 'Some error occur, sorry for inconvenient');
            return Redirect::to('/');

        }

    }

    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 Redirect::to('/');

}

检查付款状态的功能,贝宝在这里重定向

    public function getPaymentStatus()
{
    /** Get the payment ID before session clear **/
    $payment_id = Session::get('paypal_payment_id');

    /** clear the session payment ID **/
    Session::forget('paypal_payment_id');
    // dd(Request::input());
    if (empty(Request::input('PayerID')) || empty(Request::input('token'))) {

        \Session::put('error', 'Payment failed');
        return Redirect::to('/shop');

    }

    $payment = Payment::get($payment_id, $this->_api_context);
    //dd($payment);
    $execution = new PaymentExecution();
    $execution->setPayerId(Request::input('PayerID'));

    /**Execute the payment **/
    try {

    $result = $payment->execute($execution, $this->_api_context);
    var_dump($result);
    }catch (PayPal\Exception\PayPalConnectionException $ex) {
        echo $ex->getCode();
        echo $ex->getData();
        die($ex);
    } catch (Exception $ex) {
        die($ex);
    }

    if ($result->getState() == 'approved') {

        \Session::put('success', 'Payment success');

        $order = $this->addToOrdersTablesPaypal(
            '[email protected]',
            'chandan mishra',
            null
        );                              
        Mail::send(new OrderPlaced($order));

        // decrease the quantities of all the products in the cart
        $this->decreaseQuantities();

        Cart::instance('default')->destroy();
        session()->forget('coupon');

        return redirect()->route('confirmation.index')->with('success_message', 'Thank you! Your payment has been successfully accepted!');

    }

    \Session::put('error', 'Payment failed');
    return Redirect::to('/');

}

我尝试使用dd()来获取错误发生的地方,而我发现错误来自$ execution-> setPayerId(Request :: input('PayerID'));我在日志中收到的错误代码

PayPal\Core\PayPalHttpConnection : ERROR: Got Http response code 504 when accessing https://api.paypal.com/v1/payments/payment/PAYID-L3PJWHA0CM99327WY5078609/execute. {"name":"SERVICE_UNAVAILABLE","debug_id":"bee332cc21290","message":"service unavailable","links":[]}

请帮助

php laravel paypal
1个回答
0
投票
© www.soinside.com 2019 - 2024. All rights reserved.