Step 8. Prepare for checkout

Order processing with Inventory Management

Now that all the items have been added to the cart, we can prepare the quote for checkout. This process includes the following steps:

  • Estimate shipping costs
  • Set shipping and billing information

Estimate shipping costs

Magento calculates shipping costs for each shipping method that can be applied to the order. In this tutorial, the flatrate ($5 per item) shipping method is active.

Endpoint:

POST <host>/rest/default/V1/carts/mine/estimate-shipping-methods

Scope:

default store view

Headers:

Content-Type: application/json

Authorization: Bearer <customer token>

Payload:

The payload contains the shipping address.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
{  "address": {
      "region": "New York",
      "region_id": 43,
      "region_code": "NY",
      "country_id": "US",
      "street": [
        "160 1st St."
        ],
      "postcode": "11501",
      "city": "Mineola",
      "firstname": "Jane",
      "lastname": "Doe",
      "customer_id": 5,
      "email": "jdoe@example.com",
      "telephone": "(516) 555-1111",
      "same_as_billing": 1
  }
}

Response:

The cost for the flatrate shipping method is $300 (60 items x $5 each). The downloadable item does not have a shipping charge because it is not a physical product.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
[
    {
        "carrier_code": "flatrate",
        "method_code": "flatrate",
        "carrier_title": "Flat Rate",
        "method_title": "Fixed",
        "amount": 300,
        "base_amount": 300,
        "available": true,
        "error_message": "",
        "price_excl_tax": 300,
        "price_incl_tax": 300
    }
]

Set shipping and billing information

In this call, you specify the shipping and billing addresses, as well as the selected carrier_code and method_code. The customer has selected the Flat Rate shipping method.

Magento returns a list of payment options and calculates the order totals.

Endpoint:

POST <host>/rest/default/V1/carts/mine/shipping-information

Scope:

default store view

Headers:

Content-Type: application/json

Authorization: Bearer <customer token>

Payload:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
{
"addressInformation": {
    "shipping_address": {
        "region": "New York",
        "region_id": 43,
        "region_code": "NY",
        "country_id": "US",
        "street": [
            "160 1st St."
        ],
        "postcode": "11501",
        "city": "Mineola",
        "firstname": "Jane",
        "lastname": "Doe",
        "email": "jdoe@example.com",
        "telephone": "516-555-1111"
    },
    "billing_address": {
        "region": "New York",
        "region_id": 43,
        "region_code": "NY",
        "country_id": "US",
        "street": [
            "160 1st St."
        ],
        "postcode": "11501",
        "city": "Mineola",
        "firstname": "Jane",
        "lastname": "Doe",
        "email": "jdoe@example.com",
        "telephone": "516-555-1111"
    },
    "shipping_carrier_code": "flatrate",
    "shipping_method_code": "flatrate"
    }
}

Response:

The subtotal of the order is $2022, and shipping charges are $300. The grand total is $2322.

