Skip to main content

Overview

The listCards() method retrieves all enrolled cards for the current authenticated user. Returns card metadata for display — no raw PANs.

Method Signature

prava.listCards(): Promise<Card[]>

Return Value

Returns an array of Card objects:
cards
Card[]

Example

import { useEffect, useState } from 'react';
import { PravaSDK } from '@prava-sdk/core';
import type { Card } from '@prava-sdk/core';

function CardList() {
  const [cards, setCards] = useState<Card[]>([]);
  const [loading, setLoading] = useState(true);

  const prava = new PravaSDK({ publishableKey: 'pk_live_xxx' });

  useEffect(() => {
    prava.listCards()
      .then(setCards)
      .catch(err => console.error('Failed to load cards:', err))
      .finally(() => setLoading(false));

    return () => prava.destroy();
  }, []);

  if (loading) return <div>Loading cards...</div>;

  if (cards.length === 0) {
    return <div>No cards enrolled. <button>Add Card</button></div>;
  }

  return (
    <div>
      <h2>Your Cards</h2>
      {cards.map(card => (
        <div key={card.cardId}>
          {card.brand} •••• {card.last4} — exp {card.expMonth}/{card.expYear}
          <button onClick={() => handleBuy(card.cardId)}>Buy Now</button>
        </div>
      ))}
    </div>
  );
}

Use Cases

Payment Method Selection

Allow users to choose which card to use for a payment:
const cards = await prava.listCards();

// Present cards to user
const selectedCardId = await showCardSelector(cards);

// Use selected card for intent
const intent = await prava.registerIntent({
  cardId: selectedCardId,
  merchant: 'Amazon',
  amount: 99.99,
  currency: 'USD',
});

Card Expiration Handling

Check for expired cards and prompt users to re-enroll:
const cards = await prava.listCards();

const expiredCards = cards.filter(card => card.status === 'expired');

if (expiredCards.length > 0) {
  console.warn(`${expiredCards.length} card(s) expired`);
  // Prompt user to enroll a new card
}

Error Handling

Common Errors

CodeCauseResolution
CARD_NOT_FOUNDNo cards enrolledPrompt user to add first card via collectPAN()

Security Considerations

Card metadata is safe to display: The listCards() response contains only non-sensitive data (last 4, brand, expiry). Full PANs are never returned by the API.

Next Steps