Klarna Docs - Order Management
Order Management

This guide explains how to install and configure the Klarna Order Management (OMS) app for Salesforce Order Management (SFOMS). Merchants can access required adapters and code directly from the Klarna GitHub repository, where the open-source code is available for deployment into the SFOMS environment like any other customization.

The Klarna Order Management (OMS) App enables you to integrate Klarna’s payment services This documentation is designed for developers who will download, customize, and promote the code to production as part of their development lifecycle. It provides template flows and code samples that developers can use to integrate Klarna's payment adapters and 'invocable' code components. The integration options are designed to support efficient orchestration within Salesforce flows, helping developers decide on the most effective integration strategy.

To use the Klarna OMS app with SFOMS, ensure the following are in place:

  1. Klarna SFCC cartridge installed – The cartridge should already be configured in your environment.
  2. Salesforce OMS implemented – Orders should already be flowing into SFOMS. For more details, refer to the Salesforce Order Management Implementation Guide.
  3. Additional setup stepsEnable the OMS flag in SFCC to enable the cartridge to work with SFOMS: Log in to B2C Commerce Business Manager. Go to Administration > Site Preferences > Custom Preferences > Klarna_Payments. Set Enable OMS to true and click Save.

Once these prerequisites are complete, you’re ready to proceed with the Klarna OMS App setup and configuration.

To get started with Klarna's Salesforce Commerce Cloud (SFCC) Order Management integration, download the required app from Klarna's GitHub repository. This repository contains all necessary files and documentation to facilitate seamless integration.

Follow these steps to set up the Klarna app in Salesforce Order Management (SFOMS):

  1. Create a Named Credential: In Salesforce Setup, navigate to Named Credentials, click New, and configure it with the Klarna Playground URL, setting Identity Type to Named Principal and Authentication Protocol to Password Authentication. Use the Klarna Playground credentials as the username and password.
  2. Create a Payment Gateway Provider: Add a new payment gateway provider with a label, name, and the Apex adapter set to KLA_KlarnaAdapter. Ensure the Idempotency Supported flag is enabled.
  3. Create a Payment Gateway: Define the gateway name, link it to the payment gateway provider created earlier, and assign the Named Credential. Add the external reference by copying the Klarna Payments ID from B2C Commerce Business Manager under Merchant Tools > Ordering > Payment Methods.
  4. Update the Permission Set: Adjust permissions for the Order Management B2C Service permission set by enabling Read and Write access for kpOrderID and lineItemJSON fields under Orders, Order Summaries, Order Products, and Order Product Summaries in Object Settings.
  5. Deactivate and Reactivate the B2C Commerce Connection: Disable the B2C Commerce Connection in Order Management, log out for 5–10 minutes, then log back in and re-enable the connection.

SFOMS integrates with Salesforce Flow, providing templates to streamline common processes like order creation, fulfillment, and servicing. Some templates may require a Starter or Growth license. The available templates include:

  1. Create Fulfillment Orders. This flow supports fulfilling customer orders by capturing essential order details, including items to be shipped, shipping information, and inventory status.
  2. Cancel Item Flow. Allows you to cancel individual order items before they are fulfilled.
  3. Cancel Order Flow. Enables cancellation of an entire order prior to fulfillment.
  4. Return Item Flow. Processes a blind return on an order post-fulfillment, allowing customers to receive a refund without returning the item.

For more details on configuring Order Management flows, refer to the Salesforce Order Management Flow Configuration Guide.

This repository includes code for a Klarna payment adapter that can be deployed in your SFOMS Sandbox environment. Once integrated, this adapter can be orchestrated within your flows as needed.

  • KLA_KlarnaAdapter Class:
    The KLA_KlarnaAdapter class manages payment captures and refunds within the flow orchestrations. You can locate it at force-app/main/default/classes/KLA_KlarnaAdapter.cls.
  • Test Class:
    The corresponding test class, KLA_KlarnaAdapter_Test, is available at force-app/main/default/classes/KLA_KlarnaAdapter_Test.cls. This is a template class that can be adapted to meet specific requirements.

For more information on payment adapter configuration, refer to the Salesforce Developer documentation.

In addition to the Payment Adapter Class, the Klarna SFOMS package includes custom Invocable Actions that allow merchants to control key order management functions, such as updating orders or canceling transactions, directly within flows. The following recipes illustrate how these invocable actions can be integrated into your existing flows:

  • KLA__OrderUpdateAmount_Invocable: This action is used to modify the order amount and order lines within an existing flow. Pass the Order Summary ID as the input. The class can be found at force-app/main/default/classes/KLA_OrderUpdateAmount_Invocable.cls. The associated test class is KLA_Coverage_Test.cls.
  • KLA__OrderCancellation_Invocable: This action is used to cancel orders and order items within a flow. Similar to the update action, it requires the Order Summary ID as input. This class is located at force-app/main/default/classes/KLA_OrderCancellation_Invocable.cls, with the corresponding test class also in KLA_Coverage_Test.cls.
  • Klarna Cancel Order Subflow: Integrates order cancellations into existing flows without disrupting workflows.
  • Klarna Release Remaining Authorization Flow: Automates the release of unused payment authorizations.

For implementation, reference the classes and test files in the repository as templates for customization.

  1. Clone the Klarna GitHub repository to your local environment.
  2. Authorize your sandbox org using Salesforce CLI: sf org login web --alias sandboxOrg --instance-url https://test.salesforce.com
  3. Deploy the force-app folder to the sandbox: sf project deploy start --source-dir force-app --target-org sandboxOrg
  4. Verify that all components are successfully deployed in the Salesforce UI or CLI output.

  1. Test the code and configurations in the sandbox environment.
  2. Use your preferred method to deploy to production: create and deploy a change set or use the Salesforce CLI: sf project deploy start --source-dir force-app --target-org prodOrg
  3. Confirm that the deployment is successful in production and all features are functioning as expected.