Question

According to documentation - https://devdocs.magento.com/guides/v2.4/rest/tutorials/orders/order-create-order.html

I'm trying to make call on /rest/default/V1/carts/mine/payment-information with body:

{
  "paymentMethod": {
      "method": "stripe_payments"
  },
  "billing_address": {
    "email": "jdoe@example.com",
    "region": "New York",
    "region_id": 43,
    "region_code": "NY",
    "country_id": "US",
    "street": [
      "123 Oak Ave"
    ],
    "postcode": "10577",
    "city": "Purchase",
    "telephone": "512-555-1111",
    "firstname": "Jane",
    "lastname": "Doe"
  }
}

and getting error:

{
"message": "No such entity with %fieldName = %fieldValue",
    "parameters": {
        "fieldName": "cartId",
        "fieldValue": 0
    },
    "trace": "#0 /bitnami/magento/htdocs/vendor/magento/module-quote/Model/QuoteRepository.php(232): Magento\\Framework\\Exception\\NoSuchEntityException::singleField('cartId', 0)\n#1 /bitnami/magento/htdocs/vendor/magento/module-quote/Model/QuoteRepository.php(136): Magento\\Quote\\Model\\QuoteRepository->loadQuote('loadByIdWithout...', 'cartId', 0, Array)\n#2 /bitnami/magento/htdocs/vendor/magento/framework/Interception/Interceptor.php(58): Magento\\Quote\\Model\\QuoteRepository->get(0)\n#3 /bitnami/magento/htdocs/vendor/magento/framework/Interception/Interceptor.php(138): Magento\\Quote\\Model\\QuoteRepository\\Interceptor->___callParent('get', Array)\n#4 /bitnami/magento/htdocs/vendor/magento/framework/Interception/Interceptor.php(153): Magento\\Quote\\Model\\QuoteRepository\\Interceptor->Magento\\Framework\\Interception\\{closure}(0)\n#5 /bitnami/magento/htdocs/generated/code/Magento/Quote/Model/QuoteRepository/Interceptor.php(26): Magento\\Quote\\Model\\QuoteRepository\\Interceptor->___callPlugins('get', Array, Array)\n#6 /bitnami/magento/htdocs/vendor/magento/module-sales/Model/Service/PaymentFailuresService.php(102): Magento\\Quote\\Model\\QuoteRepository\\Interceptor->get(0)\n#7 /bitnami/magento/htdocs/vendor/magento/module-checkout/Helper/Data.php(231): Magento\\Sales\\Model\\Service\\PaymentFailuresService->handle(0, 'Please check th...', 'onepage')\n#8 /bitnami/magento/htdocs/vendor/stripe/module-payments/Plugin/PaymentInformationManagement.php(68): Magento\\Checkout\\Helper\\Data->sendPaymentFailedEmail(Object(Magento\\Quote\\Model\\Quote\\Interceptor), 'Please check th...')\n#9 /bitnami/magento/htdocs/vendor/magento/framework/Interception/Interceptor.php(135): StripeIntegration\\Payments\\Plugin\\PaymentInformationManagement->aroundSavePaymentInformationAndPlaceOrder(Object(Magento\\Checkout\\Model\\PaymentInformationManagement\\Interceptor), Object(Closure), 6, Object(Magento\\Quote\\Model\\Quote\\Payment\\Interceptor), Object(Magento\\Quote\\Model\\Quote\\Address\\Interceptor))\n#10 /bitnami/magento/htdocs/vendor/magento/framework/Interception/Interceptor.php(153): Magento\\Checkout\\Model\\PaymentInformationManagement\\Interceptor->Magento\\Framework\\Interception\\{closure}(6, Object(Magento\\Quote\\Model\\Quote\\Payment\\Interceptor), Object(Magento\\Quote\\Model\\Quote\\Address\\Interceptor))\n#11 /bitnami/magento/htdocs/generated/code/Magento/Checkout/Model/PaymentInformationManagement/Interceptor.php(26): Magento\\Checkout\\Model\\PaymentInformationManagement\\Interceptor->___callPlugins('savePaymentInfo...', Array, NULL)\n#12 [internal function]: Magento\\Checkout\\Model\\PaymentInformationManagement\\Interceptor->savePaymentInformationAndPlaceOrder(6, Object(Magento\\Quote\\Model\\Quote\\Payment\\Interceptor), Object(Magento\\Quote\\Model\\Quote\\Address\\Interceptor))\n#13 /bitnami/magento/htdocs/vendor/magento/module-webapi/Controller/Rest/SynchronousRequestProcessor.php(95): call_user_func_array(Array, Array)\n#14 /bitnami/magento/htdocs/vendor/magento/module-webapi/Controller/Rest.php(188): Magento\\Webapi\\Controller\\Rest\\SynchronousRequestProcessor->process(Object(Magento\\Framework\\Webapi\\Rest\\Request\\Proxy))\n#15 /bitnami/magento/htdocs/vendor/magento/framework/Interception/Interceptor.php(58): Magento\\Webapi\\Controller\\Rest->dispatch(Object(Magento\\Framework\\App\\Request\\Http))\n#16 /bitnami/magento/htdocs/vendor/magento/framework/Interception/Interceptor.php(138): Magento\\Webapi\\Controller\\Rest\\Interceptor->___callParent('dispatch', Array)\n#17 /bitnami/magento/htdocs/vendor/magento/framework/Interception/Interceptor.php(153): Magento\\Webapi\\Controller\\Rest\\Interceptor->Magento\\Framework\\Interception\\{closure}(Object(Magento\\Framework\\App\\Request\\Http))\n#18 /bitnami/magento/htdocs/generated/code/Magento/Webapi/Controller/Rest/Interceptor.php(26): Magento\\Webapi\\Controller\\Rest\\Interceptor->___callPlugins('dispatch', Array, Array)\n#19 /bitnami/magento/htdocs/vendor/magento/framework/App/Http.php(116): Magento\\Webapi\\Controller\\Rest\\Interceptor->dispatch(Object(Magento\\Framework\\App\\Request\\Http))\n#20 /bitnami/magento/htdocs/generated/code/Magento/Framework/App/Http/Interceptor.php(24): Magento\\Framework\\App\\Http->launch()\n#21 /bitnami/magento/htdocs/vendor/magento/framework/App/Bootstrap.php(263): Magento\\Framework\\App\\Http\\Interceptor->launch()\n#22 /bitnami/magento/htdocs/index.php(39): Magento\\Framework\\App\\Bootstrap->run(Object(Magento\\Framework\\App\\Http\\Interceptor))\n#23 {main}"
}
}

