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

# provide

export const parameters = "adyen-ideal";

This method allows you get a new instance of `KlarnaComponent`.

```typescript TYPESCRIPT theme={"dark"}
async provide(props: KlarnaManagerProps): Promise<KlarnaComponent>
```

## Parameters

<Expandable title="Parameters" defaultOpen>
  <ResponseField name="props" type="KlarnaManagerProps" required>
    Object that provides the payment menthod type and callback functions for
    handling steps, errors and validation.

    <Expandable title="Properties">
      <ResponseField name="primerSessionIntent" type="PrimerSessionIntent" required>
        Set the preferred session intent when showing paymentMethodType.

        <Expandable title="Properties">
          <ResponseField name="PrimerSessionIntent.CHECKOUT" />

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

      <ResponseField name="onStep" type={`(data: KlarnaPaymentStep) => void`}>
        Called whenever the component emits a new step. This usually happens when calling <a href={`#param-start`}>start</a> or <a href={`#param-submit`}>submit</a> or whenever the component collects data.

        <Expandable title="Parameters">
          <ResponseField name="PaymentSessionCreated">
            A type representing the created payment session.

            <Expandable title="Properties">
              <ResponseField name="stepName" type="paymentSessionCreated">
                The name of this component step.
              </ResponseField>

              <ResponseField name="paymentCategories" type="KlarnaPaymentCategory[]" required>
                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="boolean" 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 type that indicates that the payment view is loaded and ready to be
            displayed.

            <Expandable title="Properties">
              <ResponseField name="stepName" type="paymentViewLoaded">
                The name of this component step.
              </ResponseField>
            </Expandable>
          </ResponseField>

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

            <Expandable title="Properties">
              <ResponseField name="stepName" type="paymentSessionAuthorized">
                The name of this component step.
              </ResponseField>

              <ResponseField name="isFinalized" type="boolean" required>
                Represents the state of the finalization.
              </ResponseField>
            </Expandable>
          </ResponseField>

          <ResponseField name="PaymentSessionFinalized">
            A type representing the finalized payment session.

            <Expandable title="Properties">
              <ResponseField name="stepName" type="paymentSessionFinalized">
                The name of this component step.
              </ResponseField>
            </Expandable>
          </ResponseField>
        </Expandable>
      </ResponseField>

      This method will be called when an error occurs. It may return `PrimerCheckoutData` if the error occurs after the payment creation.

      <Note>
        Please note, that if you `override` this method, you *must* call the `errorHandler` to finalize the flow.
      </Note>

      <Expandable title="Properties">
        <ResponseField name="error" type="PrimerError" required>
          <Expandable title="Properties">
            <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>
          </Expandable>
        </ResponseField>

        <ResponseField name="checkoutData" type="PrimerCheckoutData">
          <Expandable title="Properties" defaultOpen>
            <ResponseField name="payment" type="IPrimerCheckoutDataPayment">
              <Expandable title="Properties">
                <ResponseField name="id" type="string">
                  Primer's unique identifier for the payment.
                </ResponseField>

                <ResponseField name="orderId" type="string">
                  Your order identifier as provided in the client session.
                </ResponseField>

                <ResponseField name="paymentFailureReason" type="PrimerPaymentErrorCode">
                  Can be either `payment-failed` which is an error from the PSP side, or `cancelled-by-customer` which means the failure initiated on the customer side. I.e. cancelling a 3DS flow.
                </ResponseField>
              </Expandable>
            </ResponseField>

            <ResponseField name="additionalInfo" type="object">
              Custom information, that depends on the payment method.

              <Expandable title="Variations">
                <ResponseField name="XenditCheckoutVoucherAdditionalInfo">
                  <Expandable title="Properties" defaultOpen>
                    <ResponseField name="expiresAt" type="String" required />

                    <ResponseField name="couponCode" type="String" required />

                    <ResponseField name="retailerName" type="String" required />
                  </Expandable>
                </ResponseField>

                <ResponseField name="PromptPayCheckoutAdditionalInfo">
                  <Expandable title="Properties" defaultOpen>
                    <ResponseField name="expiresAt" type="String" required />

                    <ResponseField name="qrCodeUrl" type="String?" />

                    <ResponseField name="qrCodeBase64" type="String" required />
                  </Expandable>
                </ResponseField>

                <ResponseField name="MultibancoCheckoutAdditionalInfo">
                  <Expandable title="Properties" defaultOpen>
                    <ResponseField name="expiresAt" type="String" required />

                    <ResponseField name="entity" type="String" required />

                    <ResponseField name="reference" type="String" required />
                  </Expandable>
                </ResponseField>
              </Expandable>
            </ResponseField>
          </Expandable>
        </ResponseField>

        <ResponseField name="handler" type="PrimerErrorHandler">
          <Expandable title="Methods">
            <ResponseField name="showErrorMessage(errorMessage: String | null)">
              Call with your custom error message.
            </ResponseField>
          </Expandable>
        </ResponseField>
      </Expandable>

      <ResponseField name="onInvalid" type={`(data: PrimerInvalidComponentData<KlarnaPaymentValidatableData>) => void`}>
        Called to indicate that the component data was considered invalid during validation.

        <Expandable title="Parameters">
          <ResponseField name={`PrimerInvalidComponentData<KlarnaPaymentValidatableData>`}>
            Interface that indicates that the data has been considered invalid after validation.

            <Expandable title="Properties">
              <ResponseField name="data" type="KlarnaPaymentValidatableData">
                The data that failed validation.

                <Expandable>
                  <ResponseField name="KlarnaPaymentOptions">
                    Interface representing Klarna payment options required for configuring [KlarnaComponent](#returns)

                    <Expandable title="Properties">
                      <ResponseField name="validatableDataName" type="klarnaPaymentOptions">
                        The name of this component-validatable data.
                      </ResponseField>

                      <ResponseField name="returnIntentUrl" type="string">
                        Url used by third-party Android 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="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="boolean" 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="KlarnaPaymentFinalization">
                    <Expandable title="Properties">
                      <ResponseField name="validatableDataName" type="klarnaPaymentFinalization">
                        The name of this component-validatable data.
                      </ResponseField>

                      <ResponseField name="name" type="finalizePayment" />
                    </Expandable>
                  </ResponseField>
                </Expandable>
              </ResponseField>

              <ResponseField name="errors" type="PrimerValidationError[]">
                A list of `PrimerValidationError` explaining why the data is considered invalid.

                <ResponseField name="PrimerValidationError[]">
                  <Expandable>
                    <ResponseField name="PrimerValidationError">
                      <Expandable title="Properties">
                        <ResponseField name="errorId" type="string">
                          A unique error identifier.
                        </ResponseField>

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

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

      <ResponseField name="onValid" type={`(data: PrimerValidComponentData<KlarnaPaymentValidatableData>) => void`}>
        Called to indicate that the component data was successfully validated.

        <Expandable title="Parameters">
          <ResponseField name={`PrimerValidComponentData<KlarnaPaymentValidatableData>`}>
            Interface that indicates that the data has been successfully validated.

            <Expandable title="Properties">
              <ResponseField name="data" type="KlarnaPaymentValidatableData">
                The successfully validated data.

                <Expandable>
                  <ResponseField name="KlarnaPaymentOptions">
                    Interface representing Klarna payment options required for configuring [KlarnaComponent](#returns)

                    <Expandable title="Properties">
                      <ResponseField name="validatableDataName" type="klarnaPaymentOptions">
                        The name of this component-validatable data.
                      </ResponseField>

                      <ResponseField name="returnIntentUrl" type="string">
                        Url used by third-party Android 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="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="boolean" 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="KlarnaPaymentFinalization">
                    <Expandable title="Properties">
                      <ResponseField name="validatableDataName" type="klarnaPaymentFinalization">
                        The name of this component-validatable data.
                      </ResponseField>

                      <ResponseField name="name" type="finalizePayment" />
                    </Expandable>
                  </ResponseField>
                </Expandable>
              </ResponseField>
            </Expandable>
          </ResponseField>
        </Expandable>
      </ResponseField>

      <ResponseField name="onValidating" type={`(data: PrimerValidatingComponentData<KlarnaPaymentValidatableData>) => void`}>
        Called to indicate that the component data is in the process of being validated.

        <Expandable title="Parameters">
          <ResponseField name={`PrimerValidatingComponentData<KlarnaPaymentValidatableData>`}>
            Interface that indicates that data is currently in the process of being validated.

            <Expandable title="Properties">
              <ResponseField name="data" type="KlarnaPaymentValidatableData">
                The data being validated.

                <Expandable>
                  <ResponseField name="KlarnaPaymentOptions">
                    Interface representing Klarna payment options required for configuring [KlarnaComponent](#returns)

                    <Expandable title="Properties">
                      <ResponseField name="validatableDataName" type="klarnaPaymentOptions">
                        The name of this component-validatable data.
                      </ResponseField>

                      <ResponseField name="returnIntentUrl" type="string">
                        Url used by third-party Android 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="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="boolean" 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="KlarnaPaymentFinalization">
                    <Expandable title="Properties">
                      <ResponseField name="validatableDataName" type="klarnaPaymentFinalization">
                        The name of this component-validatable data.
                      </ResponseField>

                      <ResponseField name="name" type="finalizePayment" />
                    </Expandable>
                  </ResponseField>
                </Expandable>
              </ResponseField>
            </Expandable>
          </ResponseField>
        </Expandable>
      </ResponseField>

      <ResponseField name="onValidationError" type={`(data: PrimerComponentDataValidationError<KlarnaPaymentValidatableData>) => void`}>
        Called to indicated an error that occurred during component data validation.

        <Expandable title="Parameters">
          <ResponseField name={`PrimerComponentDataValidationError<KlarnaPaymentValidatableData>`}>
            Interface that represents an error that occurred during the validation process.

            <Expandable title="Properties">
              <ResponseField name="data" type="KlarnaPaymentValidatableData">
                The data for which an error ocurred during validation.

                <Expandable>
                  <ResponseField name="KlarnaPaymentOptions">
                    Interface representing Klarna payment options required for configuring [KlarnaComponent](#returns)

                    <Expandable title="Properties">
                      <ResponseField name="validatableDataName" type="klarnaPaymentOptions">
                        The name of this component-validatable data.
                      </ResponseField>

                      <ResponseField name="returnIntentUrl" type="string">
                        Url used by third-party Android 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="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="boolean" 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="KlarnaPaymentFinalization">
                    <Expandable title="Properties">
                      <ResponseField name="validatableDataName" type="klarnaPaymentFinalization">
                        The name of this component-validatable data.
                      </ResponseField>

                      <ResponseField name="name" type="finalizePayment" />
                    </Expandable>
                  </ResponseField>
                </Expandable>
              </ResponseField>

              <ResponseField name="error" type="PrimerError">
                The `PrimerError` that ocurred during the validation attempt.

                <ResponseField name="PrimerError">
                  <Expandable title="Properties">
                    <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">
                      A unique diagnostics id for the given error.
                    </ResponseField>
                  </Expandable>
                </ResponseField>
              </ResponseField>
            </Expandable>
          </ResponseField>
        </Expandable>
      </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="handlePaymentOptionsChange(paymentOptions: KlarnaPaymentOptions)">
    Update component with options to use when initializing the Klarna payment view.

    To validate the collected data, you can refer to the appropriate
    [KlarnaManagerProps](#param-props)
    callback functions.

    <Expandable title="Parameters">
      <ResponseField name="KlarnaPaymentOptions">
        Interface representing Klarna payment options required for configuring [KlarnaComponent](#returns)

        <Expandable title="Properties">
          <ResponseField name="validatableDataName" type="klarnaPaymentOptions">
            The name of this component-validatable data.
          </ResponseField>

          <ResponseField name="returnIntentUrl" type="string">
            Url used by third-party Android 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="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="boolean" 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()">
    Finalize the payment.

    To validate the collected data, you can refer to the appropriate
    [KlarnaManagerProps](#param-props)
    callback functions.
  </ResponseField>

  <ResponseField name="cleanUp()">
    Tear down the Klarna component. Call this after a payment completes — or before initiating another — to support consecutive Klarna payments within the same app session.

    ```typescript TYPESCRIPT theme={"dark"}
    cleanUp(): Promise<void>
    ```
  </ResponseField>
</Expandable>

## Example

```typescript TYPESCRIPT theme={"dark"}
// 👇 Add this
const klarnaManagerProps: KlarnaManagerProps = {
  primerSessionIntent: PrimerSessionIntent.CHECKOUT,
  onStep: (data: KlarnaPaymentStep) => {
    // Show loading indicator, render categories or finalize payment.
    switch (data.stepName) {
      case "paymentSessionCreated":
        // Render categories
        break;

      case "paymentViewLoaded":
        // Render payment view
        break;

      case "paymentSessionAuthorized":
        if (data.isFinalized) {
          // Finalize payment
        }
        break;
      case "paymentSessionFinalized":
        // ...
        break;
    }
  },
  onError: (error: PrimerError) => {
    // An error that occurred during the component's operation.
  },
  onInvalid: (
    data: PrimerInvalidComponentData<KlarnaPaymentValidatableData>
  ) => {
    // Data was considered invalid during validation.
    switch (data.data.validatableDataName) {
      case "klarnaPaymentOptions":
        // ...
        break;
      case "klarnaPaymentFinalization":
        // ...
        break;
    }
  },
  onValid: (data: PrimerValidComponentData<KlarnaPaymentValidatableData>) => {
    // Data was successfully validated.
    switch (data.data.validatableDataName) {
      case "klarnaPaymentOptions":
        // ...
        break;
      case "klarnaPaymentFinalization":
        // ...
        break;
    }
  },
  onValidating: (
    data: PrimerValidatingComponentData<KlarnaPaymentValidatableData>
  ) => {
    // Data is in the process of being validated.
    switch (data.data.validatableDataName) {
      case "klarnaPaymentOptions":
        // ...
        break;
      case "klarnaPaymentFinalization":
        // ...
        break;
    }
  },
  onValidationError: (
    data: PrimerComponentDataValidationError<KlarnaPaymentValidatableData>
  ) => {
    // Error occurred during data validation.
    switch (data.data.validatableDataName) {
      case "klarnaPaymentOptions":
        // ...
        break;
      case "klarnaPaymentFinalization":
        // ...
        break;
    }
  },
};
const klarnaManager = new KlarnaManager();
const klarnaComponent: KlarnaComponent = await klarnaManager.provide(
  klarnaManagerProps
);
```

## Lifecycle

To run consecutive Klarna payments in the same app session, call `klarnaComponent.cleanUp()` after a payment completes — or before starting another one.

```typescript TYPESCRIPT theme={"dark"}
useEffect(() => {
  return () => {
    klarnaComponent
      ?.cleanUp()
      .catch((err) => console.warn("Klarna cleanUp failed", err));
  };
}, [klarnaComponent]);
```
