Integrations

Cross-module dependencies and data flow patterns

Module Dependencies

                    ┌─────────────────┐
                    │  Magento_Vault  │
                    │ (Token Storage) │
                    └────────┬────────┘
                             │ extends
                             ▼
┌─────────────────┐   ┌─────────────────┐   ┌─────────────────┐
│ Magento_Quote   │──▶│ Magento_Payment │◀──│ Magento_Sales   │
│ (Cart Payment)  │   │ (Gateway Core)  │   │(Order Payment)  │
└─────────────────┘   └────────┬────────┘   └─────────────────┘
                               │
                               ▼
                    ┌─────────────────┐
                    │Magento_Checkout │
                    │ (Payment Step)  │
                    └─────────────────┘
Module Relationship Integration Point
Magento_Quote Uses Payment Quote\Model\Quote\Payment extends payment methods
Magento_Sales Uses Payment Order\Payment executes payment commands
Magento_Checkout Uses Payment Payment step renders payment forms
Magento_Vault Extends Payment Adds token storage to payment methods
Magento_OfflinePayments Uses Payment Implements Check/Money Order, Bank Transfer
PayPal/Braintree Uses Gateway Full Gateway command implementation

Quote Module Integration

Payment methods are selected and validated at the quote level before order placement.

Data Flow: Quote to Payment

// Quote\Model\Quote\Payment
$quote->getPayment()->setMethod('checkmo');
$quote->getPayment()->importData([
    'method' => 'cc',
    'cc_number' => '4111...',
    'cc_exp_month' => '12',
    'cc_exp_year' => '2025'
]);

// Payment method validates data
$method = $this->methodFactory->create(
    $quote->getPayment()->getMethod()
);
$method->validate();

Key Quote-Payment Classes

  • Quote\Model\Quote\Payment - Quote payment entity
  • Quote\Model\PaymentMethodManagement - Set/get payment methods
  • Quote\Observer\SubmitObserver - Triggers payment on submit

Quote Payment Database Table

Column Type Description
payment_id int Primary key
quote_id int FK to quote
method varchar Payment method code
additional_data text Serialized additional info

Sales Module Integration

Order payment entity executes payment gateway commands and manages transactions.

┌──────────────────────────────────────────────────────────────────┐
│                    Order Payment Flow                              │
├──────────────────────────────────────────────────────────────────┤
│                                                                    │
│  Order::place()                                                    │
│       │                                                            │
│       ▼                                                            │
│  Payment::place()                                                  │
│       │                                                            │
│       ├──▶ payment_action = authorize                             │
│       │         │                                                  │
│       │         ▼                                                  │
│       │    MethodInterface::authorize()                           │
│       │         │                                                  │
│       │         ▼                                                  │
│       │    Gateway\Command::execute('authorize')                  │
│       │                                                            │
│       └──▶ payment_action = authorize_capture                     │
│                 │                                                  │
│                 ▼                                                  │
│            MethodInterface::authorize() + capture()               │
│                                                                    │
└──────────────────────────────────────────────────────────────────┘

Order Payment Entity Mapping

Quote Payment Order Payment Notes
method method Direct copy
cc_type cc_type Card type code (VI, MC, AE)
cc_last_4 cc_last4 Last 4 digits stored
additional_data additional_information Custom data (serialized)

Transaction Management

The Sales module's sales_payment_transaction table tracks all payment operations.

authorization
Initial auth
capture
Funds captured
void
Auth cancelled
refund
Money returned

Checkout Module Integration

Checkout renders payment methods in the payment step and handles method selection.

Config Provider Chain

// frontend/di.xml
<type name="Magento\Checkout\Model\
             CompositeConfigProvider">
    <arguments>
        <argument name="configProviders">
            <item name="ccform">
              CcGenericConfigProvider
            </item>
            <item name="cc_card_config">
              CcConfigProvider
            </item>
        </argument>
    </arguments>
</type>

JS Component Structure

checkout/
└── steps/
    └── billing-step/
        └── payment/
            ├── renders/
            │   └── cc-form (base CC)
            ├── payments-list
            └── before-place-order

Payment Step Flow

  1. 1 LayoutProcessor plugin injects payment config into jsLayout
  2. 2 PaymentMethodList returns available methods for quote
  3. 3 JS components render each method's form
  4. 4 PaymentMethodManagement saves selected method to quote

Vault Module Integration

Magento_Vault extends Payment to provide tokenization and stored payment methods.

Token Storage

  • PaymentTokenRepository stores encrypted tokens
  • Tokens linked to customer_id and payment method
  • Automatic expiry handling

Vault Method Pattern

// Vault payment method code
{original_method_code}_vault

// Example:
braintree → braintree_cc_vault
paypal → paypal_vault

Vault Database Schema

Table Purpose
vault_payment_token Encrypted payment tokens (gateway_token, public_hash)
vault_payment_token_order_payment_link Links tokens to order payments

Payment Gateway Implementations

Official Magento modules that implement the Payment Gateway framework:

Braintree

Full Gateway implementation

  • Credit card + Vault
  • PayPal via Braintree
  • 3D Secure support

PayPal

Multiple integration types

  • Express Checkout
  • PayPal Credit
  • Billing Agreements

Offline Payments

Non-gateway methods

  • Check/Money Order
  • Bank Transfer
  • Cash on Delivery

Payment-Related REST APIs

Payment endpoints are primarily handled by Quote and Checkout modules, not Payment directly.

Endpoint Method Module Description
/V1/carts/mine/payment-methods GET Quote List available payment methods
/V1/carts/mine/selected-payment-method PUT Quote Set payment method on cart
/V1/carts/mine/payment-information POST Checkout Save payment info + place order
/V1/customers/me/paymentTokens GET Vault List saved payment tokens