I was trying to put "cartId" with id of shopping-card created by magento rest api, but result was the same.

Was it helpful?

Solution

Ok, first of all, error occurs every time you have done something wrong, it doesn't matter it's invalid postcode, invalid region_id or something else. It's generic error, for example if you provide incorrect region_id for region this error will occur instead of for example "Your region_id is incorrect" or something like that.

In my case, the same error occurred when i incorrectly pass region_id or don't provide "additional_data" for stripe payments. This error doesn't tell you anything.

First case: This is how request body should look for stripe payments:

{
  "paymentMethod": {
      "method": "stripe_payments",
      "additional_data": {
          "cc_save": false,
          "cc_stripejs_token": "pm_card_visa:visa:4242"
      }
  },
  "billing_address": {
    "email": "jdoe@example.com",
    "region": "New York",
    "region_id": 43,
    "region_code": "NY",
    "country_id": "US",
    "street": [
      "123 Oak Ave"
    ],
    "postcode": "10577",
    "city": "Purchase",
    "telephone": "512-555-1111",
    "firstname": "Jane",
    "lastname": "Doe"
  }
}

You have to add two additional parameters - only for stripe payments with this plugin - https://marketplace.magento.com/stripe-stripe-payments.html

Second case: If your magento store works in USA everything is working correctly, but for other countries you have to configure it in admin panel: Go to Store >> Configuration >> General >> Country Options

In each request you have to provide correct region, region_id, region_code and country_id parameters on each step of this tutorial: https://devdocs.magento.com/guides/v2.4/rest/tutorials/orders/order-prepare-checkout.html

The list of available region codes is in database, in your magento database you have to check codes and ids by SQL query:

SELECT * FROM directory_country_region

and if you get prefix of your country like: "PL" or "US" you can check regions ids and codes by:

SELECT * FROM directory_country_region WHERE country_id = "PL";

that shows you: enter image description here

and now i can use this informations in request (for małopolska in my case):

{
  "paymentMethod": {
      "method": "stripe_payments",
      "additional_data": {
          "cc_save": false,
          "cc_stripejs_token": "pm_card_visa:visa:4242"
      }
  },
  "billing_address": {
        "email": "XXX@XXX.com",
        "region": "małopolskie",
        "region_id": 801,
        "region_code": "PL-12",
        "country_id": "PL",
        "street": [
            "Street XX"
        ],
        "postcode": "XX-XXX",
        "city": "Kraków",
        "telephone": "XXX-XXX-XXX",
        "firstname": "Marcin",
        "lastname": "Warzybok"
  }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top