The available payment methods are banktransfer and checkmo. The customer will specify a payment method in the next step.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
{
    "payment_methods": [
        {
            "code": "checkmo",
            "title": "Check / Money order"
        },
        {
            "code": "banktransfer",
            "title": "Bank Transfer Payment"
        }
    ],
    "totals": {
        "grand_total": 1917.6,
        "base_grand_total": 1917.6,
        "subtotal": 2022,
        "base_subtotal": 2022,
        "discount_amount": -404.4,
        "base_discount_amount": -404.4,
        "subtotal_with_discount": 1617.6,
        "base_subtotal_with_discount": 1617.6,
        "shipping_amount": 300,
        "base_shipping_amount": 300,
        "shipping_discount_amount": 0,
        "base_shipping_discount_amount": 0,
        "tax_amount": 0,
        "base_tax_amount": 0,
        "weee_tax_applied_amount": null,
        "shipping_tax_amount": 0,
        "base_shipping_tax_amount": 0,
        "subtotal_incl_tax": 2022,
        "shipping_incl_tax": 300,
        "base_shipping_incl_tax": 300,
        "base_currency_code": "USD",
        "quote_currency_code": "USD",
        "items_qty": 61,
        "items": [
            {
                "item_id": 5,
                "price": 36,
                "base_price": 36,
                "qty": 20,
                "row_total": 720,
                "base_row_total": 720,
                "row_total_with_discount": 0,
                "tax_amount": 0,
                "base_tax_amount": 0,
                "tax_percent": 0,
                "discount_amount": 144,
                "base_discount_amount": 144,
                "discount_percent": 20,
                "price_incl_tax": 36,
                "base_price_incl_tax": 36,
                "row_total_incl_tax": 720,
                "base_row_total_incl_tax": 720,
                "options": "[]",
                "weee_tax_applied_amount": null,
                "weee_tax_applied": null,
                "name": "Driven Backpack"
            },
            {
                "item_id": 6,
                "price": 32,
                "base_price": 32,
                "qty": 40,
                "row_total": 1280,
                "base_row_total": 1280,
                "row_total_with_discount": 0,
                "tax_amount": 0,
                "base_tax_amount": 0,
                "tax_percent": 0,
                "discount_amount": 256,
                "base_discount_amount": 256,
                "discount_percent": 20,
                "price_incl_tax": 32,
                "base_price_incl_tax": 32,
                "row_total_incl_tax": 1280,
                "base_row_total_incl_tax": 1280,
                "options": "[]",
                "weee_tax_applied_amount": null,
                "weee_tax_applied": null,
                "name": "Voyage Yoga Bag"
            },
            {
                "item_id": 9,
                "price": 22,
                "base_price": 22,
                "qty": 1,
                "row_total": 22,
                "base_row_total": 22,
                "row_total_with_discount": 0,
                "tax_amount": 0,
                "base_tax_amount": 0,
                "tax_percent": 0,
                "discount_amount": 4.4,
                "base_discount_amount": 4.4,
                "discount_percent": 20,
                "price_incl_tax": 22,
                "base_price_incl_tax": 22,
                "row_total_incl_tax": 22,
                "base_row_total_incl_tax": 22,
                "options": "[{\"value\":\"Yoga Adventure\",\"label\":\"Downloads\"}]",
                "weee_tax_applied_amount": null,
                "weee_tax_applied": null,
                "name": "Yoga Adventure"
            }
        ],
        "total_segments": [
            {
                "code": "subtotal",
                "title": "Subtotal",
                "value": 2022
            },
            {
                "code": "giftwrapping",
                "title": "Gift Wrapping",
                "value": null,
                "extension_attributes": {
                    "gw_item_ids": [],
                    "gw_price": "0.0000",
                    "gw_base_price": "0.0000",
                    "gw_items_price": "0.0000",
                    "gw_items_base_price": "0.0000",
                    "gw_card_price": "0.0000",
                    "gw_card_base_price": "0.0000"
                }
            },
            {
                "code": "discount",
                "title": "Discount",
                "value": -404.4
            },
            {
                "code": "shipping",
                "title": "Shipping & Handling (Flat Rate - Fixed)",
                "value": 300
            },
            {
                "code": "tax",
                "title": "Tax",
                "value": 0,
                "extension_attributes": {
                    "tax_grandtotal_details": []
                }
            },
            {
                "code": "grand_total",
                "title": "Grand Total",
                "value": 1917.6,
                "area": "footer"
            },
            {
                "code": "customerbalance",
                "title": "Store Credit",
                "value": -0
            },
            {
                "code": "reward",
                "title": "0 Reward points",
                "value": -0
            }
        ],
        "extension_attributes": {
            "reward_points_balance": 0,
            "reward_currency_amount": 0,
            "base_reward_currency_amount": 0
        }
    }
}

Verify this step

Sign in to the US store (http://<host>/us) as the customer and go to the checkout page.

The payment method is Bank Transfer, the billing and shipping addresses are displayed, and the shipping charges and shipping charges calculate and display.