Skip to content

feat(samsung_pay): collect customer address details form Samsung Pay based on business profile config and connector required fields#7320

Merged
Gnanasundari24 merged 4 commits intomainfrom
samsung-pay/session-call
Feb 22, 2025
Merged

feat(samsung_pay): collect customer address details form Samsung Pay based on business profile config and connector required fields#7320
Gnanasundari24 merged 4 commits intomainfrom
samsung-pay/session-call

Conversation

@ShankarSinghC
Copy link
Contributor

@ShankarSinghC ShankarSinghC commented Feb 19, 2025

Type of Change

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

Description

This pull request includes changes to enhance the handling of billing and shipping address requirements for Samsung Pay and Google Pay session tokens. The most important changes include adding new fields to the SamsungPaySessionTokenResponse struct, updating the create_samsung_pay_session_token function to include these new fields, and refactoring the code to use helper functions for determining address requirements.

Enhancements to session token handling:

  • Added billing_address_required and shipping_address_required fields to the SamsungPaySessionTokenResponse struct.

  • Updated the create_samsung_pay_session_token function to include the new address requirement fields and refactored the logic to use helper functions for determining if billing and shipping addresses are required.

Refactoring for address requirement determination:

  • Introduced the is_billing_address_required_to_be_collected_from_wallet and is_shipping_address_required_to_be_collected_form_wallet functions to encapsulate the logic for determining address requirements based on business profile settings and connector fields.

  • Refactored the create_gpay_session_token function to use the new helper functions for determining billing and shipping address requirements.

Additional Changes

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

Motivation and Context

Collect the customer's address details from Samsung Pay during payment to enhance the customer experience

How did you test it?

-> Create a merchant connector account with the samsung pay enabled for it
-> Create a payment with confirm false

