必填字段缺失。 PHP 贝宝 REST API

Posted

技术标签:

【中文标题】必填字段缺失。 PHP 贝宝 REST API【英文标题】:Required Field Missing. PHP Paypal REST API 【发布时间】:2013-04-11 02:56:44 【问题描述】:

我目前正在尝试使用 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 响应代码 400 https://api.sandbox.paypal.com/v1/payments/payment。字符串(269) ""name":"VALIDATION_ERROR","details":["field":"transactions[0].item_list.items[0].sku","issue":"必填 字段缺失"],"message":"无效请求 - 请参阅 details","information_link":"https://developer.paypal.com/docs/api/#VALIDATION_ERROR","debug_id":"9e292fc3a312d""

当我注释掉 $transaction->setItem_list($item_list); 时,它可以正常工作。所以很明显,项目列表或项目中缺少某些东西。但我看不到什么。

有什么想法吗?

【问题讨论】:

【参考方案1】:

错误指向您:

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

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

$item->setSKU("CODEHERE");

之后

$item->setCurrency("USD");

【讨论】:

我不敢相信我忘记了。谢谢。

以上是关于必填字段缺失。 PHP 贝宝 REST API的主要内容,如果未能解决你的问题,请参考以下文章

Django Rest Framework render_form & 必填字段

贝宝 REST .net api 提取 VALIDATION_ERROR

Django-Rest-Framework POST 对象字段必填

PHP 表单验证 - 必填字段

Jira Api对接:提交缺陷

当 API 中未发送必填字段值时,如何在 swagger 中自定义错误消息?