Drupal Commerce Rest API for checkout process

Here we are going to discuss about Rest web services for checkout process in Drupal commerce.

So here we are achieving this using the Commerce decoupled checkout module.

This module provides end points for Remote orders creation, remote payment creation/initialisation and  remote payment capturing/Finalisation.

Install the module with below composer command

$ composer require ‘drupal/commerce_decoupled_checkout:^1.0@beta’

Module available in below link.


Here we are going to create Rest API’s for below.

  • REST API – Create New Order with or without payment
  • REST API – Create a new payment for the order with or without payment capture.
  • REST API – Capture the existing payment

Here we are using HTTP basic authentication, so make sure your REST Api user has permission below in order to POST request to Rest API endpoints.

REST API – Create New Order with or without payment

After installation of module, navigate in to  Rest UI.


Enable below resources.

Also make sure below options selected in configurations of each resource.

Here we are using basic authentication. You can use cookie authentication also.

For creating order with or without payment, details provided below.

Request URL  – http:/ProjectPath/commerce/order/create?_format=json

Request Method- Post


      ContentType –  application/json


Response: 201 created response with order details.

Below provides Request body parameters and corresponding attribute documentation.


Simple Draft Order Creation 

Use below request body for creating a sample order without payment.

So you can see  order has been created 

Additionally you can provide profile information, that will be considered in Billing information.


You can see below order in Orders list

You can also create orders with payment information. You  can get payment gateway information from Commerce>Configuration->Payment->Payment Gateways

So here I have enabled example_credit_card

You can see  ID as example_credit_card, this is the gateway for us in request body.

add below additional object in  order create request body.

“payment”: {

       “gateway”: “example_credit_card”,

       “type”: “credit_card”,

       “details”: {

         “type”: “visa”,

         “number”: “4111111111111111”,

         “expiration”: {

         “month”: “01”,

         “year”: “2023”




So with above payment parameters , order will be created as completed with payment information in order Payment tab.

REST API – Create a new payment for the order with or without payment capture

Use below in your request

URL- http://yourprojectpath/commerce/payment/create/order_id?_format=json

       Order_id –  Replace with order id for which you are creating payment,

Request Method- POST


      ContentType –  application/json

Request Body


       “gateway”: “example_credit_card”,  // required. Commerce Payment Gateway name.

       “type”: “credit_card”,  // required. Commerce Payment Type name.

        ‘capture’ => FALSE, // optional. Defines if the payment has to be finalized.

       “details”: {     // optional. Payment details associated with the payment.

         “type”: “visa”,

         “number”: “4111111111111111”,

         “expiration”: {

         “month”: “01”,

         “year”: “2023”





After submission, you can see  Payment tab of that particular order  populated with payment details.

Here you will receive payment id in response. This  payment id needed to capture payment in next step.

REST API – Capture the existing payment

use below in your request


Request Method- Post


        ContentType –  application/json

No Body text 

You will receive 200 OK response upon successful submission.

So if you go to that particle order you can see its payment state completed.


So here we have discussed all Rest end points  related to  checkout process. You can see other related Drupal commerce API articles in below.

How to enable Rest API endpoints for cart operations in Drupal commerce using commerce cart api module

Drupal Commerce Rest API – list Products and Product details

Drupal Commerce Rest API configuration and creating API for product categories



Get Free E-book
Get a free Ebook on Drupal 8 -theme tutorial
I agree to have my personal information transfered to MailChimp ( more information )
if you like this article Buy me a Coffee this will be an ispiration for me to write articles like this.

You may also like...