Skip to content

feat(core): Add cardbrand union fetch logic for click to pay session response #7858

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

Conversation

sahkal
Copy link
Contributor

@sahkal sahkal commented Apr 21, 2025

Type of Change

  • Enhancement

Description

Add cardbrand union fetch logic for click to pay session response

Previously for click to pay card brands was needed to be configured via dashboard in click to pay connector create tab, with this change we will provide card brands as a union of all card networks under active payment processor

How did you test it?

Create Payment connectors that supports click to pay

Lets take the example of adyen and cybersource

in adyen configure card network as ["Visa", "Mastercard"]

and in cybersource configure card network as ["American_Express"]

curl --location 'http://localhost:8080/account/sahkal/connectors' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: dev_Yo6nUGV4YXm5VBniRWzk7w3gd8z7qIodkbIYZOqkxf7wfrUpWrDYcIJdpeYnDZcX' \
--data '
{
    "connector_type": "payment_processor",
    "connector_name": "adyen",
    "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
                }
            ]
        }
    ],
    "metadata": {
        "city": "NY",
        "unit": "245",
        "live_endpoint_prefix": "vsfbjh"
    },
    "connector_webhook_details": {
        "merchant_secret": "556B655EBE2F2F0912F6DBC893C23C8A30F5F5293746B80114844AB30549E2AB"
    },
    "business_country": "US",
    "business_label": "default"
}
'

CYBERSOURCE

curl --location 'http://localhost:8080/account/sahkal/connectors' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: dev_m0TdtUXCOCjuHAx86maD6MNJ0OAnmSYY3cnXHAZUclbMdN5Vy7C1wnq6mDFyNwBs' \
--data '
{
    "connector_type": "payment_processor",
    "connector_name": "cybersource",
    "connector_account_details": {
        "auth_type": "SignatureKey",
        "api_secret": "API-SECRET",
        "api_key": "API-KEY",
        "key1": "KET1"
    },
    "test_mode": true,
    "disabled": false,
    "payment_methods_enabled": [
        {
            "payment_method": "card",
            "payment_method_types": [
                {
                    "payment_method_type": "credit",
                    "card_networks": [
                        "AmericanExpress"
                    ],
                    "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
                }
            ]
        }
    ],
    "metadata": {
        "city": "NY",
        "unit": "245",
        "live_endpoint_prefix": "vsfbjh"
    },
    "connector_webhook_details": {
        "merchant_secret": "MERCHANT-SECRET"
    }
}

'

CTP_MASTERCARD

curl --location 'http://localhost:8080/account/sahkal/connectors' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: dev_m0TdtUXCOCjuHAx86maD6MNJ0OAnmSYY3cnXHAZUclbMdN5Vy7C1wnq6mDFyNwBs' \
--data '{
    "connector_type": "authentication_processor",
    "connector_name": "ctp_mastercard",
    "connector_account_details": {
        "auth_type": "HeaderKey",
           "api_key": "API-KEY"
    },
    "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
                }
            ]
        }
    ],
    "connector_webhook_details": {
        "merchant_secret": "MERCHANT-SECRET"
    },
    "business_country": "US",
    "business_label": "default",
    "metadata": {
        "dpa_id": "DPA-ID",
        "dpa_name": "TestMerchant",
        "locale": "en_AU",
        "card_brands": [
            "mastercard",
            "visa"
        ],
        "acquirer_bin": "545301",
        "acquirer_merchant_id": "SRC3DS",
        "merchant_category_code": "0001",
        "merchant_country_code": "US",
        "dpa_client_id": "TestMerchant"
    }
}
'

update business profile

curl --location 'http://localhost:8080/account/sahkal/business_profile/pro_7TUGcXiWxKKIE5nV0n53' \
--header 'Content-Type: application/json' \
--header 'api-key: dev_Yo6nUGV4YXm5VBniRWzk7w3gd8z7qIodkbIYZOqkxf7wfrUpWrDYcIJdpeYnDZcX' \
--data '{
    "is_click_to_pay_enabled": true,
    "authentication_product_ids": {"click_to_pay": "mca_lChk9Kk2GUHabZjoQYOu"} 
}'

Create a payment

curl --location 'http://localhost:8080/payments' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: dev_Yo6nUGV4YXm5VBniRWzk7w3gd8z7qIodkbIYZOqkxf7wfrUpWrDYcIJdpeYnDZcX' \
--data-raw '
{
    "amount": 100,
    "currency": "USD",
    "confirm": false,
    
    "browser_info": {
        "user_agent": "Mozilla\/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/70.0.3538.110 Safari\/537.36",
        "accept_header": "text\/html,application\/xhtml+xml,application\/xml;q=0.9,image\/webp,image\/apng,*\/*;q=0.8",
        "language": "nl-NL",
        "color_depth": 24,
        "screen_height": 723,
        "screen_width": 1536,
        "time_zone": 0,
        "java_enabled": true,
        "java_script_enabled": true,
        "ip_address": "125.0.0.1"
    },
    "email": "[email protected]",
    "name": "John Doe",
    "phone": "999999999",
    "phone_country_code": "+65"
}

'

do session call

