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

refactor(router): store network_transaction_id for off_session payments irrespective of the is_connector_agnostic_mit_enabled config #7083

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

ShankarSinghC
Copy link
Contributor

@ShankarSinghC ShankarSinghC commented Jan 22, 2025

Type of Change

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

Description

Currently, we store the network_transaction_id for the setup_mandate/off_session payments only if the is_connector_agnostic_mit_enabled config is enabled. During the MITs, we refer to this flag to decide whether to use the connector_mandate_id or the network_transaction_id for the MIT.

Instead of using the flag for multiple purposes, it should be used solely to determine whether to use the connector_mandate_id or the network_transaction_id for the MIT. Therefore, this change will ensure that the network_transaction_id is always stored for off-session payments if it is present in the connector response.

Additional Changes

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

Motivation and Context

Instead of using the is_connector_agnostic_mit_enabled flag for multiple purposes, it should be used solely to determine whether to use the connector_mandate_id or the network_transaction_id for the MIT. And is the connector is returning the network_transaction_id for the off_session payment it should always be stored.

How did you test it?

-> Create a business profile and is_connector_agnostic_mit_enabled disabled.

Initial CIT

-> Make an off_session payment. Even though the is_connector_agnostic_mit_enabled is false network_transaction_id should be stored in the payment methods table.

