# Main Branch Callback URL Setup

## Summary
Separated callback URLs for Main Branch (4086675) from Juja Branch (4159523) to avoid conflicts.

## Changes Made

### 1. URL Routes (payments/urls.py)
- **Juja Branch (4159523)**: Uses existing `/payments/callback/validation/` and `/payments/callback/confirmation/`
- **Main Branch (4086675)**: Uses new `/payments/callback/main/validation/` and `/payments/callback/main/confirmation/`

### 2. Branch M-Pesa Service (payments/branch_mpesa_service.py)
- Automatically selects correct callback URLs based on shortcode
- Main Branch (4086675) → `/callback/main/` URLs
- Other branches → `/callback/` URLs

### 3. Management Command (payments/management/commands/register_mpesa_urls.py)
- Updated to auto-select URLs based on shortcode
- Can still override with `--validation-url` and `--confirmation-url` flags

## How to Register Main Branch URLs

### Option 1: Simple Command (Easiest)
```bash
python manage.py register_main_branch
```
Type "yes" when prompted to confirm.

### Option 2: Skip Confirmation (For Scripts)
```bash
python manage.py register_main_branch --skip-confirmation
```

### Option 3: Using Generic Command
```bash
python manage.py register_mpesa_urls --shortcode 4086675 --consumer-key L00rQYgBd5WrsGYI4a0Agb9P8SSCgaYGA3uF0Dme0IgKsAN5 --consumer-secret nuHpJxybEO0eh3qAlpckBFPzveHEV3A6LUNOl5gUwqIU53I03aIGY4VM1vVHRJDC --production
```
Type "yes" when prompted.

### Option 4: Using Django Shell
```bash
python manage.py shell
```
Then in the shell:
```python
exec(open('register_main_branch.py').read())
```

### Option 3: Using Branch Service Directly
```python
from payments.branch_mpesa_service import BranchMpesaService
from users.models import Branch

main_branch = Branch.objects.get(mpesa_shortcode='4086675')
service = BranchMpesaService(main_branch)
result = service.register_c2b_urls()
print(result)
```

## Callback URLs

### Main Branch (4086675)
- Validation: `https://branchbusinessadvance.co.ke/payments/callback/main/validation/`
- Confirmation: `https://branchbusinessadvance.co.ke/payments/callback/main/confirmation/`

### Juja Branch (4159523) - No Changes
- Validation: `https://branchbusinessadvance.co.ke/payments/callback/validation/`
- Confirmation: `https://branchbusinessadvance.co.ke/payments/callback/confirmation/`

## Testing
After registration, test by:
1. Making a payment to paybill 4086675
2. Check callback logs: `/payments/callbacks/`
3. Check transactions: `/payments/transactions/`

## Notes
- Juja branch callbacks remain unchanged and will continue working
- Main branch now has its own dedicated callback endpoints
- The system automatically routes to the correct URLs based on shortcode
