# Order

## **Create Order**

<mark style="color:green;">`POST`</mark> `https://<domain>/<api prefix>/<version>/commerce/create-order/`&#x20;

This API Endpoint will create an order.

#### Headers

| Name                                            | Type   | Description         |
| ----------------------------------------------- | ------ | ------------------- |
| apikey<mark style="color:red;">\*</mark>        | string | apikey              |
| Authorization<mark style="color:red;">\*</mark> | string | Bearer access token |

#### Request Body

| Name                                            | Type   | Description                                                                                                                                                                                                                                                                                     |
| ----------------------------------------------- | ------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| uid<mark style="color:red;">\*</mark>           | string | user id                                                                                                                                                                                                                                                                                         |
| total\_amount<mark style="color:red;">\*</mark> | number | Order total amount                                                                                                                                                                                                                                                                              |
| address<mark style="color:red;">\*</mark>       | object | <p>Is an object for address details, the object should contain address\_first\_name, address\_last\_name, address\_mail\_id, address\_phone\_number, address\_name\_line, address\_premise, address\_locality,  address\_postal\_code, address\_country\_code, and address\_state\_code<br></p> |
| products<mark style="color:red;">\*</mark>      | array  | <p>Must be an array of products,<br>product object should contain product\_id, quantity, unit\_price, discount, and total\_amount.</p>                                                                                                                                                          |

{% tabs %}
{% tab title="200 " %}

```
​HTTP/1.1 200 OK
Content-Type: application/json
​
Body:
{
    "status_code": 200,
    "errors": {},
    "data": {}
}
```

{% endtab %}
{% endtabs %}

#### Sample code

**Node**

```javascript
var request = require('request');
var options = {
  'method': 'POST',
  'url': 'https://<domain>/<api prefix>/<version>/commerce/create-order/',
  'headers': {
    'apikey': '<apikey>'
  },
  body: JSON.stringify(
    {
        "products": [
            {
                "product_id": <product id>,
                "quantity":<product quantity>,
                "unit_price":<product unit price>,
                "discount":<product total dicount>,
                "total_amount":<lineitem total amount>
            }
        ],
        "address": {
            "address_first_name": "<address first name>",
            "address_last_name": "<address last name>",
            "address_mail_id": "<address email id>",
            "address_phone_number": "<address phone number>",
            "address_name_line": "<address house number>",
            "address_premise": "<address street>",
            "address_locality": "<address locality>",
            "address_postal_code": "<address post code>",
            "address_country_code": "<address country code>",
            "address_state_code": "<address state code>"
        },
        "total_amount":<total order amount>,
        "uid":"<user id>"
    }
  )

};
request(options, function (error, response) {
  if (error) throw new Error(error);
  console.log(response.body);
});

```

**PHP**

```php
<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => 'https://<domain>/<api prefix>/<version>/commerce/create-order/',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => '',
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => 'POST',
  CURLOPT_POSTFIELDS =>'{
    "products": [
        {
            "product_id":<product id>,
            "quantity":<product quantity>,
            "unit_price":<product unit price>,
            "discount":<product total dicount>,
            "total_amount":<lineitem total amount>
        }
    ],
    "address":{
        "address_first_name":"<address first name>",
        "address_last_name":"<address last name>",
        "address_mail_id":"<address email id>",
        "address_phone_number":"<address phone number>",
        "address_name_line":"<address house number>",
        "address_premise":"<address street>",
        "address_locality":"<address locality>",
        "address_postal_code":"<address post code>",
        "address_country_code":"<address country code>",
        "address_state_code":"<address state code>"
    },
    "total_amount":<total order amount>,
    "uid":"<user id>"
}',
  CURLOPT_HTTPHEADER => array(
    'apikey: <apikey>'
  ),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;
```

#### Error Responses

| Status Code | Error Type       | Field                  | Description                                                                                  |
| ----------- | ---------------- | ---------------------- | -------------------------------------------------------------------------------------------- |
| 400         | Validation Error | products               | This field is required. Must have one product.                                               |
| 400         | Validation Error | product\_id            | Invalid product\_id \<product id>                                                            |
| 400         | Validation Error | quantity               | Invalid quantity. Quantity must be greater than 1.                                           |
| 400         | Validation Error | address\_state\_code   | Invalid address\_state\_code                                                                 |
| 400         | Validation Error | address\_country\_code | Invalid address\_country\_code                                                               |
| 400         | Validation Error | uid                    | Invalid user id                                                                              |
| 400         | Validation Error | total\_amount          | Invalid order total\_amount. Order total\_amount must be the sum of line item total\_amount. |

