Skip to content

feat(router): Add support for storing multiple surcharge configurations at profile level #7570

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
wants to merge 31 commits into
base: main
Choose a base branch
from

Conversation

spritianeja03
Copy link
Contributor

@spritianeja03 spritianeja03 commented Mar 19, 2025

Type of Change

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

Description

This PR adds support for storing multiple surcharge configurations at profile level by adding new endpoints to list, create, activate and retrieve active surcharge configurations.

Additional Changes

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

Motivation and Context

Closes #7569

How did you test it?

  1. List surcharge endpoint
curl --location --request GET 'http://localhost:8080/routing/decision/surcharge_list?limit=10' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'X-Profile-Id: pro_RKaEhuHawLQN3gn9Fwam' \
--header 'api-key: ••••••' \
--data '{
    "limit": 10,
    "offset": 0
}'
list_surcharge
  1. Create new surcharge endpoint
curl --location 'http://localhost:8080/routing/decision/surcharge_create' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'X-Profile-Id: pro_RKaEhuHawLQN3gn9Fwam' \
--header 'api-key: ******' \
--data '{
    "name": "Surcharge -2025-03-24 -config2",
    "merchant_surcharge_configs": {
        "show_surcharge_breakup_screen": true
    },
    "algorithm": {
        "defaultSelection": {
            "surcharge_details": {
                "surcharge": {
                    "type": "rate",
                    "value": {
                        "percentage": 10
                    }
                },
                "tax_on_surcharge": {
                    "percentage": 20
                }
            }
        },
        "rules": [
            {
                "name": "rule_1",
                "connectorSelection": {},
                "statements": [
                    {
                        "condition": [],
                        "nested": null
                    },
                    {
                        "condition": [
                            {
                                "lhs": "amount",
                                "comparison": "equal",
                                "value": {
                                    "type": "number",
                                    "value": 345
                                },
                                "metadata": {}
                            },
                            {
                                "lhs": "currency",
                                "comparison": "equal",
                                "value": {
                                    "type": "enum_variant",
                                    "value": "AED"
                                },
                                "metadata": {}
                            }
                        ],
                        "nested": null
                    }
                ],
                "surcharge_details": {
                    "surcharge": {
                        "type": "rate",
                        "value": {
                            "percentage": 10
                        }
                    },
                    "tax_on_surcharge": {
                        "percentage": 10
                    }
                }
            }],
        "metadata": {}
        
    },
    "description": "This is a surcharge config"
    
    
}
'
Screenshot 2025-03-24 at 4 38 26 PM
  1. Activate surcharge endpoint
curl --location 'http://localhost:8080/routing/decision/surcharge/routing_MX3GRfXF1nE0vq7KOY3e/activate' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'X-Profile-Id: pro_RKaEhuHawLQN3gn9Fwam' \
--header 'api-key: ******' \
--data '{
    "profile_id": "pro_ZzZ5BAiPD3ePKZJVBgxT"
}'
Screenshot 2025-03-24 at 4 37 35 PM
  1. Display active surcharge endpoint
curl --location 'http://localhost:8080/routing/decision/surcharge/active?profile_id=pro_RKaEhuHawLQN3gn9Fwam' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'X-Profile-Id: pro_RKaEhuHawLQN3gn9Fwam' \
--header 'api-key: *****'
active

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

@spritianeja03 spritianeja03 added C-feature Category: Feature request or enhancement M-database-changes Metadata: This PR involves database schema changes M-api-contract-changes Metadata: This PR involves API contract changes labels Mar 19, 2025
@spritianeja03 spritianeja03 added this to the February 2025 Release milestone Mar 19, 2025
@spritianeja03 spritianeja03 self-assigned this Mar 19, 2025
@spritianeja03 spritianeja03 requested review from a team as code owners March 19, 2025 11:29
Copy link

semanticdiff-com bot commented Mar 19, 2025

Review changes with  SemanticDiff

