How to use the Shopify API to change the payment status of orders? - shopify

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"]}}

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...

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

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);
}

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.

Related

Odoo-14: How to add orderline in current POS order

I need to append a "specific" product in current order's orderline on the the click on particular button, same functionality needs to be used i.e. when you click on any product and it gets added to orderline. With following line of code, unable to get order id:
this.env.pos.get_order()
I am unable to get in-process order id as it is not yet created in backend until its paid.
To get the order and add a new orderline you can use
var order = this.env.pos.get_order();
order.add_product(product, { quantity: 1, price: total_price });

How to send email when order status is updated ? prestashop

foreach($order_to_convert as $odr_id) {
$objOrder = new Order($odr_id);
$history = new OrderHistory();
$history->id_order = (int)$objOrder->id;
//$history->changeIdOrderState((int)$sts_id, (int)($objOrder->id));
//$history->add(true);
$history->addWithemail(true);
//$history->save();
}
I have used above code to update order status & send email to customers but due to performance issue i have removed the code above & used query to perform the same. but i am not able to send email to customers.
Is their any way to send customer email when the order status is updated ?

WooCommerce products shortcode order by sku list

Is there a way to modify the WooCommerce Products shortcode to order by a list of product sku's?
A search engine send a Post to the page with a list of sku's. The page should display the Products in the same order the http post is.
Example php and mysql select (the code like this worked in my old shop system where I can use SQL syntax):
$_POST['skus'] = "51,57,34,12,111";
$skus = $_POST['skus'];
select * from products where sku in ('$skus') order by FIELD(sku,'$skus);
How can I do an "orderby" like the example with products shortcode from woocommerce or is there a better way to do that with woocommerce?
Thanks for every answer.
With the help from Gavin and the code from https://wordpress.stackexchange.com/a/67830/43362
I found this solution:
function wpse67823_orderby_post_in($orderby, $query){
//Remove it so it doesn't effect future queries
remove_filter(current_filter(), __FUNCTION__);
$post__in = $_POST['skus'];
$post__in = str_replace(',','\',\'',$post__in);
return "FIELD(CAST(mt2.meta_value AS CHAR), '$post__in' )";
}
//Add filter and perform query
add_filter('posts_orderby','wpse67823_orderby_post_in',10,2);
echo do_shortcode('[products skus="'.$skus.'" orderby="sku"]');
remove_filter('posts_orderby','wpse67823_orderby_post_in',10,2);

How can I filter sales_order_shipment.list by order increment_id

I want to find the shipments on an order (sales order info does not appear to have this information) Data::Printer Dump Format
[0] "sales_order_shipment.list",
[1] [
[0] {
increment_id {
eq 100000025
}
}
]
but this filters by shipment increment id. Also this
[0] "sales_order_shipment.list",
[1] [
[0] {
order_increment_id {
eq 100000025
}
}
]
which throws a SQL error. I suspect I need to join the tables via the API somehow, but I'm not sure how I can do that.
This is possible by using a filter on the order's order_id value.
Note that order_id is different to the order's increment_id which is the usual customer facing reference number. Therefore an extra step is required to convert the order's reference into the order_id.
I can describe the method:
Get the order data for your order number (increment_id) using sales_order.info API call
get the order_id from the order data
Use the order_id as a filter in sales_order_shipment.list
This will give you a list of shipments each with an increment_id. This id is the shipment's reference.
Use the shipment's increment_id in sales_order_shipment.info to get more details.

Adding product to shopping cart via Magento API results in a 0 price

I'm trying to programmatically create an order and invoice in Magento but whenever I add products to the shopping cart, the price of each product is set to 0, thus resulting in a NULL total.
I also tried the moveToCustomerQuote method but that throws a Magento Fault saying that the customer quote (shoppingcart ID) doesn't exist.
Here's my code
$cart = $magi->execute("cart.create");
$add_customer = $magi->execute("cart_customer.set",array($cart,$customer));
$products = array(array(
"product_id" => 167,
"qty" => 50
));
$add_product = $magi->execute("cart_product.add",array($cart,$products));
Is there something I'm doing wrong or is there another step I should take to get the product to list the price properly?