---
title: Payments Commands
description: Django-CFG CLI payments commands. Command-line interface for payments commands with examples, options, and production workflows.
sidebar_label: Payments
sidebar_position: 6
keywords:
  - django-cfg payments
  - django-cfg command payments
  - cli payments
---

# Payments Management Commands

Commands for managing payments, currencies, providers, and transactions.

## Currency Management

### `currency_stats`

Display currency statistics and usage metrics.

```bash
python manage.py currency_stats [OPTIONS]
```

| Option | Type | Default | Description |
|--------|------|---------|-------------|
| `--format` | `json\|yaml\|table` | `table` | Output format |

**Examples:**

```bash
# Show currency stats
python manage.py currency_stats

# Export as JSON
python manage.py currency_stats --format json

# Export as YAML
python manage.py currency_stats --format yaml
```

---

### `manage_currencies`

Manage payment currencies.

```bash
python manage.py manage_currencies [ACTION] [OPTIONS]
```

| Action | Description |
|--------|-------------|
| `list` | List all currencies |
| `add` | Add new currency |
| `update` | Update currency |
| `remove` | Remove currency |

| Option | Type | Description |
|--------|------|-------------|
| `--code` | `TEXT` | Currency code (BTC, ETH, USD, etc.) |
| `--name` | `TEXT` | Currency name |
| `--network` | `TEXT` | Network for crypto currencies |

**Examples:**

```bash
# List all currencies
python manage.py manage_currencies list

# Add fiat currency
python manage.py manage_currencies add --code USD --name "US Dollar"

# Add crypto currency
python manage.py manage_currencies add --code BTC --name Bitcoin

# Add crypto with network
python manage.py manage_currencies add --code USDT --name "Tether" --network TRC20

# Update currency
python manage.py manage_currencies update --code BTC --name "Bitcoin (Updated)"

# Remove currency
python manage.py manage_currencies remove --code DOGE
```

---

## Provider Management

### `manage_providers`

Manage payment providers and their configurations.

```bash
python manage.py manage_providers [ACTION] [OPTIONS]
```

| Action | Description |
|--------|-------------|
| `list` | List all providers |
| `add` | Add new provider |
| `update` | Update provider |
| `remove` | Remove provider |

| Option | Type | Description |
|--------|------|-------------|
| `--name` | `TEXT` | Provider name |
| `--type` | `TEXT` | Provider type (crypto, fiat) |
| `--api-key` | `TEXT` | API key |

**Examples:**

```bash
# List all providers
python manage.py manage_providers list

# Add crypto provider
python manage.py manage_providers add \
  --name CryptAPI \
  --type crypto

# Add fiat provider
python manage.py manage_providers add \
  --name Stripe \
  --type fiat

# Update provider API key
python manage.py manage_providers update \
  --name Stripe \
  --api-key sk_live_new_key

# Remove provider
python manage.py manage_providers remove --name PayPal
```

---

### `test_providers`

Test payment provider integrations.

```bash
python manage.py test_providers [OPTIONS]
```

| Option | Type | Description |
|--------|------|-------------|
| `--provider` | `TEXT` | Specific provider to test |

**Examples:**

```bash
# Test all providers
python manage.py test_providers

# Test specific provider
python manage.py test_providers --provider cryptapi

# Test Stripe
python manage.py test_providers --provider stripe
```

**Output:**
```
🚀 Testing payment providers...

✅ CryptAPI - Connection successful
  API Status: Active
  Supported currencies: 150+

✅ Stripe - Connection successful
  API Status: Active
  Account: live_mode

❌ PayPal - Connection failed
  Error: Invalid API credentials
```

---

## Payment Processing

### `process_pending_payments`

Process pending payment transactions.

```bash
python manage.py process_pending_payments [OPTIONS]
```

| Option | Type | Description |
|--------|------|-------------|
| `--limit` | `INTEGER` | Maximum payments to process |

**Examples:**

