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

export const collectableData = "KlarnaPaymentCollectableData";

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

```kotlin KOTLIN theme={"dark"}
fun provideKlarnaComponent(primerSessionIntent: PrimerSessionIntent): 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 title="Properties">
      <ResponseField name="PrimerSessionIntent.CHECKOUT">
        {}
      </ResponseField>

      <ResponseField name="PrimerSessionIntent.VAULT">
        {}
      </ResponseField>
    </Expandable>
  </ResponseField>
</Expandable>

## Returns

An instance of `KlarnaComponent`.

<Expandable title="KlarnaComponent" defaultOpen>
  <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="componentError: Flow<PrimerError>">
    Get a [Flow](https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/)
    of [PrimerError](/sdk/android/v2.x.x/common-objects/PrimerError) objects that represent errors emitted by this component.
    Subscribers can observe and handle errors using this Flow.
  </ResponseField>

  <ResponseField name="updateCollectedData(collectableData: KlarnaPaymentCollectableData)">
    Update component with collected data by passing implementations of sealed interface.
    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
    [componentValidationStatus](#component-validation-status-flow-primer-validation-status-klarna-payment-collectable-data)
    and receive the validation status when it's updated.

    <Expandable title="sealed interface KlarnaPaymentCollectableData">
      <ResponseField name="PaymentOptions">
        A data class representing the step of choosing a Klarna Payment method.

        <Expandable title="Properties" defaultOpen>
          <ResponseField name="context" type="Context">
            Context required for the creation of the payment view.
          </ResponseField>

          <ResponseField name="returnIntentUrl" type="String">
            Url used by third-party apps to build the intent for returning to the app.
          </ResponseField>

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

            <Expandable title="Properties">
              <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="FinalizePayment">
        Object representing the step of finalizing the Klarna payment.
      </ResponseField>
    </Expandable>
  </ResponseField>

  <ResponseField name="componentStep: Flow<KlarnaPaymentStep>">
    <p>
      <code>KlarnaPaymentStep</code> is a class holding different output data for specific steps. Whenever{' '}
      <a href={`#param-start`}>start</a> or <a href={`#param-submit`}>submit</a> methods are
      called, <code>componentStep</code> will trigger the next step in case the call to the mentioned method was successful.
    </p>

    <Expandable title="sealed interface KlarnaPaymentStep">
      <ResponseField name="PaymentSessionCreated">
        A data class representing the created payment session.

        <Expandable title="Properties" defaultOpen>
          <ResponseField name="paymentCategories" type="List<KlarnaPaymentCategory>">
            The list of available Klarna payment categories.

            <Expandable title="Properties">
              <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="PaymentViewLoaded">
        A data class holding the Klarna payment view.

        <Expandable title="Properties" defaultOpen>
          <ResponseField name="paymentView" type="PrimerKlarnaPaymentView">
            The Klarna payment view.
          </ResponseField>
        </Expandable>
      </ResponseField>

      <ResponseField name="PaymentSessionAuthorized">
        A data class representing the authorized payment session.

        <Expandable title="Properties" defaultOpen>
          <ResponseField name="isFinalized" type="Boolean">
            The state of the finalization.
          </ResponseField>
        </Expandable>
      </ResponseField>

      <ResponseField name="PaymentSessionFinalized">
        Object representing the finalized payment session.
      </ResponseField>
    </Expandable>
  </ResponseField>

  <ResponseField name={`componentValidationStatus: Flow<PrimerValidationStatus<${collectableData}>>`}>
    The `PrimerValidationStatus` interface encompasses a range of validation statuses.

    <Expandable title="sealed interface PrimerValidationStatus">
      <ResponseField name={`Validating<${collectableData}>`}>
        Indicates that data is currently in the process of being validated.

        <Expandable title="Properties" defaultOpen>
          <ResponseField name="collectableData" type={`${collectableData}`}>
            The data being validated.
          </ResponseField>
        </Expandable>
      </ResponseField>

      <ResponseField name={`Valid<${collectableData}>`}>
        Indicates that the data has successfully been validated.

        <Expandable title="Properties" defaultOpen>
          <ResponseField name="collectableData" type={`${collectableData}`}>
            The successfully validated data.
          </ResponseField>
        </Expandable>
      </ResponseField>

      <ResponseField name={`Invalid<${collectableData}>`}>
        Indicates that the data has been considered invalid after validation.

        <Expandable title="Properties" defaultOpen>
          <ResponseField name="validationErrors" type="List<PrimerValidationError>">
            List of `PrimerValidationError` objects that represent data validation errors emitted by this component.

            <Expandable title="PrimerValidationError">
              <ResponseField name="List<PrimerValidationError>">
                <Expandable title="Type">
                  <ResponseField name="PrimerValidationError">
                    <Expandable title="Properties">
                      <ResponseField name="errorId" type="String" required>
                        A unique error identifier.
                      </ResponseField>

                      <ResponseField name="description" type="String" required>
                        A error description.
                      </ResponseField>

                      <ResponseField name="diagnosticsId" type="String" required>
                        A unique diagnostics id for the given error.
                      </ResponseField>
                    </Expandable>
                  </ResponseField>
                </Expandable>
              </ResponseField>
            </Expandable>
          </ResponseField>

          <ResponseField name="collectableData" type={`${collectableData}`}>
            The data that failed validation.
          </ResponseField>
        </Expandable>
      </ResponseField>

      <ResponseField name={`Error<${collectableData}>`}>
        Represents the status when an error occurred during the validation process.

        <Expandable title="Properties" defaultOpen>
          <ResponseField name="error" type="PrimerError">
            The specific `PrimerError` that occurred during validation.

            <Expandable title="PrimerValidationError">
              <ResponseField name="errorId" type="String" required>
                A unique error identifier.
              </ResponseField>

              <ResponseField name="errorCode" type="String?">
                A unique error code.
              </ResponseField>

              <ResponseField name="description" type="String" required>
                A error description.
              </ResponseField>

              <ResponseField name="recoverySuggestion" type="String?">
                A recovery suggestion for the given error. In case it's present, use it to try
                to recover from error.
              </ResponseField>

              <ResponseField name="diagnosticsId" type="String" required>
                A unique diagnostics id for the given error.
              </ResponseField>
            </Expandable>
          </ResponseField>

          <ResponseField name="collectableData" type={`${collectableData}`}>
            The data for which the error occurred.
          </ResponseField>
        </Expandable>
      </ResponseField>
    </Expandable>
  </ResponseField>
</Expandable>

## Example

```kotlin KOTLIN theme={"dark"}
class CheckoutActivity : AppCompatActivity() {
  // 👇 Add this
  private val klarnaComponent by lazy {
	PrimerHeadlessUniversalCheckoutKlarnaManager(viewModelStoreOwner = this)
            .provideKlarnaComponent(primerSessionIntent = PrimerSessionIntent.CHECKOUT)
  }
}
```