## **Renewal or Upgrade**

<mark style="color:green;">`POST`</mark> `https://<domain>/<api prefix>/<version>/commerce/upgrade-renewal-package/`&#x20;

This API Endpoint will help to package upgrade or renewal

#### Headers

| Name                                            | Type   | Description         |
| ----------------------------------------------- | ------ | ------------------- |
| apikey<mark style="color:red;">\*</mark>        | string | apikey              |
| Authorization<mark style="color:red;">\*</mark> | string | Bearer access token |

#### Request Body

| Name                                                     | Type   | Description                         |
| -------------------------------------------------------- | ------ | ----------------------------------- |
| order\_type<mark style="color:red;">\*</mark>            | string | Possible values are upgrade,renewal |
| uid<mark style="color:red;">\*</mark>                    | string | user id                             |
| order\_total<mark style="color:red;">\*</mark>           | number | Order tatal amount                  |
| address\_state\_code<mark style="color:red;">\*</mark>   | string | Adress state code                   |
| address\_country\_code<mark style="color:red;">\*</mark> | string | Adresss county code                 |
| address\_postal\_code<mark style="color:red;">\*</mark>  | string | Adress postal code                  |
| address\_locality<mark style="color:red;">\*</mark>      | string | Address locality                    |
| address\_premise<mark style="color:red;">\*</mark>       | string | Address street                      |
| address\_name\_line<mark style="color:red;">\*</mark>    | string | Address house number                |
| address\_phone\_number<mark style="color:red;">\*</mark> | string | Address phone number                |
| address\_mail\_id<mark style="color:red;">\*</mark>      | string | Address E-mail ID                   |
| address\_last\_name<mark style="color:red;">\*</mark>    | string | Address last name                   |
| address\_first\_name<mark style="color:red;">\*</mark>   | string | Address first name                  |
| discount<mark style="color:red;">\*</mark>               | number | Total discount                      |
| unit\_price<mark style="color:red;">\*</mark>            | number | unit price of the product           |
| product\_id<mark style="color:red;">\*</mark>            | number | product id                          |

{% tabs %}
{% tab title="200 " %}

```
```

{% endtab %}
{% endtabs %}

#### Sample code

**Node**

```javascript
var request = require('request');
var options = {
  'method': 'POST',
  'url': 'https://<domain>/<api prefix>/<version>/commerce/upgrade-renewal-package/',
  'headers': {
    'apikey': '<apikey>'
  },
  body: JSON.stringify(
    {        
        "product_id": <product id>,
        "unit_price": <product unit price>,
        "discount": <total discount amount>,
        "order_total": <order total amount>          
        "address_first_name": "<address first name>",
        "address_last_name": "<address last name>",
        "address_mail_id": "<address email id>",
        "address_phone_number": "<address phone number>",
        "address_name_line": "<address house number>",
        "address_premise": "<address street>",
        "address_locality": "<address locality>",
        "address_postal_code": "<address post code>",
        "address_country_code": "<address country code>",
        "address_state_code": "<address state code>"
        "uid":"<user id>",
        "order_type":"<order type>"
    }
  )

};
request(options, function (error, response) {
  if (error) throw new Error(error);
  console.log(response.body);
});

```

**PHP**

```php
<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => 'https://<domain>/<api prefix>/<version>/commerce/create-order/',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => '',
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => 'POST',
  CURLOPT_POSTFIELDS =>'{
    "product_id": <product id>,
    "unit_price": <product unit price>,
    "discount": <total discount amount>,
    "order_total": <order total amount>          
    "address_first_name": "<address first name>",
    "address_last_name": "<address last name>",
    "address_mail_id": "<address email id>",
    "address_phone_number": "<address phone number>",
    "address_name_line": "<address house number>",
    "address_premise": "<address street>",
    "address_locality": "<address locality>",
    "address_postal_code": "<address post code>",
    "address_country_code": "<address country code>",
    "address_state_code": "<address state code>"
    "uid":"<user id>",
    "order_type":"<order type>"
}',
  CURLOPT_HTTPHEADER => array(
    'apikey: <apikey>'
  ),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;
```

#### Error Responses

| Status Code | Error Type       | Field                  | Description                                                                                                               |
| ----------- | ---------------- | ---------------------- | ------------------------------------------------------------------------------------------------------------------------- |
| 400         | Validation Error | product\_id            | Invalid product\_id \<product id>                                                                                         |
| 400         | Validation Error | address\_postcode      | Invalid postcode                                                                                                          |
| 400         | Validation Error | address\_state\_code   | Invalid address\_state\_code                                                                                              |
| 400         | Validation Error | address\_first\_name   | Invalid address\_first\_name                                                                                              |
| 400         | Validation Error | address\_last\_name    | Invalid address\_last\_name                                                                                               |
| 400         | Validation Error | address\_country\_code | Invalid address\_country\_code                                                                                            |
| 400         | Validation Error | uid                    | Invalid user id                                                                                                           |
| 400         | Validation Error | product\_id            | Couldn't process your request. Renewal package not same as the existing package. Please check your package and try again. |
| 400         | Validation Error | product\_id            | Couldn't process your request. May be you reached maximum upgrade or invalid package id.                                  |
| 400         | Validation Error | order\_total           | Discount must be less than unit\_price.                                                                                   |
| 400         | Validation Error | order\_total           | Order total must be difference of unit\_price and discount.                                                               |
| 400         | Validation Error | uid                    | You are not placed into the genealogy yet. Please wait until the placement completes.                                     |
| 400         | Validation Error | uid                    | There exists a package upgrade in processing. Please wait until the process complete or contact the site administrator.   |
| 400         | Validation Error | uid                    | System initiated package auto upgrade. Please wait until the process complete.                                            |
| 400         | Validation Error | uid                    | Payment for previous purchase is not completed yet. Please wait until the payment complete or cancel that payment.        |
| 400         | Validation Error | uid                    | There exists a package upgrade in processing. Please wait until the process complete or contact the site administrator.   |
| 400         | Validation Error | uid                    | You cannot perform package upgrade because you have an active refund request.                                             |
| 400         | Validation Error | product\_id            | The supplied package same as the existing package. Please change your package and try again.                              |
| 400         | Validation Error | order\_type            | Invalid order\_type. Supported values are upgrade,renewal                                                                 |
| 400         | Validation Error | product\_id            | You already have an active package.                                                                                       |

## List Orders

<mark style="color:blue;">`GET`</mark> `https://<domain>/<api prefix>/<version>/commerce/all-orders/`

get the list of orders

#### Query Parameters

| Name         | Type   | Description  |
| ------------ | ------ | ------------ |
| order number | string | order number |
| period       | string | period       |
| category     | string | category     |
| limit        | string | limit        |

#### Headers

| Name                                            | Type   | Description         |
| ----------------------------------------------- | ------ | ------------------- |
| apikey<mark style="color:red;">\*</mark>        | string | apikey              |
| Authorization<mark style="color:red;">\*</mark> | string | Bearer access token |

{% tabs %}
{% tab title="200 " %}

```
HTTP/1.1 200 OK
Content-Type: application/json
​
Body:
{
    "status_code": 200,
    "errors": {},
    "data": {
        "orders": [
            {
                "id": <id>,
                "uid": <uid>,
                "order_number": <order number>,
                "data": <data>,
                "order_total": <order_total>,
                "currency_symbol": <currency_symbol>,
                "currency_code": <currency_code>,
                "order_type": <order_type>,
                "status": <status>,
                "created": <created>,
                "modified": <modified>,
                "shipping_id": <shipping_id>,
                "billing_id": <billing_id>
            }
        ],
        "filter_data": <filter data>
    }
}
```

{% endtab %}
{% endtabs %}

#### Sample Code

#### Node

```php
var request = require("request");

var options = { method: 'GET',
  url: 'https://<domain>/<api prefix>/<version>/commerce/all-orders/',
  headers: 
   { authorization: 'Bearer <access-token>',
     apikey: '<apikey>',
     'content-type': 'multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW' }
   } 
};

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});
```

#### PHP

```php
<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_PORT => "8000",
  CURLOPT_URL => "https://<domain>/<api prefix>/<version>/commerce/all-orders/",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "GET",
  CURLOPT_POSTFIELDS => "------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"product_id\"\r\n\r\n46363\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW--",
  CURLOPT_HTTPHEADER => array(
    "apikey: <apikey>",
    "authorization: Bearer <access-token>",
    "content-type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW",
  ),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}
```

## Order Details

<mark style="color:blue;">`GET`</mark> `‎https://<domain>/<api prefix>/<version>/commerce/order-details/`

get details of order using order\_number

#### Headers

| Name                                            | Type   | Description         |
| ----------------------------------------------- | ------ | ------------------- |
| apikey<mark style="color:red;">\*</mark>        | string | apikey              |
| Authorization<mark style="color:red;">\*</mark> | string | Bearer access token |

#### Request Body

| Name                                            | Type   | Description  |
| ----------------------------------------------- | ------ | ------------ |
| order\_number<mark style="color:red;">\*</mark> | number | order number |

{% tabs %}
{% tab title="200 " %}

```html
{
    "status_code": 200,
    "errors": {},
    "data": [
        {
            "id": <id>,
            "product_id": <product_id>,
            "bundle_id": <bundle_id>,
            "line_item_label": "<line_item_label>",
            "quantity": <quantity>,
            "price": "<price>",
            "data": {
                "price": {
                    "data": [],
                    "items": {
                        "base_price": {
                            "data": [],
                            "title": "<title>",
                            "total": <total>,
                            "included": <included>,
                            "quantity": <quantity>,
                            "description": "<description>",
                            "currency_code": "<currency_code>"
                        }
                    },
                    "title": "<title>",
                    "total": <total>,
                    "quantity": <quantity>,
                    "description": "<description>",
                    "currency_code": "<currency_code>",
                    "revenue_total": <revenue_total>
                },
                "modules": {},
                "product": {
                    "sku": "<sku>",
                    "product_type": "<product_type>",
                    "product_type_code": "<product_type_code>"
                },
                "item_display": {
                    "items": {
                        "varient_attributes": {
                            "title": "<title>",
                            "params": {
                                "price": {
                                    "value": "<value>"
                                },
                                "images": {
                                    "value": "<images>"
                                },
                                "product-name": {
                                    "value": "<product-name>"
                                },
                                "whole-sale-price": {
                                    "value": <whole-sale-price>
                                }
                            },
                            "display": {},
                            "description": "<description>"
                        }
                    }
                }
            },
            "order_id": <order_id>,
            "currency_code": "<currency_code>",
            "order_id_id": <order_id_id>,
            "status": "<status>",
            "image_path": "<image_path>"
        },
        ....
    ]
}
```

{% endtab %}
{% endtabs %}

#### Sample Code

#### Node

```php
var request = require('request');
var options = {
  'method': 'POST',
  'url': 'https://<domain>/<api prefix>/<version>/commerce/order-details/',
  'headers': {
    'apikey': '<apikey>',
    'Authorization': 'Bearer <access token>',
  },
  formData: {
    'order_number': 'order_number'
  }
};
request(options, function (error, response) {
  if (error) throw new Error(error);
  console.log(response.body);
});

```

#### PHP

```php
<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => 'https://<domain>/<api prefix>/<version>/commerce/order-details/?order_number=<order_number>',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => '',
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => 'GET',
  CURLOPT_POSTFIELDS => array(),
  CURLOPT_HTTPHEADER => array(
    'apikey: <apikey>',
    'Authorization: Bearer <access token>'
  ),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;
```

#### Error Responses

<table data-header-hidden><thead><tr><th>status code</th><th width="200">error type</th><th>field</th><th>description</th></tr></thead><tbody><tr><td>status code</td><td>error type</td><td>field</td><td>description</td></tr><tr><td>400</td><td>Validation Error</td><td>order_number</td><td><p>Order Number maynot be blank.</p><p>Order Number is required.</p><p>Invalid order number.</p></td></tr></tbody></table>
