问题
I'm building an iOS app for my own Shopify store. I created a private app and using the API key and password to call APIs with the format:
https://apikey:password@hostname/admin/resource.json
Problem occurs when I try to use the API to make the payment status change for orders. (I can create a new order without problem). I don't find any API for changing the financial status of an order. I cannot change the financial status by modifying an order or I even cannot make any transaction by API no matter the "kind" of transactions is: "authorisation", "capture" or "sale".
So how can I change the financial status of an order using the API?
Here is an example for the request and response of using the API:
Object Called:
/admin/orders/#{order_id}/transactions.json
request:
{
"transaction": {
"amount": 50,
"test":true,
"kind": "sale"
}
}
response:
{"errors":{"kind":["sale is not a valid transaction"]}}
回答1:
Just a couple of things to try:
I noticed in the Transaction doco there are quotes around the amount, which you don't have in your code (e.g. try "50.00" instead of 50):
POST /admin/orders/#{id}/transactions.json
{
"transaction": {
"amount": "10.00",
"kind": "capture"
}
}
Also, have you seen this discussion on the Shopify forums?
...it seems to work so long as the amount of the transaction doesn't exceed the total outstanding balance of the order. From what I have gathered you can not charge or create a transaction for more than the initial sale amount of the order...
回答2:
You cannot create a transaction or modify the financial_status of any order created via the Shopify API. Refer http://docs.shopify.com/api/order which explicitly says this.
So essentially, you need to pass the financial_status as 'paid' when creating the order and in case your payment was not successful from the gateway, DELETE the order. http://docs.shopify.com/api/order.html#destroy
回答3:
I got some problem with changing the status of the order earlier , later i solved, to get rid of error you should take care of the following things.
Price of the order should be equal or less than the exact price of the order
- Price < exact order price, order will be labeled as Partial Paid
- Price = to the exact order price , order will be labbeled as Paid
- Paid Price > exact order price , you will get error
- Order with status paid, you will get error to change the status of payment
POST /admin/orders/#{id}/transactions.json
{
"transaction": {
"amount": "10.00",
"kind": "capture"
}
}
$order_get = $shopify('GET', '/admin/orders/'.$order_id.'.json' );
$total_price = $order_get['total_price'];
if( $order_get['financial_status'] != 'paid' ){
$arguments = array( "order" => array(
'note' => 'Paid'
)
);
$order_put = $shopify('PUT', '/admin/orders/'.$order_id.'.json', $arguments);
$arg = array( "transaction" => array(
"amount" => $total_price,
"kind" => "capture"
)
);
$order_put = $shopify('POST', '/admin/orders/'.$order_id.'/transactions.json', $arg);
}
回答4:
You're not able to write to the financial_status field to mark an order as paid. The financial_status is a result of the transactions that have taken place on an order. So if an order financial_status is currently authorized, you can mark the order as paid by capturing any funds still owing via our Transaction API - or by marking the order as paid within the admin.
来源:https://stackoverflow.com/questions/24340507/how-to-use-the-shopify-api-to-change-the-payment-status-of-orders