Skip to content
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

feat(users): Add V2 User APIs to Support Modularity for Merchant Accounts #7386

Open
wants to merge 29 commits into
base: main
Choose a base branch
from

Conversation

tsdk02
Copy link
Contributor

@tsdk02 tsdk02 commented Feb 27, 2025

Type of Change

  • Bugfix
  • New feature
  • Enhancement
  • Refactoring
  • Dependency updates
  • Documentation
  • CI/CD

Description

As part of the modularity effort, we are introducing user support to enable dashboard interactions with v2 merchant accounts. This allows users to create, list, and switch between merchant accounts within their organization.

Key Changes

1. User Support for v2 Merchant Accounts

Introduced APIs to facilitate user interactions with v2 merchant accounts:

  • Create Merchant Account API (v1 & v2): Allows users to create a merchant account.
  • List Merchant Accounts API: Retrieves all v2 merchant accounts associated with a user in an organization.
  • Switch Merchant Account API: Enables users to switch to a different v2 merchant account.

2. Modified Response Structure

  • The response for Create Merchant Account (v1 & v2) now returns an object instead of just StatusOk (200). The response object includes:
    • merchant_id
    • merchant_name
    • product_type
    • version
  • The List Merchant Accounts API now returns a vector of these objects instead of a raw list.

3. Request Structure Update

  • The Create Merchant Account API request now includes an optional product_type field.
  • This field is currently optional but will be made mandatory once both the frontend and backend are stabilized.

4. Recon

  • Added Merchant Account permission for Recon related activities.

Additional Changes

  • This PR modifies the API contract
  • This PR modifies the database schema
  • This PR modifies application configuration/environment variables

Motivation and Context

With the modularization of the payments solution, managing multiple merchant accounts becomes essential. This update ensures a seamless user experience for handling v1 and v2 merchant accounts within an organization.

How did you test it?

The flow looks like this:

  • Sign Up / Sign In through V1 merchant account --> Create Merchant Account (V1 or V2) --> List Merchant Accounts (V1 and V2)--> Switch Merchant Account (V1 and V2)

Testing V2 Flow:

Sign In to a V1 merchant account

Create v2 Merchant Account:

curl --location 'http://localhost:8000/v2/user/create_merchant' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoiMWI5ZGZjNWUtZjA2My00YWY3LThkNzUtYmFmOTgzZmU0ODE4IiwibWVyY2hhbnRfaWQiOiJtZXJjaGFudF92S09zQU9odGc2S3hpSldlR3Y2YiIsInJvbGVfaWQiOiJvcmdfYWRtaW4iLCJleHAiOjE3NDE3NTk2MjUsIm9yZ19pZCI6Im9yZ19kUENaYU51bmNaRDY5aVZXb0hKcyIsInByb2ZpbGVfaWQiOiJwcm9fQjV4UWZxUWE4dkNCaXpoc2FnTmkiLCJ0ZW5hbnRfaWQiOiJwdWJsaWMifQ.MMJ68FinbhA4dShNvbrOsofU_nTaw1MjGnUrEkmkeOk' \
--header 'Cookie: login_token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoiMWI5ZGZjNWUtZjA2My00YWY3LThkNzUtYmFmOTgzZmU0ODE4IiwibWVyY2hhbnRfaWQiOiJtZXJjaGFudF92S09zQU9odGc2S3hpSldlR3Y2YiIsInJvbGVfaWQiOiJvcmdfYWRtaW4iLCJleHAiOjE3NDE3NTk2MjUsIm9yZ19pZCI6Im9yZ19kUENaYU51bmNaRDY5aVZXb0hKcyIsInByb2ZpbGVfaWQiOiJwcm9fQjV4UWZxUWE4dkNCaXpoc2FnTmkiLCJ0ZW5hbnRfaWQiOiJwdWJsaWMifQ.MMJ68FinbhA4dShNvbrOsofU_nTaw1MjGnUrEkmkeOk' \
--data '{
    "company_name": "TestingMerchantAccountCreateV2",
    "product_type": "vault"
}   '

Sample Output:

{
    "merchant_id": "testingmerchantaccountcreatev2_Ku5OxNIapqaot1P8rlQr",
    "merchant_name": "TestingMerchantAccountCreateV2",
    "product_type": "vault",
    "version": "v2"
}

