【问题标题】:i am using paypal rest api and getting the error我正在使用 paypal rest api 并收到错误
【发布时间】:2019-02-28 23:01:56
【问题描述】:
    $payer = new Payer();
    $payer->setPaymentMethod("paypal");

    $amount = new Amount();
    $amount->setCurrency("INR")
        ->setTotal($request->get('amount'));

    $payee = new Payee();
    $payee->setEmail($request->get('email'));
    $transaction = new Transaction();
    $transaction->setAmount($amount)
        ->setDescription("Payment description")
        ->setPayee($payee)
        ->setInvoiceNumber(uniqid());

    $redirectUrls = new RedirectUrls();
    $redirectUrls->setReturnUrl("http://udhaarcopy.test/paymentsuccess?success=true")
                ->setCancelUrl("http://udhaarcopy.test/paymentsuccess?success=false");

    $payment = new Payment();
    $payment->setIntent("Udhaar")
        ->setPayer($payer)
        ->setRedirectUrls($redirectUrls)
        ->setTransactions(array($transaction));


    $request = clone $payment;


    try {
        $payment->create($apiContext);
          // dd( $payment->create($apiContext));
    } catch (PayPal\Exception\PPConnectionException  $ex) {
        dd($ex);
    }
     $payment->getApprovalLink();
    $approvalUrl = $payment->getApprovalLink();

    return redirect($approvalUrl)->with('payment' , $payment);
}

public function getPaymentStatus()
{
    dd($_GET);
    $status = $_GET['success'];
    $paymentId = $_GET['paymentId'];
    $PayerID = $_GET['PayerID'];
    return view('paymentstatus' , compact($status , $paymentId , $PayerID));
}

在我没有包含 $payee 变量之前它工作正常。包含 $payee 后,我的代码出错了

贝宝\异常\贝宝连接异常(400)

访问https://api.sandbox.paypal.com/v1/payments/payment时得到Http响应码400。

其实我的要求是: 一个用户可以将付款发送给其他用户,而不是我的帐户。 任何人有任何类型的建议或任何虚拟代码?

【问题讨论】:

  • 如果您尝试在问题标题中更多地定义您的问题,也许您会得到更多答案。

标签: php laravel payment-gateway paypal-sandbox laravel-5.5


【解决方案1】:

请参考Paypal HTTP status code groupings

了解您的错误

PayPal 会返回有关每个异常的详细数据(500 INTERNAL_SERVER_ERROR 除外),解释您所看到的确切错误。您可以按如下方式检索:

更新您的异常处理以捕获PayPalConnectionExceptionprint $ex->getData(),如下所示:

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

现在,如果您再试一次,您将看到如下内容:

{
    "name": "VALIDATION_ERROR",
    "details": [
        {
            "field": "transactions[0].amount",
            "issue": "Transaction amount details (subtotal, tax, shipping) must add up to specified amount total"
        }
    ],
    "message": "Invalid request - see details",
    "information_link": "https://developer.paypal.com/webapps/developer/docs/api/#VALIDATION_ERROR",
    "debug_id": "0faff23b719d8"
}

【讨论】:

    猜你喜欢
    • 2015-01-18
    • 1970-01-01
    • 2021-11-17
    • 2019-12-04
    • 1970-01-01
    • 1970-01-01
    • 2016-06-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多