Klarna Docs - Components of the extension

The purpose of this module is mainly to send order management API calls to Klarna. This includes all post order action capture, refund, and cancellation. The starting entry points for each of these actions can be found at Gateway/Command. If the API call to Klarna returns a successful response the order in Magento will be handled in the same way. For example, if the order was successfully canceled at Klarna the order will then be canceled as well in the shop.

You will find in this module basic helper and settings which are used from a wide range of other Klarna modules. In the following the most important parts of the module are:

  • Model/Api: It consists of a set of classes for creating in a general way the request parameter.
  • Model/System/Message: Checking specific Klarna settings and showing a message in the admin if there is a misconfiguration.
  • Model/OrderRepository.php: Updating and getting back the Klarna order from the table klarna_core_order. You can find the migration for it at etc/db_schema.xml

This module contains all the logic that is needed so that KCO is usable. Since KCO is a checkout solution there is a broad set of important parts to make it work. In the following you find a small summary of some of the key components:

  • Controller/Api: This is the entry point of all our callback URLs.
  • Controller/Klarna: Here you find a set of controllers which are either used by ajax calls or to redirect the customer to the correct page
  • Model/Api/Builder/Kasper.php: This class is responsible for creating the API request parameter.
  • Model/Checkout/Validation.php: This class is called in the validate callback. Depending on its result, the customer is forwarded to the confirmation controller or will be redirected back to a specific error message to a different page like the cart page. You can find the set of validations at Model/Checkout/Validations.
  • Model/System/Message: Checking specific KCO settings and showing a message in the admin if there is a misconfiguration.
  • Model/KcoConfigProvider.php: The return values of the method getConfig() are used in the whole KCO JS workflow and define how KCO should behave on specific actions.
  • Model/QuoteRepository.php: Updating and getting back the Klarna KCO quote from the table klarna_kco_quote. You can find the migration for it at etc/db_schema.xml.
  • view/frontend/web/js: In this directory, you find all JS files to make KCO workable.

The whole logic for Klarna KP can be found here. The main items of it are:

  • Model/Api/Builder/Kasper.php: This class is responsible for creating the API request parameter.
  • Model/PaymentMethods: These classes are responsible for returning the correct payment method(s) which are shown on the checkout page.
  • Model/KpConfigProvider.php: The return values of the method getConfig() are used in the whole KP JS workflow and define how KP should behave on specific actions.
  • Model/QuoteRepository.php: Updating and getting back the Klarna KP quote from the table klarna_payments_quote. You can find the migration for it at etc/db_schema.xml.
  • Model/Session.php: With this class, you can create or update a Klarna session.
  • view/frontend/web/js: In this directory, you find all JS files to make KP workable.

With this module, KP orders can be placed with GraphQl. It's a small extension of module-payments. The entry point for its logic is at Model/Resolver/CreateKlarnaPaymentsSession.php. In this class, the Klarna session is initiated and the client token and payment methods are returned.

This module extends module-kco by adding the KSA functionality. Its logic will just run if KSA is enabled in the shop admin and also on the used MID. The key components of it are:

  • Model/Checkout/Update.php: The Klarna KSA table will be updated for different use cases.
  • Model/ShippingMethodGatewayRepository.php: Updating and getting back the Klarna KSS state of a KCO session from the table klarna_shipping_method_gateway. You can find the migration for it at etc/db_schema.xml.
  • Model/Validator.php: This class decides if KSA is used and not. Its logic has a big impact if there is a KCO flow without KSA or with KSA.

The purpose of this module is to save API requests and responses to the database and also return it. The information is stored in a separate Klarna table. The main items of it are:

  • Cron: Here you find cronjobs for cleaning old logging entries and updating the increment ID
  • Model/LogRepository.php: Updating and getting back the logging entries from the table klarna_logs. You can find the migration for it at etc/db_schema.xml.

The whole logic for Klarna OSM is located here. Since not so much logic for osm is needed, there is just 1 location which is important to know. It is about the classes in the Block directory. These classes decide if OSM is displayed on the respective pages (cart, product).

All logic that is generating the orderline items and calculating their values is located here. The most important parts of this module are:

  • Model/Calculator: Here you can find a set of calculation classes that are used to create the correct values like prices and taxes.
  • Model/Items: In this directory, you can find for each orderline item type a separate class that is responsible for its structure and content.

This module provides the whole logic for the support form which is available in the admin. The key components of it are:

  • Controller/Adminhtml/Index: Here you can find actions that are triggered when someone attached a file or clicked the “send” button.
  • Mail/Template/TransportBuilder.php: This is the key class when it comes to adding attachments and sending the mail.