0

我正在关注Dwolla 的服务器到服务器方法的文档,并在正文中使用以下 json 数据向文档中的 URL 发出发布请求:

{
   "Key":"Fake_Key",
   "Secret":"Fake_Secret",
   "PurchaseOrder":{
      "DestinationId":"Fake_Destination_id",
      "Discount":0,
      "OrderItems":[
      {
            "Description":"a product",
            "Name":"lol",
            "Price":19.99,
            "Quantity":20
         }
      ]
   },
   "Shipping":0,
   "Tax":0,
   "Total":399.8,
   "Test":true
}

不幸的是,虽然数据对我来说似乎有效,但他们的服务器正在响应错误消息:

{
    "Result":"Failure",
    "Message":"Total cannot be less than $1."
}

虽然错误告诉我问题在于“总计”小于 1 美元,但显然不是。

- 更多信息

这是我用来发出请求的 php:

$result = file_get_contents('https://www.dwolla.com/payment/request', null, stream_context_create(array(
    'http' => array(
    'method' => 'POST',
    'header' => 'Content-Type: application/json' . "\r\n" .
        'Content-Length: ' . strlen(json_encode($body)) . "\r\n",
        'content' => json_encode($body),
    ),
)));

当我推荐 Content-Type 时,我得到“无效的应用程序凭据”作为错误。

4

1 回答 1

0

服务器到服务器的请求文档中可能并不完全清楚,但是“Shipping”、“Tax”和“Total”参数都应该嵌套在“PurchaseOrder”对象参数中。因此,要使您的请求生效,您需要更改这些参数的位置,如下所示:

{
   "Key":"Fake_Key",
   "Secret":"Fake_Secret",
   "PurchaseOrder":{
      "DestinationId":"Fake_Destination_id",
      "Discount":0,
      "OrderItems":[
      {
            "Description":"a product",
            "Name":"lol",
            "Price":19.99,
            "Quantity":20
         }
      ],
      "Shipping":0,
      "Tax":0,
      "Total":399.8
   },
   "Test":true
}
于 2012-09-26T14:00:09.493 回答