curl --location 'http://localhost:8080/payments' \
--header 'Accept: application/json' \
--header 'api-key: <api-key>' \
--header 'Content-Type: application/json' \
--data-raw '{
    "amount": 500,
    "currency": "USD",
    "confirm": true,
    "capture_method": "automatic",
    "capture_on": "2022-09-10T10:11:12Z",
    "customer_id": "cu_1737523971",
    "email": "[email protected]",
    "name": "John Doe",
    "phone": "999999999",
    "phone_country_code": "+65",
    "description": "Its my first payment request",
    "authentication_type": "no_three_ds",
    "return_url": "https://google.com",
    "payment_method": "card",
    "payment_method_type": "credit",
    "payment_method_data": {
        "card": {
            "card_number": "4111111111111111",
            "card_exp_month": "03",
            "card_exp_year": "2030",
            "card_holder_name": "name name",
            "card_cvc": "737"
        }
    },
    "setup_future_usage": "off_session",
    "customer_acceptance": {
        "acceptance_type": "offline",
        "accepted_at": "1963-05-03T04:07:52.723Z",
        "online": {
            "ip_address": "in sit",
            "user_agent": "amet irure esse"
        }
    },
    "billing": {
        "address": {
            "line1": "1467",
            "line2": "Harrison Street",
            "line3": "Harrison Street",
            "city": "San Fransico",
            "state": "California",
            "zip": "94122",
            "country": "US",
            "first_name": "PiX",
            "last_name": "ss"
        }
    },
    "shipping": {
        "address": {
            "line1": "1467",
            "line2": "Harrison Street",
            "line3": "Harrison Street",
            "city": "San Fransico",
            "state": "California",
            "zip": "94122",
            "country": "US",
            "first_name": "John",
            "last_name": "Doe"
        },
        "phone": {
            "number": "8056594427",
            "country_code": "+91"
        }
    },
    "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": {},
    "order_details": [
        {
            "product_name": "Apple iphone 15",
            "quantity": 1,
            "amount": 0,
            "account_name": "transaction_processing"
        }
    ]
}'
{
    "payment_id": "pay_WdSrWb2Xf2kDegvEULPM",
    "merchant_id": "merchant_1737523864",
    "status": "succeeded",
    "amount": 500,
    "net_amount": 500,
    "shipping_cost": null,
    "amount_capturable": 0,
    "amount_received": 500,
    "connector": "stripe",
    "client_secret": "pay_WdSrWb2Xf2kDegvEULPM_secret_VpuAJ51okhFJZG8TmQ0c",
    "created": "2025-01-22T05:32:47.192Z",
    "currency": "USD",
    "customer_id": "cu_1737523967",
    "customer": {
        "id": "cu_1737523967",
        "name": "John Doe",
        "email": "[email protected]",
        "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": "off_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": "name name",
            "payment_checks": {
                "cvc_check": "pass",
                "address_line1_check": "pass",
                "address_postal_code_check": "pass"
            },
            "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": "John",
            "last_name": "Doe"
        },
        "phone": {
            "number": "8056594427",
            "country_code": "+91"
        },
        "email": null
    },
    "billing": {
        "address": {
            "city": "San Fransico",
            "country": "US",
            "line1": "1467",
            "line2": "Harrison Street",
            "line3": "Harrison Street",
            "zip": "94122",
            "state": "California",
            "first_name": "PiX",
            "last_name": "ss"
        },
        "phone": null,
        "email": null
    },
    "order_details": [
        {
            "brand": null,
            "amount": 0,
            "category": null,
            "quantity": 1,
            "tax_rate": null,
            "product_id": null,
            "product_name": "Apple iphone 15",
            "product_type": null,
            "sub_category": null,
            "product_img_link": null,
            "product_tax_code": null,
            "total_tax_amount": null,
            "requires_shipping": null
        }
    ],
    "email": "[email protected]",
    "name": "John Doe",
    "phone": "999999999",
    "return_url": "https://google.com/",
    "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": "credit",
    "connector_label": null,
    "business_country": null,
    "business_label": "default",
    "business_sub_label": null,
    "allowed_payment_method_types": null,
    "ephemeral_key": {
        "customer_id": "cu_1737523967",
        "created_at": 1737523967,
        "expires": 1737527567,
        "secret": "epk_e06fef83ccd64ff8b38d5c9955b09a25"
    },
    "manual_retry_allowed": false,
    "connector_transaction_id": "pi_3QjwYWEOqOywnAIx0lOiWYTn",
    "frm_message": null,
    "metadata": {},
    "connector_metadata": null,
    "feature_metadata": null,
    "reference_id": "pi_3QjwYWEOqOywnAIx0lOiWYTn",
    "payment_link": null,
    "profile_id": "pro_L5I6p61FJYPyguLsk4W7",
    "surcharge_details": null,
    "attempt_count": 1,
    "merchant_decision": null,
    "merchant_connector_id": "mca_OrorUGWr12wrEyKfTPBT",
    "incremental_authorization_allowed": null,
    "authorization_count": null,
    "incremental_authorizations": null,
    "external_authentication_details": null,
    "external_3ds_authentication_attempted": false,
    "expires_on": "2025-01-22T05:47:47.192Z",
    "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": "pm_MtvoUeVqyzRigXnRA3B8",
    "payment_method_status": "active",
    "updated": "2025-01-22T05:32:49.202Z",
    "split_payments": null,
    "frm_metadata": null,
    "merchant_order_reference_id": null,
    "order_tax_amount": null,
    "connector_mandate_id": "pm_1QjwYWEOqOywnAIx6kk4d3Cf"
}

-> Db screenshot shown network_transaction_id being stored in the payment methods table.
image

Recurring MIT

-> Create a payment for the same customer with confirm false

