douyu0845 2013-04-18 05:50
浏览 177
已采纳

必填字段缺失。 PHP Paypal REST API

I'm currently trying to use the PHP PayPal REST API. However, it seems I am unable to pass a list of items through a transaction because "required field(s) are missing".

$item = new Item();
$item->setQuantity("1");
$item->setName("stuff");
$item->setPrice("305.00");
$item->setCurrency("USD");

$amount = new Amount();
$amount->setCurrency("USD");
$amount->setTotal("305.00");

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

$transaction = new Transaction();
$transaction->setAmount($amount);
$transaction->setDescription("This is incredibly awesome.");
$transaction->setItem_list($item_list);

I've filled all the fields that Paypal's documentation deems as "required" as per "Common Objects" in the documentation (https://developer.paypal.com/webapps/developer/docs/api/#common-objects). But I am being thrown this error when I try to redirect to Paypal to start the transaction:

Exception: Got Http response code 400 when accessing https://api.sandbox.paypal.com/v1/payments/payment. string(269) "{"name":"VALIDATION_ERROR","details":[{"field":"transactions[0].item_list.items[0].sku","issue":"Required field missing"}],"message":"Invalid request - see details","information_link":"https://developer.paypal.com/docs/api/#VALIDATION_ERROR","debug_id":"9e292fc3a312d"}"

When I comment out $transaction->setItem_list($item_list);, it works properly. So it's obvious that something is missing in the item list or the item. But I can't see what.

Any ideas?

  • 写回答

1条回答 默认 最新

  • donglu2761 2013-04-18 05:55
    关注

    the error point you to this:

    transactions[0].item_list.items[0].sku
    

    This filed seems to be required i think it just need to put sku in item array so let's do it: try to add:

    $item->setSKU("CODEHERE");
    

    after

    $item->setCurrency("USD");
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类