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

fix(core): fix metadata validation for update payment connector #3834

Merged
merged 2 commits into from
Mar 5, 2024

Conversation

srujanchikke
Copy link
Contributor

@srujanchikke srujanchikke commented Feb 27, 2024

Type of Change

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

Description

Metadata validation in update payment connector happens even if we don't pass metadata in the request. This pr fixes metadata validation in update payment connector function. If metadata is not present we consider mca metadata.

Additional Changes

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

Motivation and Context

Metadata validation in update payment connector happens even if we don't pass metadata in the request. This pr fixes metadata validation in update payment connector function. If metadata is not present we consider mca metadata.

How did you test it?

Test case 1 :
step 1 : Create merchant connector account for Fiserv.

curl --location --request POST 'https://sandbox.hyperswitch.io/account/<merchant_Id>/connectors' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: test_admin' \
--data-raw '{
    "connector_type": "fiz_operations",
    "connector_name": "fiserv",
    "connector_account_details": {
        "auth_type": "SignatureKey",
        "api_key": "API_KEY",
        "key1": "KEY1",
        "api_secret": "API_SECRET"
    },
    "test_mode": true,
    "disabled": false,
    "payment_methods_enabled": [
        {
            "payment_method": "card",
            "payment_method_types": [
                {
                    "payment_method_type": "credit",
                    "card_networks": [
                        "Visa",
                        "Mastercard"
                    ],
                    "minimum_amount": 1,
                    "maximum_amount": 68607706,
                    "recurring_enabled": true,
                    "installment_payment_enabled": true
                },
                {
                    "payment_method_type": "debit",
                    "card_networks": [
                        "Visa",
                        "Mastercard"
                    ],
                    "minimum_amount": 1,
                    "maximum_amount": 68607706,
                    "recurring_enabled": true,
                    "installment_payment_enabled": true
                }
            ]
        },
        {
            "payment_method": "pay_later",
            "payment_method_types": [
                {
                    "payment_method_type": "klarna",
                    "payment_experience": "redirect_to_url",
                    "minimum_amount": 1,
                    "maximum_amount": 68607706,
                    "recurring_enabled": true,
                    "installment_payment_enabled": true
                },
                {
                    "payment_method_type": "affirm",
                    "payment_experience": "redirect_to_url",
                    "minimum_amount": 1,
                    "maximum_amount": 68607706,
                    "recurring_enabled": true,
                    "installment_payment_enabled": true
                },
                {
                    "payment_method_type": "afterpay_clearpay",
                    "payment_experience": "redirect_to_url",
                    "minimum_amount": 1,
                    "maximum_amount": 68607706,
                    "recurring_enabled": true,
                    "installment_payment_enabled": true
                }
            ]
        },
        {
            "payment_method": "bank_redirect",
            "payment_method_types": [
                {
                    "payment_method_type": "eps",
                    "recurring_enabled": true,
                    "installment_payment_enabled": true
                },
                {
                    "payment_method_type": "sofort",
                    "recurring_enabled": true,
                    "installment_payment_enabled": true
                }
            ]
        }
    ],
    "metadata": {
        "terminal_id":"TERMINAL_ID"
    }
}'

step 2 : Update merchant connector account without updating metadata, It should not throw 422.
here below curl is updating connector webhook details.

curl --location --request POST 'https://sandbox.hyperswitch.io/account/<merchant_id>/connectors/<mca_id>' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: test_admin' \
--data-raw '{
    "connector_type": "fiz_operations",
    "connector_webhook_details": {
        "merchant_secret": "MERCHANT_SECRET",
        "additional_secret": null
    }
}'

Test case 2 :
step 1 : Pass metadata in create payment connector for fiserv. curl is same as test case 1 -> step1

step 2 : Pass valid metadata in update payment connector, This should update metadata.
where valid metadata for fiserv is {"terminal_id": "TERMINAL_ID"}

curl --location --request POST 'https://sandbox.hyperswitch.io/account/<merchant_id>/connectors/<mca_id>' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: test_admin' \
--data-raw '{
    "connector_type": "fiz_operations",
    "metadata": {"terminal_id": "DIFFERENT_TERMINAL_ID"}
}'

Test case 3 :
step 1 : Pass metadata in create payment connector for fiserv. curl is same as test case 1 -> step1
step 2 : Pass Invalid metadata or empty metadata in update payment connector, This should throw error.

curl --location --request POST 'https://sandbox.hyperswitch.io/account/<merchant_id>/connectors/<mca_id>' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: test_admin' \
--data-raw '{
    "connector_type": "fiz_operations",
    "metadata": {}
}'

This can be done for any other connector which have metadata validation while creating merchant connector account(Braintree, Coinbase ).

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
  • I added a CHANGELOG entry if applicable

@srujanchikke srujanchikke added A-core Area: Core flows C-bug Category: Bug labels Feb 27, 2024
@srujanchikke srujanchikke self-assigned this Feb 27, 2024
@srujanchikke srujanchikke requested a review from a team as a code owner February 27, 2024 05:55
@srujanchikke srujanchikke linked an issue Feb 27, 2024 that may be closed by this pull request
@Gnanasundari24 Gnanasundari24 added this pull request to the merge queue Mar 5, 2024
Merged via the queue into main with commit 54938ad Mar 5, 2024
13 of 15 checks passed
@Gnanasundari24 Gnanasundari24 deleted the mca_validation branch March 5, 2024 07:10
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-bug Category: Bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug] metadata validation for update payment connector
4 participants