> ## 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

**Parameters**

**primerSessionIntent** `\<PrimerSessionIntent\>` *required*

Sets the session intent to be used during session creation and tokenization.

**.checkout**

Use `checkout` when you want go through the checkout flow

**.vault**

Use `vault` when you want to vault a payment method, so you can use the token to pay another time.

## Returns

An instance of `KlarnaComponent`.

**KlarnaComponent**

**Data** `KlarnaCollectableData`

The Data associated type

**enum KlarnaCollectableData**

**paymentCategory**

Enum member representing the payment category.

**Properties**

**paymentCategory** `\<KlarnaPaymentCategory\>`

Payment category required for session creation.

**KlarnaPaymentCategory**

**Properties**

**identifier** `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>

**name** `String` *required*

Name of the payment method category. These names are dynamic depending on what payment method is in the
category.

**descriptiveAssetUrl** `String` *required*

URL of the descriptive asset. Using this dynamic asset will make sure that changes from Klarna be automatically
propagated.

**standardAssetUrl** `String` *required*

URL of the stadard asset. Using this dynamic asset will make sure that changes from Klarna be automatically
propagated.

**clientToken** `\<String?\>`

The client token used for validation purpose.

**finalizePayment**

Enum member representing finalizing the Klarna payment.

**Step** `KlarnaStep`

The Step associated type

**enum KlarnaStep**

**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.

**Properties**

**clientToken** `\<String\>`

**paymentCategories** `Array \<KlarnaPaymentCategory?\>`

The list of available Klarna payment categories.

**KlarnaPaymentCategory**

**Properties**

**identifier** `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>

**name** `String` *required*

Name of the payment method category. These names are dynamic depending on what payment method is in the
category.

**descriptiveAssetUrl** `String` *required*

URL of the descriptive asset. Using this dynamic asset will make sure that changes from Klarna be automatically
propagated.

**standardAssetUrl** `String` *required*

URL of the stadard asset. Using this dynamic asset will make sure that changes from Klarna be automatically
propagated.

**viewInitialized**

Indicates that the Klarna view has been initialized. This is the first step in the Klarna view handling process.

**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.

**Properties**

**height** `\<CGFloat\>`

**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.

**Properties**

**view** `\<UIView?\>`

**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.

**Properties**

**authToken** `\<String\>`

**checkoutData** `\<PrimerCheckoutData?\>`

**paymentSessionFinalizationRequired**

Signals that the payment session requires finalization step in order to be completed.

**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.

**Properties**

**authToken** `\<String\>`

**checkoutData** `\<PrimerCheckoutData?\>`

**start**

Initialize the component by calling the start function. This method should be called only once.

**submit**

Call `submit` function in order to process collected data and move component to next state.

**errorDelegate** `PrimerHeadlessErrorableDelegate`

Error delegate will be triggered every time an error is thrown in the process.

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

**validationDelegate** `PrimerHeadlessValidatableDelegate`

Validation delegate will be triggered every time collected data is updated.

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

**PrimerValidationStatus** `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.

**enum PrimerValidationStatus**

**validating**

Enum case representing the ongoing validation state.
This indicates that the validation process is currently in progress.

**valid**

Enum case representing a successful validation state.
This indicates that the validation process has completed successfully and the data is valid.

**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.

**Associated Value**

**errors** `[PrimerValidationError]`

An array of `PrimerValidationError` representing the specific validation errors found.

**error**

Enum case representing an error state due to an unexpected issue.
This indicates that an unexpected error has occurred during the validation process.

**Associated Value**

**error** `PrimerError`

A `PrimerError` representing the unexpected error that occurred.

**stepDelegate** `PrimerHeadlessSteppableDelegate`

Whenever [start](#param-start) or [submit](#param-submit) methods are
called, `stepDelegate` will trigger the next step in case the call to the mentioned method was successful.

In the case of KLARNA, the steps will be of type `KlarnaStep`.

`KlarnaStep` is an enum holding different output data for specific steps.

**enum KlarnaStep**

**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.

**Properties**

**clientToken** `\<String\>`

**paymentCategories** `Array \<KlarnaPaymentCategory?\>`

The list of available Klarna payment categories.

**KlarnaPaymentCategory**

**Properties**

**identifier** `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>

**name** `String` *required*

Name of the payment method category. These names are dynamic depending on what payment method is in the
category.

**descriptiveAssetUrl** `String` *required*

URL of the descriptive asset. Using this dynamic asset will make sure that changes from Klarna be automatically
propagated.

**standardAssetUrl** `String` *required*

URL of the stadard asset. Using this dynamic asset will make sure that changes from Klarna be automatically
propagated.

**viewInitialized**

Indicates that the Klarna view has been initialized. This is the first step in the Klarna view handling process.

**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.

**Properties**

**height** `\<CGFloat\>`

**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.

**Properties**

**view** `\<UIView?\>`

**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.

**Properties**

**authToken** `\<String\>`

**checkoutData** `\<PrimerCheckoutData?\>`

**paymentSessionFinalizationRequired**

Signals that the payment session requires finalization step in order to be completed.

**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.

**Properties**

**authToken** `\<String\>`

**checkoutData** `\<PrimerCheckoutData?\>`

Example:

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

**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 [validationDelegate](#param-validation-delegate).

In case of KLARNA, the Data will be of type `KlarnaCollectableData`.

**enum KlarnaCollectableData**

**paymentCategory**

Enum member representing the payment category.

**Properties**

**paymentCategory** `\<KlarnaPaymentCategory\>`

Payment category required for session creation.

**KlarnaPaymentCategory**

**Properties**

**identifier** `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>

**name** `String` *required*

Name of the payment method category. These names are dynamic depending on what payment method is in the
category.

**descriptiveAssetUrl** `String` *required*

URL of the descriptive asset. Using this dynamic asset will make sure that changes from Klarna be automatically
propagated.

**standardAssetUrl** `String` *required*

URL of the stadard asset. Using this dynamic asset will make sure that changes from Klarna be automatically
propagated.

**clientToken** `\<String?\>`

The client token used for validation purpose.

**finalizePayment**

Enum member representing finalizing the Klarna payment.

Example:

```swift SWIFT theme={"dark"}
func updateCollectedData(collectableData: KlarnaCollectableData)
```

## Example

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


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.