I have special order form and now I need to create orders without payment. So the payment needs to be skipped. I am not sure what would be the best way to accomplish this part. Should I send my form data as JSON to REST API like how it's doing in the default checkout module and current theme? Or it would be better and easy to have my own controller and model where I can use some factory methods to create orders like what we did in Magento 1.x?
Magento 2 Order Creation – How to Create Order Programmatically in Magento 2
apicheckoutmagento2
Related Solutions
REST API
Reasons:
- it is much easier to implement than SOAP as PHP notoriously does not always follow the same standards as - for instance - Microsoft products do. Also, dealing with SOAP implies dealing with XML, namespaces and WSDL. Of course it will work, if done properly, but the cost of developing this for iOS would be greater;
- SOAP is based on XML, and requires downloading (and perhaps caching) of a service definition file (also XML), and XML is mostly more verbose and therefore more bandwidth-consuming than REST data encoding, not to mention memory usage for parsing (if you use DOM parsers), decoding and in-memory object-based tree-like document representation. REST, at the other hand, is much less bandwidth and memory consumptive, which makes it more suitable for mobile devices;
- JSON would be great, but that would require for you to implement a whole new API interface at Magento side, which may have consequences with regards to Magento security as well, not to mention the complexity of it overall.
I would suggest to use the native Magento REST-based API, and eventually plug in it your custom services. This would be a more reliable (REST API is supported by Magento, it's tested by a wider range of customers, and Magento provides some updates - as security updates - for it along with releases) and cost-effective solution.
Good luck!
We also had the same issue when we tried the below payload it worked
Endpoint: http://localhost:8888/Magento/index.php/rest/V1/carts/mine/payment-information
{
"paymentMethod": {
"method": "paypal_express",
"additional_data": {
"paypal_express_checkout_token" : "EC-xxxxxxxxxxxx",
"paypal_express_checkout_redirect_required" : false,
"paypal_express_checkout_payer_id" : "XXXXXXXXXX"
}
}
}
In order to get the payment token we used the paypal set express checkout api directly
Here is more details
When the customer approves the payment we will get the payer id in the returned url.
Hope this helps!
Best Answer
IMHO best Magento2 way is to use a REST call.
The Magento2 frontend is going to have a complete frontend/backend isolation, so a REST call should be the best option.
Otherwise, if you wish to programmatically create an order use the following code (Source: http://webkul.com/blog/create-quote-and-order-programmatically-in-magento2/)
Parameters example: