【问题标题】:Required Field Missing. PHP Paypal REST API必填字段缺失。 PHP 贝宝 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); 时,它可以正常工作。所以很明显,项目列表或项目中缺少某些东西。但我看不到什么。

有什么想法吗?

【问题讨论】:

    标签: php paypal paypal-sandbox


    【解决方案1】:

    错误指向您:

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

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

    $item->setSKU("CODEHERE");
    

    之后

    $item->setCurrency("USD");
    

    【讨论】:

    • 我不敢相信我忘记了。谢谢。
    猜你喜欢
    • 2013-10-04
    • 2016-06-09
    • 2012-01-02
    • 2013-04-03
    • 2018-04-25
    • 2021-06-23
    • 2017-01-12
    • 2016-08-03
    • 2013-10-17
    相关资源
    最近更新 更多