Klarna Docs - Components of the Klarna extension

Components of the Klarna extension

The Klarna extension consists of smaller building blocks called modules. Read this article to learn more about the modules.

The diagram below shows how the individual modules of the Klarna extension depend on each other:

A diagram showing

Modules within the Klarna Adobe Commerce extension.

The backend module sends the Order management API requests to Klarna. This includes all post-order captures, refunds, and cancellations. The starting entry points for each of these actions can be found in Gateway/Command. If the API request to Klarna returns a successful response, the order in Adobe Commerce will be handled in the same way. For example, if the order was successfully canceled in Klarna, it will then be canceled in the shop as well.

The backend module has dependencies with the following Klarna modules:

  • logger
  • base

In the base module, you can find the basic helper and settings which are used by other Klarna modules. The key components of the base module are:

  • Model/Api consists of a set of classes for creating the request parameter.
  • Model/System/Message is responsible for checking specific Klarna settings and showing a message in the Admin if there’s a misconfiguration.
  • Model/OrderRepository.php updates and retrieves Klarna orders from the klarna_core_order table. You can find the migration for it in etc/db_schema.xml.

The base module has dependencies with the following Klarna modules:

  • logger
  • backend
  • kss
  • orderlines
  • payments
  • payments-graph-ql

The kco module contains all the logic that makes Klarna checkout work. The key components of the kco module are:

  • Controller/Api is the entry point of all our callback URLs.
  • Controller/Klarna comprises 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 is a class responsible for creating the API request parameter.
  • Model/Checkout/Validation.php is a class called in the order validation callback. Depending on the callback’s result, the customer is redirected to the confirmation controller or back to a specific error message pointing to a different page, for example, the cart page. You can find the set of validations in Model/Checkout/Validations.
  • Model/System/Message checks specific Klarna checkout settings and shows a message in the Admin if there’s a misconfiguration.
  • Model/KcoConfigProvider.php: The return values of the getConfig() method are used in the whole Klarna checkout JavaScript flow and define how Klarna checkout behaves after specific actions.
  • Model/QuoteRepository.php updates and returns the Klarna checkout quote from the klarna_kco_quote table. You can find the migration for it in etc/db_schema.xml.
  • view/frontend/web/js contains all JavaScript files that fuel Klarna checkout.

The kco module has dependencies with the following Klarna modules:

  • kss 
  • logger
  • base
  • orderlines

The kss module extends the kco module by adding the Shipping assistant functionality. Its logic will run if Shipping assistant is enabled in the Admin and also for the active Merchant ID (MID). The key components of the kss module are:

  • Model/Checkout/Update.php handles updating the Shipping assistant table for different use cases.
  • Model/ShippingMethodGatewayRepository.php updates returns the Shipping assistant state of a Klarna checkout session from the klarna_shipping_method_gateway table. You can find the migration for it in etc/db_schema.xml.
  • Model/Validator.php is a class that controls if Shipping assistant is used or not. Its logic controls whether Shipping assistant is part of a Klarna checkout flow.

The kss module has dependencies with the following Klarna modules:

  • kco
  • orderlines
  • base

The purpose of the logger module is to save API requests and responses to the database and return them if needed. The information is stored in a separate Klarna table. The key components of the logger module are:

  • Cron contains cron jobs for cleaning old logging entries and updating the increment ID
  • Model/LogRepository.php updates and returns the logging entries from the klarna_logs table. You can find the migration for it in etc/db_schema.xml.

The logger module has dependencies with the following Klarna modules:

  • backend
  • base
  • kco
  • payments

The osm module contains all of the logic for Klarna On-site messaging (OSM). The OSM logic isn’t complex. The most important information about the module is the classes in the Block directory. These classes determine if OSM is displayed on specific pages, for example, product and cart pages. Refer to these classes if you want to modify how the messaging is displayed, or to understand how OSM works.

The orderlines module contains all logic to generate the order line items and calculate their value. The key components of the orderlines module are:

  • Model/Calculator contains a set of calculation classes that are used to create the correct values like prices and taxes.
  • Model/Items contains a class for each order line item type that is responsible for the order line item’s structure and content.

The orderlines module has dependencies with the following Klarna modules:

  • base
  • kco
  • kss

The payments module contains all the logic that makes Klarna payments work. The key components of the payments module are:

  • Model\Api\Builder\Request.php is a class responsible for creating the API request parameter.
  • Model/PaymentMethods classes are responsible for returning the correct payment methods shown on the checkout page.
  • Model/KpConfigProvider.php: the return values of the getConfig() method are used in the whole Klarna payments JavaScript flow and define how Checkout behaves after specific actions.
  • Model/QuoteRepository.php updates and returns the Klarna payments quote from the klarna_payments_quote table. You can find the migration for it in etc/db_schema.xml.
  • Model/Session.php is a class that allows you to create or update a payment session.
  • view/frontend/web/js contains all JavaScript files that fuel Klarna payments.

The payments module has dependencies with the following Klarna modules:

  • logger
  • base
  • payments-graph-ql

The payments-graph-ql module is an extension of the payments module and enables placing Klarna with GraphQL. The entry point for its logic is stored in Model/Resolver/CreateKlarnaPaymentsSession.php. In this class, a Klarna session is initiated and the client token and payment methods are returned.

The payments-graph-ql module has dependencies with the following Klarna modules:

  • base
  • payments

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

  • Controller/Adminhtml/Index contains actions that are triggered when a user attaches a file or clicks the Send button.
  • Mail/Template/TransportBuilder.php is the key class when it comes to adding attachments and sending the mail.