curl --location 'http://localhost:8080/payments/session_tokens' \
--header 'Content-Type: application/json' \
--header 'api-key: pk_dev_220c67f397a446a5bd74670be511dc22' \
--data '{
    "payment_id": "pay_psophzCF50w1qjRjKR1O",
    "wallets": [],
    "client_secret": "pay_psophzCF50w1qjRjKR1O_secret_WUPOg3OCoQX1lcRHHCYk"
}'

Response

{
    "payment_id": "pay_psophzCF50w1qjRjKR1O",
    "client_secret": "pay_psophzCF50w1qjRjKR1O_secret_WUPOg3OCoQX1lcRHHCYk",
    "session_token": [
        {
            "wallet_name": "click_to_pay",
            "dpa_id": "DPA-ID",
            "dpa_name": "TestMerchant",
            "locale": "en_AU",
            "card_brands": [
                "AmericanExpress",
                "Mastercard",
                "Visa"
            ],
            "acquirer_bin": "545301",
            "acquirer_merchant_id": "SRC3DS",
            "merchant_category_code": "0001",
            "merchant_country_code": "US",
            "transaction_amount": "1.00",
            "transaction_currency_code": "USD",
            "phone_number": "999999999",
            "email": "[email protected]",
            "phone_country_code": "+65",
            "provider": "mastercard",
            "dpa_client_id": null
        }
    ]
}

card brands should contain union of card brands supported via both cybersource and adyen

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

@sahkal sahkal added A-core Area: Core flows C-feature Category: Feature request or enhancement labels Apr 21, 2025
@sahkal sahkal added this to the April 2025 Release milestone Apr 21, 2025
@sahkal sahkal self-assigned this Apr 21, 2025
@sahkal sahkal requested review from a team as code owners April 21, 2025 11:34
Copy link

semanticdiff-com bot commented Apr 21, 2025

Review changes with  SemanticDiff

Changed Files
File Status
  crates/api_models/src/payments.rs  38% smaller
  crates/router/src/core/payments.rs  5% smaller
  api-reference-v2/openapi_spec.json  0% smaller
  api-reference/openapi_spec.json  0% smaller
  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/connector_configs/toml/development.toml Unsupported file format
  crates/connector_configs/toml/production.toml Unsupported file format
  crates/connector_configs/toml/sandbox.toml Unsupported file format
  crates/diesel_models/src/query/merchant_connector_account.rs  0% smaller
  crates/router/src/configs/secrets_transformers.rs  0% smaller
  crates/router/src/configs/settings.rs  0% smaller
  crates/router/src/db/kafka_store.rs  0% smaller
  crates/router/src/db/merchant_connector_account.rs  0% smaller

@hyperswitch-bot hyperswitch-bot bot added the M-api-contract-changes Metadata: This PR involves API contract changes label Apr 21, 2025
hyperswitch-bot bot and others added 3 commits April 21, 2025 12:38
…-fetching-connectors-based-on-ctp-eligible' of https://github.com/juspay/hyperswitch into 9296-feature-add-card-brands-to-ctp-session-response-by-fetching-connectors-based-on-ctp-eligible
sahkal added 2 commits April 23, 2025 12:56
…-fetching-connectors-based-on-ctp-eligible' of https://github.com/juspay/hyperswitch into 9296-feature-add-card-brands-to-ctp-session-response-by-fetching-connectors-based-on-ctp-eligible
Copy link
Contributor

@deepanshu-iiitu deepanshu-iiitu left a comment

Choose a reason for hiding this comment

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

Config changes look good

Chethan-rao
Chethan-rao previously approved these changes Apr 24, 2025
@@ -508,6 +509,31 @@ pub struct CorsSettings {
pub allowed_methods: HashSet<String>,
}

#[derive(Debug, Deserialize, Clone, Default)]
pub struct AuthenticationProviders {
#[serde(deserialize_with = "deserialize_connector_list")]
Copy link
Contributor

Choose a reason for hiding this comment

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

there's already a deserializer for this type, deserialize_hashset, is it possible to use that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the requirement is little different here, the one you mentioning goes something like bank_debit.ach = { connector_list = "gocardless,adyen" } where as mine is click_to_pay = {connector_list = "adyen, cybersource"}

swangi-kumari
swangi-kumari previously approved these changes Apr 24, 2025
swangi-kumari
swangi-kumari previously approved these changes Apr 25, 2025
@sahkal sahkal removed the request for review from ShankarSinghC April 28, 2025 07:47
@likhinbopanna likhinbopanna added this pull request to the merge queue Apr 28, 2025
github-merge-queue bot pushed a commit that referenced this pull request Apr 28, 2025
…response (#7858)

Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
Co-authored-by: Sahkal Poddar <[email protected]>
Merged via the queue into main with commit d2ff66b Apr 28, 2025
16 of 20 checks passed
@likhinbopanna likhinbopanna deleted the 9296-feature-add-card-brands-to-ctp-session-response-by-fetching-connectors-based-on-ctp-eligible branch April 28, 2025 12:21
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-feature Category: Feature request or enhancement M-api-contract-changes Metadata: This PR involves API contract changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants