# Walkthrough - PayPal-Style Popup Flow

We have implemented a seamless payment experience that mimics the behavior of the Gravity Forms PayPal Add-on.

## Features Implemented

### 1. Custom Payment Button
Instead of the standard "Submit" button, the form now shows a **"Pagar con Tarjeta"** button when the Redsys field is present.
- The original submit button is safely hidden and only triggered programmatically after a successful payment.

### 2. AJAX-Powered Parameter Generation
When the user clicks the payment button:
- A secure AJAX request is sent to the server.
- The server calculates the real total based on the current form data.
- Redsys signature and parameters are generated on the fly.

### 3. Centered Popup & Communication
- A centered modal window (`window.open`) opens with the Redsys payment page.
- A full-screen overlay (with blur effect) blocks the parent form, preventing multiple clicks or interaction during payment.
- The parent and child windows communicate via `postMessage`.

### 4. Automatic Form Submission
- Upon successful payment in the popup, it sends a `redsys_ok` message to the parent.
- The parent window automatically fills the hidden token fields and **submits the form**, finalize the entry in Gravity Forms.

## Verification Checklist
- [x] JS dependency on jQuery verified.
- [x] AJAX response includes correct URL and Order ID.
- [x] Popup opens with correct dimensions.
- [x] Parent window receives the success message and submits.
- [x] IPN handler matches the entry via Meta `_redsys_order_id`.

### 5. Quick Pay Shortcode
You can embed a simple payment button/form anywhere using the shortcode:
`[redsys_quick_pay amount="10.00" concept="Donation" button_text="Donate Now"]`
- Use `amount=""` to let the user input the amount.
- Use `concept=""` to let the user input the concept.
- Use `lang="en"` (or "es") to switch the interface language.
- Use `url_ok="https://..."` and `url_ko="https://..."` to override destination pages.

### 6. Admin Dashboard
A new top-level menu **Redsys** is now available in your admin sidebar.
- **Gravity Forms**: Check configuration status.
- **Quick Pay**: 
    - Configure **Global Default IDs** for OK/KO pages.
    - Generate shortcodes with specific destination URLs.
    - **Developer Helper**: View list of Redsys parameters (`Ds_Order`, `Ds_Amount`, etc.) available on your "Thank You" page.

### 7. Sales Stats & Integrations
We fixed the issue where payments were not registering as "Sales" in Gravity Forms dashboards.
- **The Problem**: Our custom AJAX/Popup flow bypassed the standard `entry_post_save` method, which is responsible for generating Order Metadata.
- **The Solution**: We updated `complete_payment` to manually invoke `parent::entry_post_save` after setting up the necessary context (`is_payment_gateway`, `current_feed`). This ensures that:
    - `gform_order` meta is created correctly.
    - Transaction Type is set to "1" (Sale).
    - Payment is fully recognized by Gravity Forms, triggering all "Payment Received" automations.

## Media
(Placeholder for user recordings/screenshots)
