This is a beta release of documentation for Magento 2.4, published for previewing soon-to-be-released functionality. Content in this version is subject to change. Links to the v2.4 code base may not properly resolve until the code is officially released.

Step 6. Prepare for checkout

Order Processing tutorial

Now that all the items have been added to the cart, we can prepare the order 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) and tablerate shipping methods are active.

Use the V1/guest-carts/<cartId>/estimate-shipping-methods endpoint to estimate shipping costs on behalf of a guest. Do not include an authorization token.

Endpoint:

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

Headers:

Content-Type: application/json

Authorization: Bearer <customer token>

Payload:

The payload contains the shipping address.

Show code sample
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
{
  "address": {
    "region": "New York",
    "region_id": 43,
    "region_code": "NY",
    "country_id": "US",
    "street": [
      "123 Oak Ave"
    ],
    "postcode": "10577",
    "city": "Purchase",
    "firstname": "Jane",
    "lastname": "Doe",
    "customer_id": 4,
    "email": "jdoe@example.com",
    "telephone": "(512) 555-1111",
    "same_as_billing": 1
  }
}

Response:

Note that the cost for the flatrate shipping method is $15. The Sprite Yoga Companion Kit bundled product counts as one item. The Advanced Pilates & Yoga item does not have a shipping charge because the customer downloads this item.

Show code sample
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
[
  {
    "carrier_code": "flatrate",
    "method_code": "flatrate",
    "carrier_title": "Flat Rate",
    "method_title": "Fixed",
    "amount": 15,
    "base_amount": 15,
    "available": true,
    "error_message": "",
    "price_excl_tax": 15,
    "price_incl_tax": 15
  },
  {
    "carrier_code": "tablerate",
    "method_code": "bestway",
    "carrier_title": "Best Way",
    "method_title": "Table Rate",
    "amount": 5,
    "base_amount": 5,
    "available": true,
    "error_message": "",
    "price_excl_tax": 5,
    "price_incl_tax": 5
  }
]

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. Since the Table Rate shipping method costs only $5, the customer selected this option.

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

Use the V1/guest-carts/<cartId>/shipping-information endpoint to set the billing and shipping information on behalf of a guest. Do not include an authorization token.

Endpoint:

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

Headers:

Content-Type: application/json

Authorization: Bearer <customer token>

Payload:

Show code sample
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": [
        "123 Oak Ave"
      ],
      "postcode": "10577",
      "city": "Purchase",
      "firstname": "Jane",
      "lastname": "Doe",
      "email": "jdoe@example.com",
      "telephone": "512-555-1111"
    },
    "billing_address": {
      "region": "New York",
      "region_id": 43,
      "region_code": "NY",
      "country_id": "US",
      "street": [
        "123 Oak Ave"
      ],
      "postcode": "10577",
      "city": "Purchase",
      "firstname": "Jane",
      "lastname": "Doe",
      "email": "jdoe@example.com",
      "telephone": "512-555-1111"
    },
    "shipping_carrier_code": "tablerate",
    "shipping_method_code": "bestway"
  }
}

Response:

The subtotal of the order is $160, and shipping charges are $5. The grand total is $165.

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

