> For the complete documentation index, see [llms.txt](https://aplazo.gitbook.io/aplazo-integrations/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://aplazo.gitbook.io/aplazo-integrations/plugins/magento.md).

# Magento

### Payment Flow

The following diagram illustrates the interaction between the **Customer**, **Magento**, and **Aplazo** during the checkout process.

#### Flow Summary

1. The customer selects **Aplazo** as the payment method at checkout and clicks **Pay**.
2. Magento generates an order using the customer's cart and sends a request to Aplazo to create a corresponding order.
3. Aplazo receives the payload, creates the order, and returns a checkout URL in the response.
4. Magento redirects the customer to the Aplazo checkout URL.
5. The customer completes the payment in Aplazo's checkout.
6. Once the payment is confirmed, Aplazo notifies Magento via a **webhook**.
7. Magento receives the webhook and updates the order status from **Pending** to **Processing**.
8. Aplazo redirects the customer to the **Success Page URL** (included in the original order payload).
9. The customer sees the Thank You (Success) page with order details.

***

```mermaid
sequenceDiagram
    participant C as Customer
    participant M as Magento
    participant A as Aplazo

    C->>M: Selects Aplazo as payment method<br/>and clicks "Pay"
    M->>M: Generates an order using<br/>the customer's cart
    M->>A: Sends request to create<br/>an order in Aplazo
    A->>A: Receives the payload<br/>and creates an order
    A-->>M: Returns an Aplazo checkout<br/>URL in the response
    M-->>C: Redirects the customer<br/>to the Aplazo checkout URL
    C->>A: Completes payment in<br/>Aplazo's checkout
    A->>M: Payment confirmed —<br/>notifies Magento via Webhook
    M->>M: Moves the order from<br/>"Pending" to "Processing"
    A-->>C: Redirects to the Success Page URL<br/>included in the original payload
    Note over C: Customer sees the Thank You<br/>(Success) page with order details
```

### Installation

From the Magento project root, run the following commands in order:

1. **Install the package:**

   ```bash
   composer require aplazo/aplazopayment
   ```
2. **Enable the module:**

   ```bash
   bin/magento module:enable Aplazo_AplazoPayment
   ```
3. **Deploy and compile the environment:**

   ```bash
   bin/magento setup:upgrade
   bin/magento setup:di:compile
   bin/magento setup:static-content:deploy en_US es_MX
   bin/magento cache:flush
   ```

***

### Configuration

1. Navigate to **Stores → Configuration → Sales → Payment Methods**.
2. Under the **Other Payment Methods** section, locate **Aplazo**.
3. Click **Configure** to expand the available options.

<figure><img src="/files/uySbt1t0sDFH1lEQqCVm" alt=""><figcaption></figcaption></figure>

Once the options are displayed, you will need to configure the credentials and the variables supported by the payment method.

#### Credentials

Go to the **Credentials** section and fill in the required fields. The **Merchant ID** and **API Token** will be provided by Aplazo.

<figure><img src="/files/U8to0D4T2H2DXzqaIruJ" alt=""><figcaption></figcaption></figure>

> Once valid credentials are saved, you will be able to configure the remaining variables.

***

### Configurable Variables

Beyond Credentials, there are three additional sections: **General**, **Aplazo Checkout Abandonment**, and **Test & Debug**.

#### General

<figure><img src="/files/7ruvSgOCsj9L4MVxvh6Q" alt=""><figcaption></figcaption></figure>

| Variable                                                                  | Description                                                                                                                                                                                                                                                        |
| ------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| **Activar** (Enable)                                                      | Set to **Yes** to enable Aplazo as a payment method in the checkout.                                                                                                                                                                                               |
| **Posición en el checkout** (Checkout position)                           | Defines the display priority of Aplazo relative to other payment methods. A lower value means higher priority.                                                                                                                                                     |
| **Estado de orden nueva** (New order status)                              | The status assigned to the Magento order at the moment of creation (e.g., *Pending*).                                                                                                                                                                              |
| **Estado de orden aprobada** (Approved order status)                      | The status the order transitions to once Aplazo confirms payment via webhook (e.g., *Processing*).                                                                                                                                                                 |
| **Estado de orden rechazada** (Rejected order status)                     | The status assigned to the order if the payment is not completed successfully.                                                                                                                                                                                     |
| **Reservar stock** (Stock reservation)                                    | **Yes:** Stock is reserved (not decremented) in Magento until the order is fully paid and confirmed via webhook. **No:** Stock is decremented as soon as the order is created, regardless of whether the payment is completed.                                     |
| **Tiempo en que se cancelan las órdenes** (Auto-cancel order timeout)     | A cron process will automatically cancel all orders that remain in the "New order status" after the specified time period.                                                                                                                                         |
| **Mostrar widget en página de producto** (Display widget on product page) | Controls whether the Aplazo promotional widget is displayed on product pages.                                                                                                                                                                                      |
| **Mostrar widget en página de carrito** (Display widget on cart page)     | Controls whether the Aplazo promotional widget is displayed on the cart page.                                                                                                                                                                                      |
| **Habilitar reembolsos** (Enable refunds)                                 | Enables or disables refund processing. When enabled, creating a **Credit Memo** in Magento will send a refund request to Aplazo (partial or full).                                                                                                                 |
| **Enviar correo de confirmación** (Order confirmation email)              | Configures when Magento sends the order confirmation email: **Yes (Sí):** The email is sent only after the order is confirmed by Aplazo. **No:** The email is sent as soon as the customer is redirected to Aplazo's checkout (i.e., before payment confirmation). |

#### Aplazo Checkout Abandonment

<figure><img src="/files/TblgYLAQl0oVPS2lGu0c" alt=""><figcaption></figcaption></figure>

| Variable                                                                                            | Description                                                                                                                                                                                                                                            |
| --------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| **Cancelar orden si el usuario abandona checkout de Aplazo** (Cancel order on checkout abandonment) | Magento creates the order before redirecting the customer to Aplazo's offsite checkout. If the customer does not complete the payment, the order remains in Pending status. Setting this to **Yes** will automatically cancel the order in such cases. |
| **Mensaje a mostrar** (Message to display)                                                          | The message shown to the customer if they return from Aplazo's checkout to Magento without completing the payment.                                                                                                                                     |
| **Recuperar carrito al regresar de checkout de Aplazo** (Recover cart on return)                    | When enabled, the plugin attempts to recover the products from the pending order and rebuild the customer's cart, so it remains consistent upon return to Magento.                                                                                     |

#### Test & Debug

<figure><img src="/files/iDkzvyMkglTQ89ERqf9k" alt=""><figcaption></figcaption></figure>

| Variable                       | Description                                                                                                                                                                                                                                                    |
| ------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **Check Healthy Site**         | Should remain set to **No** under normal circumstances. When set to **Yes** and saved, a series of communication tests with Aplazo are executed. Results are logged in `var/log/aplazo_payment/info.log`. Useful for diagnosing connectivity or module issues. |
| **Activar logs** (Enable logs) | It is recommended to enable the **Important Logs** option, which records key events from the Aplazo payment process into `var/log/aplazo_payment/info.log`.                                                                                                    |

> **Important:** After making any changes, click **Save** to confirm and apply the configuration.
