# Install the Mirakl app

Set up the Miraki app for Stripe.

To install and run the Mirakl app, you must meet the following requirements:

- PHP 7.3+
- PostgreSQL
- A web server (Nginx recommended)
- A valid SSL or *TLS* (TLS refers to the process of securely transmitting data between the client—the app or browser that your customer is using—and your server. This was originally performed using the SSL (Secure Sockets Layer) protocol) certificate
- Supervisord or an equivalent process manager
- Crontab or an equivalent task scheduler

## Use Docker 

You can build and start the application by embedding it in a container. See our [Docker sample](https://github.com/stripe/stripe-mirakl-connector/tree/master/examples/docker) for more information.

## Use Composer 

1. Install [Composer](https://getcomposer.org/download/).

1. Clone or download the [Mirakl app](https://github.com/stripe/stripe-mirakl-connector.git) from GitHub.

1. Move the content to your web server directory (for example, `/var/www`).

1. Download dependencies:

   ```bash
   composer install --prefer-dist --no-dev
   ```

1. Properly configure the [.env file](https://docs.stripe.com/use-stripe-apps/mirakl/configuration.md).

1. Run the migrations to set up the database. If you encounter any errors at this stage, check the `DATABASE_URL` variable in your .env file.

   ```bash
   bin/console doctrine:migration:migrate --no-interaction
   ```

1. Update your supervisor to automatically start and restart the workers. A [configuration example](https://github.com/stripe/stripe-mirakl-connector/blob/master/examples/docker/app/config/supervisord.conf) is available in our Docker sample. You can skip this step in a development environment and start the workers manually when needed, for example:

   ```bash
   php bin/console messenger:consume process_transfers --time-limit=3600 --env=prod
   ```

1. Update your job scheduler to run the commands periodically. A [configuration example](https://github.com/stripe/stripe-mirakl-connector/blob/master/examples/docker/app/config/crontab) is available in our Docker sample. You can skip this step in a development environment and start the jobs manually when needed, for example:

   ```bash
   php bin/console connector:dispatch:process-transfer -q 2>&1
   ```

1. Make sure that your web server is configured to use the `public` directory as document root.

## Test your installation

Open your terminal and run the following command to confirm that your application is up and running correctly:

```bash
curl -X GET "https://app-url/api/mappings" \
  -H "accept: application/json" \
  -H "X-AUTH-TOKEN: $OPERATOR_PASSWORD" # Generated during the configuration.
```

You should get a `200` response code along with an empty payload.

## Restrict inbound traffic 

On your server, *restrict all inbound traffic* to the plugin except for the following endpoints:

- `/api/public/onboarding/refresh`: Stripe redirects the seller to this URL to get a new onboarding link if it expires.

- `/api/public/webhook/operator`:  Stripe notifies this endpoint when a payment is updated to map it with a Mirakl order within the app.

- `/api/public/webhook/sellers`: Stripe notifies this endpoint when a Stripe account is updated to synchronize the seller’s status within the app.

These endpoints are safe to expose, because they each have an internal protection mechanism. Other endpoints aren’t safe to expose unless protected by a strong `OPERATOR_PASSWORD`.
