# Implementation Plan - Dynamic Button & AJAX Feed Fix

## Goal
Fix the issue where the "Pay with Card" button is always present (hiding the standard button) and resolve the "No active Redsys feed" error in AJAX.
Also, ensure Redsys payments are correctly registered as "Sales" and trigger value-added feeds (like User Registration, Mailchimp, etc.).

## Components

### 1. `GF_Field_Redsys` Updates
- **Editor Settings**: Ensure `conditional_logic_setting` and `force_validaion` (if needed) are properly registered.
- **Frontend Output**: Add a wrapper class to the Redsys button container for easier JS targeting.

### 2. JavaScript (`assets/js/gf-redsys.js`)
- **Dynamic Visibility**:
    - Listen to Gravity Forms' `gform_post_render` and `gform_input_change` (or field visibility changes).
    - If the Redsys field container is `visible`:
        - Hide the standard Submit button.
        - Show the Redsys "Pay with Card" button.
    - If the Redsys field container is `hidden`:
        - Show the standard Submit button.
        - Hide the Redsys "Pay with Card" button.

### 3. `GF_Redsys` Class Updates
- **AJAX Handler (`get_params_ajax`)**:
    - Parse the incoming `form_data` string and temporarily populate `$_POST` so `GFFormsModel::create_lead($form)` has the necessary data to evaluate feed conditional logic.
- **Submit Button Filter**: Remove the PHP-side hiding of the button to allow JS to control it dynamically.
- **New Billing Fields**: Add Address, City, Zip, Province, and Country to the Feed Settings via `billing_info_fields()`.
### Sales Stats & Integrations
- [x] **Override `complete_payment` in `GF_Redsys`:**
    - [x] Explicitly set entry properties (`payment_status`, `transaction_type` = 1, `is_fulfilled`).
    - [x] Call `parent::entry_post_save` to generate Order Meta & Gateway Meta (Standard GF Flow).
    - [x] Trigger delayed feeds (`trigger_payment_delayed_feeds`).
    - [x] Call `parent::complete_payment` for standard hooks.
- **Refactor Payment Handling**:
    - Update `save_redsys_meta` (the "Popup" reconciliator) to use `$this->complete_payment` instead of manual entry updates.
    - Ensure `handle_ipn` uses `$this->complete_payment`.

## Flow
1. User interacts with form.
2. Gravity Forms conditional logic shows/hides the Redsys field.
3. JS syncs the Submit button visibility based on the Redsys field visibility.
4. User clicks "Pay with Card".
5. AJAX evaluates feeds correctly by spoofing `$_POST`.
6. Payment proceed as before.
7. Upon successful payment (Popup or IPN), `complete_payment` is called, registering the Sale and triggering delayed feeds.

## Files to Modify
- `includes/class-gf-redsys.php`
- `includes/class-gf-field-redsys.php`
- `assets/js/gf-redsys.js`

## 4. Admin Dashboard
Create a top-level **Redsys** menu.
### Submenus:
1.  **Gravity Forms**:
    - Explanation of how to use Redsys with GF.
    - Status check (Environment, keys partial view).
    - Link to GF Settings > Redsys.
2.  **Quick Pay**:
    - Usage guide for shortcode.
    - Shortcode Generator.
