douqiao8032 2017-04-16 08:14
浏览 158
已采纳

create方法中的Paypal验证错误

1)The problem is that $paypal->create($api) Returns such an error

 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)this is my code

$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 and secret take from here

This is screen shot

  • 写回答

1条回答 默认 最新

  • duandiaoqian5795 2017-04-16 08:17
    关注

    You have $amount->setCurrency('USA'). It should be $amount->setCurrency('USD'). It's explained in the error message:

    Currency should be a valid ISO currency code

    the valid ISO currency code for USA is USD.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 交替优化波束形成和ris反射角使保密速率最大化
  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程