Show code sample
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
{
  "payment_methods": [
    {
      "code": "cashondelivery",
      "title": "Cash On Delivery"
    },
    {
      "code": "banktransfer",
      "title": "Bank Transfer Payment"
    },
    {
      "code": "purchaseorder",
      "title": "Purchase Order"
    },
    {
      "code": "checkmo",
      "title": "Check / Money order"
    }
  ],
  "totals": {
    "grand_total": 165,
    "base_grand_total": 165,
    "subtotal": 160,
    "base_subtotal": 160,
    "discount_amount": 0,
    "base_discount_amount": 0,
    "subtotal_with_discount": 160,
    "base_subtotal_with_discount": 160,
    "shipping_amount": 5,
    "base_shipping_amount": 5,
    "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": 160,
    "shipping_incl_tax": 5,
    "base_shipping_incl_tax": 5,
    "base_currency_code": "USD",
    "quote_currency_code": "USD",
    "items_qty": 4,
    "items": [
      {
        "item_id": 6,
        "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": 0,
        "base_discount_amount": 0,
        "discount_percent": 0,
        "price_incl_tax": 22,
        "base_price_incl_tax": 22,
        "row_total_incl_tax": 22,
        "base_row_total_incl_tax": 22,
        "options": "[]",
        "weee_tax_applied_amount": null,
        "weee_tax_applied": null,
        "name": "Radiant Tee-M-Orange"
      },
      {
        "item_id": 7,
        "price": 18,
        "base_price": 18,
        "qty": 1,
        "row_total": 18,
        "base_row_total": 18,
        "row_total_with_discount": 0,
        "tax_amount": 0,
        "base_tax_amount": 0,
        "tax_percent": 0,
        "discount_amount": 0,
        "base_discount_amount": 0,
        "discount_percent": 0,
        "price_incl_tax": 18,
        "base_price_incl_tax": 18,
        "row_total_incl_tax": 18,
        "base_row_total_incl_tax": 18,
        "options": "[{\"value\":\"Advanced Pilates & Yoga (Strength)\",\"label\":\"Downloads\"}]",
        "weee_tax_applied_amount": null,
        "weee_tax_applied": null,
        "name": "Advanced Pilates & Yoga (Strength)"
      },
      {
        "item_id": 8,
        "price": 68,
        "base_price": 68,
        "qty": 1,
        "row_total": 68,
        "base_row_total": 68,
        "row_total_with_discount": 0,
        "tax_amount": 0,
        "base_tax_amount": 0,
        "discount_amount": 0,
        "base_discount_amount": 0,
        "discount_percent": 0,
        "price_incl_tax": 68,
        "base_price_incl_tax": 68,
        "row_total_incl_tax": 68,
        "base_row_total_incl_tax": 68,
        "options": "[{\"value\":\"1 x Sprite Stasis Ball 65 cm <span class=\\\"price\\\">$27.00<\\/span>\",\"label\":\"Sprite Stasis Ball\"},{\"value\":\"1 x Sprite Foam Yoga Brick <span class=\\\"price\\\">$5.00<\\/span>\",\"label\":\"Sprite Foam Yoga Brick\"},{\"value\":\"1 x Sprite Yoga Strap 8 foot <span class=\\\"price\\\">$17.00<\\/span>\",\"label\":\"Sprite Yoga Strap\"},{\"value\":\"1 x Sprite Foam Roller <span class=\\\"price\\\">$19.00<\\/span>\",\"label\":\"Sprite Foam Roller\"}]",
        "weee_tax_applied_amount": null,
        "weee_tax_applied": null,
        "name": "Sprite Yoga Companion Kit"
      },
      {
        "item_id": 13,
        "price": 52,
        "base_price": 52,
        "qty": 1,
        "row_total": 52,
        "base_row_total": 52,
        "row_total_with_discount": 0,
        "tax_amount": 0,
        "base_tax_amount": 0,
        "tax_percent": 0,
        "discount_amount": 0,
        "base_discount_amount": 0,
        "discount_percent": 0,
        "price_incl_tax": 52,
        "base_price_incl_tax": 52,
        "row_total_incl_tax": 52,
        "base_row_total_incl_tax": 52,
        "options": "[{\"value\":\"Gray\",\"label\":\"Color\"},{\"value\":\"S\",\"label\":\"Size\"}]",
        "weee_tax_applied_amount": null,
        "weee_tax_applied": null,
        "name": "Chaz Kangeroo Hoodie"
      }
    ],
    "total_segments": [
      {
        "code": "subtotal",
        "title": "Subtotal",
        "value": 160
      },
      {
        "code": "shipping",
        "title": "Shipping & Handling (Best Way - Table Rate)",
        "value": 5
      },
      {
        "code": "tax",
        "title": "Tax",
        "value": 0,
        "extension_attributes": {
          "tax_grandtotal_details": []
        }
      },
      {
        "code": "grand_total",
        "title": "Grand Total",
        "value": 165,
        "area": "footer"
      }
    ]
  }
}

If you tried this call on your own, and the value of the shipping_amount parameter is 0, then you did not deactivate the “Spend $50 or more - shipping is free!” cart price rule. See Deactivate a cart price rule for details.

Verify this step

Sign in 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 have been calculated.