2017-04-16 111 views
0

1)的問題是,$ paypal->創建($ API)返回這樣的錯誤貝寶驗證錯誤在創建方法

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)從這裏

This is screen shot

+1

你正在做的第一件事是重置你擁有的任何密鑰/祕密,即使它是用於沙箱。 – Scuzzy

+0

是的,請這樣做。我編輯了你的帖子,但是你的憑證在編輯歷史記錄中仍然可見。請按照已經說過的那樣改變它們,就像Scuzzy一樣。 – Pharaoh

回答

3

客戶端ID和祕密帶您有$amount->setCurrency('USA')。它應該是$amount->setCurrency('USD')。它在錯誤信息說明:

貨幣應該是一個有效的ISO貨幣代碼

對美國有效的ISO貨幣代碼爲美元。

+0

感謝您的回答我已經修復了這個錯誤,但代碼仍然無效 –

+0

例外:訪問https://api.sandbox.paypal.com/v1/payments/payment時得到了Http響應代碼400。字符串(319)「{」name「:」VALIDATION_ERROR「,」details「:[{」field「:」transactions [0] .amount「,」issue「:」交易金額明細(小計,稅金,運費) 「]],」message「:」無效請求 - 查看詳細信息「,」information_link「:」https://developer.paypal.com/docs/api/payments/#errors「,」debug_id「: 「15f5b6503f1d」}「 –

+2

這是因爲您的稅和小計合計爲22,而總數設置爲20.您甚至讀過您收到的錯誤消息嗎? – junkfoodjunkie