使用Paypal PHP SDK在PHP上出现MALFORMED_REQUEST错误?

时间:2019-02-16 02:29:56

标签: php api paypal sdk

我正在接收此错误,但我不确定为什么我的代码在正确制作的情况下看起来还不错,有人可以帮我解决这个问题吗?

使用Paypal SDK PHP v1 完整的错误是 stdClass对象 (     [名称] => MALFORMED_REQUEST     [消息] =>传入的JSON请求未映射到API请求     [information_link] => https://developer.paypal.com/webapps/developer/docs/api/#MALFORMED_REQUEST     [debug_id] => 47013277923b )

$precio = 1;
$total = ($cantidad / 100) *2;
$cantidad =1;


$compra = new Payer();
$compra->setPaymentMethod("paypal");

$item = new item();
$item->setName("Servicio")
     ->setCurrency('USD')
     ->setQuantity($cantidad)
     ->setPrice($precio);

$lista = new ItemList();
$lista->setItems(array($item));

$detalles = new Details();
$detalles->setShipping(0)
->setSubtotal($precio);

$amount = new Amount();
$amount->setCurrency("USD")
->setTotal($total)
->setDetails($detalles);

$transicion = new Transaction();
$transicion->setAmount($cantidad) 
->setItemList($lista)
->setDescription("Pago ")
->setInvoiceNumber(uniqid());


$redirect = new RedirectUrls();
$redirect->setReturnUrl(URL_SITIO."/pago?exito=true")
->setCancelUrl(URL_SITIO."/pago?exito=false");

$pago = new Payment();
$pago->setIntent("sale")
->setIntent($compra)
->setRedirectUrls($redirect)
->setTransactions(array($transicion));

try {
    //code...
    $pago->create($apiContext);
}catch (PayPal\Exception\PayPalConnectionException $pce) {
    //throw $th;
    echo '<pre>';print_r(json_decode($pce->getData()));exit;

}

$aprobado = $pago->getApprovalLink();
header("Location: {$aprobado}");

0 个答案:

没有答案