问题
I'm following the docs for Dwolla for the Server to Server method, and making a post request to the URL in the docs with the following json data in the body:
{
"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
}
Unfortunately, while the data seems valid to me, their server is responding with the error message:
{
"Result":"Failure",
"Message":"Total cannot be less than $1."
}
While the error tells me that the problem is that the "Total" is less than $1, it very clearly isn't.
-- Further Information
Here's the php I'm using to make the request:
$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),
),
)));
When I commend out the Content-Type, I get "Invalid Application Credentials" as the error.
回答1:
It might not be completely clear from the server-to-server request docs, but the "Shipping", "Tax", and "Total" parameters, should all be nested within the "PurchaseOrder" object parameter. So, to get your request to work, you'll need to change the position of those parameters, as such:
{
"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
}
来源:https://stackoverflow.com/questions/9522593/invalid-total-error-with-dwolla-server-to-server-checkout-method