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

# usePrimerVaultManager

> Hook for listing, selecting, paying with and deleting the customer's saved payment methods.

> [!WARNING]
>
> Primer Checkout React Native SDK is currently in **beta** (v3.0.0-beta.1).
> The API is subject to change before the stable release.

`usePrimerVaultManager` gives you the customer's saved (vaulted) payment methods and the actions to pay with or delete one. Use it to build saved-method UI in a custom layout; the prebuilt `PrimerCheckoutSheet` shows saved methods itself.

The provider loads the saved methods once the checkout is ready, and again after every client session update, whether or not a component uses this hook. Call the hook inside [`PrimerCheckoutProvider`](https://primer.io/docs/sdk/react-native-checkout/v3.0.0-beta/api/primer-checkout-provider); it throws outside one.

> [!NOTE]
>
> Saved payment methods belong to a customer, so create the client session with a `customerId`.

## Signature

```tsx theme={"dark"}
function usePrimerVaultManager(): UsePrimerVaultManagerReturn
```

## Returns

| Field | Type | Description |
| - | - | - |
| `vaultedMethods` | `VaultedPaymentMethodItem[]` | The saved methods, in the order the native SDK returns them. Empty before the checkout is ready, during the first load, when the customer has none, and when the first load failed. A reload keeps the current list until it finishes. |
| `activeMethod` | `VaultedPaymentMethodItem \| null` | The method `pay()` charges: the one selected with `selectVaultedMethodId`, otherwise the first saved method. `null` when there are none. |
| `primaryMethod` | `VaultedPaymentMethodItem \| null` | The first saved method. |
| `originalDefault` | `VaultedPaymentMethodItem \| null` | The first saved method, whatever the selection. |
| `vaultDisplayMode` | `'expanded' \| 'lite'` | The layout the prebuilt sheet uses: `'lite'` (the selected saved method only) once a method was selected with `selectVaultedMethodId`, `'expanded'` before that and after `requestExpandedVaultDisplay()`. |
| `isLoading` | `boolean` | `true` while the saved methods load, including each reload after a client session update. It is `false` before the checkout is ready. |
| `error` | `Error \| null` | Set when loading the saved methods failed. |
| `requiresVaultedCardCvv` | `boolean` | Whether the shopper must enter the CVV again to pay with a saved card. See [CVV recapture](#cvv-recapture). |

| Method | Description |
| - | - |
| `pay(additionalData?: VaultedPaymentMethodAdditionalData): Promise<void>` | Starts a payment with `activeMethod`. Does nothing when `activeMethod` is `null`. See [Pay with a saved method](#pay-with-a-saved-method). |
| `payById(id: string, additionalData?: VaultedPaymentMethodAdditionalData): Promise<void>` | Starts a payment with the saved method `id`. |
| `selectVaultedMethodId(id: string): void` | Makes `id` the `activeMethod`. It doesn't pay. Ids that aren't in `vaultedMethods` are ignored. |
| `requestExpandedVaultDisplay(): void` | Sets `vaultDisplayMode` to `'expanded'` and keeps the selection. |
| `deleteVaultedPaymentMethod(id: string): Promise<void>` | Deletes the saved method `id`. See [Delete a saved method](#delete-a-saved-method). |

To tell "not loaded yet" from "no saved methods", check [`usePrimerCheckout().isReady`](https://primer.io/docs/sdk/react-native-checkout/v3.0.0-beta/api/use-primer-checkout) together with `isLoading`.

## VaultedPaymentMethodItem

One saved method, ready to render. It is a union on `kind`.

| Field | Type | Description |
| - | - | - |
| `kind` | `'card' \| 'bank' \| 'other'` | `'card'` when `paymentMethodType` is `PAYMENT_CARD`, `'bank'` when `paymentInstrumentType` is `AUTOMATED_CLEARING_HOUSE`, `'other'` for anything else. |
| `id` | `string` | Saved method id. Pass it to `payById`, `selectVaultedMethodId` and `deleteVaultedPaymentMethod`. |
| `paymentMethodType` | `string` | Payment method type, for example `PAYMENT_CARD` or `PAYPAL`. |
| `paymentInstrumentType` | `string` | Payment instrument type, as the native SDK reports it. |
| `iconUri` | `string \| undefined` | For a card, the card network's icon. For other kinds, the payment method's logo. |
| `displayName` | `string \| undefined` | The payment method's name, for `bank` and `other` kinds. `undefined` for cards. |
| `rawMethod` | `VaultedPaymentMethod` | The saved method as the native SDK returns it: `id`, `analyticsId`, `paymentInstrumentType`, `paymentMethodType`, `paymentInstrumentData` and `threeDSecureAuthentication`. |

Fields for `kind: 'card'`:

| Field | Type | Description |
| - | - | - |
| `cardholderName` | `string \| undefined` | Name on the card. |
| `last4` | `string \| undefined` | Last four digits of the card number. |
| `expiryMonth` | `string \| undefined` | Expiry month, two digits (`'04'`). |
| `expiryYear` | `string \| undefined` | Last two digits of the expiry year (`'27'`). |
| `network` | `string \| undefined` | Card network, as the native SDK reports it. |
| `brandName` | `string \| undefined` | `network` with only its first letter in upper case, for example `Visa`. |

Fields for `kind: 'bank'`:

| Field | Type | Description |
| - | - | - |
| `bankName` | `string \| undefined` | Name of the bank. |
| `accountLast4` | `string \| undefined` | Last four digits of the account number. |

Fields for `kind: 'other'`:

| Field | Type | Description |
| - | - | - |
| `detail` | `string \| undefined` | The payer's email address with most of the name hidden (`jo••••@example.com`), for methods such as PayPal that report one. |

## Pay with a saved method

`pay` and `payById` clear the previous payment outcome and start the payment. The native SDK runs it, and the result arrives in [`usePrimerCheckout().paymentOutcome`](https://primer.io/docs/sdk/react-native-checkout/v3.0.0-beta/api/use-primer-checkout), like any other payment.

* They don't reject. A failure ends the attempt with an error outcome.
* They do nothing until the saved methods have been set up during the first load.
* Keep your own loading flag: set it on tap and clear it only when `paymentOutcome` reports a failure.

For a failed payment, log the description of `paymentOutcome.error` and show your own message in your UI. See [`PrimerError`](https://primer.io/docs/sdk/react-native-checkout/v3.0.0-beta/api/common/primer-error) for the error IDs.

## CVV recapture

`requiresVaultedCardCvv` is `true` when the client session asks for the CVV of saved cards again (the card option `captureVaultedCardCvv`).

When `requiresVaultedCardCvv` is `true` and the method is a card, render your own CVV field and pass the value: `pay({ cvv })` or `payById(id, { cvv })`. A CVV has 3 or 4 digits, depending on the card network.

`VaultedPaymentMethodAdditionalData` is `{ cvv: string }`.

## Delete a saved method

`deleteVaultedPaymentMethod(id)` deletes the method at once, with no confirmation step. Add your own confirmation if you want one.

* When the delete succeeds, the list reloads. If the deleted method was the selected one, the first remaining method becomes `activeMethod`. If the reload fails, the deleted method is still removed from `vaultedMethods` and the promise resolves.
* It rejects in three cases:
  * `{ errorId: 'INVALID_VAULTED_METHOD_ID', description }` when `id` isn't in `vaultedMethods`.
  * `{ errorId: 'VAULT_MANAGER_NOT_CONFIGURED', description }` when the saved methods haven't been set up yet.
  * The native SDK's error when the delete itself fails.

```tsx theme={"dark"}
import { Alert } from 'react-native';
import { usePrimerVaultManager } from '@primer-io/react-native';

function useDeleteSavedMethod() {
  const { deleteVaultedPaymentMethod } = usePrimerVaultManager();

  return async (id: string) => {
    try {
      await deleteVaultedPaymentMethod(id);
    } catch (e) {
      const error = e as { errorId?: string; code?: string; description?: string; message?: string };
      console.warn(`Delete failed [${error.errorId ?? error.code}]: ${error.description ?? error.message}`);
      Alert.alert('Could not remove this payment method', 'Try again later.');
    }
  };
}
```

## Usage

A list of saved methods with a Pay button and CVV recapture:

```tsx theme={"dark"}
import { useEffect, useState } from 'react';
import { Button, Pressable, Text, TextInput, View } from 'react-native';
import { usePrimerCheckout, usePrimerVaultManager } from '@primer-io/react-native';
import type { VaultedPaymentMethodItem } from '@primer-io/react-native';

function describe(method: VaultedPaymentMethodItem): string {
  switch (method.kind) {
    case 'card':
      return `${method.brandName ?? 'Card'} •••• ${method.last4?.padStart(4, '0') ?? ''}`;
    case 'bank':
      return `${method.bankName ?? method.displayName ?? 'Bank account'} •••• ${method.accountLast4?.padStart(4, '0') ?? ''}`;
    case 'other':
      return method.detail ?? method.displayName ?? method.paymentMethodType;
  }
}

function SavedPaymentMethods() {
  const { isReady, paymentOutcome } = usePrimerCheckout();
  const { vaultedMethods, activeMethod, isLoading, requiresVaultedCardCvv, selectVaultedMethodId, pay } =
    usePrimerVaultManager();
  const [cvv, setCvv] = useState('');
  const [isPaying, setIsPaying] = useState(false);

  useEffect(() => {
    if (paymentOutcome?.status === 'error') setIsPaying(false);
  }, [paymentOutcome]);

  if (!isReady || isLoading || vaultedMethods.length === 0) {
    return null;
  }

  const needsCvv = requiresVaultedCardCvv && activeMethod?.kind === 'card';

  const onPay = () => {
    setIsPaying(true);
    void pay(needsCvv ? { cvv } : undefined);
  };

  return (
    <View style={{ gap: 8 }}>
      {vaultedMethods.map((method) => (
        <Pressable
          key={method.id}
          onPress={() => {
            selectVaultedMethodId(method.id);
            setCvv('');
          }}
        >
          <Text style={{ fontWeight: method.id === activeMethod?.id ? '600' : '400' }}>{describe(method)}</Text>
        </Pressable>
      ))}
      {needsCvv ? (
        <TextInput value={cvv} onChangeText={setCvv} keyboardType="number-pad" secureTextEntry maxLength={4} />
      ) : null}
      <Button title="Pay" disabled={isPaying || (needsCvv && cvv.length < 3)} onPress={onPay} />
    </View>
  );
}
```

## See also

> [card] [usePrimerCheckout](https://primer.io/docs/sdk/react-native-checkout/v3.0.0-beta/api/use-primer-checkout.md)
>
> The payment outcome and checkout state.

> [card] [Handle the payment result](https://primer.io/docs/sdk/react-native-checkout/v3.0.0-beta/guides/handle-payment-result.md)
>
> React to success, pending and error outcomes.

> [card] [PrimerPaymentMethodList](https://primer.io/docs/sdk/react-native-checkout/v3.0.0-beta/api/payment-methods/primer-payment-method-list.md)
>
> List the session's other payment methods.

> [card] [PrimerError](https://primer.io/docs/sdk/react-native-checkout/v3.0.0-beta/api/common/primer-error.md)
>
> Error fields and where errors arrive.


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