# AddPay Payment Gateway Plugin

## Overview

The AddPay Payment Gateway is a WooCommerce plugin that integrates AddPay's payment processing service into your WordPress online store. It enables merchants to securely accept payments via methods like credit cards and mobile payments (e.g., ScanToPay) by redirecting customers to a hosted checkout page. The plugin handles payment initiation, RSA-SHA256 signature generation, and transaction status updates, ensuring a secure and seamless payment experience for merchants and customers.

## Installation for Users

1. **Sign up for AddPay**:

    - Go to [https://onboarding.addpay.cloud/merchant/onboarding](https://onboarding.addpay.cloud/merchant/onboarding) and create an account.
    - Log in to the AddPay administration console at [https://mp.paycloud.africa/user/login](https://mp.paycloud.africa/user/login).
    - Navigate to settings and retrieve your **Private Key**, **Application ID**, **Merchant ID**, and **Store ID**.

2. **Automatic Install**:

    - In WordPress Admin, go to Plugins > Add New and search for "AddPay".
    - Click "Install Now" and activate the plugin.
    - Go to plugin settings, enter your **Private Key**, **Application ID**, **Merchant ID**, and **Store ID**, and save.
    - Test the checkout process with a product, selecting AddPay as the payment method.

3. **Manual Install**:
    - Download the plugin: [AddPay WooCommerce](https://github.com/AddPay/woo_addpay_gateway/archive/refs/heads/master.zip).
    - In WordPress Admin, go to Plugins > Add New, click "Upload Plugin", and select the downloaded .zip file.
    - Click "Install Now" and activate the plugin.
    - Go to plugin settings, enter your **Private Key**, **Application ID**, **Merchant ID**, and **Store ID**, and save.
    - Test the checkout process with a product, selecting AddPay as the payment method.

## Developer Setup

### Prerequisites

- **NPM**: For managing JavaScript dependencies and build scripts. [Install NPM](https://www.npmjs.com/)
- **Composer**: For managing PHP dependencies. [Install Composer](https://getcomposer.org/download/)
- **wp-env**: For running a local WordPress environment. [Learn about wp-env](https://developer.wordpress.org/block-editor/reference-guides/packages/packages-env/)
- **PHP**: Required to run WordPress and the plugin.

### Installation and Setup

1. **Clone the Repository**:

    ```bash
    git clone https://github.com/ZonicaP/AddPay-Woocommerce-Gateway.git
    cd woo_addpay_gateway
    ```

2. **Install Dependencies and Build Plugin**:

    ```bash
    composer install
    npm install
    npm run build
    wp-env start
    ```

3. **Test using LocalWP (Optional)**:
    - Download [LocalWP](https://localwp.com/).
    - Create a new site or import an existing site .zip file to test the plugin in a local WordPress environment.

### Running Tests

The plugin includes a test suite built with PHPUnit to verify functionality.

1. **Install Dependencies**:
   Ensure dependencies are installed (run `composer install` and `npm install` if not already done).

2. **Run the Test Suite**:

    ```bash
    npm run test
    ```

    - This executes `./vendor/bin/phpunit`, running all tests in `Test_AddPay_Gateway`.
    - For detailed output (e.g., to debug failures):
        ```bash
        npm run test -- --debug
        ```

3. **Test Output**:
    - Tests are located in the test suite and cover key functionality like payment processing, webhook handling, and payload signing.
    - A successful run will show all tests passing with no errors. An exit code of 0 indicates success.

### Building the Plugin

To create a distributable .zip file for the plugin:

```bash
npm run build
npm run plugin-zip
```

## Contributing

Contributions are welcome! Please submit pull requests or issues to the [GitHub repository](https://github.com/AddPay/woo_addpay_gateway).

## License

This plugin is licensed under the [GPLv2 or later](http://www.gnu.org/licenses/gpl-2.0.html).
