WooCommerce API: Creating Order and Checkout

WHAT DO YOU TRY

I want to create a Native Android APP (not HTML5 / jQuery mobile) for my Woocommerce website. I am trying to configure the API using kloon / WooCommerce-REST-API-Client-Library .

So far, I have managed to get lists of products, coupons, customers, orders, etc., which I could use to display in my Android application.

Now I want to replicate the add to cart / checkout process in an Android application, but this library does not seem to provide functions for such a workflow.

MY QUESTION

How can I achieve a workflow with REST APIs in an Android app? (Similar to website design process)

Flow:

  • Add to Cart

enter image description here enter image description here

enter image description here

enter image description here enter image description here

, , - API.

- , . -//- .

!

+4
2

example.php php lib, , ...

example.php - :

// orders
//print_r( $client->orders->get() );
//print_r( $client->orders->get( $order_id ) );
//print_r( $client->orders->update_status( $order_id, 'pending' ) );

class-wc-api-client-resource-orders.php, :

/**
 * Create an order
 *
 * POST /orders
 *
 * @since 2.0
 * @param array $data valid order data
 * @return array|object your newly-created order
 */
public function create( $data ) {
    $this->set_request_args( array(
        'method' => 'POST',
        'body'   => $data,
    ) );
    return $this->do_request();
}

.

$orderData = array(
    "order" => array(
        "line_items" => array( 
            array(
                "product_id" => 1, 
                "quantity" => 1
            ) 
        )
    )
);

$client->orders->create($orderData);

- WooCommerce REST API? .

+2

$ orderData = array (   "order" => (

/*

"set_paid"=>true

*/

"status"=>"processing",

"payment_details"=>array("method_id"=>"cod","method_title"=>"Cash on Delivery"),

"billing_address"=>array("first_name"=>"Tumusime","last_name"=>"Deus","company"=>"mcash",
"city"=>"Kampala","address_1"=>"Plot 7 Mukalazi zone","email"=>"jones@mcash.ug","phone"=>"0784529043",
),

"shipping_address"=>array("first_name"=>"Tumusime","last_name"=>"Deus","company"=>"mcash",
"city"=>"Kampala","address_1"=>"Plot 7 Mukalazi zone","email"=>"jones@mcash.ug","phone"=>"0784529043",
),
"shipping_lines"=>array(
array("id"=>5,"method_id"=>"flat_rate:1",
"method_title"=>"Flat rate","total"=>"10000.00")

),


    "line_items" => array( 
        array(
            "product_id" => 10, 
            "quantity" => 1,

        ) ,
         array(
            "product_id" => 15, 
            "quantity" => 2,

        ) 

    )
)

);

//$client->orders->create($orderData);

print_r($client->orders->create($orderData));
0

Source: https://habr.com/ru/post/1618993/


All Articles