curl --location 'http://localhost:8080/payments' \
--header 'Accept: application/json' \
--header 'api-key: <api-key>' \
--header 'Content-Type: application/json' \
--data '{
    "amount": 10000,
    "currency": "USD",
    "capture_method": "automatic",
    "authentication_type": "three_ds",
    "confirm": false,
    "customer_id": "cu_1737523967"
}'
{
    "payment_id": "pay_i04r0cC5OTVNrNBbWHLk",
    "merchant_id": "merchant_1737523864",
    "status": "requires_payment_method",
    "amount": 10000,
    "net_amount": 10000,
    "shipping_cost": null,
    "amount_capturable": 0,
    "amount_received": null,
    "connector": null,
    "client_secret": "pay_i04r0cC5OTVNrNBbWHLk_secret_WsYRWkHY7vxbD2AOt1tL",
    "created": "2025-01-22T05:37:20.683Z",
    "currency": "USD",
    "customer_id": "cu_1737523967",
    "customer": {
        "id": "cu_1737523967",
        "name": "John Doe",
        "email": "[email protected]",
        "phone": "999999999",
        "phone_country_code": "+65"
    },
    "description": null,
    "refunds": null,
    "disputes": null,
    "mandate_id": null,
    "mandate_data": null,
    "setup_future_usage": null,
    "off_session": null,
    "capture_on": null,
    "capture_method": "automatic",
    "payment_method": null,
    "payment_method_data": null,
    "payment_token": null,
    "shipping": null,
    "billing": null,
    "order_details": null,
    "email": "[email protected]",
    "name": "John Doe",
    "phone": "999999999",
    "return_url": null,
    "authentication_type": "three_ds",
    "statement_descriptor_name": null,
    "statement_descriptor_suffix": null,
    "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_1737523967",
        "created_at": 1737524240,
        "expires": 1737527840,
        "secret": "epk_5036d7ff60ff4b76a31e2a12bf758273"
    },
    "manual_retry_allowed": null,
    "connector_transaction_id": null,
    "frm_message": null,
    "metadata": null,
    "connector_metadata": null,
    "feature_metadata": null,
    "reference_id": null,
    "payment_link": null,
    "profile_id": "pro_L5I6p61FJYPyguLsk4W7",
    "surcharge_details": null,
    "attempt_count": 1,
    "merchant_decision": null,
    "merchant_connector_id": null,
    "incremental_authorization_allowed": null,
    "authorization_count": null,
    "incremental_authorizations": null,
    "external_authentication_details": null,
    "external_3ds_authentication_attempted": false,
    "expires_on": "2025-01-22T05:52:20.683Z",
    "fingerprint": null,
    "browser_info": null,
    "payment_method_id": null,
    "payment_method_status": null,
    "updated": "2025-01-22T05:37:20.704Z",
    "split_payments": null,
    "frm_metadata": null,
    "merchant_order_reference_id": null,
    "order_tax_amount": null,
    "connector_mandate_id": null
}

-> List payment methods using the above client_secret

curl --location 'http://localhost:8080/customers/payment_methods?client_secret=pay_i04r0cC5OTVNrNBbWHLk_secret_WsYRWkHY7vxbD2AOt1tL' \
--header 'Accept: application/json' \
--header 'api-key: pk_dev_2075ddba1e634912bd68c04d912b9da4'
{
    "customer_payment_methods": [
        {
            "payment_token": "token_4LrYcGKdvscFoqp6OzWZ",
            "payment_method_id": "pm_MtvoUeVqyzRigXnRA3B8",
            "customer_id": "cu_1737523967",
            "payment_method": "card",
            "payment_method_type": "credit",
            "payment_method_issuer": null,
            "payment_method_issuer_code": null,
            "recurring_enabled": true,
            "installment_payment_enabled": false,
            "payment_experience": [
                "redirect_to_url"
            ],
            "card": {
                "scheme": null,
                "issuer_country": null,
                "last4_digits": "1111",
                "expiry_month": "03",
                "expiry_year": "2030",
                "card_token": null,
                "card_holder_name": "name name",
                "card_fingerprint": null,
                "nick_name": null,
                "card_network": null,
                "card_isin": "411111",
                "card_issuer": null,
                "card_type": null,
                "saved_to_locker": true
            },
            "metadata": null,
            "created": "2025-01-22T05:32:49.170Z",
            "bank": null,
            "surcharge_details": null,
            "requires_cvv": true,
            "last_used_at": "2025-01-22T05:32:49.170Z",
            "default_payment_method_set": true,
            "billing": {
                "address": {
                    "city": "San Fransico",
                    "country": "US",
                    "line1": "1467",
                    "line2": "Harrison Street",
                    "line3": "Harrison Street",
                    "zip": "94122",
                    "state": "California",
                    "first_name": "name",
                    "last_name": "name"
                },
                "phone": null,
                "email": null
            }
        }
    ],
    "is_guest_customer": false
}

-> Confirm the payment with the above listed token. Even though network_transaction_id is present, as the is_connector_agnostic_mit_enabled is false the MIT should be processed by using connector_mandate_id.