```bash
# Process all pending payments
python manage.py process_pending_payments

# Process up to 100 payments
python manage.py process_pending_payments --limit 100

# Process up to 10 (testing)
python manage.py process_pending_payments --limit 10
```

**Cron Setup:**

```bash
# Process every 5 minutes
*/5 * * * * cd /path/to/project && python manage.py process_pending_payments

# Process every minute (high volume)
* * * * * cd /path/to/project && python manage.py process_pending_payments --limit 50
```

---

## Data Management

### `cleanup_expired_data`

Cleanup expired payment data and old records.

```bash
python manage.py cleanup_expired_data [OPTIONS]
```

| Option | Type | Default | Description |
|--------|------|---------|-------------|
| `--days` | `INTEGER` | `90` | Days to keep |
| `--dry-run` | `flag` | `False` | Show what would be deleted |

**Examples:**

```bash
# Cleanup data older than 90 days (default)
python manage.py cleanup_expired_data

# Keep only last 30 days
python manage.py cleanup_expired_data --days 30

# Keep last 180 days
python manage.py cleanup_expired_data --days 180

# Dry run to see what would be deleted
python manage.py cleanup_expired_data --dry-run

# Dry run for 30 days
python manage.py cleanup_expired_data --days 30 --dry-run
```

**Cron Setup:**

```bash
# Daily cleanup at 3 AM
0 3 * * * cd /path/to/project && python manage.py cleanup_expired_data

# Weekly cleanup (Sundays at 2 AM)
0 2 * * 0 cd /path/to/project && python manage.py cleanup_expired_data --days 60
```

---

## Common Workflows

### Initial Payment Setup

```bash
# 1. Add currencies
python manage.py manage_currencies add --code BTC --name Bitcoin
python manage.py manage_currencies add --code ETH --name Ethereum
python manage.py manage_currencies add --code USDT --name Tether --network TRC20

# 2. Add providers
python manage.py manage_providers add --name CryptAPI --type crypto
python manage.py manage_providers add --name Stripe --type fiat

# 3. Test providers
python manage.py test_providers

# 4. Check stats
python manage.py currency_stats
```

### Add New Crypto Currency

```bash
# 1. Add currency with network
python manage.py manage_currencies add \
  --code USDC \
  --name "USD Coin" \
  --network ERC20

# 2. Verify addition
python manage.py manage_currencies list

# 3. Test payment flow
python manage.py test_providers --provider cryptapi
```

### Production Maintenance

```bash
# 1. Process pending payments
python manage.py process_pending_payments

# 2. Check currency stats
python manage.py currency_stats

# 3. Cleanup old data
python manage.py cleanup_expired_data --dry-run
python manage.py cleanup_expired_data
```

---

## Configuration

### Django Configuration

```python
# config.py
class MyConfig(DjangoConfig):
    # Enable payments app
    enable_payments: bool = True

    # Provider API keys
    cryptapi_api_key: str = env.payments.cryptapi_key
    stripe_api_key: str = env.payments.stripe_key
```

### Environment Variables

```yaml
# config.dev.yaml
payments:
  cryptapi_key: "your_cryptapi_api_key"
  stripe_key: "sk_test_..."
```

---

## Cron Setup

```bash
*/5 * * * * python manage.py process_pending_payments  # Process payments
0 * * * * python manage.py test_providers              # Health check
0 3 * * * python manage.py cleanup_expired_data        # Daily cleanup
```

## Troubleshooting

| Problem | Solution |
|---------|----------|
| Provider connection failed | `test_providers --provider stripe` |
| Payments not processing | `currency_stats` then `process_pending_payments --limit 10` |
| Before cleanup | Always use `--dry-run` first |

---

## Related Documentation

- **[Quick Reference](./quick-reference)** - Fast command lookup
- **[Currency Module](/docs/features/modules/currency/overview)** - Currency conversion

---

**Payments made easy!** 💳
