# Install Merchant Account

> Connect a payment provider to your Telegram or Discord subscription bot using its project API key and provider credentials.

Source: https://docs.botsubscription.com/api/merchant-accounts/install/

Connect a payment provider to your <strong>Telegram subscription bot</strong> or <strong>Discord subscription bot</strong>. Start with [provider discovery](https://docs.botsubscription.com/api/merchant-accounts/list/) to get this project's available providers and their current installation requirements.

<ApiEndpoint method="POST" endpoint="/v2/projects/{project_id}/merchant-accounts" />

<ApiAuthorization type="Bearer API Key" />

**API key access:** Unrestricted project API key required. Restricted keys cannot call this endpoint.

**Retries:** save the initial response. Completed keyed successes are not replayed; a repeated `Idempotency-Key` returns `409 IDEMPOTENCY_RESPONSE_NOT_REPLAYABLE`. Check account state before starting another installation attempt.

<ApiSection title="Path Parameters">
  <ApiParameter name="project_id" type="string" required description="The unique identifier of the project." />
</ApiSection>

<ApiSection title="Request Body">
  <ApiParameter name="provider" type="string" required description="Provider ID returned as a key in the discovery response's data object. Availability depends on the project." />
  <ApiParameter name="environment" type="string" description="Required when discovery reports multiple_environments_supported: true; use sandbox or production. Omit it for production-only providers." />
  <ApiParameter name="label" type="string|null" description="Optional label (3–120 characters), or null. For generated labels, use ASCII letters/digits, spaces, hyphens, underscores or dots, starting and ending with a letter/digit." />
</ApiSection>

## Discover installation fields

Call `GET /v2/projects/{project_id}/merchant-accounts` before building the installation request. Each key in its `data` object is a provider ID; that provider's entry describes the fields to collect:

| Discovery field | How to use it |
| --- | --- |
| `required_params` | Declared credential field names. Some may be optional; also check `optional_params`. |
| `optional_params` | Optional field names, when supplied. Collect these only when needed. |
| `credential_help` | Optional translated instructions keyed by credential name; guidance may not cover every field. |
| `multiple_environments_supported` | Whether to send `environment` with `sandbox` or `production`. |

Fields listed in `required_params` but absent from `optional_params` are required. Treat an omitted `optional_params` as an empty list. Use the returned field names exactly.

Add the selected provider's credential fields as **top-level string fields** alongside `provider`, `environment` and `label`. For example, the Stripe request below uses `stripe_secret_key`. Credential names come from discovery, so new providers can be supported without maintaining a separate field list.

Send the fields advertised for the selected provider. Unsupported installation fields return `422 VALIDATION_ERROR`.

When `multiple_environments_supported` is `true`, omitting `environment` returns `400 BAD_REQUEST`. An invalid value returns `422 VALIDATION_ERROR`. When the flag is `false`, omit the field: the provider is production-only, and sending `sandbox` does not enable a sandbox environment.

Use the returned `merchant_account_id` with [Get Merchant Account](https://docs.botsubscription.com/api/merchant-accounts/get/) to retrieve account details. If `webhook_setup` is present, finish the provider setup using its instructions. `webhook_recovery`, when returned, identifies webhooks removed during provider-capacity recovery; review `deleted_foreign` for other integrations that may need reconfiguration.

When the credentials already belong to an account in this project, installation returns `422 VALIDATION_ERROR` with `error.reason: "DUPLICATE_CREDENTIALS"`. Each `error.details` entry identifies the existing `merchant_account_id` and its `active` state. Use that ID to inspect the existing connection; changing the label does not create a separate connection for the same credentials.

<ApiSamplePane>

<ApiRequestSample title="Request">

```bash
curl -X POST "https://api.botsubscription.com/v2/projects/YOUR_PROJECT_ID/merchant-accounts" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "provider": "stripe",
    "stripe_secret_key": "sk_live_...",
    "environment": "production"
  }'
```

```javascript
const project_id = 'YOUR_PROJECT_ID';
const response = await fetch(`https://api.botsubscription.com/v2/projects/${project_id}/merchant-accounts`, {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer YOUR_API_KEY',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    provider: 'stripe',
    stripe_secret_key: 'sk_live_...',
    environment: 'production'
  })
});
const data = await response.json();
```

```python
import requests

