Description
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 detailsget_merchant_key_store()
: Access cryptographic key store
Why
- Unified Context: Encapsulates merchant authentication and operational context in one place
- Cleaner Architecture: Replaces scattered merchant account and key store parameters with a single context object
- Enhanced Control: Method-based access enables validation, transformation, and future enhancements
- Maintainability: Centralized merchant context management reduces code duplication and improves traceability
How
The implementation follows a tree-like flow where the MerchantContext
is:
- Declared at the route handler level (root)
- Passed down through core operation handlers (branches)
- 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
-
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
-
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.