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): add phone and country_code in dynamic fields #5968

Merged
merged 1 commit into from
Sep 19, 2024

Conversation

ShankarSinghC
Copy link
Contributor

@ShankarSinghC ShankarSinghC commented Sep 19, 2024

Type of Change

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

Description

This is to extend the feature of collecting address details from wallets to paylater.

Additionally also include phone and country_code in the dynamic fields.

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?

-> Create a merchant connector of Klarna with klarna payment method enabled.
-> Set the below business profile config

curl --location 'http://localhost:8080/account/merchant_1726764490/business_profile/pro_XOWZOwYWMAmTV4wEyGgh' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header '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_1726764490",
    "profile_id": "pro_XOWZOwYWMAmTV4wEyGgh",
    "profile_name": "US_default",
    "return_url": "https://google.com/success",
    "enable_payment_response_hash": true,
    "payment_response_hash_key": "cG93fXrQQUtILvsThLoMz2EGwi7b3avGaiEb5NQ2OAbHYbFP2Lx2VigfrdbICkLK",
    "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": false,
    "payout_link_config": null,
    "outgoing_webhook_custom_http_headers": null,
    "tax_connector_id": null,
    "is_tax_connector_enabled": false,
    "is_network_tokenization_enabled": false
}

-> Create a payment

curl --location 'http://localhost:8080/payments' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: dev_EAjkFh4IFwdG0BhppR4qc8duYSjLtl5e2cYy1eADeQ4MAtLazHsE3fpA6wI4cUk9' \
--data '{
  "amount": 100000,
  "currency": "USD",
  "capture_method": "automatic",
  "authentication_type": "no_three_ds",
  "confirm": false,
  "customer_id": "cu_1726764583"
}'
{
    "payment_id": "pay_66ZCSMDS1OQlfVVzAYNf",
    "merchant_id": "merchant_1726764490",
    "status": "requires_payment_method",
    "amount": 100000,
    "net_amount": 100000,
    "amount_capturable": 0,
    "amount_received": null,
    "connector": null,
    "client_secret": "pay_66ZCSMDS1OQlfVVzAYNf_secret_pdtSN8kQV4w5SsUXw6La",
    "created": "2024-09-19T16:49:40.260Z",
    "currency": "USD",
    "customer_id": "cu_1726764580",
    "customer": {
        "id": "cu_1726764580",
        "name": null,
        "email": null,
        "phone": null,
        "phone_country_code": null
    },
    "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": null,
    "name": null,
    "phone": null,
    "return_url": null,
    "authentication_type": "no_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_1726764580",
        "created_at": 1726764580,
        "expires": 1726768180,
        "secret": "epk_82cd32e8fe0a4190a5db562353a40f33"
    },
    "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_XOWZOwYWMAmTV4wEyGgh",
    "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": "2024-09-19T17:04:40.260Z",
    "fingerprint": null,
    "browser_info": null,
    "payment_method_id": null,
    "payment_method_status": null,
    "updated": "2024-09-19T16:49:40.288Z",
    "charges": null,
    "frm_metadata": null,
    "merchant_order_reference_id": null,
    "order_tax_amount": null
}

-> Merchant payment method list

