We had followed the add order process of
Magento 2 - Create order using REST API on the process of "Place Order" using the API "$base_url/index.php/rest/V1/guest-carts/56241bf6bc084cd7589426c8754fc9c5/order" with the params of { "paymentMethod": { "method": "checkmo" } } as put Method we are getting "Please select a valid payment method." from Rest API.
2 Answers
1. Get Customer Token
http://magento-host/index.php/rest/V1/integration/customer/token?
[email protected]&password=test@123
method : POST
2. Get Cart ID (Quote ID) - using customer id.
This will return quote id, which will be used for placing an order.
http://magento-host/rest/V1/carts/mine
method : POSTAuthorization : Bearer <customer token>
3. Add Configurable product in cart.
http://magento-host/index.php/rest/default/V1/carts/mine/items
method : POSTAuthorization : Bearer <customer token>body data : json
{
"cartItem": {
"sku": "HKrh15hc", <product SKU>
"qty": 5,
"quote_id": "75", <Quote ID - Cart ID [see. step 2]>
"product_option": {
"extension_attributes": {
"configurable_item_options": [
{
"option_id": "93",
"option_value": 49
},
{
"option_id": "141",
"option_value": 168
}
]
}
},
"extension_attributes": {}
}
}
Now, this will save your configurable product in your cart.
4. Get & put Shipping Information.
http://magento-host/index.php/rest/V1/carts/mine/shipping-information
method : POSTAuthorization : Bearer <customer token>body data : json
{
"addressInformation": {
"shippingAddress": {
"region": "MH",
"region_id": 0,
"country_id": "IN",
"street": [
"221,Baker-street (e)"
],
"company": "Lumos",
"telephone": "12345678",
"postcode": "400001",
"city": "Mumbai",
"firstname": "Aditya",
"lastname": "Shah",
"email": "[email protected]",
"prefix": "address_",
"region_code": "MH",
"sameAsBilling": 1
},
"billingAddress": {
"region": "MH",
"region_id": 0,
"country_id": "IN",
"street": [
"221,Baker-street (e)"
],
"company": "Lumos",
"telephone": "12345678",
"postcode": "4000001",
"city": "Mumbai",
"firstname": "Aditya",
"lastname": "Shah",
"email": "[email protected]",
"prefix": "address_",
"region_code": "MH"
},
"shipping_method_code": "flatrate",
"shipping_carrier_code": "flatrate"
}
}
5. Get payment method.
http://magento-host/index.php/rest/V1/carts/75/payment-methods
method : POSTAuthorization : Bearer <customer token>
6. Place an order.
http://magento-host/index.php/rest/V1/carts/mine/order
method : POSTAuthorization : Bearer <customer token>body data : json
{
"paymentMethod": {
"method": "checkmo"
}
}
And finally, this will return order ID, which you just placed!
Is the payment method checkmo enabled for use in a normal checkout?
Do a normal onepage checkout and check what is being sent in the network tab of chrome developer tools. If my memory serves me, it also uses the rest api for that step.
-
in Stores -> configuration -> sales -> checkout, the checkout Option for "Allow Guest Checkout" is set to yes. The onepage checkout is working but not able to get the API in network which they are using for the same, We are currently using Magento 2.1.2 versionharish– harish2016-12-13 08:37:19 +00:00Commented Dec 13, 2016 at 8:37