PayPal付款 - HTTP响应代码400

时间:2015-02-22 15:47:27

标签: php exception paypal error-handling

我正在使用PHP进行PayPal付款。一切都很好,直到我收到这个错误:

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

当我尝试为我的付款创建方法时抛出:$ payment-> create($ api);

<?php

use PayPal\Api\Payer;
use PayPal\Api\Details;
use PayPal\Api\Amount;
use PayPal\Api\Transaction;
use PayPal\Api\Payment;
use PayPal\Api\RedirectUrls;
use PayPal\Exception\PayPalConnectionException;

require '../src/start.php';

$payer = new Payer();
$details = new Details();
$amount = new Amount();
$transaction = new Transaction();
$payment = new Payment();
$redirectUrls = new RedirectUrls();


// Payer
$payer->setPaymentMethod('paypal');



// Details
$details->setShipping('2.00')
->setTax('0.00')
->setSubtotal('20.00');

// Amount
$amount->setCurrency('GBP')
->setTotal('22.00')
->setDetails($details);

// Transaction
$transaction->setAmount($amount)
->setDescription('Membership');


// Payment
$payment->setIntent('sale')
->setPayer($payer)
->setTransactions($transaction);

// Redirect urls
$redirectUrls->setReturnUrl($myReturnUrl)
->setCancelUrl($myCancelUrl);

$payment->setRedirectUrls($redirectUrls);

try {

$payment->create($api);


} catch (Exception $e) {
    echo $e->getMessage();
}

为什么会这样?我该如何解决这个问题?我最终能得到更详细的异常消息吗?

2 个答案:

答案 0 :(得分:0)

while

确保您提供了正确的值

答案 1 :(得分:0)

// Amount
$amount->setCurrency('GBP')
->setTotal('22.00')
->setDetails($details);

请确保您的PayPal商业帐户中包含您的主要货币,在我的情况下,它可以更改“GBP&#39; GBP&#39;到美国&#39;

// Amount
$amount->setCurrency('USA')
->setTotal('22.00')
->setDetails($details);