Zend certified PHP/Magento developer

Magento 2 checkout: Get payment method form from API?

I am looking to implement the checkout using the API as documented here: https://devdocs.magento.com/guides/v2.4/rest/tutorials/orders/order-intro.html

I can do the whole checkout using the API if I use a simple payment method such as “Check / Money order”.

However, if I use an advanced third-party payment integration that has its own payment form (for example to enter the credit card details), I am unable to submit the additional fields using the API, as I do not know which fields are required.

In the frontend, I noticed that there is an API call that returns the payment form HTML required for the selected payment method, as soon as that payment method is selected, with the URL being something like this:

/rest/default/V1/carts/mine/<payment_method_front_name>/checkout/payment-form/<payment_method_code>

And the response returns the HTML for that payment method’s form:

{"html":"<script type="text/javascript">nnrequire(['jquery', ...

I noticed though that this call is made from a JS script using a hardcoded URL specifically for this payment method.

Is there a standardized API call that I can use to get the “payment form” data for a payment method, instead of having to rely on a hardcoded URL?

The call that sets the shipping methods and returns the available payment methods unfortunately does not include the HTML required for rendering the payment method forms, or any information about the required fields for a payment method:

Request:

/rest/<store_code>/V1/guest-carts/<quote_id>/shipping-information

Response:

{
    "payment_methods": [
        {
            "code": "checkmo",
            "title": "Check / Money order"
        },
        {
            "code": "mastercard",
            "title": "Mastercard"
        },
        ...