project_id = 'YOUR_PROJECT_ID'
response = requests.post(
    f'https://api.botsubscription.com/v2/projects/{project_id}/merchant-accounts',
    headers={
        'Authorization': 'Bearer YOUR_API_KEY',
        'Content-Type': 'application/json'
    },
    json={
        'provider': 'stripe',
        'stripe_secret_key': 'sk_live_...',
        'environment': 'production'
    }
)
data = response.json()
```

```php
$project_id = 'YOUR_PROJECT_ID';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.botsubscription.com/v2/projects/{$project_id}/merchant-accounts");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    'Authorization: Bearer YOUR_API_KEY',
    'Content-Type: application/json'
]);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([
    'provider' => 'stripe',
    'stripe_secret_key' => 'sk_live_...',
    'environment' => 'production'
]));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
```

</ApiRequestSample>

<ApiResponseTabs>
  <ApiResponse status={201} description="Merchant account installed">

```json
{
  "ok": true,
  "request_id": "11111111-1111-1111-1111-111111111111",
  "method": "POST",
  "path": "/v2/projects/11111111-1111-4111-8111-111111111111/merchant-accounts",
  "code": 201,
  "message": "Merchant account installed successfully",
  "data": {
    "merchant_account_id": "11111111-1111-4111-8111-111111111111",
    "webhook_verification": {
      "required": false,
      "mode": "auto",
      "status": "not_required",
      "verification_method": null,
      "verification_supported": false,
      "can_mark_verified": false,
      "action_required": false
    }
  }
}
```

  </ApiResponse>
  <ApiResponse status={201} description="Installation requires manual provider webhook setup">

```json
{
  "ok": true,
  "request_id": "11111111-1111-1111-1111-111111111111",
  "method": "POST",
  "path": "/v2/projects/11111111-1111-4111-8111-111111111111/merchant-accounts",
  "code": 201,
  "message": "Merchant account installed successfully",
  "data": {
    "merchant_account_id": "22222222-2222-4222-8222-222222222222",
    "webhook_verification": {
      "required": true,
      "mode": "manual",
      "status": "pending",
      "verification_method": "webhook_arrival",
      "verification_supported": true,
      "can_mark_verified": false,
      "action_required": true
    },
    "webhook_setup": {
      "required": true,
      "mode": "manual",
      "status": "pending",
      "webhook_url": "https://api.example.com/v2/ipn/11111111-1111-4111-8111-111111111111/frisbii/22222222-2222-4222-8222-222222222222",
      "instructions": [
        {
          "step": 1,
          "text": "Open the Frisbii admin and go to Developers \u2192 Webhooks, or use the button below. New accounts have webhooks turned off; turn them on."
        },
        {
          "step": 2,
          "text": "Add the Webhook URL shown above to the webhook URL list. Keep any existing URLs: every listed URL receives each event."
        },
        {
          "step": 3,
          "text": "Select at least these events: invoice_authorized, invoice_settled, invoice_failed, invoice_cancelled, invoice_refund, invoice_refund_failed and every invoice_dispute event. Then save."
        },
        {
          "step": 4,
          "text": "Copy the webhook secret from the same page and paste it here with Enter Webhook Secret."
        },
        {
          "step": 5,
          "text": "After the secret is saved, resend a recent event from the webhook log (or make a test payment). The first signed delivery verifies this account."
        }
      ],
      "dashboard_url": "https://admin.frisbii.com/",
      "missing_credentials": [
        "frisbii_webhook_secret"
      ]
    }
  }
}
```

  </ApiResponse>
  <ApiResponse status={201} description="Installation recovered provider webhook capacity">

```json
{
  "ok": true,
  "request_id": "11111111-1111-1111-1111-111111111111",
  "method": "POST",
  "path": "/v2/projects/11111111-1111-4111-8111-111111111111/merchant-accounts",
  "code": 201,
  "message": "Merchant account installed successfully",
  "data": {
    "merchant_account_id": "11111111-1111-4111-8111-111111111111",
    "webhook_verification": {
      "required": false,
      "mode": "auto",
      "status": "not_required",
      "verification_method": null,
      "verification_supported": false,
      "can_mark_verified": false,
      "action_required": false
    },
    "webhook_recovery": {
      "deleted_orphans": [
        {
          "id": "wh_example_orphan",
          "url": "https://api.example.com/webhooks/old-example"
        }
      ],
      "deleted_foreign": [
        {
          "id": "wh_example_other",
          "url": "https://other-integration.example.com/…"
        }
      ]
    }
  }
}
```

  </ApiResponse>
  <ApiResponse status={400} description="Invalid credentials">

```json
{
  "ok": false,
  "request_id": "11111111-1111-1111-1111-111111111111",
  "method": "POST",
  "path": "/v2/projects/11111111-1111-4111-8111-111111111111/merchant-accounts",
  "code": 400,
  "error": {
    "error_code": "BAD_REQUEST",
    "message": "Invalid Stripe credentials"
  }
}
```

  </ApiResponse>
  <ApiResponse status={422} description="Validation error">

```json
{
  "ok": false,
  "request_id": "11111111-1111-1111-1111-111111111111",
  "method": "POST",
  "path": "/v2/projects/11111111-1111-4111-8111-111111111111/merchant-accounts",
  "code": 422,
  "errors": [
    {
      "message": "Invalid environment: must be one of: sandbox, production",
      "error_code": "VALIDATION_ERROR"
    }
  ]
}
```

  </ApiResponse>
  <ApiResponse status={422} description="Duplicate credentials">

```json
{
  "ok": false,
  "request_id": "11111111-1111-1111-1111-111111111111",
  "method": "POST",
  "path": "/v2/projects/11111111-1111-4111-8111-111111111111/merchant-accounts",
  "code": 422,
  "error": {
    "error_code": "VALIDATION_ERROR",
    "message": "A merchant account with identical credentials already exists in this project (merchant account 11111111-1111-4111-8111-111111111111, currently active)",
    "reason": "DUPLICATE_CREDENTIALS",
    "details": [
      {
        "merchant_account_id": "11111111-1111-4111-8111-111111111111",
        "active": true
      }
    ]
  }
}
```

  </ApiResponse>
  <ApiResponse status={401} description="Invalid or expired API key">

```json
{
  "ok": false,
  "request_id": "44444444-4444-4444-8444-444444444444",
  "method": "POST",
  "path": "/v2/projects/11111111-1111-4111-8111-111111111111/merchant-accounts",
  "code": 401,
  "error": {
    "message": "Invalid or expired authentication token.",
    "error_code": "UNAUTHORIZED"
  }
}
```

  </ApiResponse>
</ApiResponseTabs>

</ApiSamplePane>
