0-访问https://api.sandbox.paypal.com/v1/payments/payment时获得Http响应代码400 [英] 0 - Got Http response code 400 when accessing https://api.sandbox.paypal.com/v1/payments/payment

查看:404
本文介绍了0-访问https://api.sandbox.paypal.com/v1/payments/payment时获得Http响应代码400的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Paypal Rest API,但出现错误.这是我的代码:

I'm using the paypal rest API, but I am getting an error. Here is my code:

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);

Everything works fine until I call $payment->create($apiContext);

然后显示此错误:

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

推荐答案

如果将调用包装在try/catch块中并捕获PPConnectionException,则可以检查数据以查看错误的确切原因:

If you wrap your call in a try/catch block and catch the PPConnectionException, you can examine the data to see exactly what the error is:

// ...
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;
}

这篇关于0-访问https://api.sandbox.paypal.com/v1/payments/payment时获得Http响应代码400的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