curl --location 'http://localhost:8080/payments/pay_i04r0cC5OTVNrNBbWHLk/confirm' \
--header 'api-key: pk_dev_2075ddba1e634912bd68c04d912b9da4' \
--header 'Content-Type: application/json' \
--data-raw '{
    "payment_token": "token_4LrYcGKdvscFoqp6OzWZ",
    "payment_method_type": "credit",
    "payment_method": "card",
    "setup_future_usage": "off_session",
    "client_secret": "pay_i04r0cC5OTVNrNBbWHLk_secret_WsYRWkHY7vxbD2AOt1tL",
    
    "billing": {
        "address": {
            "city": "test",
            "country": "US",
            "line1": "here",
            "line2": "there",
            "line3": "anywhere",
            "zip": "560095",
            "state": "Washington",
            "first_name": "One",
            "last_name": "Two"
        },
        "phone": {
            "number": "1234567890",
            "country_code": "+1"
        },
        "email": "[email protected]"
    }
}'
{
    "payment_id": "pay_i04r0cC5OTVNrNBbWHLk",
    "merchant_id": "merchant_1737523864",
    "status": "succeeded",
    "amount": 10000,
    "net_amount": 10000,
    "shipping_cost": null,
    "amount_capturable": 0,
    "amount_received": 10000,
    "connector": "stripe",
    "client_secret": "pay_i04r0cC5OTVNrNBbWHLk_secret_WsYRWkHY7vxbD2AOt1tL",
    "created": "2025-01-22T05:37:20.683Z",
    "currency": "USD",
    "customer_id": "cu_1737523967",
    "customer": {
        "id": "cu_1737523967",
        "name": "John Doe",
        "email": "[email protected]",
        "phone": "999999999",
        "phone_country_code": "+65"
    },
    "description": null,
    "refunds": null,
    "disputes": null,
    "mandate_id": null,
    "mandate_data": null,
    "setup_future_usage": "off_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": "name name",
            "payment_checks": null,
            "authentication_data": null
        },
        "billing": null
    },
    "payment_token": "token_4LrYcGKdvscFoqp6OzWZ",
    "shipping": null,
    "billing": {
        "address": {
            "city": "test",
            "country": "US",
            "line1": "here",
            "line2": "there",
            "line3": "anywhere",
            "zip": "560095",
            "state": "Washington",
            "first_name": "One",
            "last_name": "Two"
        },
        "phone": {
            "number": "1234567890",
            "country_code": "+1"
        },
        "email": "[email protected]"
    },
    "order_details": null,
    "email": "[email protected]",
    "name": "John Doe",
    "phone": "999999999",
    "return_url": null,
    "authentication_type": "three_ds",
    "statement_descriptor_name": null,
    "statement_descriptor_suffix": null,
    "next_action": null,
    "cancellation_reason": null,
    "error_code": null,
    "error_message": null,
    "unified_code": null,
    "unified_message": null,
    "payment_experience": null,
    "payment_method_type": "credit",
    "connector_label": null,
    "business_country": null,
    "business_label": "default",
    "business_sub_label": null,
    "allowed_payment_method_types": null,
    "ephemeral_key": null,
    "manual_retry_allowed": false,
    "connector_transaction_id": "pi_3QjwfBEOqOywnAIx0lXPFXLq",
    "frm_message": null,
    "metadata": null,
    "connector_metadata": null,
    "feature_metadata": null,
    "reference_id": "pi_3QjwfBEOqOywnAIx0lXPFXLq",
    "payment_link": null,
    "profile_id": "pro_L5I6p61FJYPyguLsk4W7",
    "surcharge_details": null,
    "attempt_count": 1,
    "merchant_decision": null,
    "merchant_connector_id": "mca_OrorUGWr12wrEyKfTPBT",
    "incremental_authorization_allowed": null,
    "authorization_count": null,
    "incremental_authorizations": null,
    "external_authentication_details": null,
    "external_3ds_authentication_attempted": false,
    "expires_on": "2025-01-22T05:52:20.683Z",
    "fingerprint": null,
    "browser_info": {
        "os_type": null,
        "language": null,
        "time_zone": null,
        "ip_address": "::1",
        "os_version": null,
        "user_agent": null,
        "color_depth": null,
        "device_model": null,
        "java_enabled": null,
        "screen_width": null,
        "accept_header": null,
        "screen_height": null,
        "java_script_enabled": null
    },
    "payment_method_id": "pm_MtvoUeVqyzRigXnRA3B8",
    "payment_method_status": "active",
    "updated": "2025-01-22T05:39:42.150Z",
    "split_payments": null,
    "frm_metadata": null,
    "merchant_order_reference_id": null,
    "order_tax_amount": null,
    "connector_mandate_id": "pm_1QjwYWEOqOywnAIx6kk4d3Cf"
}

