# activemerchant/active_merchant architecture

> Architecture diagram of the GitHub repository activemerchant/active_merchant, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-20). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/activemerchant/active_merchant
- Repository: https://github.com/activemerchant/active_merchant

## Overview

Active Merchant is a Ruby payment integration library that gives applications a common interface to many payment gateways. The README’s example shows the principal flow: configure a gateway, construct and validate card details, submit a purchase, then inspect the response. The tree also documents gateway-specific extensions for stored customer profiles and recurring billing, alongside shared payment, response, and transport components. Many gateway implementations are unsampled, so their individual internal calls and protocol details are not mapped; optional processor links are shown as unverified.

Main entry points: [`lib/active_merchant/billing/gateway.rb`](https://github.com/activemerchant/active_merchant/blob/master/lib/active_merchant/billing/gateway.rb) (Gateway API), [`lib/active_merchant/billing/gateways/authorize_net.rb`](https://github.com/activemerchant/active_merchant/blob/master/lib/active_merchant/billing/gateways/authorize_net.rb) (Authorize.Net), [`lib/active_merchant/billing/gateways/authorize_net_cim.rb`](https://github.com/activemerchant/active_merchant/blob/master/lib/active_merchant/billing/gateways/authorize_net_cim.rb) (Customer profiles), [`lib/active_merchant/billing/gateways/authorize_net_arb.rb`](https://github.com/activemerchant/active_merchant/blob/master/lib/active_merchant/billing/gateways/authorize_net_arb.rb) (Recurring billing)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["Billing API"]
  node_billing_base["Billing base<br/>[base.rb]"]
  node_gateway_api["Gateway API<br/>[gateway.rb]"]
end

subgraph group_payment["Payment Data"]
  node_credit_card["Credit card<br/>[credit_card.rb]"]
  node_card_methods["Card validation"]
  node_payment_tokens["Payment tokens<br/>[payment_token.rb]"]
  node_network_tokens["Network tokens"]
  node_response["Transaction response<br/>[response.rb]"]
  node_country["Country codes<br/>[country.rb]"]
end

subgraph group_adapters["Gateway Adapters"]
  node_anet["Authorize.Net<br/>[authorize_net.rb]"]
  node_anet_cim["Customer profiles"]
  node_anet_arb["Recurring billing"]
  node_gateway_families["Other gateway adapters"]
end

subgraph group_infra["Shared Infrastructure"]
  node_connection["HTTP connection<br/>[connection.rb]"]
  node_ssl_connection["SSL transport"]
  node_retry["Connection retries"]
end

node_app(("Ruby application"))
node_processor(("Payment processor"))

node_app -->|"constructs and validates"| node_credit_card
node_app -->|"configures gateway"| node_gateway_api
node_app -->|"submits purchase"| node_gateway_api
node_app -->|"checks result"| node_response
node_gateway_api -.->|"selects adapter"| node_anet
node_gateway_api -.->|"selects adapter"| node_gateway_families
node_anet -.->|"sends transaction"| node_processor
node_anet_cim -.->|"manages profiles"| node_processor
node_anet_arb -.->|"manages subscriptions"| node_processor

click node_billing_base "https://github.com/activemerchant/active_merchant/blob/master/lib/active_merchant/billing/base.rb"
click node_gateway_api "https://github.com/activemerchant/active_merchant/blob/master/lib/active_merchant/billing/gateway.rb"
click node_credit_card "https://github.com/activemerchant/active_merchant/blob/master/lib/active_merchant/billing/credit_card.rb"
click node_card_methods "https://github.com/activemerchant/active_merchant/blob/master/lib/active_merchant/billing/credit_card_methods.rb"
click node_payment_tokens "https://github.com/activemerchant/active_merchant/blob/master/lib/active_merchant/billing/payment_token.rb"
click node_network_tokens "https://github.com/activemerchant/active_merchant/blob/master/lib/active_merchant/billing/network_tokenization_credit_card.rb"
click node_response "https://github.com/activemerchant/active_merchant/blob/master/lib/active_merchant/billing/response.rb"
click node_anet "https://github.com/activemerchant/active_merchant/blob/master/lib/active_merchant/billing/gateways/authorize_net.rb"
click node_anet_cim "https://github.com/activemerchant/active_merchant/blob/master/lib/active_merchant/billing/gateways/authorize_net_cim.rb"
click node_anet_arb "https://github.com/activemerchant/active_merchant/blob/master/lib/active_merchant/billing/gateways/authorize_net_arb.rb"
click node_gateway_families "https://github.com/activemerchant/active_merchant/tree/master/lib/active_merchant/billing/gateways"
click node_country "https://github.com/activemerchant/active_merchant/blob/master/lib/active_merchant/country.rb"
click node_connection "https://github.com/activemerchant/active_merchant/blob/master/lib/active_merchant/connection.rb"
click node_ssl_connection "https://github.com/activemerchant/active_merchant/blob/master/lib/active_merchant/net_http_ssl_connection.rb"
click node_retry "https://github.com/activemerchant/active_merchant/blob/master/lib/active_merchant/network_connection_retries.rb"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_billing_base,node_gateway_api toneBlue
class node_credit_card,node_card_methods,node_payment_tokens,node_network_tokens,node_response,node_country toneAmber
class node_anet,node_anet_cim,node_anet_arb,node_gateway_families toneMint
class node_connection,node_ssl_connection,node_retry toneRose
class node_app,node_processor toneIndigo
```

## Components

### Billing API

- [Billing base](https://github.com/activemerchant/active_merchant/blob/master/lib/active_merchant/billing/base.rb): `lib/active_merchant/billing/base.rb`
- [Gateway API](https://github.com/activemerchant/active_merchant/blob/master/lib/active_merchant/billing/gateway.rb): `lib/active_merchant/billing/gateway.rb`

### Payment Data

- [Credit card](https://github.com/activemerchant/active_merchant/blob/master/lib/active_merchant/billing/credit_card.rb): `lib/active_merchant/billing/credit_card.rb`
- [Card validation](https://github.com/activemerchant/active_merchant/blob/master/lib/active_merchant/billing/credit_card_methods.rb): `lib/active_merchant/billing/credit_card_methods.rb`
- [Payment tokens](https://github.com/activemerchant/active_merchant/blob/master/lib/active_merchant/billing/payment_token.rb): `lib/active_merchant/billing/payment_token.rb`
- [Network tokens](https://github.com/activemerchant/active_merchant/blob/master/lib/active_merchant/billing/network_tokenization_credit_card.rb): `lib/active_merchant/billing/network_tokenization_credit_card.rb`
- [Transaction response](https://github.com/activemerchant/active_merchant/blob/master/lib/active_merchant/billing/response.rb): `lib/active_merchant/billing/response.rb`
- [Country codes](https://github.com/activemerchant/active_merchant/blob/master/lib/active_merchant/country.rb): `lib/active_merchant/country.rb`

### Gateway Adapters

- [Authorize.Net](https://github.com/activemerchant/active_merchant/blob/master/lib/active_merchant/billing/gateways/authorize_net.rb): `lib/active_merchant/billing/gateways/authorize_net.rb`
- [Customer profiles](https://github.com/activemerchant/active_merchant/blob/master/lib/active_merchant/billing/gateways/authorize_net_cim.rb): `lib/active_merchant/billing/gateways/authorize_net_cim.rb`
- [Recurring billing](https://github.com/activemerchant/active_merchant/blob/master/lib/active_merchant/billing/gateways/authorize_net_arb.rb): `lib/active_merchant/billing/gateways/authorize_net_arb.rb`
- [Other gateway adapters](https://github.com/activemerchant/active_merchant/tree/master/lib/active_merchant/billing/gateways): `lib/active_merchant/billing/gateways`

### Shared Infrastructure

- [HTTP connection](https://github.com/activemerchant/active_merchant/blob/master/lib/active_merchant/connection.rb): `lib/active_merchant/connection.rb`
- [SSL transport](https://github.com/activemerchant/active_merchant/blob/master/lib/active_merchant/net_http_ssl_connection.rb): `lib/active_merchant/net_http_ssl_connection.rb`
- [Connection retries](https://github.com/activemerchant/active_merchant/blob/master/lib/active_merchant/network_connection_retries.rb): `lib/active_merchant/network_connection_retries.rb`

### Other components

- **Ruby application**
- **Payment processor**

## Connections

- Ruby application → Credit card: constructs and validates (evidence: `README.md`)
- Ruby application → Gateway API: configures gateway (evidence: `README.md`)
- Ruby application → Gateway API: submits purchase (evidence: `README.md`)
- Ruby application → Transaction response: checks result (evidence: `README.md`)
- Gateway API → Authorize.Net: selects adapter
- Gateway API → Other gateway adapters: selects adapter
- Authorize.Net → Payment processor: sends transaction
- Customer profiles → Payment processor: manages profiles
- Recurring billing → Payment processor: manages subscriptions
