# Configure the Mirkal app

Define your integration variables.

Before you install the Mirakl app, prepare a file with the variables outlined in this guide. To get started, you can copy our [sample configuration file](https://github.com/stripe/stripe-mirakl-connector/blob/master/.env.dist) and rename to `.env`.

## General settings

Configure the app’s general settings:

| Parameter                 | Description                                                                                                                                                                                                                                                                                      |
| ------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `APP_SECRET`              | To be generated. Commonly used to add more entropy to security related operations. Learn more on the [Symfony documentation](https://symfony.com/doc/current/reference/configuration/framework.html#secret).                                                                                     |
| `OPERATOR_PASSWORD`       | To be generated. Used to secure requests to the API exposed by the plugin. Set the `X-AUTH-TOKEN` header to this value when calling the API.                                                                                                                                                     |
| `DATABASE_URL`            | The connection URL to your database. Learn more on the [Doctrine documentation](https://www.doctrine-project.org/projects/doctrine-dbal/en/2.9/reference/configuration.html#connecting-using-a-url). For example, `pgsql://symfony:symfony@db:5432/symfony?charset=UTF-8`.                       |
| `MESSENGER_TRANSPORT_DSN` | The transport used for the queuing system. See the [Symfony Messenger documentation](https://symfony.com/doc/current/messenger.html#transports-async-queued-messages) for supported transports. For example, `amqp://guest:guest@localhost:5672/%2f/messages`. Defaults to `doctrine://default`. |
| `STRIPE_CLIENT_SECRET`    | Your Stripe API secret key available in your [API keys settings](https://dashboard.stripe.com/apikeys). We recommend creating a specific API key for the plugin. Restricted keys aren’t supported.                                                                                               |
| `MIRAKL_HOST_NAME`        | Host name of your Mirakl Instance. For example, `https://mymarketplace.mirakl.net`.                                                                                                                                                                                                              |
| `MIRAKL_API_KEY`          | The Mirakl operator key. Can be generated as a Mirakl operator in your API settings. We recommend creating a specific operator for the plugin.                                                                                                                                                   |

## Onboarding

Configure the app’s onboarding settings:

| Parameter                       | Description                                                                                                                                                                                                                                                                                                                                      |
| ------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `REDIRECT_ONBOARDING`           | The plugin redirects the seller to this URL after completing their account creation on Stripe. Defaults to `$MIRAKL_HOST_NAME/mmp/shop/account/shop`.                                                                                                                                                                                            |
| `BASE_HOST`                     | The domain of the server hosting your plugin. For example, `stripe-mirakl.example.com`.                                                                                                                                                                                                                                                          |
| `SCHEME`                        | The scheme used by your base host. Defaults to `https`.                                                                                                                                                                                                                                                                                          |
| `STRIPE_SELLERS_WEBHOOK_SECRET` | Your Stripe webhook secret available in your [Connect webhook settings](https://dashboard.stripe.com/workbench/webhooks) when adding the endpoint. See [Add a Stripe webhook endpoint for connected accounts](https://docs.stripe.com/use-stripe-apps/mirakl/configuration.md#add-a-stripe-webhook-endpoint-for-connected-accounts) for details. |
| `MIRAKL_CUSTOM_FIELD_CODE`      | Code of the custom field that you have to add, see below. Defaults to `stripe-url`.                                                                                                                                                                                                                                                              |

### Add a Stripe webhook endpoint for connected accounts

1. Go to your [webhook settings](https://dashboard.stripe.com/workbench/webhooks).

1. Add a *webhook* (A webhook is a real-time push notification sent to your application as a JSON payload through HTTPS requests) endpoint by clicking the **Add destination** button.

1. Select **Connected accounts** from the **Events from** options and select `account.updated` from the list of available events. Enter your desired Stripe API version. Click **Continue**.

1. Select **Webhook endpoint** from the list of available destination types. Click **Continue**.

1. Set the endpoint URL to `<BASE_HOST>/api/public/webhook/sellers` and fill out the remaining fields as desired.

1. Click **Create destination**.

1. Use the webhook secret for the `STRIPE_SELLERS_WEBHOOK_SECRET` environment variable.

### Add a custom field to your Mirakl shops

1. Log in to your Mirakl back office as an Operator.

1. Visit **Settings** > **Advanced Parameters** > **Shops**.

1. Go to **Custom Fields**.

1. Create a new field using the following values:

| Parameter         | Description                                                                 |
| ----------------- | --------------------------------------------------------------------------- |
| Code              | Use `stripe-url` unless you chose a different key in your environment file. |
| Type              | `Link`                                                                      |
| Shops permissions | `Read only`                                                                 |
| Required field    | `No`                                                                        |

## Payments

Configure the app’s payment settings:

| Parameter                              | Description                                                                                                                                                                                                                                                                                                                                           |
| -------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `PAYMENT_METADATA_COMMERCIAL_ORDER_ID` | Metadata key used in Charges to convey the Mirakl commercial order ID. Defaults to `mirakl_commercial_order_id`.                                                                                                                                                                                                                                      |
| `ENABLE_PRODUCT_PAYMENT_SPLIT`         | Enable the [payment split workflow](https://docs.stripe.com/use-stripe-apps/mirakl/payments.md#payment-split) for product orders. Defaults to `false`.                                                                                                                                                                                                |
| `NABLE_SERVICE_PAYMENT_SPLIT`          | Enable the [payment split workflow](https://docs.stripe.com/use-stripe-apps/mirakl/payments.md#payment-split) for service orders. Defaults to `false`.                                                                                                                                                                                                |
| `ENABLE_PRODUCT_PAYMENT_REFUND`        | Enable the [payment refund workflow](https://docs.stripe.com/use-stripe-apps/mirakl/payments.md#payment-refund) for product orders. Defaults to `false`.                                                                                                                                                                                              |
| `ENABLE_SERVICE_PAYMENT_REFUND`        | Enable the [payment refund workflow](https://docs.stripe.com/use-stripe-apps/mirakl/payments.md#payment-refund) for service orders. Defaults to `false`.                                                                                                                                                                                              |
| `STRIPE_OPERATOR_WEBHOOK_SECRET`       | Your Stripe webhook secret is available in your [account event destination details page](https://dashboard.stripe.com/workbench/webhooks) when adding the endpoint. See [Add a Stripe webhook endpoint for your account](https://docs.stripe.com/use-stripe-apps/mirakl/configuration.md#add-a-stripe-webhook-endpoint-for-your-account) for details. |

### Add a Stripe webhook endpoint for your account

1. Go to your [webhook settings](https://dashboard.stripe.com/workbench/webhooks).

1. Add a *webhook* (A webhook is a real-time push notification sent to your application as a JSON payload through HTTPS requests) endpoint by clicking the **Add destination** button.

1. Select **Your account** from the **Events from** options and select `charge.succeeded` and `charge.updated` from the list of available events. Enter your desired Stripe API version. Click **Continue**.

1. Select **Webhook endpoint** from the list of available destination types. Click **Continue**.

1. Set the endpoint URL to `<BASE_HOST>/api/public/webhook/operator` and fill out the remaining fields as desired.

1. Click **Create destination**.

1. Use the webhook secret for the `STRIPE_OPERATOR_WEBHOOK_SECRET` environment variable.

## Notifications and alerting 

Configure the app’s notifications and alerting settings:

| Parameter                                     | Description                                                                                                                                                                                                                                                                |
| --------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `MAILER_DSN`                                  | The entire Symfony Mailer configuration using a DSN-like URL format. Learn more on the [Symfony documentation](https://symfony.com/doc/current/components/mailer.html#mailer-dsn). For example, `smtp://user:pass@host:port`. Defaults to `smtp://null` (mailer disabled). |
| `TECHNICAL_ALERT_EMAIL`                       | The recipicient of all technical alerts. For example, `myemail@example.com`. Defaults to empty. Required if mailer is enabled per `MAILER_DSN`.                                                                                                                            |
| `TECHNICAL_ALERT_EMAIL_FROM`                  | The sender of all technical emails. Defaults to empty, required if mailer is configured. For example, `noreply@example.com`.                                                                                                                                               |
| `OPERATOR_NOTIFICATION_URL`                   | The endpoint on your server set to receive notifications from the plugin. Defaults to empty (notifications disabled).                                                                                                                                                      |
| `MAIL_ON_NOTIFICATION_ENDPOINT_DOWN`          | Enable email alerts if a URL is provided in `OPERATOR_NOTIFICATION_URL` and that URL isn’t available or responds with an error. Defaults to `true`.                                                                                                                        |
| `MAIL_ON_NOTIFICATION_ENDPOINT_DOWN_COOLDOWN` | Time between each email alert. Use `0` to disable throttling. The maximum value depends on the notification worker maximum life, that is, `3600` by default. Defaults to `10`.                                                                                             |