Changed Files
File Status
  crates/openapi/src/openapi.rs  24% smaller
  crates/openapi/src/openapi_v2.rs  19% smaller
  crates/router/src/core/surcharge_decision_config.rs  5% smaller
  crates/api_models/src/events/routing.rs  5% smaller
  crates/router/src/core/admin.rs  1% smaller
  api-reference-v2/openapi_spec.json  0% smaller
  api-reference/openapi_spec.json  0% smaller
  crates/api_models/src/admin.rs  0% smaller
  crates/api_models/src/routing.rs  0% smaller
  crates/api_models/src/surcharge_decision_configs.rs  0% smaller
  crates/common_enums/src/enums.rs  0% smaller
  crates/common_utils/src/consts.rs  0% smaller
  crates/common_utils/src/id_type.rs  0% smaller
  crates/common_utils/src/id_type/routing.rs  0% smaller
  crates/diesel_models/src/business_profile.rs  0% smaller
  crates/diesel_models/src/payment_attempt.rs  0% smaller
  crates/diesel_models/src/query/routing_algorithm.rs  0% smaller
  crates/diesel_models/src/routing_algorithm.rs  0% smaller
  crates/diesel_models/src/schema.rs  0% smaller
  crates/diesel_models/src/schema_v2.rs  0% smaller
  crates/diesel_models/src/user/sample_data.rs  0% smaller
  crates/hyperswitch_domain_models/src/business_profile.rs  0% smaller
  crates/hyperswitch_domain_models/src/payments/payment_attempt.rs  0% smaller
  crates/router/src/core/payments/helpers.rs  0% smaller
  crates/router/src/core/payments/operations/payment_create.rs  0% smaller
  crates/router/src/core/payments/retry.rs  0% smaller
  crates/router/src/core/routing.rs  0% smaller
  crates/router/src/core/routing/helpers.rs  0% smaller
  crates/router/src/db/kafka_store.rs  0% smaller
  crates/router/src/db/routing_algorithm.rs  0% smaller
  crates/router/src/routes/app.rs  0% smaller
  crates/router/src/routes/routing.rs  0% smaller
  crates/router/src/services/authorization/permissions.rs  0% smaller
  crates/router/src/types/api/admin.rs  0% smaller
  crates/router/src/types/storage/payment_attempt.rs  0% smaller
  crates/router/src/utils/user/sample_data.rs  0% smaller
  crates/storage_impl/src/mock_db/payment_attempt.rs  0% smaller
  crates/storage_impl/src/payments/payment_attempt.rs  0% smaller
  migrations/2025-03-05-093403_add_algorithm_type_to_routing_algorithm/down.sql Unsupported file format
  migrations/2025-03-05-093403_add_algorithm_type_to_routing_algorithm/up.sql Unsupported file format
  migrations/2025-03-05-105913_add_active_surcharge_algorithm_id_to_business_profile/down.sql Unsupported file format
  migrations/2025-03-05-105913_add_active_surcharge_algorithm_id_to_business_profile/up.sql Unsupported file format
  migrations/2025-03-06-075521_add_surcharge_algorithm_id_to_payment_attempt/down.sql Unsupported file format
  migrations/2025-03-06-075521_add_surcharge_algorithm_id_to_payment_attempt/up.sql Unsupported file format

@hyperswitch-bot hyperswitch-bot bot removed the M-api-contract-changes Metadata: This PR involves API contract changes label Mar 19, 2025
@hyperswitch-bot hyperswitch-bot bot added the M-api-contract-changes Metadata: This PR involves API contract changes label Mar 19, 2025
maverox
maverox previously approved these changes Apr 11, 2025
SanchithHegde
SanchithHegde previously approved these changes Apr 16, 2025
hrithikesh026
hrithikesh026 previously approved these changes Apr 17, 2025
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 M-api-contract-changes Metadata: This PR involves API contract changes M-database-changes Metadata: This PR involves database schema changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEATURE] Add support for multiple surcharge configurations at profile level
5 participants