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(core): implemented platform merchant account #6882

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

Conversation

racnan
Copy link
Contributor

@racnan racnan commented Dec 18, 2024

Type of Change

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

Description

About the feature

  • This the first PR for the Platform Account feature.
  • Feature is under development and behind the feature flag.
  • Feature is supposed to be disabled for sandbox and production environments.

Enabling the platform account.

  • New API has been created to enable platform account.
  • API requires Admin API auth.
  • Once enabled, there is no way of disabling platform account as of now.

How it works

  • A new special header is to be sent by the platform called x-connected-merchant-id.
  • Platform will use its own API key irrespective of the merchant id present in the above header.
  • Value of this header is supposed to be the merchant id of the merchant account on behalf of which the platform is performing the operation.
  • If the platform has is_platform true and the merchant account on behalf of which operation is performed belongs to the same organisation as platform then the operation is allowed.

Payment Intent

  • Operation will be performed for merchant id present in the x-connected-merchant-id header.
  • platform_merchant_id column for the payment intent will be populated with platforms merchant id.

Other operations

  • Will add context of platform_merchant_id in other operations as well.

Additional Changes

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

Motivation and Context

#6883

How did you test it?

  1. Create a merchant account(m1).
  2. Use below api to convert it into platform account.
curl --location --request POST '<BASE URL>/accounts/{merchant_id}/platform' \
--header 'api-key:<ADMIN API KEY>'
  1. Create another merchant account in the same organisation(m2).
  2. Do a payment using platform's(m1) API key for connected merchant account(m2) by passing header x-connected-merchant-id with value as connected merchant account's merchant id.
  3. Check if payment is created for connected merchant account.
  4. Check if platform_merchant_id is populated with platform's merchant id.

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

@racnan racnan requested review from a team as code owners December 18, 2024 18:20
Copy link

semanticdiff-com bot commented Dec 18, 2024

Review changes with  SemanticDiff

Changed Files
File Status
  crates/router/src/routes/lock_utils.rs  86% smaller
  crates/router/build.rs  66% smaller
  crates/router/src/routes/app.rs  16% smaller
  crates/router/src/compatibility/stripe/errors.rs  6% smaller
  crates/router/src/services/authentication.rs  3% smaller
  .github/workflows/postman-collection-runner.yml Unsupported file format
  config/deployments/integration_test.toml Unsupported file format
  config/deployments/production.toml Unsupported file format
  config/deployments/sandbox.toml Unsupported file format
  config/development.toml Unsupported file format
  config/docker_compose.toml Unsupported file format
  crates/diesel_models/src/merchant_account.rs  0% smaller
  crates/diesel_models/src/payment_intent.rs  0% smaller
  crates/diesel_models/src/schema.rs  0% smaller
  crates/diesel_models/src/schema_v2.rs  0% smaller
  crates/hyperswitch_domain_models/src/errors/api_error_response.rs  0% smaller
  crates/hyperswitch_domain_models/src/merchant_account.rs  0% smaller
  crates/hyperswitch_domain_models/src/payments.rs  0% smaller
  crates/hyperswitch_domain_models/src/payments/payment_intent.rs  0% smaller
  crates/router/src/compatibility/stripe/payment_intents.rs  0% smaller
  crates/router/src/compatibility/stripe/setup_intents.rs  0% smaller
  crates/router/src/configs/secrets_transformers.rs  0% smaller
  crates/router/src/configs/settings.rs  0% smaller
  crates/router/src/core/admin.rs  0% smaller
  crates/router/src/core/fraud_check.rs  0% smaller
  crates/router/src/core/fraud_check/operation.rs  0% smaller
  crates/router/src/core/fraud_check/operation/fraud_check_post.rs  0% smaller
  crates/router/src/core/payments.rs  0% smaller
  crates/router/src/core/payments/helpers.rs  0% smaller
  crates/router/src/core/payments/operations.rs  0% smaller
  crates/router/src/core/payments/operations/payment_approve.rs  0% smaller
  crates/router/src/core/payments/operations/payment_cancel.rs  0% smaller
  crates/router/src/core/payments/operations/payment_capture.rs  0% smaller
  crates/router/src/core/payments/operations/payment_capture_v2.rs  0% smaller
  crates/router/src/core/payments/operations/payment_complete_authorize.rs  0% smaller
  crates/router/src/core/payments/operations/payment_confirm.rs  0% smaller
  crates/router/src/core/payments/operations/payment_confirm_intent.rs  0% smaller
  crates/router/src/core/payments/operations/payment_create.rs  0% smaller
  crates/router/src/core/payments/operations/payment_create_intent.rs  0% smaller
  crates/router/src/core/payments/operations/payment_get.rs  0% smaller
  crates/router/src/core/payments/operations/payment_get_intent.rs  0% smaller
  crates/router/src/core/payments/operations/payment_post_session_tokens.rs  0% smaller
  crates/router/src/core/payments/operations/payment_reject.rs  0% smaller
  crates/router/src/core/payments/operations/payment_session.rs  0% smaller
  crates/router/src/core/payments/operations/payment_session_intent.rs  0% smaller
  crates/router/src/core/payments/operations/payment_start.rs  0% smaller
  crates/router/src/core/payments/operations/payment_status.rs  0% smaller
  crates/router/src/core/payments/operations/payment_update.rs  0% smaller
  crates/router/src/core/payments/operations/payment_update_intent.rs  0% smaller
  crates/router/src/core/payments/operations/payments_incremental_authorization.rs  0% smaller
  crates/router/src/core/payments/operations/tax_calculation.rs  0% smaller
  crates/router/src/core/payments/session_operation.rs  0% smaller
  crates/router/src/core/webhooks/incoming.rs  0% smaller
  crates/router/src/lib.rs  0% smaller
  crates/router/src/routes/admin.rs  0% smaller
  crates/router/src/routes/payments.rs  0% smaller
  crates/router/src/utils/user/sample_data.rs  0% smaller
  crates/router/src/workflows/outgoing_webhook_retry.rs  0% smaller
  crates/router/src/workflows/payment_sync.rs  0% smaller
  crates/router/tests/payments.rs  0% smaller
  crates/router/tests/payments2.rs  0% smaller
  crates/router_env/src/logger/types.rs  0% smaller
  migrations/2024-12-03-072318_platform_merchant_account/down.sql Unsupported file format
  migrations/2024-12-03-072318_platform_merchant_account/up.sql Unsupported file format