-> Logs showing connector_mandate_id is used for the MIT
image

Recurring MIT by passing different connector in the routing.

-> Create a network_transaction_id support connector (stripe, adyen or cybersource)
-> Create a payment for the same customer

curl --location 'http://localhost:8080/payments' \
--header 'Accept: application/json' \
--header 'api-key: <api-key>' \
--header 'Content-Type: application/json' \
--data '{
    "amount": 10000,
    "currency": "USD",
    "capture_method": "automatic",
    "authentication_type": "three_ds",
    "confirm": false,
    "customer_id": "cu_1737523967"
}'
{
    "payment_id": "pay_Bi0rNupobukz2roRumXE",
    "merchant_id": "merchant_1737523864",
    "status": "requires_payment_method",
    "amount": 10000,
    "net_amount": 10000,
    "shipping_cost": null,
    "amount_capturable": 0,
    "amount_received": null,
    "connector": null,
    "client_secret": "pay_Bi0rNupobukz2roRumXE_secret_5p8bU6yvNJeims5isKKM",
    "created": "2025-01-22T05:43:24.656Z",
    "currency": "USD",
    "customer_id": "cu_1737523967",
    "customer": {
        "id": "cu_1737523967",
        "name": "John Doe",
        "email": "[email protected]",
        "phone": "999999999",
        "phone_country_code": "+65"
    },
    "description": null,
    "refunds": null,
    "disputes": null,
    "mandate_id": null,
    "mandate_data": null,
    "setup_future_usage": null,
    "off_session": null,
    "capture_on": null,
    "capture_method": "automatic",
    "payment_method": null,
    "payment_method_data": null,
    "payment_token": null,
    "shipping": null,
    "billing": null,
    "order_details": null,
    "email": "[email protected]",
    "name": "John Doe",
    "phone": "999999999",
    "return_url": null,
    "authentication_type": "three_ds",
    "statement_descriptor_name": null,
    "statement_descriptor_suffix": null,
    "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_1737523967",
        "created_at": 1737524604,
        "expires": 1737528204,
        "secret": "epk_b8b07628bfa247d395517dbdc54c26b1"
    },
    "manual_retry_allowed": null,
    "connector_transaction_id": null,
    "frm_message": null,
    "metadata": null,
    "connector_metadata": null,
    "feature_metadata": null,
    "reference_id": null,
    "payment_link": null,
    "profile_id": "pro_L5I6p61FJYPyguLsk4W7",
    "surcharge_details": null,
    "attempt_count": 1,
    "merchant_decision": null,
    "merchant_connector_id": null,
    "incremental_authorization_allowed": null,
    "authorization_count": null,
    "incremental_authorizations": null,
    "external_authentication_details": null,
    "external_3ds_authentication_attempted": false,
    "expires_on": "2025-01-22T05:58:24.656Z",
    "fingerprint": null,
    "browser_info": null,
    "payment_method_id": null,
    "payment_method_status": null,
    "updated": "2025-01-22T05:43:24.666Z",
    "split_payments": null,
    "frm_metadata": null,
    "merchant_order_reference_id": null,
    "order_tax_amount": null,
    "connector_mandate_id": null
}

-> List payment methods using the above client_secret

