2014-03-26 68 views
6

我想让PayPal REST API创建存储在保险库中的信用卡的付款。但是,每当我尝试,并与在跳马PayPal的API将挂起周边半分钟卡付款,然后给我下面的500错误:PayPal REST API返回信用卡令牌的服务器错误

Exception: Got Http response code 500 when accessing https://api.sandbox.paypal.com/v1/payments/payment. 
{"name":"INTERNAL_SERVICE_ERROR","message":"An internal service error has occurred","information_link":"https://developer.paypal.com/webapps/developer/docs/api/#INTERNAL_SERVICE_ERROR","debug_id":"e3c779ea99f73"} 

这是我使用的代码(我很抱歉,如果这里有太多的信息,我不知道什么样的信息是有关我的问题)

<?php 
include("bootstrap.php"); //Sample bootstrap file configured with my clientId and Secret, creates $apiContext 
use PayPal\Api\CreditCard; 
use PayPal\Api\Payer; 
use PayPal\Api\FundingInstrument; 
use PayPal\Api\Details; 
use PayPal\Api\Amount; 
use PayPal\Api\Transaction; 
use PayPal\Api\Payment; 
use PayPal\Api\Address; 
use PayPal\Api\CreditCardToken; 

$useVault = true; 

$addr = new Address(); 
$addr->setLine1('52 N Main ST'); 
$addr->setCity('Johnstown'); 
$addr->setCountry_code('US'); 
$addr->setPostal_code(''); 
$addr->setState('OH'); 


$card = new CreditCard(); 
//Also used PayPal Sandbox account number here 
$card->setNumber('4111111111111111'); 
$card->setExpire_month('03'); 
$card->setExpire_year('2019'); 
$card->setCvv2('123'); 
$card->setFirst_name('Joe'); 
$card->setLast_name('Shopper'); 
$card->setType('visa'); 
$card->setBilling_address($addr); 
$fi = new FundingInstrument(); 

//Setting $useVault to false here 
// will attempt to make the payment without storing the CC in the vault 
// Which works. having it use the vault will return a 500 error 
if($useVault){ 
    //use Store the CC in the vault 
    $response = $card->create($apiContext); 
    $ccToken = new CreditCartToken(); 
    $ccToken->setCredit_card_id($response->id); 
    $fi->setCredit_card_token($creditCardToken); 
}else{ 
    $fi->setCredit_card($card); 
} 


$payer = new Payer(); 
$payer->setPayment_method('credit_card'); 
$payer->setFunding_instruments(array($fi)); 
$amountDetails = new Details(); 
$amountDetails->setSubtotal('7.41'); 
$amountDetails->setTax('0.03'); 
$amountDetails->setShipping('0.03'); 


$amount = new Amount(); 
$amount->setCurrency('USD'); 
$amount->setTotal('7.47'); 
$amount->setDetails($amountDetails); 
$transaction = new Transaction(); 
$transaction->setAmount($amount); 
$transaction->setDescription('This is the payment transaction description.'); 

$payment = new Payment(); 
$payment->setIntent('sale'); 
$payment->setPayer($payer); 
$payment->setTransactions(array($transaction)); 
try { 
    var_dump($payment->create($apiContext)); 
} catch (PayPal\Exception\PPConnectionException $ex) { 
    echo "Exception: " . $ex->getMessage() . PHP_EOL; 
    var_dump($ex->getData()); 
    exit(1); 
} 

如果我改变$useVaultfalse那么付款将与交易将在开发者现身沙箱。 我用this guide at dev-tools.paypal.com,它似乎是具有相同的问题,因为我(I获得到步骤4 3,并将其打印出一个内部服务错误发生

回答

9

使用常用的测试CC就像当贝宝有时会抛出错误500你正在使用的那个,所以尝试另一个,或者只是尝试一个真正的CC号码,只要你在沙箱模式,它不会向你收取任何费用或其他任何东西

+0

相当正确。 API目前在沙箱中,它正在运行,但我没有修复ETA。 – tomwhipple

+0

谢谢。我不知道这是一个问题,只是贝宝沙箱API或什么 –

+2

谢谢,非常令人沮丧,贝宝至少没有提供有用的答复年龄! – RogerRoger

相关问题