# Payment Methods Transition Guide

This document outlines the transition from the legacy `credit_cards` table to the new `payment_methods` table.

## Overview

The application is transitioning from using a dedicated `credit_cards` table to a more flexible `payment_methods` table that supports multiple payment types:

- Credit Cards
- ACH (Bank Transfers)
- Invoices

## Current Status

A migration has been created and run to copy all existing credit card data from the `credit_cards` table to the `payment_methods` table. The application is currently in a transition phase where both tables are supported.

## Transition Strategy

### Phase 1: Dual Support (Current)

- The `PaymentMethodTransitionService` provides methods to work with both tables
- The UI has been updated to display payment methods from both tables
- New payment methods are stored in the `payment_methods` table
- Legacy credit cards remain in the `credit_cards` table

### Phase 2: Deprecation

- Update all code to use the `payment_methods` table exclusively
- Mark the `credit_cards` table and related code as deprecated
- Add warnings when using the legacy code

### Phase 3: Removal

- Remove all code that directly interacts with the `credit_cards` table
- Keep the migration that copies data from `credit_cards` to `payment_methods`
- Eventually, drop the `credit_cards` table

## Implementation Details

### PaymentMethodTransitionService

This service provides methods to work with both tables during the transition:

- `getPaymentMethodsForUser`: Returns payment methods from both tables
- `processPayment`: Processes payments using either table based on the ID format

### ID Format

To distinguish between payment methods from different tables:

- Payment methods from the `payment_methods` table use their numeric ID
- Credit cards from the `credit_cards` table use a string ID prefixed with `cc_`

Example:
```
// Payment method from payment_methods table
id: 123

// Credit card from credit_cards table
id: "cc_456"
```

### UI Components

The `PaymentMethodManagement.vue` component has been updated to:

- Display payment methods from both tables
- Handle setting default payment methods for both tables
- Handle deleting payment methods from both tables

## Developer Guidelines

### Adding New Code

- All new code should use the `payment_methods` table
- Do not add new features that directly interact with the `credit_cards` table

### Modifying Existing Code

- When modifying code that uses the `credit_cards` table, consider updating it to use the `payment_methods` table
- Use the `PaymentMethodTransitionService` for code that needs to support both tables

### Testing

- Test with both new payment methods and legacy credit cards
- Ensure that setting default payment methods works correctly across both tables
- Verify that deleting payment methods works for both tables

## Future Work

- Complete the transition to using only the `payment_methods` table
- Remove all direct references to the `credit_cards` table
- Eventually drop the `credit_cards` table (after ensuring all data is properly migrated)