curl --location 'http://localhost:8080/customers/payment_methods?client_secret=pay_Bi0rNupobukz2roRumXE_secret_5p8bU6yvNJeims5isKKM' \
--header 'Accept: application/json' \
--header 'api-key: pk_dev_2075ddba1e634912bd68c04d912b9da4'
{
    "customer_payment_methods": [
        {
            "payment_token": "token_1nBgsEHUEWZbafeYF91S",
            "payment_method_id": "pm_MtvoUeVqyzRigXnRA3B8",
            "customer_id": "cu_1737523967",
            "payment_method": "card",
            "payment_method_type": "credit",
            "payment_method_issuer": null,
            "payment_method_issuer_code": null,
            "recurring_enabled": true,
            "installment_payment_enabled": false,
            "payment_experience": [
                "redirect_to_url"
            ],
            "card": {
                "scheme": null,
                "issuer_country": null,
                "last4_digits": "1111",
                "expiry_month": "03",
                "expiry_year": "2030",
                "card_token": null,
                "card_holder_name": "name name",
                "card_fingerprint": null,
                "nick_name": null,
                "card_network": null,
                "card_isin": "411111",
                "card_issuer": null,
                "card_type": null,
                "saved_to_locker": true
            },
            "metadata": null,
            "created": "2025-01-22T05:32:49.170Z",
            "bank": null,
            "surcharge_details": null,
            "requires_cvv": true,
            "last_used_at": "2025-01-22T05:39:42.140Z",
            "default_payment_method_set": true,
            "billing": {
                "address": {
                    "city": "San Fransico",
                    "country": "US",
                    "line1": "1467",
                    "line2": "Harrison Street",
                    "line3": "Harrison Street",
                    "zip": "94122",
                    "state": "California",
                    "first_name": "name",
                    "last_name": "name"
                },
                "phone": null,
                "email": null
            }
        }
    ],
    "is_guest_customer": false
}

-> Confirm the payment by pass the newly configured connector (the connector that was not used in the initially CIT). Even though cybersource was sent in the routing input, the payment was processed with stripe as the is_connector_agnostic_mit_enabled is false and connector_mandate_id that is present is of stripe.

