【问题标题】:0 - Got Http response code 400 when accessing https://api.sandbox.paypal.com/v1/payments/payment0 - 访问 https://api.sandbox.paypal.com/v1/payments/payment 时获得 Http 响应代码 400
【发布时间】:2014-06-11 14:25:33
【问题描述】:

我正在使用 paypal rest API,但出现错误。这是我的代码:

function makePaymentUsingPayPal($total, $currency, $paymentDesc, $returnUrl, $cancelUrl) {

    // set billing address
    $addr = new Address();
    $addr->setLine1('fh52 N Main ST');
    $addr->setCity('Johnstownfhf');
    $addr->setCountry_code('UK');
    $addr->setPostal_code('35345');
    $addr->setState('DF');

    // set credit card information
    $card = new CreditCard();
    $card->setNumber('4111111111111111');
    $card->setType('visa');
    $card->setExpire_month('12');
    $card->setExpire_year('2015');
    $card->setCvv2('123');
    $card->setFirst_name('dgdg');
    $card->setLast_name('dgdgdShopper');
    $card->setBilling_address($addr);

    $fi = new FundingInstrument();
    $fi->setCredit_card($card);

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

    //$payer = new Payer();
    //$payer->setPayment_method('credit_card');
    //$payer->setFunding_instruments(array($fi));

    // Specify the payment amount.        
    $amountDetails = new Details();
    $amountDetails->setSubtotal('57.41');
    $amountDetails->setTax('0.06');
    $amountDetails->setShipping('0.06');

    $amount = new Amount();
    $amount->setCurrency('USD');
    $amount->setTotal('5.47');
    $amount->setDetails($amountDetails);

    // ###Transaction
    // A transaction defines the contract of a
    // payment - what is the payment for and who
    // is fulfilling it. Transaction is created with
    // a `Payee` and `Amount` types
    $transaction = new Transaction();
    $transaction->setAmount($amount);
    $transaction->setDescription('sdgdfg This is the payment transaction description.');

    $redirectUrls = new RedirectUrls();
    $redirectUrls->setReturnUrl($returnUrl);
    $redirectUrls->setCancelUrl($cancelUrl);

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

    //print_r($payment);exit; 
    $payment->create($apiContext);

    // return $payment;
}

在我致电$payment->create($apiContext);之前一切正常

然后它显示这个错误:

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

【问题讨论】:

  • 我也遇到了同样的问题,有人解决了吗?

标签: paypal


【解决方案1】:

如果您将调用包装在 try/catch 块中并捕获 PPConnectionException,则可以检查数据以确切了解错误是什么:

// ...
try {
    $response = $pp_payment->create();
} catch (PayPal\Exception\PPConnectionException $pce) {
    // Don't spit out errors or use "exit" like this in production code
    echo '<pre>';print_r(json_decode($pce->getData()));exit;
}

【讨论】:

  • 这有帮助,尽管异常命名空间是:PayPal\Exception\PayPalConnectionException
  • 答案和@Iwazaru 的评论都非常有帮助。 PayPal PHP SDK 1.6.2 版本的异常命名空间现在是PayPal\Exception\PayPalConnectionException
【解决方案2】:

我认为 400 的原因是您的小计 + 税 + 运费加起来不等于总数。您应该能够在收到的响应中检查原因,它应该包含一系列错误。

小计 + 税 + 运费 = 总计

57.41 + 0.06 + 0.06 != 5.47

【讨论】:

    【解决方案3】:

    遇到了同样的问题。问题是我在 returnurl 中传递的参数中的space

    确保您的 $returnUrl$cancelUrlurlencoded 如果您传递任何特殊字符。

    【讨论】:

      【解决方案4】:

      您应该仔细检查小计和总计是否正确。 就我而言,我使用的是沙盒,我没有注意总计和小计不正确。一些美分产生了差异并输出了错误,只是修复了值并且它正常工作。

      【讨论】:

        猜你喜欢
        • 2015-05-23
        • 2021-02-28
        • 2020-11-25
        • 2018-12-26
        • 2020-11-20
        • 2019-12-04
        • 2019-08-07
        • 2017-01-07
        • 2019-06-26
        相关资源
        最近更新 更多