Paypal CC直接付款错误

时间:2015-06-09 04:10:18

标签: paypal payment-gateway paypal-sandbox

我需要一些帮助来找出paypal的API,我试图做的就是对我的沙盒帐户收取cc费用,我一直在查看他们的文档和代码示例但是我现在无法找到正确的信息,比如添加沙箱端点的位置。所以,当我运行下面的函数时,我得到以下错误:

  

string(213)" {" name":" MALFORMED_REQUEST"," message":"传入的JSON请求未映射到API请求"," information_link":" https://developer.paypal.com/webapps/developer/docs/api/#MALFORMED_REQUEST"," debug_id":" 6eb15180f8d92"}&#34 ;

这是我打电话的功能:

public static function ccPayment($paymentInfo, $credentials)
{

$apiContext = new \PayPal\Rest\ApiContext(
    new \PayPal\Auth\OAuthTokenCredential(
        $credentials['clientId'],
        $credentials['secret']
    )
);

$card = new CreditCard();
$card->setType("visa")
    ->setNumber("xxxxxxxxxxxxxxxx")
    ->setExpireMonth("11")
    ->setExpireYear("2019")
    ->setCvv2("012")
    ->setFirstName("Joe")
    ->setLastName("Shopper");

$fi = new FundingInstrument();
$fi->setCreditCard($card);


$payer = new Payer();
$payer->setPaymentMethod("credit_card")
      ->setFundingInstruments(array($fi));

$item1 = new Item();
$item1->setName('Ground Coffee 40 oz')
    ->setDescription('Ground Coffee 40 oz')
    ->setCurrency('USD')
    ->setQuantity(1)
    ->setTax(0.3)
    ->setPrice(7.50);

$itemList = new ItemList();
$itemList->setItems(array($item1));

$transaction = new Transaction();
$transaction->setAmount(489)
    ->setItemList($itemList)
    ->setDescription("Payment description")
    ->setInvoiceNumber(uniqid());

$payment = new Payment();
$payment->setIntent("sale")
    ->setPayer($payer)
    ->setTransactions(array($transaction));

// $request = clone $payment;

try
{
    $payment->create($apiContext);
}
catch (Exception $ex)
{
    dd($ex->getData());
}

dd($paymentInfo);

}

从早上开始编码所以我现在需要另一套眼睛,因为我无法看清我做错了什么。我将不胜感激。

PS。道歉,如果它是愚蠢的东西。例如。一个丢失的逗号。

感谢。

1 个答案:

答案 0 :(得分:0)

搞定了!这是工作代码:

$apiContext = new \PayPal\Rest\ApiContext(
    new \PayPal\Auth\OAuthTokenCredential(
        $credentials['clientId'],
        $credentials['secret']
    )
);

$apiContext->setConfig(
  array(
    'log.LogEnabled' => true,
    'log.FileName' => '../app/storage/paypal/PayPal.log',
    'log.LogLevel' => 'FINE'
  )
);

$card = new CreditCard();
$card->setType("visa")
    ->setNumber("xxxxxxxxxxxxxxxxx")
    ->setExpireMonth("11")
    ->setExpireYear("2019")
    ->setCvv2("012")
    ->setFirstName("Joe")
    ->setLastName("Shopper");

$fi = new FundingInstrument();
$fi->setCreditCard($card);

$payer = new Payer();
$payer->setPaymentMethod("credit_card")
    ->setFundingInstruments(array($fi));

$item1 = new Item();
$item1->setName('Ground Coffee 40 oz')
    ->setDescription('Ground Coffee 40 oz')
    ->setCurrency('USD')
    ->setQuantity(1)
    ->setPrice(49.99);

$itemList = new ItemList();
$itemList->setItems(array($item1));

$details = new Details();
$details->setSubtotal(49.99);

$amount = new Amount();
$amount->setCurrency("USD")
    ->setTotal(49.99)
    ->setDetails($details);

$transaction = new Transaction();
$transaction->setAmount($amount)
    ->setItemList($itemList)
    ->setDescription("Payment description")
    ->setInvoiceNumber(uniqid());

$payment = new Payment();
$payment->setIntent("sale")
    ->setPayer($payer)
    ->setTransactions(array($transaction));

try
{
    $payment->create($apiContext);
}
catch (Exception $ex)
{
    dd($ex->getData());
}

dd($payment);

我错过了新金额&新细节。此外,为了记录,您的货币总额必须加起来。例如。税,小计,总计。