> ## Documentation Index
> Fetch the complete documentation index at: https://docs.younegotiate.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Payment Setup

> Jane accepts a settlement and enters a debit card.

## Real-World Example

Jane accepts a settlement and enters a debit card. The portal should use the creditor's configured merchant gateway, store or use the payment method safely, and only create the schedule once payment setup succeeds.

## Visual Flow

```mermaid placement="top-right" actions={true} theme={"system"}
flowchart TD
    A["Consumer reaches payment setup"] --> B["Portal loads merchant and payment options"]
    B --> C["Consumer enters or selects payment method"]
    C --> D{"Payment method valid?"}
    D -->|Yes| E["Portal completes setup"]
    D -->|No| F["Consumer fixes payment details"]
    E --> G["Schedule or payment is ready"]
    classDef default fill:#F8FAFC,stroke:#64748B,stroke-width:1.5px,color:#0F172A;
    classDef actor fill:#E0F2FE,stroke:#0284C7,stroke-width:2px,color:#0C4A6E;
    classDef system fill:#F8FAFC,stroke:#64748B,stroke-width:1.5px,color:#0F172A;
    classDef decision fill:#FEF3C7,stroke:#D97706,stroke-width:2px,color:#78350F;
    classDef risk fill:#FEE2E2,stroke:#DC2626,stroke-width:2px,color:#7F1D1D;
    classDef outcome fill:#DCFCE7,stroke:#16A34A,stroke-width:2px,color:#14532D;
    class A,C,F actor;
    class B,E,G system;
    class D decision;
    class G outcome;
    linkStyle default stroke:#94A3B8,stroke-width:2px;
```

## How It Should Work

* It should use the creditor merchant setup and supported payment gateway.
* It should support saved wallet methods when allowed.
* It should create or update payment setup only after payment method validation succeeds.
* It should move the account into the right scheduled or payment-plan status.
* It should immediately charge a one-time settlement due today or earlier, create the successful transaction, and settle the account.
* It should prefer a verified sub-account merchant and fall back to the creditor-level merchant for the same payment method.
* It should increment the campaign settlement or payment-plan completion counter once when setup first completes.
* It should allow the consumer to add a payment profile while a custom settlement or payment-plan offer is pending creditor response, and Back should return to Pending Creditor Response.

## How It Should Not Work

* It should not store sensitive payment details outside the approved payment profile flow.
* It should not schedule payments when merchant setup is missing or invalid.
* It should not confuse one-time settlement setup with installment plan setup.

## Developer Notes

* Payment setup connects consumer UI, payment profiles, merchant services, and schedule transactions.
* Gateway-specific behavior should remain behind the existing service/job layers.
* Confirmation returns `payment_processed` for an immediately charged settlement and `payment_scheduled` for a future settlement or installment plan.

## Related App Areas

* `app/Livewire/Consumer/Payment.php`
* `app/Livewire/Consumer/Forms/PaymentForm.php`
* `app/Services/Consumer/PaymentProfileCreationService.php`
* `app/Services/Consumer/PaymentSetupCompletionService.php`
