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

# createPaymentMethodManager

```ts TS theme={"dark"}
createPaymentMethodManager(
  type: string
): Promise<
  | ICardPaymentMethodManager
  | INativePaymentMethodManager
  | IRedirectPaymentMethodManager
  | IKlarnaPaymentMethodManager
  | IAchPaymentMethodManager
  | null
>
```

There are five types of manager that can be returned by this function,
depending on the `type` provided as first argument:
[Card](#card), [Native](#native), [Redirect](#redirect), [Klarna Payment Method](#klarna) and [ACH](#ach).

In case the type specified is not supported, the function will return `null` instead.

## Card

```ts TS theme={"dark"}
createPaymentMethodManager(
	type: "PAYMENT_CARD",
	options?: PaymentMethodManagerOptions
): Promise<ICardPaymentMethodManager | null>
```

Create an instance of the `ICardPaymentMethodManager`, which can be used to manage credit card payments.

### Parameters

**Parameters**

**type** `"PAYMENT_CARD"`

When it matches this type, a manager for card payment methods will be
returned.

**options** `object`

Options to configure the payment method manager.

**Properties**

**onCardMetadataChange** `(metadata: CardMetadata) =\> void`

Called when the card metadata changes. Takes a `CardMetadata` object as its argument.

**CardMetadata**

**type** `CardNetwork | null` *deprecated*

*Deprecated: Use [onCardNetworksChange](#param-on-card-networks-change) instead*

Allowed card networks for credit card payments, one of
[CardNetwork](https://primer.io/docs/sdk/web/v2.x.x/constants/card-networks.md).

**possibleTypes** `CardNetwork[]` *deprecated*

*Deprecated: Use [onCardNetworksChange](#param-on-card-networks-change) instead*

An array of [CardNetwork](https://primer.io/docs/sdk/web/v2.x.x/constants/card-networks.md). Reduces to one or zero elements as more digits on the card number are input.

**cvvLength** `number`

Usually 3 digits, but can sometimes be 4.

**cardNumberLength** `number`

Represents the length of the card number for the given card type.

**onBinDataAvailable** `(event: BinDataAvailableEvent) =\> void`

Called when Headless Checkout detects BIN data from the card number entered by the user. This callback provides detailed information about the card including issuer details and card attributes.

Makes available an `event` of type `BinDataAvailableEvent`.

**BinDataAvailableEvent**

**preferred** `BinDataDetails | undefined`

The recommended card network to use, based on the order specified in `orderedAllowedCardNetworks`.

If no network is allowed, `undefined`.

**BinDataDetails**

**displayName** `string` *required*

A human readable name for the card network.

**network** `string` *required*

A value that represents the card network in Primer's systems.

**allowed** `boolean` *required*

Whether or not the card network is allowed, according to `orderedAllowedCardNetworks` passed in the Client Session.

**issuerCountryCode** `string`

The ISO 3166-1 alpha-2 country code of the card issuer.

**issuerName** `string`

The name of the card issuer (e.g., bank name).

**accountFundingType** `string`

The type of account funding (e.g., "CREDIT", "DEBIT", "PREPAID").

**prepaidReloadableIndicator** `string`

Indicates whether a prepaid card is reloadable.

**productUsageType** `string`

The usage type of the card product (e.g., "CONSUMER", "BUSINESS", "GOVERNMENT").

**productCode** `string`

The product code assigned by the card network.

**productName** `string`

The product name assigned by the card network (e.g., "Visa Signature").

**issuerCurrencyCode** `string`

The ISO 4217 currency code associated with the card issuer.

**regionalRestriction** `string`

Regional restrictions that apply to the card.

**accountNumberType** `string`

The type of account number (e.g., "PAN", "TOKEN").

**alternatives** `BinDataDetails[]`

All the detected card networks, including the ones that are not allowed. For co-badged cards, this array contains multiple networks.

To get the list of selectable networks for co-badged cards, use:

`[preferred, ...alternatives].filter(n => n.allowed)`

**BinDataDetails**

**displayName** `string` *required*

A human readable name for the card network.

**network** `string` *required*

A value that represents the card network in Primer's systems.

**allowed** `boolean` *required*

Whether or not the card network is allowed, according to `orderedAllowedCardNetworks` passed in the Client Session.

**issuerCountryCode** `string`

The ISO 3166-1 alpha-2 country code of the card issuer.

**issuerName** `string`

The name of the card issuer (e.g., bank name).

**accountFundingType** `string`

The type of account funding (e.g., "CREDIT", "DEBIT", "PREPAID").

**prepaidReloadableIndicator** `string`

Indicates whether a prepaid card is reloadable.

**productUsageType** `string`

The usage type of the card product (e.g., "CONSUMER", "BUSINESS", "GOVERNMENT").

**productCode** `string`

The product code assigned by the card network.

**productName** `string`

The product name assigned by the card network (e.g., "Visa Signature").

**issuerCurrencyCode** `string`

The ISO 4217 currency code associated with the card issuer.

**regionalRestriction** `string`

Regional restrictions that apply to the card.

**accountNumberType** `string`

The type of account number (e.g., "PAN", "TOKEN").

**status** `'complete' | 'partial'`

The status of the BIN data retrieval.

**Values**

**complete**

This happens when 8 digits or more are entered in the card number field.

Headless Checkout retrieved the BIN data using Primer's BIN data service. This provides the most accurate information including issuer details.

**partial**

This happens when less than 8 digits are entered in the card number field, or when Headless Checkout fails to contact Primer's BIN data service.

Headless Checkout retrieved the card networks using static information bundled with the SDK. This information can only identify international card networks and does not include issuer details.

**firstDigits** `string | undefined`

The first digits (BIN prefix) of the card number, when available.

**onBinDataLoadingChange** `(loading: boolean) =\> void`

Called when BIN data is being fetched from Primer's servers. Use this to show a loading indicator while card network and issuer information is being retrieved.

Makes available a `loading` parameter of type `boolean`.

* `true` when BIN data retrieval starts
* `false` when BIN data retrieval completes (followed by an `onBinDataAvailable` callback)

**onCardNetworksChange** `(event: CardNetworkChangeEvent) =\> void` *deprecated*

> [!WARNING]
>
> **Deprecated:** This callback is deprecated. Use [`onBinDataAvailable`](#card.parameters.options-properties.onBinDataAvailable) instead, which provides richer BIN data including issuer information and card attributes.

Called when Headless Checkout detects new card networks from the card number entered by the user.

Makes available an `event` of type `CardNetworkChangeEvent`.

**CardNetworkChangeEvent**

**detectedCardNetworks** `CardNetworks`

All the detected card networks, including the ones that are not allowed.

Use the following snippet to get the card network that should be presented to the user:

`detectedCardNetworks.preferred ?? detectedCardNetworks.items[0]`

**CardNetworks**

**items** `CardNetworkDetails[]`

An array of the card networks.

**CardNetworkDetails**

**allowed** `boolean`

Whether or not the card network is allowed, according to `orderedAllowedCardNetworks` passed in the Client Session.

**displayName** `string`

A human readable name for the card network.

**network** `string`

A value that represents the card network in Primer's systems.

**preferred** `CardNetworkDetails | undefined`

The first allowed card network in `items`.
In case no network is allowed, `undefined`.

**CardNetworkDetails**

**allowed** `boolean`

Whether or not the card network is allowed, according to `orderedAllowedCardNetworks` passed in the Client Session.

**displayName** `string`

A human readable name for the card network.

**network** `string`

A value that represents the card network in Primer's systems.

**selectableCardNetworks** `CardNetworks | undefined`

In case the card has zero or only one network that is allowed, `undefined`. Otherwise, all the allowed cards.

Use this to show the card networks the user can choose from in the case of a co-badged cards.

**CardNetworks**

**items** `CardNetworkDetails[]`

An array of the card networks.

**CardNetworkDetails**

**allowed** `boolean`

Whether or not the card network is allowed, according to `orderedAllowedCardNetworks` passed in the Client Session.

**displayName** `string`

A human readable name for the card network.

**network** `string`

A value that represents the card network in Primer's systems.

**preferred** `CardNetworkDetails | undefined`

The first allowed card network in `items`.
In case no network is allowed, `undefined`.

**CardNetworkDetails**

**allowed** `boolean`

Whether or not the card network is allowed, according to `orderedAllowedCardNetworks` passed in the Client Session.

**displayName** `string`

A human readable name for the card network.

**network** `string`

A value that represents the card network in Primer's systems.

**source** `'REMOTE' | 'LOCAL' | 'LOCAL_FALLBACK'`

The source of the information.

**Values**

**LOCAL**

This happens when less than 8 digits are entered in the cardnumber field.

Headless Checkout retrieved the card networks using static information bundled with the SDK. This information can only identify international cards.

**REMOTE**

This happens when 8 digits or more are entered in the cardnumber field.

Headless Checkout retrieved the card networks using Primer's BIN data.

**LOCAL\_FALLBACK**

This happens when Headless Checkout fails to contact Primer's BIN data.

Falls back to the static information bundled with the SDK (see `LOCAL`).

**onCardNetworksLoading** `() =\> void` *deprecated*

> [!WARNING]
>
> **Deprecated:** This callback is deprecated. Use [`onBinDataLoadingChange`](#card.parameters.options-properties.onBinDataLoadingChange) instead.

Called when card network information is being fetched from Primer's servers.
Will only trigger when `event.source === 'REMOTE'` in `onCardNetworksChange`.

### Returns

**Promise\<ICardPaymentMethodManager | null>**

**Promise\<ICardPaymentMethodManager | null>**

A promise that resolves to an instance of `ICardPaymentMethodManager` or `null`.

**ICardPaymentMethodManager**

**createHostedInputs** `() =\> HostedInputs`

Create an object with three hosted inputs: `cardNumberInput`, `expiryInput`, and `cvvInput`.

**HostedInputs**

**cardNumberInput** `IHeadlessHostedInput`

The headless hosted input for the card number.

See [HeadlessHostedInput](https://primer.io/docs/sdk/web/v2.x.x/primer-headless-checkout/types/HeadlessHostedInput.md).

**expiryInput** `IHeadlessHostedInput`

The headless hosted input for the expiry date.

See [HeadlessHostedInput](https://primer.io/docs/sdk/web/v2.x.x/primer-headless-checkout/types/HeadlessHostedInput.md).

**cvvInput** `IHeadlessHostedInput`

The headless hosted input for the CVV.

See [HeadlessHostedInput](https://primer.io/docs/sdk/web/v2.x.x/primer-headless-checkout/types/HeadlessHostedInput.md).

**setCardholderName** `(cardholderName: string) =\> void`

Set the name of the cardholder.

**removeHostedInputs** `() =\> void`

Remove the hosted inputs.

**submit** `() =\> Promise\<void\>`

Create a payment method based on the current values after tokenization.
Returns a Promise that resolves when the payment has been created.

**validate** `() =\> Promise\<Validation\>`

Validate the state of the payment method. Returns a Promise that resolves
with a Validation object.

**Validation**

**valid** `boolean` *required*

Indicates whether the validation was successful or not.

**validationErrors** `InputValidationError[]` *required*

An array of objects containing information about any input validation errors that occurred during the validation
process.

**InputValidationError**

**name** `string` *required*

The name of the input field that produced the error.

**error** `string` *required*

The type of error that occurred.

Possible values:

* `cardNameRequired`: cardholder's name is not provided.
* `cardNameContainsNumbers`: cardholder's name contains numbers.
* `cardNameLength`: cardholder's name does not match the expected length (minimum: 2, maximum: 45 characters).
* `cardNameContainsInvalidCharacters`: cardholder's name contains characters that are not supported (only Latin characters are allowed).
* `cardRequired`: card number is not provided.
* `unsupportedCardType`: provided card number does not match the allowed card networks.
* `cardIncomplete`: provided card number does not match the expected length.
* `cardInvalid`: provided card number is invalid. Additional details might be available in the `message` field.
* `cvvRequired`: card's security code (CVV) is not provided.
* `cvvIncomplete`: card's security code (CVV) does not match the expected length (minimum: 3 characters).
* `cvvInvalid3`: card's security code (CVV) does not match the expected length (exact: 3 characters).
* `cvvInvalid4`: card's security code (CVV) does not match the expected length (exact: 4 characters).
* `expiryRequired`: card's expiry date is not provided.
* `cardExpired`: card has expired.
* `expiryMonthInvalid`: expiry date's month is invalid.
* `expiryYearInvalid`: expiry date's year is invalid.

**message** `string` *required*

A human-readable message describing the error that occurred.

**error** `string`

A string describing any error that occurred during the validation process.

**reset** `() =\> void`

Reset the hosted fields to their initial state.

## Native

```ts TS theme={"dark"}
createPaymentMethodManager(
	type: "PAYPAL" | "GOOGLE_PAY" | "APPLE_PAY",
): Promise<INativePaymentMethodManager | null>
```

Create an instance of the `INativePaymentMethodManager`, which can be used to manage native payment methods like
PayPal, Google Pay, and Apple Pay.

### Parameters

**Parameters**

**type** `"PAYPAL" | "GOOGLE_PAY" | "APPLE_PAY"`

The type of native payment method to manage.

### Returns

**Promise\<INativePaymentMethodManager | null>**

**Promise\<INativePaymentMethodManager | null>**

A promise that resolves to an instance of `INativePaymentMethodManager` or `null`.
An interface for creating a native payment method button.

**INativePaymentMethodManager**

**createButton** `() =\> IHeadlessPaymentMethodButton`

Create a native payment method button. Returns a
[HeadlessPaymentMethodButton](https://primer.io/docs/sdk/web/v2.x.x/primer-headless-checkout/types/HeadlessPaymentMethodButton.md).

## Redirect

```ts TS theme={"dark"}
createPaymentMethodManager(
	type: PaymentMethodType,
): Promise<IRedirectPaymentMethodManager | null>
```

Create an instance of the `IRedirectPaymentMethodManager`, which can be used to manage redirect-based payment
methods.

### Parameters

**Parameters**

**type** `PaymentMethodType`

The type of redirect-based payment method to manage, one of [PaymentMethodType](https://primer.io/docs/sdk/web/v2.x.x/constants/payment-method-types.md).

### Returns

**Promise\<IRedirectPaymentMethodManager | null>**

**Promise\<IRedirectPaymentMethodManager | null>**

A promise that resolves to an instance of `IRedirectPaymentMethodManager` or `null`.

**IRedirectPaymentMethodManager**

**start** `() =\> Promise\<void\>`

Start the redirect payment flow.

**addEventListener** `(event: EventTypes, callback: EventListener) =\> void`

Add an event listener to the button.

**Parameters**

**EventTypes** `"blur" | "change" | "click" | "close" | "error" | "focus"`

&#x20;

**EventListener** `(event?: Event) =\> void`

&#x20;

## Klarna

```ts TS theme={"dark"}
createPaymentMethodManager(
	type: "KLARNA",
	options?: KlarnaPaymentMethodManagerOptions
): Promise<IKlarnaPaymentMethodManager | null>
```

Create an instance of the `IKlarnaPaymentMethodManager`, which can be used to manage Klarna specific payment methods which also require an extra form and user interaction.

### Parameters

**Parameters**

**type** `"KLARNA"`

The type of payment method to manage.

**options** `KlarnaPaymentMethodManagerOptions`

Options to configure the payment method manager.

**Properties**

**onPaymentMethodCategoriesChange** `(paymentMethodCategories: KlarnaPaymentMethodCategory[]) =\> void`

A callback that is called when the payment categories for Klarna have
changed. Sends back an array with the values needed to render the payment
categories for Klarna.

**Parameters**

**paymentMethodCategories** `KlarnaPaymentMethodCategory[] | []`

**Properties**

**id** `string`

**name** `string`

**descriptiveAssetUrl** `string`

**standardAssetUrl** `string`

### Returns

**Promise\<IKlarnaPaymentMethodManager | null>**

**Promise\<IKlarnaPaymentMethodManager | null>**

A promise that resolves to an instance of `IKlarnaPaymentMethodManager` or `null`.

**IKlarnaPaymentMethodManager**

**start** `(paymentPayload: KlarnaPaymentPayload) =\> Promise\<void\>`

This function starts the payment process. It should be called with the
selected payment method category id, when the user has selected and
confirmed the desired payment category. The payment method category id which
needs to be sent to the start function can be retrieved from the
onPaymentMethodCategoriesChange function

**paymentPayload** `\{ paymentMethodCategoryId: string \}`

**Properties**

**paymentMethodCategoryId** `string`

**renderCategory** `(details: RenderCategoryDetails) =\> Promise\<void\>`

This function is used so that Klarna can render the selected payment
category details (paymentMethodCategoryId) in a DOM element (containerId).
It uses a callback (onHeightChange) to inform when the height of the
contianer has changed.

**details** `\{ containerId: string, paymentMethodCategoryId: string, onHeightChange:(newHeight:number)=\> void \}`

**Properties**

**containerId** `string`

**paymentMethodCategoryId** `string`

**onHeightChange** `(height: number) =\> void`

**Parameters**

**height** `number`

## ACH

```ts TS theme={"dark"}
createPaymentMethodManager(
	type: "STRIPE_ACH",
	options?: AchPaymentMethodManagerOptions
): Promise<IAchPaymentMethodManager | null>
```

Create an instance of the `IAchPaymentMethodManager`, which can be used to manage ACH payment methods which also require an extra form and the mandate confirmation.

### Parameters

**Parameters**

**type** `"STRIPE_ACH"`

The type of payment method to manage.

**options** `AchPaymentMethodManagerOptions`

Options to configure the payment method manager.

**Properties**

**stripePublishableKey** `string`

Stripe Publishable Key, used to interact with Stripe's SDK and collect the bank account details, necessary for the `STRIPE_ACH` payment method. The Publishable Key can be found in the [Stripe Dashboard API keys](https://dashboard.stripe.com/test/apikeys).

### Returns

**Promise\<IAchPaymentMethodManager | null>**

**Promise\<IAchPaymentMethodManager | null>**

A promise that resolves to an instance of `IAchPaymentMethodManager` or `null`.

**IAchPaymentMethodManager**

**start** `(data: T) =\> Promise\<Validation | undefined\>`

Submits and validates the customer data starting the ACH payment method flow.

When the payment method is `STRIPE_ACH`, the required data `T` is:

```typescript TS theme={"dark"}
interface StripeAchFormData {
  firstName: string;
  lastName: string;
  emailAddress: string;
}
```

**collectBankAccountDetails** `() =\> Promise\<void\>`

When the payment method is `STRIPE_ACH`, displays the Stripe UI to collect the bank account details.

Throws an error if the `start` method didn't run successfully or wasn't called before.

**confirmMandate** `() =\> Promise\<void\>`

Submits the mandate confirmation. Should be triggered by a "Confirm" button next to the mandate text.

Throws an error if the methods `start` and `collectBankAccountDetails` weren't successfully called before.


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