curl --location 'http://localhost:8080/account/payment_methods?client_secret=pay_66ZCSMDS1OQlfVVzAYNf_secret_pdtSN8kQV4w5SsUXw6La' \
--header 'Accept: application/json' \
--header 'api-key:'
{
    "redirect_url": "https://google.com/success",
    "currency": "USD",
    "payment_methods": [
        {
            "payment_method": "pay_later",
            "payment_method_types": [
                {
                    "payment_method_type": "klarna",
                    "payment_experience": [
                        {
                            "payment_experience_type": "invoke_sdk_client",
                            "eligible_connectors": [
                                "klarna"
                            ]
                        }
                    ],
                    "card_networks": null,
                    "bank_names": null,
                    "bank_debits": null,
                    "bank_transfers": null,
                    "required_fields": {
                        "shipping.address.first_name": {
                            "required_field": "shipping.address.first_name",
                            "display_name": "shipping_first_name",
                            "field_type": "user_shipping_name",
                            "value": null
                        },
                        "shipping.phone.country_code": {
                            "required_field": "shipping.phone.country_code",
                            "display_name": "dialing_code",
                            "field_type": "user_phone_number_country_code",
                            "value": null
                        },
                        "shipping.phone.number": {
                            "required_field": "shipping.phone.number",
                            "display_name": "phone_number",
                            "field_type": "user_phone_number",
                            "value": null
                        },
                        "billing.address.last_name": {
                            "required_field": "payment_method_data.billing.address.last_name",
                            "display_name": "billing_last_name",
                            "field_type": "user_billing_name",
                            "value": null
                        },
                        "billing.address.country": {
                            "required_field": "payment_method_data.billing.address.country",
                            "display_name": "country",
                            "field_type": {
                                "user_address_country": {
                                    "options": [
                                        "ALL"
                                    ]
                                }
                            },
                            "value": null
                        },
                        "billing.address.line2": {
                            "required_field": "payment_method_data.billing.address.line2",
                            "display_name": "line2",
                            "field_type": "user_address_line2",
                            "value": null
                        },
                        "shipping.address.last_name": {
                            "required_field": "shipping.address.last_name",
                            "display_name": "shipping_last_name",
                            "field_type": "user_shipping_name",
                            "value": null
                        },
                        "billing.phone.number": {
                            "required_field": "payment_method_data.billing.phone.number",
                            "display_name": "phone_number",
                            "field_type": "user_phone_number",
                            "value": null
                        },
                        "billing.address.zip": {
                            "required_field": "payment_method_data.billing.address.zip",
                            "display_name": "zip",
                            "field_type": "user_address_pincode",
                            "value": null
                        },
                        "shipping.address.country": {
                            "required_field": "shipping.address.country",
                            "display_name": "country",
                            "field_type": {
                                "user_shipping_address_country": {
                                    "options": [
                                        "ALL"
                                    ]
                                }
                            },
                            "value": null
                        },
                        "billing.address.line1": {
                            "required_field": "payment_method_data.billing.address.line1",
                            "display_name": "line1",
                            "field_type": "user_address_line1",
                            "value": null
                        },
                        "billing.phone.country_code": {
                            "required_field": "payment_method_data.billing.phone.country_code",
                            "display_name": "dialing_code",
                            "field_type": "user_phone_number_country_code",
                            "value": null
                        },
                        "shipping.address.state": {
                            "required_field": "shipping.address.state",
                            "display_name": "state",
                            "field_type": "user_shipping_address_state",
                            "value": null
                        },
                        "billing.address.first_name": {
                            "required_field": "payment_method_data.billing.address.first_name",
                            "display_name": "billing_first_name",
                            "field_type": "user_billing_name",
                            "value": null
                        },
                        "billing.address.state": {
                            "required_field": "payment_method_data.billing.address.state",
                            "display_name": "state",
                            "field_type": "user_address_state",
                            "value": null
                        },
                        "billing.address.city": {
                            "required_field": "payment_method_data.billing.address.city",
                            "display_name": "city",
                            "field_type": "user_address_city",
                            "value": null
                        },
                        "shipping.address.line1": {
                            "required_field": "shipping.address.line1",
                            "display_name": "line1",
                            "field_type": "user_shipping_address_line1",
                            "value": null
                        },
                        "shipping.address.city": {
                            "required_field": "shipping.address.city",
                            "display_name": "city",
                            "field_type": "user_shipping_address_city",
                            "value": null
                        },
                        "shipping.address.zip": {
                            "required_field": "shipping.address.zip",
                            "display_name": "zip",
                            "field_type": "user_shipping_address_pincode",
                            "value": null
                        }
                    },
                    "surcharge_details": null,
                    "pm_auth_connector": null
                }
            ]
        }
    ],
    "mandate_payment": null,
    "merchant_name": "NewAge Retailer",
    "show_surcharge_breakup_screen": false,
    "payment_type": "normal",
    "request_external_three_ds_authentication": false,
    "collect_shipping_details_from_wallets": true,
    "collect_billing_details_from_wallets": true,
    "is_tax_calculation_enabled": false
}

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 a team as a code owner September 19, 2024 14:51
Copy link

semanticdiff-com bot commented Sep 19, 2024

Review changes with SemanticDiff.

Analyzed 2 of 2 files.

Overall, the semantic diff is 7% smaller than the GitHub diff.

Filename Status
✔️ crates/router/src/core/payment_methods/cards.rs 48.81% smaller
✔️ crates/router/src/configs/defaults.rs Analyzed

@ShankarSinghC ShankarSinghC requested a review from a team as a code owner September 19, 2024 16:38
@ShankarSinghC ShankarSinghC self-assigned this Sep 19, 2024
@ShankarSinghC ShankarSinghC added C-refactor Category: Refactor A-payment-methods Area: Payment Methods labels Sep 19, 2024
@ShankarSinghC ShankarSinghC linked an issue Sep 19, 2024 that may be closed by this pull request
@SanchithHegde SanchithHegde added this pull request to the merge queue Sep 19, 2024
Merged via the queue into main with commit 1151d21 Sep 19, 2024
21 of 22 checks passed
@SanchithHegde SanchithHegde deleted the ref/pml branch September 19, 2024 20:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-payment-methods Area: Payment Methods C-refactor Category: Refactor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

add phone and country_code in dynamic fields
3 participants