curl --location 'http://localhost:8080/payments' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: api-key' \
--data-raw '{
    "amount": 6100,
    "currency": "USD",
    "confirm": false,
    "business_country": "US",
    "business_label": "default",
    "amount_to_capture": 6100,
    "capture_method": "automatic",
    "capture_on": "2022-09-10T10:11:12Z",
    "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",
    "customer_id": "1739970997",
    
    "billing": {
        "address": {
            "line1": "1467",
            "line2": "Harrison Street",
            "line3": "Harrison Street",
            "city": "San Fransico",
            "state": "California",
            "zip": "94122",
            "country": "US",
            "first_name": "joseph",
            "last_name": "Doe"
        },
        "phone": {
            "number": "8056594427",
            "country_code": "+91"
        }
    }
}'
{
    "payment_id": "pay_2B9WMNGYhzpVoUHGxvpS",
    "merchant_id": "merchant_1739965434",
    "status": "requires_payment_method",
    "amount": 6100,
    "net_amount": 6100,
    "shipping_cost": null,
    "amount_capturable": 0,
    "amount_received": null,
    "connector": null,
    "client_secret": "pay_2B9WMNGYhzpVoUHGxvpS_secret_vQZZ2vDYnZJOUi8JDVdL",
    "created": "2025-02-19T13:16:04.153Z",
    "currency": "USD",
    "customer_id": "1739970964",
    "customer": {
        "id": "1739970964",
        "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": null,
    "off_session": null,
    "capture_on": null,
    "capture_method": "automatic",
    "payment_method": null,
    "payment_method_data": null,
    "payment_token": null,
    "shipping": null,
    "billing": {
        "address": {
            "city": "San Fransico",
            "country": "US",
            "line1": "1467",
            "line2": "Harrison Street",
            "line3": "Harrison Street",
            "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": null,
    "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": null,
    "connector_label": null,
    "business_country": "US",
    "business_label": "default",
    "business_sub_label": null,
    "allowed_payment_method_types": null,
    "ephemeral_key": {
        "customer_id": "1739970964",
        "created_at": 1739970964,
        "expires": 1739974564,
        "secret": "epk_40529c632d7946338b7ad09430a613e6"
    },
    "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_2STAgRa16ISVgMLO11F2",
    "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-02-19T13:31:04.153Z",
    "fingerprint": null,
    "browser_info": null,
    "payment_method_id": null,
    "payment_method_status": null,
    "updated": "2025-02-19T13:16:04.173Z",
    "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
}

-> Set the below profile configuration

curl --location 'http://localhost:8080/account/merchant_1739965434/business_profile/pro_2STAgRa16ISVgMLO11F2' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: api-key' \
--data '{
    "collect_billing_details_from_wallet_connector": false,
    "collect_shipping_details_from_wallet_connector": false,
    "always_collect_shipping_details_from_wallet_connector": true,
    "always_collect_billing_details_from_wallet_connector": true,
}'
{
    "merchant_id": "merchant_1739965434",
    "profile_id": "pro_2STAgRa16ISVgMLO11F2",
    "profile_name": "US_default",
    "return_url": "https://google.com/success",
    "enable_payment_response_hash": true,
    "payment_response_hash_key": "0txdls9EorK9Gzx1OYRGV0X9xS87pn5sUxfFHFlfq9endVIs7S1iqV5TnCsZUYD7",
    "redirect_to_merchant_with_http_post": false,
    "webhook_details": {
        "webhook_version": "1.0.1",
        "webhook_username": "ekart_retail",
        "webhook_password": "password_ekart@123",
        "webhook_url": null,
        "payment_created_enabled": true,
        "payment_succeeded_enabled": true,
        "payment_failed_enabled": true
    },
    "metadata": null,
    "routing_algorithm": null,
    "intent_fulfillment_time": 900,
    "frm_routing_algorithm": null,
    "payout_routing_algorithm": null,
    "applepay_verified_domains": null,
    "session_expiry": 900,
    "payment_link_config": null,
    "authentication_connector_details": null,
    "use_billing_as_payment_method_billing": true,
    "extended_card_info_config": null,
    "collect_shipping_details_from_wallet_connector": false,
    "collect_billing_details_from_wallet_connector": false,
    "always_collect_shipping_details_from_wallet_connector": true,
    "always_collect_billing_details_from_wallet_connector": true,
    "is_connector_agnostic_mit_enabled": true,
    "payout_link_config": null,
    "outgoing_webhook_custom_http_headers": null,
    "tax_connector_id": null,
    "is_tax_connector_enabled": false,
    "is_network_tokenization_enabled": false,
    "is_auto_retries_enabled": false,
    "max_auto_retries_enabled": null,
    "always_request_extended_authorization": null,
    "is_click_to_pay_enabled": false,
    "authentication_product_ids": null
}

-> For this profile configuration the shipping_address_required and billing_address_required be true in the session resposne

curl --location 'http://localhost:8080/payments/session_tokens' \
--header 'Content-Type: application/json' \
--header 'api-key: api-key' \
--data '{
    "payment_id": "pay_2B9WMNGYhzpVoUHGxvpS",
    "wallets": [],
    "client_secret": "pay_2B9WMNGYhzpVoUHGxvpS_secret_vQZZ2vDYnZJOUi8JDVdL"
}'
{
    "payment_id": "pay_2B9WMNGYhzpVoUHGxvpS",
    "client_secret": "pay_2B9WMNGYhzpVoUHGxvpS_secret_vQZZ2vDYnZJOUi8JDVdL",
    "session_token": [
        {
            "wallet_name": "google_pay",
            "merchant_info": {
                "merchant_name": "Stripe"
            },
            "shipping_address_required": true,
            "email_required": true,
            "shipping_address_parameters": {
                "phone_number_required": true
            },
            "allowed_payment_methods": [
                {
                    "type": "CARD",
                    "parameters": {
                        "allowed_auth_methods": [
                            "PAN_ONLY",
                            "CRYPTOGRAM_3DS"
                        ],
                        "allowed_card_networks": [
                            "AMEX",
                            "DISCOVER",
                            "INTERAC",
                            "JCB",
                            "MASTERCARD",
                            "VISA"
                        ],
                        "billing_address_required": true,
                        "billing_address_parameters": {
                            "phone_number_required": true,
                            "format": "FULL"
                        }
                    },
                    "tokenization_specification": {
                        "type": "PAYMENT_GATEWAY",
                        "parameters": {
                            "gateway": "stripe",
                            "stripe:version": "2018-10-31",
                            "stripe:publishableKey": "pk_test_51Msk2GAGHc77EJXX78h549SX2uaOnEkUYqBfjcoD05PIpAnDkYxMn8nQ4d19im85NQuX4Z6WDyHaUw2fFTPBWsIY00Wa7oNerO"
                        }
                    }
                }
            ],
            "transaction_info": {
                "country_code": "US",
                "currency_code": "USD",
                "total_price_status": "Final",
                "total_price": "61.00"
            },
            "delayed_session_token": false,
            "connector": "cybersource",
            "sdk_next_action": {
                "next_action": "confirm"
            },
            "secrets": null
        },
        {
            "wallet_name": "samsung_pay",
            "version": "2",
            "service_id": "49400558c67f4a97b3925f",
            "order_number": "pay-2B9WMNGYhzpVoUHGxvpS",
            "merchant": {
                "name": "Hyperswitch",
                "url": null,
                "country_code": "IN"
            },
            "amount": {
                "option": "FORMAT_TOTAL_PRICE_ONLY",
                "currency_code": "USD",
                "total": "61.00"
            },
            "protocol": "PROTOCOL3DS",
            "allowed_brands": [
                "visa",
                "masterCard",
                "amex",
                "discover"
            ],
            "billing_address_required": true,
            "shipping_address_required": true
        },
        {
            "wallet_name": "apple_pay",
            "session_token_data": {},
            "payment_request_data": {
                "country_code": "AU",
                "currency_code": "USD",
                "total": {
                    "label": "applepay",
                    "type": "final",
                    "amount": "61.00"
                },
                "merchant_capabilities": [
                    "supports3DS"
                ],
                "supported_networks": [
                    "visa",
                    "masterCard",
                    "amex",
                    "discover"
                ],
                "merchant_identifier": "merchant.sandbox.hyperswitch",
                "required_billing_contact_fields": [
                    "postalAddress"
                ],
                "required_shipping_contact_fields": [
                    "postalAddress",
                    "phone",
                    "email"
                ]
            },
            "connector": "cybersource",
            "delayed_session_token": false,
            "sdk_next_action": {
                "next_action": "confirm"
            },
            "connector_reference_id": null,
            "connector_sdk_public_key": null,
            "connector_merchant_id": null
        }
    ]
}

-> Set the below profile configuration

curl --location 'http://localhost:8080/account/merchant_1739965434/business_profile/pro_2STAgRa16ISVgMLO11F2' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: api-key' \
--data '{
    "collect_billing_details_from_wallet_connector": true,
    "collect_shipping_details_from_wallet_connector": true,
    "always_collect_shipping_details_from_wallet_connector": false,
    "always_collect_billing_details_from_wallet_connector": false,
    "is_connector_agnostic_mit_enabled": true

}'
{
    "merchant_id": "merchant_1739965434",
    "profile_id": "pro_2STAgRa16ISVgMLO11F2",
    "profile_name": "US_default",
    "return_url": "https://google.com/success",
    "enable_payment_response_hash": true,
    "payment_response_hash_key": "0txdls9EorK9Gzx1OYRGV0X9xS87pn5sUxfFHFlfq9endVIs7S1iqV5TnCsZUYD7",
    "redirect_to_merchant_with_http_post": false,
    "webhook_details": {
        "webhook_version": "1.0.1",
        "webhook_username": "ekart_retail",
        "webhook_password": "password_ekart@123",
        "webhook_url": null,
        "payment_created_enabled": true,
        "payment_succeeded_enabled": true,
        "payment_failed_enabled": true
    },
    "metadata": null,
    "routing_algorithm": null,
    "intent_fulfillment_time": 900,
    "frm_routing_algorithm": null,
    "payout_routing_algorithm": null,
    "applepay_verified_domains": null,
    "session_expiry": 900,
    "payment_link_config": null,
    "authentication_connector_details": null,
    "use_billing_as_payment_method_billing": true,
    "extended_card_info_config": null,
    "collect_shipping_details_from_wallet_connector": true,
    "collect_billing_details_from_wallet_connector": true,
    "always_collect_shipping_details_from_wallet_connector": false,
    "always_collect_billing_details_from_wallet_connector": false,
    "is_connector_agnostic_mit_enabled": true,
    "payout_link_config": null,
    "outgoing_webhook_custom_http_headers": null,
    "tax_connector_id": null,
    "is_tax_connector_enabled": false,
    "is_network_tokenization_enabled": false,
    "is_auto_retries_enabled": false,
    "max_auto_retries_enabled": null,
    "always_request_extended_authorization": null,
    "is_click_to_pay_enabled": false,
    "authentication_product_ids": null
}

-> As per the above profile configuration the the billing_address_required will be true as the cybersource requires billing derails to be passed and shipping_address_required will be false as shipping details are not required by cybserourec.

curl --location 'http://localhost:8080/payments/session_tokens' \
--header 'Content-Type: application/json' \
--header 'api-key: api-key' \
--data '{
    "payment_id": "pay_2B9WMNGYhzpVoUHGxvpS",
    "wallets": [],
    "client_secret": "pay_2B9WMNGYhzpVoUHGxvpS_secret_vQZZ2vDYnZJOUi8JDVdL"
}'
{
    "payment_id": "pay_2B9WMNGYhzpVoUHGxvpS",
    "client_secret": "pay_2B9WMNGYhzpVoUHGxvpS_secret_vQZZ2vDYnZJOUi8JDVdL",
    "session_token": [
        {
            "wallet_name": "google_pay",
            "merchant_info": {
                "merchant_name": "Stripe"
            },
            "shipping_address_required": false,
            "email_required": true,
            "shipping_address_parameters": {
                "phone_number_required": false
            },
            "allowed_payment_methods": [
                {
                    "type": "CARD",
                    "parameters": {
                        "allowed_auth_methods": [
                            "PAN_ONLY",
                            "CRYPTOGRAM_3DS"
                        ],
                        "allowed_card_networks": [
                            "AMEX",
                            "DISCOVER",
                            "INTERAC",
                            "JCB",
                            "MASTERCARD",
                            "VISA"
                        ],
                        "billing_address_required": true,
                        "billing_address_parameters": {
                            "phone_number_required": true,
                            "format": "FULL"
                        }
                    },
                    "tokenization_specification": {
                        "type": "PAYMENT_GATEWAY",
                        "parameters": {
                            "gateway": "stripe",
                            "stripe:version": "2018-10-31",
                            "stripe:publishableKey": "pk_test_51Msk2GAGHc77EJXX78h549SX2uaOnEkUYqBfjcoD05PIpAnDkYxMn8nQ4d19im85NQuX4Z6WDyHaUw2fFTPBWsIY00Wa7oNerO"
                        }
                    }
                }
            ],
            "transaction_info": {
                "country_code": "US",
                "currency_code": "USD",
                "total_price_status": "Final",
                "total_price": "61.00"
            },
            "delayed_session_token": false,
            "connector": "cybersource",
            "sdk_next_action": {
                "next_action": "confirm"
            },
            "secrets": null
        },
        {
            "wallet_name": "samsung_pay",
            "version": "2",
            "service_id": "49400558c67f4a97b3925f",
            "order_number": "pay-2B9WMNGYhzpVoUHGxvpS",
            "merchant": {
                "name": "Hyperswitch",
                "url": null,
                "country_code": "IN"
            },
            "amount": {
                "option": "FORMAT_TOTAL_PRICE_ONLY",
                "currency_code": "USD",
                "total": "61.00"
            },
            "protocol": "PROTOCOL3DS",
            "allowed_brands": [
                "visa",
                "masterCard",
                "amex",
                "discover"
            ],
            "billing_address_required": true,
            "shipping_address_required": false
        },
        {
            "wallet_name": "apple_pay",
            "session_token_data": {},
            "payment_request_data": {
                "country_code": "AU",
                "currency_code": "USD",
                "total": {
                    "label": "applepay",
                    "type": "final",
                    "amount": "61.00"
                },
                "merchant_capabilities": [
                    "supports3DS"
                ],
                "supported_networks": [
                    "visa",
                    "masterCard",
                    "amex",
                    "discover"
                ],
                "merchant_identifier": "merchant.sandbox.hyperswitch",
                "required_billing_contact_fields": [
                    "postalAddress"
                ],
                "required_shipping_contact_fields": [
                    "phone",
                    "email"
                ]
            },
            "connector": "cybersource",
            "delayed_session_token": false,
            "sdk_next_action": {
                "next_action": "confirm"
            },
            "connector_reference_id": null,
            "connector_sdk_public_key": null,
            "connector_merchant_id": 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

…based on business profile config and connector required fields
@ShankarSinghC ShankarSinghC added A-core Area: Core flows C-feature Category: Feature request or enhancement A-payment-methods Area: Payment Methods M-api-contract-changes Metadata: This PR involves API contract changes labels Feb 19, 2025
@ShankarSinghC ShankarSinghC self-assigned this Feb 19, 2025
@ShankarSinghC ShankarSinghC requested review from a team as code owners February 19, 2025 13:28
@semanticdiff-com
Copy link

semanticdiff-com bot commented Feb 19, 2025

Review changes with  SemanticDiff

Changed Files
File Status
  crates/router/src/core/payments/flows/session_flow.rs  20% smaller
  api-reference-v2/openapi_spec.json  17% smaller
  api-reference/openapi_spec.json  17% smaller
  crates/api_models/src/payments.rs  0% smaller

@hyperswitch-bot hyperswitch-bot bot added the M-api-contract-changes Metadata: This PR involves API contract changes label Feb 19, 2025
@Gnanasundari24 Gnanasundari24 added this pull request to the merge queue Feb 22, 2025
Merged via the queue into main with commit c14519e Feb 22, 2025
16 of 20 checks passed
@Gnanasundari24 Gnanasundari24 deleted the samsung-pay/session-call branch February 22, 2025 08:38
pixincreate added a commit that referenced this pull request Feb 22, 2025
…tusedPM

* 'main' of github.com:juspay/hyperswitch: (22 commits)
  feat(connector): add Samsung pay mandate support for Cybersource (#7298)
  chore(masking): add peek_mut to PeekInterface (#7281)
  feat(samsung_pay): collect customer address details form Samsung Pay based on business profile config and connector required fields (#7320)
  ci: update creds (#7345)
  feat(router): add `merchant_configuration_id` in netcetera metadata and make other merchant configurations optional (#7347)
  fix(routing): Fixed 5xx error logs in dynamic routing metrics (#7335)
  fix(connector): [DATATRANS] Fix Force Sync Flow (#7331)
  chore(version): 2025.02.21.0
  fix(connector): [DATATRANS] Add new payment status (#7327)
  feat(router): [Xendit] add support for split payments (#7143)
  fix(payment_methods_v2): update fingerprint implementation in v2 (#7270)
  feat(router): Add Payments - List endpoint for v2 (#7191)
  feat(core): add support for confirmation flow for click to pay (#6982)
  chore(version): 2025.02.20.0
  fix(connector): [SCRIPT] Update template generating script and updated connector doc (#7301)
  ci(cypress): add assertions for `requires_cvv` (#7296)
  refactor(utils): match string for state with SDK's naming convention (#7300)
  feat(core): add hypersense integration api  (#7218)
  chore(version): 2025.02.19.0
  feat(connector): [Moneris] Add payments flow (#7249)
  ...
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 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.

add support to collect customer address details form Samsung Pay based on business profile config and connector required fields

4 participants