Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
maverox opened this issue Apr 23, 2025 · 0 comments · May be fixed by #7882
Assignees
Labels
A-core Area: Core flows C-feature Category: Feature request or enhancement C-refactor Category: Refactor E-medium Effort: Requires a fair amount of work enhancement New feature or request

Comments

@maverox
Copy link
Contributor

maverox commented Apr 23, 2025

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.

@maverox maverox added A-core Area: Core flows C-feature Category: Feature request or enhancement C-refactor Category: Refactor E-medium Effort: Requires a fair amount of work enhancement New feature or request labels Apr 23, 2025
@maverox maverox self-assigned this Apr 23, 2025
@maverox maverox changed the title feat(merchant_context): add struct merchant_context and replace all instances of merchant_account and key_store in core feat(merchant_context): add struct merchant_context and replace all instances of merchant_account and key_store in core Apr 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-core Area: Core flows C-feature Category: Feature request or enhancement C-refactor Category: Refactor E-medium Effort: Requires a fair amount of work enhancement New feature or request
Projects
None yet
1 participant