缺少必需字段.PHP贝宝REST API


Required Field Missing. PHP Paypal REST API

我目前正在尝试使用PHP PayPal REST API。但是,似乎我无法通过事务传递项目列表,因为"缺少必需的字段"。

$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);

我已经按照文档(https://developer.paypal.com/webapps/developer/docs/api/#common-objects)中的"通用对象"填写了Paypal文档中认为是"必需的"的所有字段。但是当我尝试重定向到Paypal开始交易时,我被抛出了这个错误:

异常:访问时得到Http响应码400https://api.sandbox.paypal.com/v1/payments/payment。字符串(269)"{"名称":"VALIDATION_ERROR"、"细节":[{"字段":"交易[0].item_list.items [0] .sku","问题":"必须的字段缺少"}],"message":"无效请求-参见细节"、"information_link":"https://developer.paypal.com/docs/api/VALIDATION_ERROR"、"debug_id":"9 e292fc3a312d"}"

当我注释掉$transaction->setItem_list($item_list);,它工作正常。所以很明显,物品列表或物品中缺少了一些东西。但我看不出。

任何想法?

错误提示:

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

这个文件似乎是必需的,我认为它只需要把sku在项目数组,所以让我们这样做:尝试添加:

$item->setSKU("CODEHERE");

$item->setCurrency("USD");