# External Payment Solutions and MT4 Account Lifecycle

## External payment links

Administrators manage external payment destinations from:

```text
Admin → Settings → CMS → External Payments
```

Each entry contains:

- Label
- HTTP or HTTPS URL

Entries can be added, removed and reordered. The client navigation displays **External Payment Solutions** only after the authenticated client owns at least one local MT4 account. The destination opens in a new tab with `noopener`, `noreferrer` and `nofollow`; the platform does not collect credentials entered on the third-party site.

## Duplicate account-creation protection

Administrator MT4 account creation has three layers:

1. The first form submission disables the full page until the request completes.
2. A per-client server lock rejects overlapping account-creation requests.
3. A per-form idempotency token rejects a replay of an already completed request.

The request is released after a failed response so the administrator can correct the form and retry.

## New-account activation

Before creating the account, the selected local MT4 group must be active and an explicit remote `Enabled=false` group response is rejected. After `CreateAccount`, the application:

1. Reconciles the requested leverage.
2. Reads the account through `GetAccount`.
3. Calls `enable_disable_trade_account` with `action=1` unless the authoritative account response already confirms `Enabled=true`.
4. Retries `GetAccount` and stores the complete account snapshot.

String values such as `"false"` and `"0"` are parsed as false rather than being cast with PHP's normal string-to-boolean behavior.

## Account removal

From the administrator client profile, **Disable & Delete** performs this sequence:

1. Reads the account state from MT4.
2. If necessary, calls `enable_disable_trade_account` with `action=0`.
3. Re-reads the account until MT4 confirms `Enabled=false`.
4. Deletes the local `client_mt5_accounts` record.
5. Assigns another remaining account as primary when required.

If the provider does not confirm the disabled state, the local record is retained so the administrator can safely retry.
