Order Processing with REST APIs Tutorial
Step 6. Prepare for checkout
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.
Endpoint
POST http://<host>/rest/default/V1/carts/mine/estimate-shipping-methods
Headers
Content-Type
application/json
Authorization
Bearer <customer token>
Payload
The payload contains the shipping address.
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.
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.
Endpoint
POST http://<host>/rest/default/V1/carts/mine/shipping-information
Headers
Content-Type
application/json
Authorization
Bearer <customer token>
Payload
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.
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.