Magento 2 Payment API: Make Payment Using REST API

In this post, I will explain to you step-by-step methods to pay for any product through Magento 2 Payment API.

While making payment you can select the payment method like if you want to make cash on delivery (COD) payment then which API will be hit or if you want to make cash memo payment then which rest API will be used for that.

Through this post, we will also know that if you want to make a PayPal payment, then which API will be used for that.

I am explaining below the details of the steps to use all these payment APIs.

 

Create Order from Admin Dashboard via REST API

If you want to create an order through rest API from Magento 2 Admin Dashboard, then you will also have to complete payment for that.

When your payment is complete, the newly created order will appear in this dashboard.

Create Order From Admin via REST API

You can create an order directly from the sales admin dashboard using this rest api.

Admin > Sales > Order > Create New Order

 

Magento 2 Payment API for Guest Customer

You have to execute the below-mentioned four REST APIs step by step then only you will be able to complete the payment for the guest customers.

Guest customers can select and pay through the available payment options.

You can make payment based on whatever payment method available in your store like cash on delivery case money order paper payment etc.

Step 1

http://m243p1s.com/index.php/rest/V1/guest-carts/

Step 2

http://m243p1s.com/index.php/rest/V1/guest-carts/quote_id/items

Step 3

http://m243p1s.com/index.php/rest/V1/guest-carts/quote_id

Step 4

http://m243p1s.com/index.php/rest/V1/guest-carts/quote_id/shipping-information

If you want to know the above four steps in detail, then you can see our separate post for guest cart PayPal payment steps.

 

Step 5: Check Money Order Payment REST API

Payload:

http://m243p1s.com/index.php/rest/V1/guest-carts/quote_id/order

Method: PUT

Header:

  • Content-type = application/json

Body:

{ "paymentMethod": { "method": "checkmo" } }
Magento 2 Payment API
Now if you will go into the admin dashboard section then you can see the order has been created.
Created order Via API in dashboard

Cash On Delivery Payment REST API in Magento 2

Now if you want to make cash on delivery payment, then for that you have to follow the above-mentioned four states similarly.

If the guest wants to checkout, the steps will remain the same.

If you want to check out for Login Customer, then you can check the add to cart for login customer rest API to see other steps of Login Customer.

This is a final step that can be used to make payment by making payment through Cas on Delivery payment option via API in Magento 2.

Endpoint:

https://wishusucess.com/index.php/rest/V1/guest-carts/DUaFoHjVIQtfRk4W2xanZcVYTRhy4xav/shipping-information

Method: POST

Header:

  • Content-type = application/json

Now if you hit the above rest API Magento 2 gives you the response as a list of available payment methods, along with the total cart and details.

Magento 2 Payment API

 

Endpoint:

https://wishusucess.com/index.php/rest/V1/guest-carts/DUaFoHjVIQtfRk4W2xanZcVYTRhy4xav/order

Method: PUT

Body:

{ "paymentMethod": { "method": "cashondelivery" } }

Cash on delivery payment via REST API

 

 

Conclusion:

You can order the product for the guest customer and also complete the payment.

For this, you will need to hit at least four REST APIs, and based on the quote id, you can place the order of the product.

 

Read more: Magento 2.4 Installation Guide: How to Install Magento 2.4.2