@racnan racnan self-assigned this Dec 18, 2024
@hyperswitch-bot hyperswitch-bot bot added the M-database-changes Metadata: This PR involves database schema changes label Dec 18, 2024
@racnan racnan added A-core Area: Core flows S-waiting-on-review Status: This PR has been implemented and needs to be reviewed A-payments Area: payments M-database-changes Metadata: This PR involves database schema changes and removed M-database-changes Metadata: This PR involves database schema changes labels Dec 18, 2024
jarnura
jarnura previously approved these changes Dec 20, 2024
@@ -77,6 +77,7 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, api::PaymentsRequest>
key_store: &domain::MerchantKeyStore,
auth_flow: services::AuthFlow,
header_payload: &hyperswitch_domain_models::payments::HeaderPayload,
_platform_merchant_account: Option<&domain::MerchantAccount>,
Copy link
Member

Choose a reason for hiding this comment

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

we should validate that this belongs to the same merchant_id that was passed in create right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yess, will add validations in eventual PRs.

@@ -548,8 +573,31 @@ where
.await
.to_not_found_response(errors::ApiErrorResponse::Unauthorized)?;

// Get connected merchant account if API call is done by Platform merchant account on behalf of connected merchant account
let (merchant, platform_merchant_account) = if state.conf().platform.enabled {
get_platform_merchant_account(state, request_headers, merchant).await?
Copy link
Member

Choose a reason for hiding this comment

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

we can pass key store from this function itself

Narayanbhat166
Narayanbhat166 previously approved these changes Dec 20, 2024
@racnan racnan dismissed stale reviews from Narayanbhat166 and jarnura via 6be65ca December 20, 2024 19:19
@racnan racnan force-pushed the platform-merchant-account branch from a1c7434 to 7102076 Compare December 21, 2024 19:05
@racnan racnan requested a review from a team as a code owner December 23, 2024 08:55
pixincreate
pixincreate previously approved these changes Dec 23, 2024
Copy link
Member

@pixincreate pixincreate left a comment

Choose a reason for hiding this comment

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

configs and ci, look good to me

NishantJoshi00
NishantJoshi00 previously approved these changes Dec 23, 2024
Copy link
Member

@NishantJoshi00 NishantJoshi00 left a comment

Choose a reason for hiding this comment

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

The HeaderAuth side of things look good

Narayanbhat166
Narayanbhat166 previously approved these changes Dec 23, 2024
Copy link
Member

@SanchithHegde SanchithHegde Dec 23, 2024

Choose a reason for hiding this comment

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

Can you make the same changes in the other config files as well: config/development.toml and config/docker_compose.toml?

@@ -724,12 +775,14 @@ where
}

#[cfg(all(feature = "partial-auth", feature = "v1"))]
#[allow(unused)]
Copy link
Member

Choose a reason for hiding this comment

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

Do we still need this annotation?

@@ -1412,15 +1537,20 @@ pub struct MerchantIdAuth(pub id_type::MerchantId);

#[cfg(feature = "v1")]
#[async_trait]
#[allow(unused)]
Copy link
Member

Choose a reason for hiding this comment

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

Same here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-core Area: Core flows A-payments Area: payments M-database-changes Metadata: This PR involves database schema changes S-waiting-on-review Status: This PR has been implemented and needs to be reviewed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feat(core): setup platform merchant account
6 participants