List V2 Merchant Accounts for User in Org:

curl --location 'http://localhost:8000/v2/user/list/merchant' \
--header 'Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoiMWI5ZGZjNWUtZjA2My00YWY3LThkNzUtYmFmOTgzZmU0ODE4IiwibWVyY2hhbnRfaWQiOiJtZXJjaGFudF92S09zQU9odGc2S3hpSldlR3Y2YiIsInJvbGVfaWQiOiJvcmdfYWRtaW4iLCJleHAiOjE3NDE3NTk2MjUsIm9yZ19pZCI6Im9yZ19kUENaYU51bmNaRDY5aVZXb0hKcyIsInByb2ZpbGVfaWQiOiJwcm9fQjV4UWZxUWE4dkNCaXpoc2FnTmkiLCJ0ZW5hbnRfaWQiOiJwdWJsaWMifQ.MMJ68FinbhA4dShNvbrOsofU_nTaw1MjGnUrEkmkeOk' \
--header 'Cookie: login_token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoiMWI5ZGZjNWUtZjA2My00YWY3LThkNzUtYmFmOTgzZmU0ODE4IiwibWVyY2hhbnRfaWQiOiJtZXJjaGFudF92S09zQU9odGc2S3hpSldlR3Y2YiIsInJvbGVfaWQiOiJvcmdfYWRtaW4iLCJleHAiOjE3NDE3NTk2MjUsIm9yZ19pZCI6Im9yZ19kUENaYU51bmNaRDY5aVZXb0hKcyIsInByb2ZpbGVfaWQiOiJwcm9fQjV4UWZxUWE4dkNCaXpoc2FnTmkiLCJ0ZW5hbnRfaWQiOiJwdWJsaWMifQ.MMJ68FinbhA4dShNvbrOsofU_nTaw1MjGnUrEkmkeOk'

Sample Output:

[
    {
        "merchant_id": "merchant_vKOsAOhtg6KxiJWeGv6b",
        "merchant_name": "merchant",
        "product_type": "orchestration",
        "version": "v2"
    },
    {
        "merchant_id": "testingmerchantaccountcreatev2_Ku5OxNIapqaot1P8rlQr",
        "merchant_name": "TestingMerchantAccountCreateV2",
        "product_type": "vault",
        "version": "v2"
    }
]

Switch to V2 merchant Account:

curl --location 'http://localhost:8000/v2/user/switch/merchant' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI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FvdDFQOHJsUXIiLCJyb2xlX2lkIjoib3JnX2FkbWluIiwiZXhwIjoxNzQxNzU5NzYyLCJvcmdfaWQiOiJvcmdfZFBDWmFOdW5jWkQ2OWlWV29ISnMiLCJwcm9maWxlX2lkIjoicHJvX2huN2RqaVpKckJTMnYxS1hjdWIxIiwidGVuYW50X2lkIjoicHVibGljIn0.kxj8dXx4KBXRl-Ayfy6qVJxZF5hLvwqxouJ2ENubm8Q",
    "token_type": "user_info"
}

Testing V1 flow:

Sign in to V1 merchant account

Create V1 merchant Account:

curl --location 'http://localhost:8080/user/create_merchant' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoiNTk0OTE4YzUtOTM0OS00YjEzLWIzZDItZDc0Mzg0OTk3MWNkIiwibWVyY2hhbnRfaWQiOiJtZXJjaGFudF8xNzQxNTg4NTI2Iiwicm9sZV9pZCI6Im9yZ19hZG1pbiIsImV4cCI6MTc0MTc2MTM0OCwib3JnX2lkIjoib3JnX3NYdWNFTGFKSURtVFU2YVlsbmJZIiwicHJvZmlsZV9pZCI6InByb184QnNld0tIRUlaa3ppdUhKa282YiIsInRlbmFudF9pZCI6InB1YmxpYyJ9.lyeIOXMCXVdDaE7ACHxzoFgAZeCY0rjDRFq1rSxu1NE' \
--header 'Cookie: login_token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoiNTk0OTE4YzUtOTM0OS00YjEzLWIzZDItZDc0Mzg0OTk3MWNkIiwibWVyY2hhbnRfaWQiOiJtZXJjaGFudF8xNzQxNTg4NTI2Iiwicm9sZV9pZCI6Im9yZ19hZG1pbiIsImV4cCI6MTc0MTc2MTM0OCwib3JnX2lkIjoib3JnX3NYdWNFTGFKSURtVFU2YVlsbmJZIiwicHJvZmlsZV9pZCI6InByb184QnNld0tIRUlaa3ppdUhKa282YiIsInRlbmFudF9pZCI6InB1YmxpYyJ9.lyeIOXMCXVdDaE7ACHxzoFgAZeCY0rjDRFq1rSxu1NE' \
--data '{
    "company_name": "TestingV1",
    "product_type": "recovery"
}'

Sample Output:

{
    "merchant_id": "merchant_1741588579",
    "merchant_name": "TestingV1",
    "product_type": "recovery",
    "version": "v1"
}

List V1 Merchant Accounts for User in Org:

curl --location 'http://localhost:8080/user/list/merchant' \
--header 'Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoiNTk0OTE4YzUtOTM0OS00YjEzLWIzZDItZDc0Mzg0OTk3MWNkIiwibWVyY2hhbnRfaWQiOiJtZXJjaGFudF8xNzQxNTg4NTI2Iiwicm9sZV9pZCI6Im9yZ19hZG1pbiIsImV4cCI6MTc0MTc2MTM0OCwib3JnX2lkIjoib3JnX3NYdWNFTGFKSURtVFU2YVlsbmJZIiwicHJvZmlsZV9pZCI6InByb184QnNld0tIRUlaa3ppdUhKa282YiIsInRlbmFudF9pZCI6InB1YmxpYyJ9.lyeIOXMCXVdDaE7ACHxzoFgAZeCY0rjDRFq1rSxu1NE' \
--header 'Cookie: login_token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoiNTk0OTE4YzUtOTM0OS00YjEzLWIzZDItZDc0Mzg0OTk3MWNkIiwibWVyY2hhbnRfaWQiOiJtZXJjaGFudF8xNzQxNTg4NTI2Iiwicm9sZV9pZCI6Im9yZ19hZG1pbiIsImV4cCI6MTc0MTc2MTM0OCwib3JnX2lkIjoib3JnX3NYdWNFTGFKSURtVFU2YVlsbmJZIiwicHJvZmlsZV9pZCI6InByb184QnNld0tIRUlaa3ppdUhKa282YiIsInRlbmFudF9pZCI6InB1YmxpYyJ9.lyeIOXMCXVdDaE7ACHxzoFgAZeCY0rjDRFq1rSxu1NE'

Sample Output:

[
    {
        "merchant_id": "merchant_1741588526",
        "merchant_name": null,
        "product_type": "orchestration",
        "version": "v1"
    },
    {
        "merchant_id": "merchant_1741588579",
        "merchant_name": "TestingV1",
        "product_type": "recovery",
        "version": "v1"
    }
]

Switch to V1 Merchant Account:

curl --location 'http://localhost:8080/user/switch/merchant' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoiNTk0OTE4YzUtOTM0OS00YjEzLWIzZDItZDc0Mzg0OTk3MWNkIiwibWVyY2hhbnRfaWQiOiJtZXJjaGFudF8xNzQxNTg4NTI2Iiwicm9sZV9pZCI6Im9yZ19hZG1pbiIsImV4cCI6MTc0MTc2MTM0OCwib3JnX2lkIjoib3JnX3NYdWNFTGFKSURtVFU2YVlsbmJZIiwicHJvZmlsZV9pZCI6InByb184QnNld0tIRUlaa3ppdUhKa282YiIsInRlbmFudF9pZCI6InB1YmxpYyJ9.lyeIOXMCXVdDaE7ACHxzoFgAZeCY0rjDRFq1rSxu1NE' \
--header 'Cookie: login_token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoiNTk0OTE4YzUtOTM0OS00YjEzLWIzZDItZDc0Mzg0OTk3MWNkIiwibWVyY2hhbnRfaWQiOiJtZXJjaGFudF8xNzQxNTg4NTc5Iiwicm9sZV9pZCI6Im9yZ19hZG1pbiIsImV4cCI6MTc0MTc2MTUwNSwib3JnX2lkIjoib3JnX3NYdWNFTGFKSURtVFU2YVlsbmJZIiwicHJvZmlsZV9pZCI6InByb19PVnQ0OTIzYmdoS0dVRU13Y1JiOSIsInRlbmFudF9pZCI6InB1YmxpYyJ9.5yi6unFpacer1FO_wcxxQIHRls_mjDjPraIHD6BO0ME' \
--data '{
    "merchant_id": "merchant_1741588579"
}'

Sample Output:

{
    "token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoiNTk0OTE4YzUtOTM0OS00YjEzLWIzZDItZDc0Mzg0OTk3MWNkIiwibWVyY2hhbnRfaWQiOiJtZXJjaGFudF8xNzQxNTg4NTc5Iiwicm9sZV9pZCI6Im9yZ19hZG1pbiIsImV4cCI6MTc0MTc2MTUwNSwib3JnX2lkIjoib3JnX3NYdWNFTGFKSURtVFU2YVlsbmJZIiwicHJvZmlsZV9pZCI6InByb19PVnQ0OTIzYmdoS0dVRU13Y1JiOSIsInRlbmFudF9pZCI6InB1YmxpYyJ9.5yi6unFpacer1FO_wcxxQIHRls_mjDjPraIHD6BO0ME",
    "token_type": "user_info"
}

Checklist

  • I formatted the code cargo +nightly fmt --all
  • I addressed lints thrown by cargo clippy
  • I reviewed the submitted code
  • I added unit tests for my changes where possible

@tsdk02 tsdk02 added the C-feature Category: Feature request or enhancement label Feb 27, 2025
@tsdk02 tsdk02 self-assigned this Feb 27, 2025
@tsdk02 tsdk02 requested a review from a team as a code owner February 27, 2025 06:26
Copy link

semanticdiff-com bot commented Feb 27, 2025

@tsdk02 tsdk02 requested a review from a team as a code owner February 27, 2025 07:20
@tsdk02 tsdk02 changed the title feat(users): dashboard modularity changes for v2 merchant accounts feat(users): Add V2 User APIs to Support Modularity for Merchant Accounts Feb 27, 2025
@tsdk02 tsdk02 requested a review from a team as a code owner March 8, 2025 08:25
jarnura
jarnura previously approved these changes Mar 10, 2025
Copy link
Member

@jarnura jarnura left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

#[default]
Legacy,
Orchestration,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make sure data for legacy is not inserted in DB.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checked integ and sandbox db, no entry with product_type = legacy present

Comment on lines +511 to +533
let key_manager_state = &(&state).into();
let merchant_key_store = state
.store
.get_merchant_key_store_by_merchant_id(
key_manager_state,
&merchant_account_response.merchant_id,
&state.store.get_master_key().to_vec().into(),
)
.await
.change_context(UserErrors::InternalServerError)
.attach_printable("Failed to retrieve merchant key store by merchant_id")?;

let merchant_account = state
.store
.find_merchant_account_by_merchant_id(
key_manager_state,
&merchant_account_response.merchant_id,
&merchant_key_store,
)
.await
.change_context(UserErrors::InternalServerError)
.attach_printable("Failed to retrieve merchant account by merchant_id")?;
Ok(merchant_account)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we skip these two queries and use create merchant account response ?

Comment on lines +1494 to +1499
user_api::UserMerchantAccountResponse {
merchant_id: domain_merchant_account.get_id().to_owned(),
merchant_name: domain_merchant_account.merchant_name,
product_type: domain_merchant_account.product_type,
version: domain_merchant_account.version,
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can implement From/Into implementation for these types.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will take this up in a separate PR

ThisIsMani
ThisIsMani previously approved these changes Mar 11, 2025
racnan
racnan previously approved these changes Mar 11, 2025
@tsdk02 tsdk02 dismissed stale reviews from racnan and ThisIsMani via 1ebf9b9 March 11, 2025 09:29
jarnura
jarnura previously approved these changes Mar 11, 2025
racnan
racnan previously approved these changes Mar 11, 2025
ThisIsMani
ThisIsMani previously approved these changes Mar 11, 2025
@tsdk02 tsdk02 dismissed stale reviews from ThisIsMani, racnan, and jarnura via 78134dd March 11, 2025 11:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-feature Category: Feature request or enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feat(users): Add V2 User APIs to Support Modularity for Merchant Accounts
4 participants