curl --location 'http://localhost:8080/payments/pay_Bi0rNupobukz2roRumXE/confirm' \
--header 'api-key: pk_dev_2075ddba1e634912bd68c04d912b9da4' \
--header 'Content-Type: application/json' \
--data-raw '{
    "payment_token": "token_1nBgsEHUEWZbafeYF91S",
    "payment_method_type": "credit",
    "payment_method": "card",
    "setup_future_usage": "off_session",
    "client_secret": "pay_Bi0rNupobukz2roRumXE_secret_5p8bU6yvNJeims5isKKM",
    "routing": {
        "type": "single",
        "data": {
            "connector": "cybersource",
            "merchant_connector_id": "mca_Z8Jdk0UIzjgZHVlOHjuX"
        }
    },
    "billing": {
        "address": {
            "city": "test",
            "country": "US",
            "line1": "here",
            "line2": "there",
            "line3": "anywhere",
            "zip": "560095",
            "state": "Washington",
            "first_name": "One",
            "last_name": "Two"
        },
        "phone": {
            "number": "1234567890",
            "country_code": "+1"
        },
        "email": "[email protected]"
    }
}'
{
    "payment_id": "pay_Bi0rNupobukz2roRumXE",
    "merchant_id": "merchant_1737523864",
    "status": "succeeded",
    "amount": 10000,
    "net_amount": 10000,
    "shipping_cost": null,
    "amount_capturable": 0,
    "amount_received": 10000,
    "connector": "stripe",
    "client_secret": "pay_Bi0rNupobukz2roRumXE_secret_5p8bU6yvNJeims5isKKM",
    "created": "2025-01-22T05:43:24.656Z",
    "currency": "USD",
    "customer_id": "cu_1737523967",
    "customer": {
        "id": "cu_1737523967",
        "name": "John Doe",
        "email": "[email protected]",
        "phone": "999999999",
        "phone_country_code": "+65"
    },
    "description": null,
    "refunds": null,
    "disputes": null,
    "mandate_id": null,
    "mandate_data": null,
    "setup_future_usage": "off_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": "name name",
            "payment_checks": null,
            "authentication_data": null
        },
        "billing": null
    },
    "payment_token": "token_1nBgsEHUEWZbafeYF91S",
    "shipping": null,
    "billing": {
        "address": {
            "city": "test",
            "country": "US",
            "line1": "here",
            "line2": "there",
            "line3": "anywhere",
            "zip": "560095",
            "state": "Washington",
            "first_name": "One",
            "last_name": "Two"
        },
        "phone": {
            "number": "1234567890",
            "country_code": "+1"
        },
        "email": "[email protected]"
    },
    "order_details": null,
    "email": "[email protected]",
    "name": "John Doe",
    "phone": "999999999",
    "return_url": null,
    "authentication_type": "three_ds",
    "statement_descriptor_name": null,
    "statement_descriptor_suffix": null,
    "next_action": null,
    "cancellation_reason": null,
    "error_code": null,
    "error_message": null,
    "unified_code": null,
    "unified_message": null,
    "payment_experience": null,
    "payment_method_type": "credit",
    "connector_label": null,
    "business_country": null,
    "business_label": "default",
    "business_sub_label": null,
    "allowed_payment_method_types": null,
    "ephemeral_key": null,
    "manual_retry_allowed": false,
    "connector_transaction_id": "pi_3QjwjAEOqOywnAIx1JaY1wKs",
    "frm_message": null,
    "metadata": null,
    "connector_metadata": null,
    "feature_metadata": null,
    "reference_id": "pi_3QjwjAEOqOywnAIx1JaY1wKs",
    "payment_link": null,
    "profile_id": "pro_L5I6p61FJYPyguLsk4W7",
    "surcharge_details": null,
    "attempt_count": 1,
    "merchant_decision": null,
    "merchant_connector_id": "mca_OrorUGWr12wrEyKfTPBT",
    "incremental_authorization_allowed": null,
    "authorization_count": null,
    "incremental_authorizations": null,
    "external_authentication_details": null,
    "external_3ds_authentication_attempted": false,
    "expires_on": "2025-01-22T05:58:24.656Z",
    "fingerprint": null,
    "browser_info": {
        "os_type": null,
        "language": null,
        "time_zone": null,
        "ip_address": "::1",
        "os_version": null,
        "user_agent": null,
        "color_depth": null,
        "device_model": null,
        "java_enabled": null,
        "screen_width": null,
        "accept_header": null,
        "screen_height": null,
        "java_script_enabled": null
    },
    "payment_method_id": "pm_MtvoUeVqyzRigXnRA3B8",
    "payment_method_status": "active",
    "updated": "2025-01-22T05:43:49.519Z",
    "split_payments": null,
    "frm_metadata": null,
    "merchant_order_reference_id": null,
    "order_tax_amount": null,
    "connector_mandate_id": "pm_1QjwYWEOqOywnAIx6kk4d3Cf"
}

-> Log showing routing order is [Cybersource, Stripe] and connector_mandate_id was used to process the MIT
image

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 added A-core Area: Core flows A-payment-methods Area: Payment Methods C-refactor Category: Refactor A-payments Area: payments labels Jan 22, 2025
@ShankarSinghC ShankarSinghC self-assigned this Jan 22, 2025
@ShankarSinghC ShankarSinghC requested review from a team as code owners January 22, 2025 05:52
Copy link

semanticdiff-com bot commented Jan 22, 2025

Review changes with  SemanticDiff

Changed Files
File Status
  crates/router/src/core/payments/operations/payment_response.rs  58% smaller
  crates/router/src/core/payments/tokenization.rs  55% smaller

let network_transaction_id =
let network_transaction_id = if payment_data.payment_intent.setup_future_usage
== Some(diesel_models::enums::FutureUsage::OffSession)
{
if let Some(network_transaction_id) = pm_resp_network_transaction_id {
Copy link
Member

Choose a reason for hiding this comment

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

what is the purpose of this if let? Just for logger this can be achieved via an if statement as well

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-refactor Category: Refactor
Projects
None yet
3 participants