Skip to content

feat(merchant_context): add struct merchant_context and replace all instances of merchant_account and key_store in core #7875

@maverox

Description

@maverox

Introduction of MerchantContext: Unified Merchant Operation Context

Challenge

Currently, merchant account and key store information are passed separately throughout the codebase, leading to scattered merchant context handling and reduced maintainability. Functions individually manage these components, making it difficult to implement platform-wide features or connected account capabilities.

Proposed Changes

Introducing MerchantContext, a new type that encapsulates both merchant account and key store information:

pub enum MerchantContext {
    NormalMerchant(Box<Context>),
}

pub struct Context(pub MerchantAccount, pub MerchantKeyStore);

The type provides controlled access through methods:

  • get_merchant_account(): Access merchant account details
  • get_merchant_key_store(): Access cryptographic key store

Why

  1. Unified Context: Encapsulates merchant authentication and operational context in one place
  2. Cleaner Architecture: Replaces scattered merchant account and key store parameters with a single context object
  3. Enhanced Control: Method-based access enables validation, transformation, and future enhancements
  4. Maintainability: Centralized merchant context management reduces code duplication and improves traceability

How

The implementation follows a tree-like flow where the MerchantContext is:

  1. Declared at the route handler level (root)
  2. Passed down through core operation handlers (branches)
  3. Finally consumed in database operations or other terminal functions (leaves)

This creates a clear, traceable flow of merchant context through the entire operation chain, making it easier to understand and maintain merchant-related operations.

Future Objectives

  1. Operational Context extension: The enum structure allows adding new variants for different operations, enabling:

    • Platform-level context inheritance
    • Connected account operations
    • cherry picking context for individual fragment of flows
  2. Granular Context Control:

    • Move context declaration to auth layer
    • Enable advanced platform features by implementing context creation logic for platform operations

This architectural change sets the foundation for future platform features while maintaining current functionality and improving code organization.

Metadata

Metadata

Assignees

Labels

A-coreArea: Core flowsC-featureCategory: Feature request or enhancementC-refactorCategory: RefactorE-mediumEffort: Requires a fair amount of workenhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions