> ## Documentation Index
> Fetch the complete documentation index at: https://primer.io/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# provideKlarnaComponent

This method allows you get an instance of `KlarnaComponent` to manage payments for Klarna.

```swift SWIFT theme={"dark"}
public func provideKlarnaComponent(with intent: PrimerSessionIntent) throws -> (any KlarnaComponent)? { }
```

## Parameters

<Expandable title="Parameters" defaultOpen>
  <ResponseField name="primerSessionIntent" type="<PrimerSessionIntent>" required>
    Sets the session intent to be used during session creation and tokenization.

    <Expandable defaultOpen>
      <ResponseField name=".checkout">
        Use `checkout` when you want go through the checkout flow
      </ResponseField>

      <ResponseField name=".vault">
        Use `vault` when you want to vault a payment method, so you can use the token to pay another time.
      </ResponseField>
    </Expandable>
  </ResponseField>
</Expandable>

## Returns

An instance of `KlarnaComponent`.

<Expandable title="KlarnaComponent" defaultOpen>
  <ResponseField name="Data" type="KlarnaCollectableData">
    The Data associated type

    <Expandable title="enum KlarnaCollectableData">
      <ResponseField name="paymentCategory">
        Enum member representing the payment category.

        <Expandable title="Properties" defaultOpen>
          <ResponseField name="paymentCategory" type="<KlarnaPaymentCategory>">
            Payment category required for session creation.

            <Expandable>
              <ResponseField name="KlarnaPaymentCategory">
                <Expandable title="Properties">
                  <ResponseField name="identifier" type="String" required>
                    ID of the payment method category to be used while loading the payment view. The possible values are:

                    <ul>
                      <li>klarna</li>
                      <li>pay\_later</li>
                      <li>pay\_now</li>
                      <li>pay\_over\_time</li>
                      <li>direct\_bank\_transfer</li>
                      <li>direct\_debit</li>
                    </ul>
                  </ResponseField>

                  <ResponseField name="name" type="String" required>
                    Name of the payment method category. These names are dynamic depending on what payment method is in the
                    category.
                  </ResponseField>

                  <ResponseField name="descriptiveAssetUrl" type="String" required>
                    URL of the descriptive asset. Using this dynamic asset will make sure that changes from Klarna be automatically
                    propagated.
                  </ResponseField>

                  <ResponseField name="standardAssetUrl" type="String" required>
                    URL of the stadard asset. Using this dynamic asset will make sure that changes from Klarna be automatically
                    propagated.
                  </ResponseField>
                </Expandable>
              </ResponseField>
            </Expandable>
          </ResponseField>

          <ResponseField name="clientToken" type="<String?>">
            The client token used for validation purpose.
          </ResponseField>
        </Expandable>
      </ResponseField>

      <ResponseField name="finalizePayment">
        Enum member representing finalizing the Klarna payment.
      </ResponseField>
    </Expandable>
  </ResponseField>

  <ResponseField name="Step" type="KlarnaStep">
    The Step associated type

    <Expandable title="enum KlarnaStep">
      <ResponseField name="paymentSessionCreated(clientToken: String, paymentCategories: [KlarnaPaymentCategory])">
        Indicates a successful creation of a payment session. It caries `clientToken` string, which is used for validation purposes and `paymentCategories` of type `KlarnaPaymentCategory`, representing the available payment options for the user.

        <Expandable title="Properties" defaultOpen>
          <ResponseField name="clientToken" type="<String>">
            {}
          </ResponseField>

          <ResponseField name="paymentCategories" type="Array <KlarnaPaymentCategory?>">
            The list of available Klarna payment categories.

            <Expandable>
              <ResponseField name="KlarnaPaymentCategory">
                <Expandable title="Properties">
                  <ResponseField name="identifier" type="String" required>
                    ID of the payment method category to be used while loading the payment view. The possible values are:

                    <ul>
                      <li>klarna</li>
                      <li>pay\_later</li>
                      <li>pay\_now</li>
                      <li>pay\_over\_time</li>
                      <li>direct\_bank\_transfer</li>
                      <li>direct\_debit</li>
                    </ul>
                  </ResponseField>

                  <ResponseField name="name" type="String" required>
                    Name of the payment method category. These names are dynamic depending on what payment method is in the
                    category.
                  </ResponseField>

                  <ResponseField name="descriptiveAssetUrl" type="String" required>
                    URL of the descriptive asset. Using this dynamic asset will make sure that changes from Klarna be automatically
                    propagated.
                  </ResponseField>

                  <ResponseField name="standardAssetUrl" type="String" required>
                    URL of the stadard asset. Using this dynamic asset will make sure that changes from Klarna be automatically
                    propagated.
                  </ResponseField>
                </Expandable>
              </ResponseField>
            </Expandable>
          </ResponseField>
        </Expandable>
      </ResponseField>

      <ResponseField name="viewInitialized">
        Indicates that the Klarna view has been initialized. This is the first step in the Klarna view handling process.
      </ResponseField>

      <ResponseField name="viewResized(height: CGFloat)">
        Represents a change in the view's height, which may occur when the Klarna view adjusts to display different content. The `height` parameter specifies the new height of the view.

        <Expandable title="Properties" defaultOpen>
          <ResponseField name="height" type="<CGFloat>">
            {}
          </ResponseField>
        </Expandable>
      </ResponseField>

      <ResponseField name="viewLoaded(view: UIView?)">
        Indicates that the Klarna view has finished loading its initial content and is ready for interaction. The `view` parameter represents the klarna view.

        <Expandable title="Properties" defaultOpen>
          <ResponseField name="view" type="<UIView?>">
            {}
          </ResponseField>
        </Expandable>
      </ResponseField>

      <ResponseField name="paymentSessionAuthorized(authToken: String, checkoutData: PrimerCheckoutData)">
        Indicates that the payment session has been successfully authorized. It carries an `authToken` string for subsequent operations that require authorization and `checkoutData` for showing the checkout results, after the merchant finishes the payment.

        <Expandable title="Properties" defaultOpen>
          <ResponseField name="authToken" type="<String>">
            {}
          </ResponseField>

          <ResponseField name="checkoutData" type="<PrimerCheckoutData?>">
            {}
          </ResponseField>
        </Expandable>
      </ResponseField>

      <ResponseField name="paymentSessionFinalizationRequired">
        Signals that the payment session requires finalization step in order to be completed.
      </ResponseField>

      <ResponseField name="paymentSessionFinalized(authToken: String, checkoutData: PrimerCheckoutData)">
        Indicates that the payment session has been finalized. It carries an `authToken` string for subsequent operations that require authorization and `checkoutData` for showing the checkout results, after the merchant finishes the payment.

        <Expandable title="Properties" defaultOpen>
          <ResponseField name="authToken" type="<String>">
            {}
          </ResponseField>

          <ResponseField name="checkoutData" type="<PrimerCheckoutData?>">
            {}
          </ResponseField>
        </Expandable>
      </ResponseField>
    </Expandable>
  </ResponseField>

  <ResponseField name="start">
    Initialize the component by calling the start function. This method should be called only once.
  </ResponseField>

  <ResponseField name="submit">
    Call `submit` function in order to process collected data and move component to next state.
  </ResponseField>

  <ResponseField name="errorDelegate" type="PrimerHeadlessErrorableDelegate">
    Error delegate will be triggered every time an error is thrown in the process.

    ```swift SWIFT theme={"dark"}
      func didReceiveError(error: PrimerError)
    ```
  </ResponseField>

  <ResponseField name="validationDelegate" type="PrimerHeadlessValidatableDelegate">
    Validation delegate will be triggered every time collected data is updated.

    ```swift SWIFT theme={"dark"}
      func didUpdate(validationStatus: PrimerValidationStatus, for data: PrimerCollectableData?)
    ```

    <ResponseField name="PrimerValidationStatus" type="Enum">
      `PrimerValidationStatus` is an enum that represents the different validation statuses in the Primer SDK. It helps to communicate the state of validation for a particular process, providing clear categorization of validation states.

      <Expandable title="enum PrimerValidationStatus" defaultOpen>
        <ResponseField name="validating">
          Enum case representing the ongoing validation state.
          This indicates that the validation process is currently in progress.
        </ResponseField>

        <ResponseField name="valid">
          Enum case representing a successful validation state.
          This indicates that the validation process has completed successfully and the data is valid.
        </ResponseField>

        <ResponseField name="invalid">
          Enum case representing an unsuccessful validation state due to validation errors.
          This indicates that the validation process has completed but has found one or more errors in the data.

          <Expandable title="Associated Value" defaultOpen>
            <ResponseField name="errors" type="[PrimerValidationError]">
              An array of `PrimerValidationError` representing the specific validation errors found.
            </ResponseField>
          </Expandable>
        </ResponseField>

        <ResponseField name="error">
          Enum case representing an error state due to an unexpected issue.
          This indicates that an unexpected error has occurred during the validation process.

          <Expandable title="Associated Value" defaultOpen>
            <ResponseField name="error" type="PrimerError">
              A `PrimerError` representing the unexpected error that occurred.
            </ResponseField>
          </Expandable>
        </ResponseField>
      </Expandable>
    </ResponseField>
  </ResponseField>

  <ResponseField name="stepDelegate" type="PrimerHeadlessSteppableDelegate">
    <p>
      Whenever <a href={`#param-start`}>start</a> or <a href={`#param-submit`}>submit</a> methods are
      called, <code>stepDelegate</code> will trigger the next step in case the call to the mentioned method was successful.
    </p>

    <p>
      In the case of KLARNA, the steps will be of type <code>KlarnaStep</code>.
    </p>

    <p>
      <code>KlarnaStep</code> is an enum holding different output data for specific steps.
    </p>

    <Expandable title="enum KlarnaStep">
      <ResponseField name="paymentSessionCreated(clientToken: String, paymentCategories: [KlarnaPaymentCategory])">
        Indicates a successful creation of a payment session. It caries `clientToken` string, which is used for validation purposes and `paymentCategories` of type `KlarnaPaymentCategory`, representing the available payment options for the user.

        <Expandable title="Properties" defaultOpen>
          <ResponseField name="clientToken" type="<String>">
            {}
          </ResponseField>

          <ResponseField name="paymentCategories" type="Array <KlarnaPaymentCategory?>">
            The list of available Klarna payment categories.

            <Expandable>
              <ResponseField name="KlarnaPaymentCategory">
                <Expandable title="Properties">
                  <ResponseField name="identifier" type="String" required>
                    ID of the payment method category to be used while loading the payment view. The possible values are:

                    <ul>
                      <li>klarna</li>
                      <li>pay\_later</li>
                      <li>pay\_now</li>
                      <li>pay\_over\_time</li>
                      <li>direct\_bank\_transfer</li>
                      <li>direct\_debit</li>
                    </ul>
                  </ResponseField>

                  <ResponseField name="name" type="String" required>
                    Name of the payment method category. These names are dynamic depending on what payment method is in the
                    category.
                  </ResponseField>

                  <ResponseField name="descriptiveAssetUrl" type="String" required>
                    URL of the descriptive asset. Using this dynamic asset will make sure that changes from Klarna be automatically
                    propagated.
                  </ResponseField>

                  <ResponseField name="standardAssetUrl" type="String" required>
                    URL of the stadard asset. Using this dynamic asset will make sure that changes from Klarna be automatically
                    propagated.
                  </ResponseField>
                </Expandable>
              </ResponseField>
            </Expandable>
          </ResponseField>
        </Expandable>
      </ResponseField>

      <ResponseField name="viewInitialized">
        Indicates that the Klarna view has been initialized. This is the first step in the Klarna view handling process.
      </ResponseField>

      <ResponseField name="viewResized(height: CGFloat)">
        Represents a change in the view's height, which may occur when the Klarna view adjusts to display different content. The `height` parameter specifies the new height of the view.

        <Expandable title="Properties" defaultOpen>
          <ResponseField name="height" type="<CGFloat>">
            {}
          </ResponseField>
        </Expandable>
      </ResponseField>

      <ResponseField name="viewLoaded(view: UIView?)">
        Indicates that the Klarna view has finished loading its initial content and is ready for interaction. The `view` parameter represents the klarna view.

        <Expandable title="Properties" defaultOpen>
          <ResponseField name="view" type="<UIView?>">
            {}
          </ResponseField>
        </Expandable>
      </ResponseField>

      <ResponseField name="paymentSessionAuthorized(authToken: String, checkoutData: PrimerCheckoutData)">
        Indicates that the payment session has been successfully authorized. It carries an `authToken` string for subsequent operations that require authorization and `checkoutData` for showing the checkout results, after the merchant finishes the payment.

        <Expandable title="Properties" defaultOpen>
          <ResponseField name="authToken" type="<String>">
            {}
          </ResponseField>

          <ResponseField name="checkoutData" type="<PrimerCheckoutData?>">
            {}
          </ResponseField>
        </Expandable>
      </ResponseField>

      <ResponseField name="paymentSessionFinalizationRequired">
        Signals that the payment session requires finalization step in order to be completed.
      </ResponseField>

      <ResponseField name="paymentSessionFinalized(authToken: String, checkoutData: PrimerCheckoutData)">
        Indicates that the payment session has been finalized. It carries an `authToken` string for subsequent operations that require authorization and `checkoutData` for showing the checkout results, after the merchant finishes the payment.

        <Expandable title="Properties" defaultOpen>
          <ResponseField name="authToken" type="<String>">
            {}
          </ResponseField>

          <ResponseField name="checkoutData" type="<PrimerCheckoutData?>">
            {}
          </ResponseField>
        </Expandable>
      </ResponseField>
    </Expandable>

    Example:

    ```swift SWIFT theme={"dark"}
      func didReceiveStep(step: KlarnaStep)
    ```
  </ResponseField>

  <ResponseField name="updateCollectedData(collectableData: KlarnaCollectableData)">
    Update component with collected data by passing an enum representing collectable data. This method can be called at any point, even if you have only partially collected data.
    To validate the partially collected data, you can refer to the <a href={`#param-validation-delegate`}>validationDelegate</a>.

    In case of KLARNA, the Data will be of type <code>KlarnaCollectableData</code>.

    <Expandable title="enum KlarnaCollectableData">
      <ResponseField name="paymentCategory">
        Enum member representing the payment category.

        <Expandable title="Properties" defaultOpen>
          <ResponseField name="paymentCategory" type="<KlarnaPaymentCategory>">
            Payment category required for session creation.

            <Expandable>
              <ResponseField name="KlarnaPaymentCategory">
                <Expandable title="Properties">
                  <ResponseField name="identifier" type="String" required>
                    ID of the payment method category to be used while loading the payment view. The possible values are:

                    <ul>
                      <li>klarna</li>
                      <li>pay\_later</li>
                      <li>pay\_now</li>
                      <li>pay\_over\_time</li>
                      <li>direct\_bank\_transfer</li>
                      <li>direct\_debit</li>
                    </ul>
                  </ResponseField>

                  <ResponseField name="name" type="String" required>
                    Name of the payment method category. These names are dynamic depending on what payment method is in the
                    category.
                  </ResponseField>

                  <ResponseField name="descriptiveAssetUrl" type="String" required>
                    URL of the descriptive asset. Using this dynamic asset will make sure that changes from Klarna be automatically
                    propagated.
                  </ResponseField>

                  <ResponseField name="standardAssetUrl" type="String" required>
                    URL of the stadard asset. Using this dynamic asset will make sure that changes from Klarna be automatically
                    propagated.
                  </ResponseField>
                </Expandable>
              </ResponseField>
            </Expandable>
          </ResponseField>

          <ResponseField name="clientToken" type="<String?>">
            The client token used for validation purpose.
          </ResponseField>
        </Expandable>
      </ResponseField>

      <ResponseField name="finalizePayment">
        Enum member representing finalizing the Klarna payment.
      </ResponseField>
    </Expandable>

    Example:

    ```swift SWIFT theme={"dark"}
    func updateCollectedData(collectableData: KlarnaCollectableData)
    ```
  </ResponseField>
</Expandable>

## Example

```swift SWIFT theme={"dark"}
do {
 manager = PrimerHeadlessUniversalCheckout.KlarnaManager()
 klarnaComponent = try manager.provideKlarnaComponent(with: sessionIntent)
} catch {
 // Catch errors here
}
```
