If you use the payment by credit card at the shipping you must inform Magento that your order has been shipped and need to be capture.

A capture in Magento is the action which trigger the notification to the PSP (Payment Service Provider) to take the fund of your order from the bank account of your customer.

In first you need to create an invoice, with the invoice Magento can take the correct amount for example if you have a product out of stock, the amount of this product will not be invoiced to your customer and must not be captured.

How to create an invoice in Magento with REST API ?

The REST API offer two possibilities to make an invoice on an order.

You can either use one or the other route it lead to the same thing.

Route order/{id}/invoice or invoices

For the first route you give the order id in the url and not in the json payload, for the second you need to pass it in the json.

How to create the bearer token ?

You need to go to your Magento 2 back office, then go the System menu and select Integrations.

After in the page you can create your integration token, the documentation of Magento give you all the possibilities to authentificate your requests https://devdocs.magento.com/guides/v2.4/get-started/authentication/gs-authentication.html

How to create an invoice with the order route ?

You need to make a post call to the road URL_OF_MAGENTO/rest/STORE_CODE/v1/order/{id}/invoice

You must replace URL_OF_YOUR_MAGENTO by the url starting with https to the first “/”, then the store code of your store and after the order id.

You can find below the payload to capture the order directly with the invoice and make an invoice for 5 qty of 1009 order item id.

{


  "capture": true,

  "notify": true,

  "appendComment": true,

   "items": [


    {


      "order_item_id": "1009",
      "qty": 5.000

    }

  ],  "comment": {


     "extension_attributes": {

    },

     "comment": "Number of invoice 002344897 ",
      "is_visible_on_front": 0


  }


}

The second route which is related to the invoice entity, you need to pass the order id directly in the payload and make a post request.

{


  "entity": {


    "order_id": "388",

                        "items": [


                         {


                           "order_item_id": "1009",
                           "qty": 5.000

                         }

                       ]


  }


}

How to capture an order after the creation of an invoice ?

In the previous example i put capture at true but you can put it at false and make the capture after your parcel is delivered for example.

So you only have to make a POST request to URL_OF_MAGENTO/rest/STORE_CODE/v1/invoices/{invoice_id}/capture

You don’t need to pass a payload with the request