必填字段缺失.PHP Paypal REST API

Sef*_*fam 2 php paypal paypal-sandbox

我目前正在尝试使用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);
Run Code Online (Sandbox Code Playgroud)

根据文档(https://developer.paypal.com/webapps/developer/docs/api/#common-objects)中的"Common Objects",我填写了Paypal文档认为"必需"的所有字段.但是当我尝试重定向到Paypal以启动事务时,我被抛出此错误:

例外:访问https://api.sandbox.paypal.com/v1/payments/payment时获得Http响应代码400 .string(269)"{"name":"VALIDATION_ERROR","details":[{"field":"transactions [0] .item_list.items [0] .sku","issue":"必填字段缺失"} ],"消息":"无效请求 - 请参阅详细信息","information_link":" https://developer.paypal.com/docs/api/#VALIDATION_ERROR ","debug_id":"9e292fc3a312d"}"

当我注释掉$ transaction-> setItem_list($ item_list);时,它可以正常工作.因此很明显项目列表或项目中缺少某些内容.但我看不清楚.

有任何想法吗?

Fab*_*bio 5

错误指向你:

transactions[0].item_list.items[0].sku
Run Code Online (Sandbox Code Playgroud)

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

$item->setSKU("CODEHERE");
Run Code Online (Sandbox Code Playgroud)

$item->setCurrency("USD");
Run Code Online (Sandbox Code Playgroud)