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

# fetchVaultedPaymentMethods

Get a list of `PrimerVaultedPaymentMethod` for the `customerId` attached to the [client session](/api-reference/v2.4/api-reference/client-session-api/create-a-client-session).
Build your own UI to display, manage and perform payments with them.

<Warning>
  The list of vaulted payment methods is not affected by the checkout builder's conditions.
  For example, if you configured the checkout builder to not show `Paypal` with the current client session,
  but `Paypal` was vaulted previously, `fetchVaultedPaymentMethods` will still return it.

  <b>
    The mentioned issue will be addressed and resolved in an upcoming release,
    improving the overall functionality of the Vault Manager.
  </b>
</Warning>

```kotlin KOTLIN theme={"dark"}
suspend fun fetchVaultedPaymentMethods(): Result<List<PrimerVaultedPaymentMethod>>
```

## Returns

The `fetchVaultedPaymentMethods` method fetches the vaulted payment methods for the `customerId` attached to the [client session](/api-reference/v2.4/api-reference/client-session-api/create-a-client-session)
and returns a result object of type [Result](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-result/).

The Result class represents the outcome of the operation, indicating `success` or `failure`.

By inspecting the returned Result object, you can determine the success or failure of the fetching of the vaulted payment methods.
This allows you to handle different scenarios based on the result.

<Expandable title="Results" defaultOpen>
  <ResponseField name="success">
    In case of successful operation result, SDK will return:

    <Expandable title="Return Type" defaultOpen>
      <ResponseField name="List<PrimerVaultedPaymentMethod>">
        <Expandable title="PrimerVaultedPaymentMethod">
          <ResponseField name="id" type="String">
            A *temporary* identifier for the vaulted payment method. You should use this id with [deleteVaultedPaymentMethod](/sdk/android/v2.x.x/primer-headless-checkout/vault-manager/deleteVaultedPaymentMethod),
            [validate](/sdk/android/v2.x.x/primer-headless-checkout/vault-manager/validate) and [startPaymentFlow](/sdk/android/v2.x.x/primer-headless-checkout/vault-manager/startPaymentFlow).

            ℹ️ This id changes with each call to [fetchVaultedPaymentMethods](/sdk/android/v2.x.x/primer-headless-checkout/vault-manager/fetchVaultedPaymentMethods).
          </ResponseField>

          <ResponseField name="analyticsId" type="String" required>
            An identifier for the vaulted payment method that doesn't change across calls to [fetchVaultedPaymentMethods](/sdk/android/v2.x.x/primer-headless-checkout/vault-manager/fetchVaultedPaymentMethods).
          </ResponseField>

          <ResponseField name="paymentInstrumentType" type="String" required>
            The type of the payment instrument associated to the vaulted payment method.
          </ResponseField>

          <ResponseField name="paymentMethodType" type="String" required>
            A unique string identifier for the payment method.
          </ResponseField>

          <ResponseField name="paymentInstrumentData" type="PaymentInstrumentData" required>
            Data associated to the payment instrument. You can use this information to display the vaulted payment method in your UI.

            <Expandable title="Properties">
              <ResponseField name="network" type="String?">
                The human readable representation of card network (e.g., Visa, Mastercard).
              </ResponseField>

              <ResponseField name="cardholderName" type="String?">
                The name of the cardholder.
              </ResponseField>

              <ResponseField name="first6Digits" type="Int?">
                The first 6 digits of the card number.
              </ResponseField>

              <ResponseField name="last4Digits" type="Int?">
                The last 4 digits of the card number.
              </ResponseField>

              <ResponseField name="accountNumberLast4Digits" type="Int?">
                The last 4 digits of the account number.
              </ResponseField>

              <ResponseField name="expirationMonth" type="Int?">
                The expiration month of the card, in 2-digit format.
              </ResponseField>

              <ResponseField name="expirationYear" type="Int?">
                The expiration year of the card, in 4-digit format.
              </ResponseField>

              <ResponseField name="externalPayerInfo" type="ExternalPayerInfo?">
                External information about the payer associated with the transaction.

                <Expandable title="Properties" defaultOpen>
                  <ResponseField name="email" type="String">
                    The payer's email address.
                  </ResponseField>

                  <ResponseField name="externalPayerId" type="String?">
                    The payer's unique ID.
                  </ResponseField>

                  <ResponseField name="firstName" type="String?">
                    The payer's given name.
                  </ResponseField>

                  <ResponseField name="lastName" type="String?">
                    The payer's given surname.
                  </ResponseField>
                </Expandable>
              </ResponseField>

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

              <ResponseField name="sessionData" type="SessionData?" />

              <ResponseField name="paymentMethodType" type="String?">
                A unique string identifier for the payment method. (e.g. `PAYPAL`,
                `GOOGLE_PAY`)
              </ResponseField>

              <ResponseField name="binData" type="BinData?">
                Additional BIN data.

                <Expandable title="Properties" defaultOpen>
                  <ResponseField name="network" type="String?">
                    The card network (e.g., VISA, MASTERCARD, AMEX).
                  </ResponseField>
                </Expandable>
              </ResponseField>

              <ResponseField name="bankName" type="String?">
                The name of the bank.
              </ResponseField>
            </Expandable>
          </ResponseField>

          <ResponseField name="threeDSecureAuthentication" type="Nullable<ThreeDSAuthenticationData>" />
        </Expandable>
      </ResponseField>
    </Expandable>
  </ResponseField>

  <ResponseField name="failure">
    In case of unsuccessful operation result, as part of `Result` object SDK will return:

    <Expandable title="Exceptions" defaultOpen>
      <ResponseField name="VaultManagerFetchException">
        If an error occurs while fetching vaulted payment methods.
      </ResponseField>

      <ResponseField name="IOException">
        if an I/O error occurs during the API request.
      </ResponseField>
    </Expandable>
  </ResponseField>
</Expandable>

## Example

```kotlin KOTLIN theme={"dark"}
// 👇  initialize PrimerHeadlessUniversalCheckoutVaultManager after SDK was successfully initialized
val vaultManager = PrimerHeadlessUniversalCheckoutVaultManager.newInstance()

private fun fetchVaultedPaymentMethods() {
    // 👇 fetch vaulted payment methods by calling suspend function within the scope
    scope.launch {
        vaultManager.fetchVaultedPaymentMethods().onSuccess { vaultedPaymentMethods ->
            // display vaulted payment methods to the user
        }.onFailure { throwable ->
            // handle error
        }
    }
}
```
