Change Status of Order

Highlighted
Shopify Partner
4 0 0

I am

$params = array(
          "billing_address" =>  $billing_address,
          "browser_ip" => $order['ip_address'],
          "buyer_accepts_marketing" => true,
          "customer" => array("id" => $customer,"email"=>$order['email_address']),
          "email" => $order['email_address'],
          "financial_status"=> "paid",
          "line_items" => $line_items,
           "name" => "#".$order['order_id'],
           "note" => "Imported from LL",
           "phone" => $order['customers_telephone'],
           "shipping_address" => $shipping_address,
           "source_name" =>$order['campaign_id'],
           "subtotal_price" => $this->get_sub_total($order),
           "taxes_included"=> false,
           "total_price" => $order_total,
           "total_tax"=> $order['order_sales_tax_amount']
        ); //
    
        $shop_order=$this->shopify->Order->post($params);
        
        if(isset($shop_order['id']) && $shop_order['id']>0){
                $this->post_transaction($order,$order_total,$shop_order);
            return $shop_order['id'];
        }else{
            return 0;
        }

    public function post_transaction($order,$order_total,$shop_order){
      $kind="sale";
        $amount=$order_total;
        $authorization=$order['auth_id'];
        $payment_details=array("credit_card_bin"=>$order['cc_first_6'],"credit_card_number"=>$order['credit_card_number'],"credit_card_company"=>$this->get_card_type($order['credit_card_number']));
        $order_id=$shop_order['id'];
        $status = "success";
        /*
        "amount"=>$amount,
          "authorization"=>$authorization,
          "payment_details"=>$payment_details,
          "order_id"=>$order_id,
          "status"=>$status,
        */
          $params = array(
          "kind"=>$kind
          );
          $this->shopify->Order($order_id)->Transaction->post($params);    
    }

 I am tried a few combos of the transaction kind.  Not sure what I am missing

 

Thanks for the feedback

0 Likes
Highlighted
Tourist
3 0 3

For anyone who's trying to find the solution:

Please refer to my reply to my post above, the only thing I did wrong is I create a transaction with "status": "pending".

If I do change the "status" to "success",  I can capture order successfully.
 

0 Likes
Highlighted
Tourist
5 0 1

For the people getting "sale is not a valid transaction", using "capture" for the "kind" field when posting the transaction worked. Using "sale" for the "kind" field did not work.

0 Likes
Highlighted
Tourist
49 0 2

Hi guys, as this is slightly related. Did anyone of you been able to add data to 

"receipt": {}

while doing such API calls?

I noticed that Shopify uses this for PayPal and I see an opportunity for placing plenty of transaction data there.

0 Likes
Highlighted
Shopify Partner
3 0 0

Hi,

Has anyone got the answer?

I am trying to create an order and mark this order as paid (using the API) to force the webhook orders/paid to be triggered. As it seems impossible to mark as paid an order using the API I can't receive the orders/paid webhook.

Thank you.

0 Likes
Shopify Partner
3 0 0

Hi again,

After trying to create orders and transactions in multiple ways I find out a way to change the order status.

If you are using the Shopify API gem, you can use this code:

 

order = ShopifyAPI::Order.create(financial_status: 'pending',line_items: [ShopifyAPI::LineItem.new(variant_id: [VARIANT_ID], quantity: 1)])
transaction = ShopifyAPI::Transaction.new(test: true, gateway: 'bogus', source: 'external', kind: 'capture', amount: [AMOUNT], status: 'success', currency: 'EUR')
transaction.prefix_options[:order_id] = order.id
transaction.save!

First, we create an order that has 'pending' as financial_status. After that, we just have to create a transaction with source = external and kind = capture. This will automatically capture the payment and change the order's financial_status to 'paid'.

I hope it'll help!

0 Likes