# Mangopay

Source: https://docs.formance.com/modules/payments/connectors/psp/mangopay

Stack: v3.2

The Mangopay connector polls a Mangopay client and surfaces multi-currency e-wallets, balances, bank accounts (external), and transactional events. It also initiates transfers and payouts, registers bank accounts, and ingests webhooks.

## Prerequisites

You need a Mangopay client and an API key pair. Mangopay uses HTTP Basic Auth (`clientID:apiKey`); the connector sets the header on every request.

Make sure to create an API key dedicated to Formance. Doing so will improve your auditability and security and will allow you to revoke access to Formance at any time if needed.

## Installation

curl

```bash
curl -X POST $FORMANCE_API_URL/api/payments/v3/connectors/install/mangopay \
  -H "Content-Type: application/json" \
  -d @'config.json'
```

fctl

```bash
fctl payments connectors install mangopay config.json
```

### Configuration fields

| Field         | Type    | Required | Default |
| ------------- | ------- | -------- | ------- |
| apiKey        | string  | true     |         |
| clientID      | string  | true     |         |
| endpoint      | string  | true     |         |
| pageSize      | integer | false    | 25      |
| pollingPeriod | string  | false    | 30m     |

`endpoint` is `https://api.mangopay.com` for production,
`https://api.sandbox.mangopay.com` for sandbox.

## Capabilities

- `FETCH_ACCOUNTS` — e-wallets, grouped by `UserId`.
- `FETCH_BALANCES` — per-wallet balance via Mangopay's `Balance` resource.
- `FETCH_EXTERNAL_ACCOUNTS` — bank accounts attached to each user.
- `FETCH_PAYMENTS` — payins, transfers, payouts, refunds, and disputes, unified into `PSPPayment`.
- `FETCH_OTHERS` — KYC documents and mandates, surfaced under `mangopay-*` on `v3ListPaymentsOther`.
- `CREATE_BANK_ACCOUNT` — IBAN / US / GB / CA / OTHER variants.
- `CREATE_TRANSFER` — wallet-to-wallet via `POST /transfers`.
- `CREATE_PAYOUT` — wallet-to-bank-account via `POST /payouts/bankwire`.
- `CREATE_WEBHOOKS` + `TRANSLATE_WEBHOOKS` — one hook per consumed `EventType`.

## Account model

Every Payments internal account is one Mangopay **e-wallet** (single-currency, scoped to a `UserId`). The `reference` is the wallet ID; `defaultAsset` is the wallet's currency at ISO 4217 precision. Accounts are emitted per user (one fetch cycle per user from the workflow's parent payload). EXTERNAL accounts come from `/users/{UserId}/bankaccounts`; `v3CreateBankAccount` registers new ones (IBAN / US / GB / CA / OTHER). See [Accounts](https://docs.formance.com/modules/payments/accounts) for the cross-connector model.

## Asset model

Multi-currency (EUR / USD / GBP, …), formatted to UMN at ISO 4217 precision. Amounts are already in minor units — no scaling.

## Status mapping

| Mangopay `Status` (Transactions) | Payment `status` |
| -------------------------------- | ---------------- |
| `CREATED`, `IN_PROGRESS`         | `PENDING`        |
| `SUCCEEDED`                      | `SUCCEEDED`      |
| `FAILED`                         | `FAILED`         |
| `CANCELLED`                      | `CANCELLED`      |

`CREATE_*` initiations schedule `PollTransferStatus` / `PollPayoutStatus` against the relevant endpoint until terminal.

## Metadata keys

Under `com.mangopay.spec/`:

- **Account**: `wallet_id`, `description`, `owners` (comma-joined `UserId` list), `currency`.
- **External account**: `bank_account_id`, `type` (`IBAN` / `US` / `GB` / `CA` / `OTHER`), `iban`, `bic`, `owner_name`, `owner_address`.
- **Payment**: `transaction_id`, `transaction_type` (`PAYIN` / `PAYOUT` / `TRANSFER` / `REFUND`), `nature` (`REGULAR` / `REPUDIATION` / `REFUND` / `SETTLEMENT`), `result_code`, `result_message`.

Bank-account creation uses `com.mangopay.spec/bank_account_type` on the `v3CreateBankAccount` body to select the variant (default `IBAN`).

## Workflow tree

```text
FetchAccounts (periodic) — paginated over UserList → WalletList
  ├── FetchBalances (FromPayload — no extra API call)
  └── FetchPayments (periodic) — per wallet
FetchExternalAccounts (periodic) — per user
FetchOthers (periodic) — KYC docs, mandates
CreateBankAccount / CreateTransfer / CreatePayout (event-driven)
  └── PollTransferStatus / PollPayoutStatus until terminal
CreateWebhooks (one-shot at install) — one hook per EventType
```

## Pagination and recovery

1-indexed `Page` + `Per_Page` (max 100). The connector persists the watermark per stream in platform-managed `State`. Webhook deliveries dedupe by `(EventType, ResourceId)` against `PSPPayment.Reference`.

## Known gaps

- **Pre-authorizations**: not surfaced; only successful captures land as `PSPPayment`s.
- **Disputes**: arrive via webhooks as `PSPPayment` rows tagged `transaction_type=DISPUTE`; the full lifecycle lives in Mangopay's dashboard.
- **KYC**: documents surface via `FETCH_OTHERS` only — submission happens in Mangopay's UI.
