Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
0-访问时获取Http响应代码400https://api.sandbox.paypal.com/v1/payments/payment_Paypal - Fatal编程技术网

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

0-访问时获取Http响应代码400https://api.sandbox.paypal.com/v1/payments/payment,paypal,Paypal,我正在使用PayPalRESTAPI,但是我得到了一个错误。这是我的密码: function makePaymentUsingPayPal($total, $currency, $paymentDesc, $returnUrl, $cancelUrl) { // set billing address $addr = new Address(); $addr->setLine1('fh52 N Main ST'); $addr->setCity('J

我正在使用PayPalRESTAPI,但是我得到了一个错误。这是我的密码:

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-访问时获取Http响应代码400


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

小计+税+运费=总计


57.41+0.06+0.06!=5.47有同样的问题。问题是我在returnurl中传递的参数中有一个
空格

确保您的$returnUrl$cancelUrl是 如果您正在传递任何特殊字符


如果将调用包装在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;
}
/。。。
试一试{
$response=$pp_payment->create();
}捕获(PayPal\Exception\PPConnectionException$pce){
//不要吐出错误,也不要在生产代码中这样使用“退出”
回显“”;打印(json解码($pce->getData());退出;
}

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

我也有同样的问题,有人解决了吗?尽管异常名称空间是:
PayPal\exception\PayPalConnectionException
答案和@Iwazaru的注释都非常有用。PayPal PHP SDK 1.6.2版的异常名称空间现在是
PayPal\exception\PayPalConnectionException
You saved my day:)