## Overview

The Reservepay WooCommerce plugin lets you accept payments on your WordPress store using Reservepay's pre-built payment form. The plugin handles the full checkout flow — redirecting customers to a secure payment page, processing the payment via the Reservepay API, and returning them to your order confirmation page.

The plugin supports both the classic WooCommerce checkout and the block-based checkout editor.

## Prerequisites

Before installing the plugin, make sure you have the following:

* **WordPress 5.0 or higher** and **PHP 7.0 or higher**
* **WooCommerce** installed and activated
* **Pretty permalinks enabled** — go to Settings > Permalinks in your WordPress admin and select any option other than "Plain"
* **A Reservepay merchant account** with the following credentials (available in your merchant dashboard under developer settings):
  * **Merchant ID**
  * **Installation ID** — create an SDK installation for your website
  * **API Key** — create a new API key and keep it secret

## Installation

1. [Download the Reservepay WooCommerce plugin](/downloads/reservepay-woocommerce.zip).
2. In your WordPress admin, go to **Plugins > Add New > Upload Plugin**.
3. Select the ZIP file and click **Install Now**.
4. Click **Activate Plugin**.

Alternatively, you can upload the plugin folder via FTP to `wp-content/plugins/` and activate it from the Plugins page.

## Configuration

After activation, go to **WooCommerce > Settings > Payments**. You will see **Reservepay** listed as a payment method. Click **Manage** to configure it.

* **Enable/Disable** — Check to enable Reservepay as a payment option at checkout.
* **Title** — The payment method name displayed to customers during checkout. Defaults to "Reservepay".
* **Description** — Optional text shown to customers when they select this payment method.
* **Installation ID** — Your Reservepay Installation ID from the merchant dashboard.
* **Merchant ID** — Your Reservepay Merchant ID from the merchant dashboard.
* **API Key** — Your secret Reservepay API key. This is used server-side to authenticate requests to the Reservepay API. Never share this key publicly.

Click **Save changes** when done.

## How it works

When a customer selects Reservepay at checkout and places their order, the following flow occurs:

1. **Redirect to payment page** — WooCommerce redirects the customer to `/reservepay-page`, a custom page created by the plugin. The Reservepay SDK loads and renders an embedded payment form.

2. **Payment session created** — When the form initializes, the SDK fires `onPaymentSessionReady` with a `payment_session_id`. The plugin sends this to your WordPress backend via a REST API call.

3. **Initiate payment flow** — Your backend calls `merchants/initiate-payment-flow` with the session ID, order amount, and currency, authenticated with your API key. The returned `payment_id` is stored on the order.

4. **Customer completes payment** — The customer enters their payment details in the embedded form. On success, the SDK fires `onPaymentSuccess`.

5. **Verify and complete** — The plugin calls `merchants/find-payment` from the backend to verify the payment status. If the status is `SUCCESSFUL`, the order is marked as paid and the customer is redirected to the order confirmation page.

If the payment fails at any point, the customer is redirected back to the checkout page to try again.

## Testing

To verify your integration is working:

1. Enable the Reservepay payment method in WooCommerce settings.
2. Add a product to your cart and proceed to checkout.
3. Select **Reservepay** as the payment method and place the order.
4. Confirm you are redirected to the payment form page.
5. Complete a test payment and verify:
   * You are redirected to the order confirmation page.
   * The order status in WooCommerce is updated to "Processing" or "Completed".
   * The order notes show "Reservepay payment completed successfully."
