Skip to content

Conversation

Narayanbhat166
Copy link
Contributor

@Narayanbhat166 Narayanbhat166 commented Dec 8, 2023

Type of Change

  • Refactoring

Description

This Pr changes the unique constraint of merchant_connector_account to connector_label and profile_id

Motivation and Context

In order to allow multiple instances of the same connector to be created.

How did you test it?

  • Create two stripe accounts with different connector_labels.
    • First stripe account.
curl --location 'http://localhost:8080/account/merchant_1708077471/connectors' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: test_admin' \
--data '{
    "connector_type": "fiz_operations",
    "connector_name": "stripe",
    "connector_account_details": {
        "auth_type": "HeaderKey",
        "api_key": "<STRIPE_API_KEY>"
    },
    "test_mode": false,
    "disabled": false,
    "connector_label": "first_stripe",
    "payment_methods_enabled": [
        {
            "payment_method": "card"
        }
    ],
    "metadata": {
        "city": "NY",
        "unit": "245"
    }
}'
  • Second stripe account.
curl --location 'http://localhost:8080/account/merchant_1708077471/connectors' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: test_admin' \
--data '{
    "connector_type": "fiz_operations",
    "connector_name": "stripe",
    "connector_account_details": {
        "auth_type": "HeaderKey",
        "api_key": "<STRIPE_API_KEY>"
    },
    "test_mode": false,
    "disabled": false,
    "connector_label": "second_stripe",
    "payment_methods_enabled": [
        {
            "payment_method": "card"
        }
    ],
    "connector_webhook_details": {
        "merchant_secret": "..."
    },
    "metadata": {
        "city": "NY",
        "unit": "245"
    }
}'
  • Create a stripe account with the same connector twice with same connector_label -> Second time an error must be
    thrown.
    Curl to create the merchant connector account.
curl --location 'http://localhost:8080/account/merchant_1708077471/connectors' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: test_admin' \
--data '{
    "connector_type": "fiz_operations",
    "connector_name": "stripe",
    "connector_account_details": {
        "auth_type": "HeaderKey",
        "api_key": "<STRIPE_API_KEY>"
    },
    "test_mode": false,
    "disabled": false,
    "connector_label": "stripe_fallback",
    "payment_methods_enabled": [
        {
            "payment_method": "card"
        }
    ],
    "metadata": {
        "city": "NY",
        "unit": "245"
    }
}'
{
    "error": {
        "type": "invalid_request",
        "message": "The merchant connector account with the specified profile_id 'pro_BrafXvLpgRJNdRDVhS4P' and connector_label 'stripe_fallback' already exists in our records",
        "code": "HE_01"
    }
}

Checklist

  • I formatted the code cargo +nightly fmt --all
  • I addressed lints thrown by cargo clippy
  • I reviewed the submitted code

@Narayanbhat166 Narayanbhat166 added the C-refactor Category: Refactor label Dec 8, 2023
@Narayanbhat166 Narayanbhat166 added this to the December 2023 Release milestone Dec 8, 2023
@Narayanbhat166 Narayanbhat166 self-assigned this Dec 8, 2023
@Narayanbhat166 Narayanbhat166 requested review from a team as code owners December 8, 2023 07:51
@vspecky
Copy link
Contributor

vspecky commented Dec 8, 2023

@Narayanbhat166 We cannot make this change until we have removed backwards compatibility from routing (i.e. made merchant_connector_id mandatory) and ensured that every connector in every payment intent/attempt is coupled with a merchant connector id.

If we remove the constraint before the aforementioned is done, we'll run into issues (eg: for PSync, if the payment attempt only has stripe but no merchant connector id, and the profile has 3 stripe connector accounts, there's a 2/3 chance that the call will fail since the wrong credentials will be picked)

@Aprabhat19 is working on removing the backwards compatibility and backfilling all payment intents/attempts in the DB.

Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Add the new index before deleting the old one, in case it fails.

@Narayanbhat166 Narayanbhat166 added the M-database-changes Metadata: This PR involves database schema changes label Feb 20, 2024
@Gnanasundari24 Gnanasundari24 added this pull request to the merge queue Feb 20, 2024
Merged via the queue into main with commit 073310c Feb 20, 2024
@Gnanasundari24 Gnanasundari24 deleted the change_mca_constraint branch February 20, 2024 07:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-refactor Category: Refactor M-database-changes Metadata: This PR involves database schema changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants