Skip to content

fix(router): add payment method Wallet check for decrypted wallet payment method token logic#8747

Merged
likhinbopanna merged 1 commit intohotfix-2025.07.23.0from
debit-routing/wallets/hot-fix/refactor-tokenization
Jul 24, 2025
Merged

fix(router): add payment method Wallet check for decrypted wallet payment method token logic#8747
likhinbopanna merged 1 commit intohotfix-2025.07.23.0from
debit-routing/wallets/hot-fix/refactor-tokenization

Conversation

@ShankarSinghC
Copy link
Contributor

@ShankarSinghC ShankarSinghC commented Jul 24, 2025

Type of Change

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

Description

Updated to check if the payment method is Wallet before proceeding with the wallet decryption operation.

main branch pr #8744

Additional Changes

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

Motivation and Context

How did you test it?

-> Make a card payment without sending the payment method type

curl --location 'http://localhost:8080/payments' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'x-feature: router-custom' \
--header 'x-tenant-id: hyperswitch' \
--header 'api-key: dev_TkMYapm8vMYMcImjnH6Gkud5hM6jGVayHZTi3WSVU8eYUiMItzwlRYQlN3RtHIkD' \
--data-raw '{
    "amount": 1000000,
    "amount_to_capture": 1000000,
    "currency": "USD",
    "confirm": true,
    "capture_method": "automatic",
    "setup_future_usage": "on_session",
    "capture_on": "2022-09-10T10:11:12Z",
    "email": "guest@example.com",
    "name": "John Doe",
    "phone": "999999999",
    "phone_country_code": "+1",
    "description": "Its my first payment request",
    "authentication_type": "no_three_ds",
    "customer_id": "cu_1753349404",
    "return_url": "http://127.0.0.1:4040",
    "payment_method": "card",
    "payment_method_data": {
        "card": {
            "card_number": "4111111111111111",
            "card_exp_month": "03",
            "card_exp_year": "2030",
            "card_holder_name": "joseph Doe",
            "card_cvc": "737"
        }
    },
    "billing": {
        "address": {
            "line1": "1467",
            "line2": "Harrison Street",
            "line3": "Harrison Street",
            "city": "San",
            "state": "California",
            "zip": "94122",
            "country": "US",
            "first_name": "PiX",
            "last_name": "ss"
        },
        "email": "raj@gmail.com"
    },
    "shipping": {
        "address": {
            "line1": "1467",
            "line2": "Harrison Street",
            "line3": "Harrison Street",
            "city": "San Fransico",
            "state": "California",
            "zip": "94122",
            "country": "US",
            "first_name": "PiX"
        }
    },
    "customer_acceptance": {
        "acceptance_type": "offline",
        "accepted_at": "1963-05-03T04:07:52.723Z",
        "online": {
            "ip_address": "in sit",
            "user_agent": "amet irure esse"
        }
    },
    "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"
    },
    "statement_descriptor_name": "joseph",
    "statement_descriptor_suffix": "JS",
    "metadata": {
        "udf1": "value1",
        "new_customer": "true",
        "login_date": "2019-09-10T10:11:12Z"
    }
}'
{
    "payment_id": "pay_IUCHPAl9h0w2pU42MSjP",
    "merchant_id": "merchant_1753349359",
    "status": "succeeded",
    "amount": 1000000,
    "net_amount": 1000000,
    "shipping_cost": null,
    "amount_capturable": 0,
    "amount_received": 1000000,
    "connector": "adyen",
    "client_secret": "pay_IUCHPAl9h0w2pU42MSjP_secret_qtpg5D3tmmR47Pa9zemV",
    "created": "2025-07-24T09:29:57.265Z",
    "currency": "USD",
    "customer_id": "cu_1753349397",
    "customer": {
        "id": "cu_1753349397",
        "name": "John Doe",
        "email": "guest@example.com",
        "phone": "999999999",
        "phone_country_code": "+1"
    },
    "description": "Its my first payment request",
    "refunds": null,
    "disputes": null,
    "mandate_id": null,
    "mandate_data": null,
    "setup_future_usage": "on_session",
    "off_session": null,
    "capture_on": null,
    "capture_method": "automatic",
    "payment_method": "card",
    "payment_method_data": {
        "card": {
            "last4": "1111",
            "card_type": null,
            "card_network": null,
            "card_issuer": null,
            "card_issuing_country": null,
            "card_isin": "411111",
            "card_extended_bin": null,
            "card_exp_month": "03",
            "card_exp_year": "2030",
            "card_holder_name": "joseph Doe",
            "payment_checks": null,
            "authentication_data": null
        },
        "billing": null
    },
    "payment_token": null,
    "shipping": {
        "address": {
            "city": "San Fransico",
            "country": "US",
            "line1": "1467",
            "line2": "Harrison Street",
            "line3": "Harrison Street",
            "zip": "94122",
            "state": "California",
            "first_name": "PiX",
            "last_name": null
        },
        "phone": null,
        "email": null
    },
    "billing": {
        "address": {
            "city": "San",
            "country": "US",
            "line1": "1467",
            "line2": "Harrison Street",
            "line3": "Harrison Street",
            "zip": "94122",
            "state": "California",
            "first_name": "PiX",
            "last_name": "ss"
        },
        "phone": null,
        "email": "raj@gmail.com"
    },
    "order_details": null,
    "email": "guest@example.com",
    "name": "John Doe",
    "phone": "999999999",
    "return_url": "http://127.0.0.1:4040/",
    "authentication_type": "no_three_ds",
    "statement_descriptor_name": "joseph",
    "statement_descriptor_suffix": "JS",
    "next_action": null,
    "cancellation_reason": null,
    "error_code": null,
    "error_message": null,
    "unified_code": null,
    "unified_message": null,
    "payment_experience": null,
    "payment_method_type": null,
    "connector_label": null,
    "business_country": null,
    "business_label": "default",
    "business_sub_label": null,
    "allowed_payment_method_types": null,
    "ephemeral_key": {
        "customer_id": "cu_1753349397",
        "created_at": 1753349397,
        "expires": 1753352997,
        "secret": "epk_e313bd1d47874c7fa7379c5c8d69fe53"
    },
    "manual_retry_allowed": false,
    "connector_transaction_id": "N7DWCX9JCT8SXC75",
    "frm_message": null,
    "metadata": {
        "udf1": "value1",
        "login_date": "2019-09-10T10:11:12Z",
        "new_customer": "true"
    },
    "connector_metadata": null,
    "feature_metadata": null,
    "reference_id": "pay_IUCHPAl9h0w2pU42MSjP_1",
    "payment_link": null,
    "profile_id": "pro_gtFgPCNzLPlZCIzitXyr",
    "surcharge_details": null,
    "attempt_count": 1,
    "merchant_decision": null,
    "merchant_connector_id": "mca_F4voD3pzs9339zlOTZeT",
    "incremental_authorization_allowed": null,
    "authorization_count": null,
    "incremental_authorizations": null,
    "external_authentication_details": null,
    "external_3ds_authentication_attempted": false,
    "expires_on": "2025-07-24T09:44:57.265Z",
    "fingerprint": null,
    "browser_info": {
        "language": "nl-NL",
        "time_zone": 0,
        "ip_address": "125.0.0.1",
        "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",
        "color_depth": 24,
        "java_enabled": true,
        "screen_width": 1536,
        "accept_header": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
        "screen_height": 723,
        "java_script_enabled": true
    },
    "payment_method_id": null,
    "payment_method_status": null,
    "updated": "2025-07-24T09:29:58.665Z",
    "split_payments": null,
    "frm_metadata": null,
    "extended_authorization_applied": null,
    "capture_before": null,
    "merchant_order_reference_id": null,
    "order_tax_amount": null,
    "connector_mandate_id": null,
    "card_discovery": "manual",
    "force_3ds_challenge": false,
    "force_3ds_challenge_trigger": false,
    "issuer_error_code": null,
    "issuer_error_message": null,
    "is_iframe_redirection_enabled": null,
    "whole_connector_response": null
}

-> apple pay hyperswitch decrypt

curl --location 'http://localhost:8080/payments' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: dev_fG0Py6LkKzjLXPtMoUgqPAnmfzCxcRuf7nuOERwaXv1PBWEjjaqFARqp8PJL7yCZ' \
--data-raw '{
    "amount": 6500,
    "currency": "USD",
    "confirm": true,
    "business_country": "US",
    "business_label": "default",
    "amount_to_capture": 6500,
    "customer_id": "cu_1753349907",
    "capture_method": "automatic",
    "capture_on": "2022-09-10T10:11:12Z",
    "setup_future_usage": "on_session",
    "authentication_type": "no_three_ds",
    "return_url": "https://google.com",
    "email": "something@gmail.com",
    "name": "Joseph Doe",
    "phone": "999999999",
    "phone_country_code": "+65",
    "description": "Its my first payment request",
    "statement_descriptor_name": "Juspay",
    "statement_descriptor_suffix": "Router",
    "payment_method": "wallet",
    "payment_method_type": "apple_pay",
    "billing": {
        "address": {
            "line1": "1467",
            "city": "San Fransico",
            "state": "California",
            "zip": "94122",
            "country": "US",
            "first_name": "joseph",
            "last_name": "Doe"
        },
        "phone": {
            "number": "8056594427",
            "country_code": "+91"
        }
    },
    "customer_acceptance": {
        "acceptance_type": "offline",
        "accepted_at": "1963-05-03T04:07:52.723Z",
        "online": {
            "ip_address": "in sit",
            "user_agent": "amet irure esse"
        }
    }
    ,
    "payment_method_data": {
        "wallet": {
            "apple_pay": {
                "payment_data": "=",
                "payment_method": {
                    "display_name": "Discover 9319",
                    "network": "Discover",
                    "type": "debit"
                },
                "transaction_identifier": "c635c5b3af900d7bd81fecd7028f1262f9d030754ee65ec7afd988a678194751"
            }
        }
    }
}'
{
    "payment_id": "pay_ehf8EOyIovaVY9IQudiA",
    "merchant_id": "merchant_1753349865",
    "status": "succeeded",
    "amount": 6500,
    "net_amount": 6500,
    "shipping_cost": null,
    "amount_capturable": 0,
    "amount_received": 6500,
    "connector": "stripe",
    "client_secret": "pay_ehf8EOyIovaVY9IQudiA_secret_kSZD9Lzhn0I7WWc10KJu",
    "created": "2025-07-24T09:38:18.751Z",
    "currency": "USD",
    "customer_id": "cu_1753349899",
    "customer": {
        "id": "cu_1753349899",
        "name": "Joseph Doe",
        "email": "something@gmail.com",
        "phone": "999999999",
        "phone_country_code": "+65"
    },
    "description": "Its my first payment request",
    "refunds": null,
    "disputes": null,
    "mandate_id": null,
    "mandate_data": null,
    "setup_future_usage": "on_session",
    "off_session": null,
    "capture_on": null,
    "capture_method": "automatic",
    "payment_method": "wallet",
    "payment_method_data": {
        "wallet": {
            "apple_pay": {
                "last4": "9319",
                "card_network": "Discover",
                "type": "debit"
            }
        },
        "billing": null
    },
    "payment_token": null,
    "shipping": null,
    "billing": {
        "address": {
            "city": "San Fransico",
            "country": "US",
            "line1": "1467",
            "line2": null,
            "line3": null,
            "zip": "94122",
            "state": "California",
            "first_name": "joseph",
            "last_name": "Doe"
        },
        "phone": {
            "number": "8056594427",
            "country_code": "+91"
        },
        "email": null
    },
    "order_details": null,
    "email": "something@gmail.com",
    "name": "Joseph Doe",
    "phone": "999999999",
    "return_url": "https://google.com/",
    "authentication_type": "no_three_ds",
    "statement_descriptor_name": "Juspay",
    "statement_descriptor_suffix": "Router",
    "next_action": null,
    "cancellation_reason": null,
    "error_code": null,
    "error_message": null,
    "unified_code": null,
    "unified_message": null,
    "payment_experience": null,
    "payment_method_type": "apple_pay",
    "connector_label": "stripe_US_default",
    "business_country": "US",
    "business_label": "default",
    "business_sub_label": null,
    "allowed_payment_method_types": null,
    "ephemeral_key": {
        "customer_id": "cu_1753349899",
        "created_at": 1753349898,
        "expires": 1753353498,
        "secret": "epk_679a71f8c93842d397d49838846707c6"
    },
    "manual_retry_allowed": false,
    "connector_transaction_id": "pi_3RoLbUEOqOywnAIx0OUznkxA",
    "frm_message": null,
    "metadata": null,
    "connector_metadata": null,
    "feature_metadata": null,
    "reference_id": "pi_3RoLbUEOqOywnAIx0OUznkxA",
    "payment_link": null,
    "profile_id": "pro_AHhiUwwtdVJF4wpev3kl",
    "surcharge_details": null,
    "attempt_count": 1,
    "merchant_decision": null,
    "merchant_connector_id": "mca_Nm3XaDfdM55WDDfkPSLi",
    "incremental_authorization_allowed": null,
    "authorization_count": null,
    "incremental_authorizations": null,
    "external_authentication_details": null,
    "external_3ds_authentication_attempted": false,
    "expires_on": "2025-07-24T09:53:18.751Z",
    "fingerprint": null,
    "browser_info": null,
    "payment_method_id": null,
    "payment_method_status": null,
    "updated": "2025-07-24T09:38:21.475Z",
    "split_payments": null,
    "frm_metadata": null,
    "extended_authorization_applied": null,
    "capture_before": null,
    "merchant_order_reference_id": null,
    "order_tax_amount": null,
    "connector_mandate_id": null,
    "card_discovery": null,
    "force_3ds_challenge": false,
    "force_3ds_challenge_trigger": false,
    "issuer_error_code": null,
    "issuer_error_message": null,
    "is_iframe_redirection_enabled": null,
    "whole_connector_response": null
}

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

@ShankarSinghC ShankarSinghC requested a review from jagan-jaya July 24, 2025 09:43
@ShankarSinghC ShankarSinghC self-assigned this Jul 24, 2025
@ShankarSinghC ShankarSinghC requested a review from a team as a code owner July 24, 2025 09:43
@ShankarSinghC ShankarSinghC added A-core Area: Core flows C-bug Category: Bug A-payment-methods Area: Payment Methods A-payments Area: payments labels Jul 24, 2025
@semanticdiff-com
Copy link

semanticdiff-com bot commented Jul 24, 2025

Review changes with  SemanticDiff

Changed Files
File Status
  crates/router/src/core/payments.rs  60% smaller

@ShankarSinghC ShankarSinghC linked an issue Jul 24, 2025 that may be closed by this pull request
jagan-jaya
jagan-jaya previously approved these changes Jul 24, 2025
@ShankarSinghC ShankarSinghC changed the base branch from main to hotfix-2025.07.23.0 July 24, 2025 10:22
@ShankarSinghC ShankarSinghC dismissed stale reviews from jagan-jaya and sai-harsha-vardhan July 24, 2025 10:22

The base branch was changed.

@likhinbopanna likhinbopanna merged commit 52e193c into hotfix-2025.07.23.0 Jul 24, 2025
25 of 31 checks passed
@likhinbopanna likhinbopanna deleted the debit-routing/wallets/hot-fix/refactor-tokenization branch July 24, 2025 11:44
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-payment-methods Area: Payment Methods A-payments Area: payments C-bug Category: Bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

decrypt the wallet token before the debit routing call

5 participants