创建方法中的贝宝验证错误

Paypal validation error in create method

1)问题是$paypal->create($api)Returns这样的错误

 Exception: Got Http response code 400 when accessing 
    https://api.sandbox.paypal.com/v1/payments/payment. string(271) "
    {"name":"VALIDATION_ERROR","details":
    [{"field":"transactions.amount","issue":"Currency should be a valid ISO 
    currency code"}],"message":"Invalid request - see 
    details","information_link":"https://developer.paypal.com/docs/api/
    payments/#errors","debug_id":"cea4b8e54646c"}"

2)这是我的代码

$paypal = new \PayPal\Rest\ApiContext(
    new \PayPal\Auth\OAuthTokenCredential(
        'XXX',
        'YYY'
    )
);

$paypal->setConfig([
    'mode' => 'sandbox',
    'http.ConnectionTimeOut' => 30,
    'log.LogEnabled' => false,
    'log.fileName' => '',
    'log.LogLevel' => 'FINE',
    'validation.level' => 'log'
]);

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

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

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

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

//Transactions
$transaction->setAmount($amount)
    ->setDescription('Add balance');

$redirectUrls->setReturnUrl('http://thechaller.com/paypal/pay')
    ->setCancelUrl('http://thechaller.com/paypal/paypalCancel');

$payment->setIntent('sale')
    ->setPayer($payer)
    ->setRedirectUrls($redirectUrls)
    ->setTransactions([$transaction]);

try {
    $payment->create($paypal);
} catch (\PayPal\Exception\PayPalConnectionException $e) {
    echo "Exception: " . $e->getMessage() . PHP_EOL;
    var_dump($e->getData());
    exit(1);
} catch (Exception $e) {
    echo $e->getMessage();
    exit(1);
}

3) client id 和 secret 从这里获取

This is screen shot

你有 $amount->setCurrency('USA')。应该是$amount->setCurrency('USD')。错误消息中对此进行了解释:

Currency should be a valid ISO currency code

美国的有效 ISO 货币代码是 USD。