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 矩阵加法的规则是两个矩阵中对应位置的数的绝对值进行加和
  • ¥15 活动选择题。最多可以参加几个项目?
  • ¥15 飞机曲面部件如机翼,壁板等具体的孔位模型
  • ¥15 vs2019中数据导出问题
  • ¥20 云服务Linux系统TCP-MSS值修改?
  • ¥20 关于#单片机#的问题:项目:使用模拟iic与ov2640通讯环境:F407问题:读取的ID号总是0xff,自己调了调发现在读从机数据时,SDA线上并未有信号变化(语言-c语言)
  • ¥20 怎么在stm32门禁成品上增加查询记录功能
  • ¥15 Source insight编写代码后使用CCS5.2版本import之后,代码跳到注释行里面
  • ¥50 NT4.0系统 STOP:0X0000007B
  • ¥15 想问一下stata17中这段代码哪里有问题呀