Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix(router): Persist card_network if present for non co-badged cards #6212

Merged
merged 13 commits into from
Oct 4, 2024

Conversation

Sakilmostak
Copy link
Contributor

@Sakilmostak Sakilmostak commented Oct 3, 2024

Type of Change

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

Description

This fixes the bug where is the card is not a co-badged card, it makes the card network as none if passed in request.

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?

Tested through Postman:

Create a payment through Adyen(EU) for non co-badged card:

{
    "amount": 1000,
    "currency": "USD",
    "confirm": true,
    "capture_method": "automatic",
    "capture_on": "2022-09-10T10:11:12Z",
    "amount_to_capture": 1000,
    "customer_id": "{{customer_id}}",
    "email": "guest@example.com",
    "name": "John Doe",
    "phone": "999999999",
    "phone_country_code": "+1",
    "description": "Its my first payment request",
    "authentication_type": "three_ds",
    "return_url": "https://duck.com",
    "payment_method": "card",
    "payment_method_type": "credit",
    "payment_method_data": {
        "card": {
            "card_number": "4871049999999910",
            "card_exp_month": "03",
            "card_exp_year": "2030",
            "card_holdewdwedjhwqbdhj": "Joseph Doe",
            "card_cvc": "737",
            "card_network": "Visa"
        }
    },
    "routing": {
        "type": "single",
        "data": "adyen"
    },
    "setup_future_usage": "on_session",
    "customer_acceptance": {
        "acceptance_type": "offline",
        "accepted_at": "1963-05-03T04:07:52.723Z",
        "online": {
            "ip_address": "13.232.74.226",
            "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": "swangi",
            "last_name": "kumari"
        }
    },
    "shipping": {
        "address": {
            "line1": "1467",
            "line2": "Harrison Street",
            "line3": "Harrison Street",
            "city": "San Fransico",
            "state": "California",
            "zip": "94122",
            "country": "US",
            "first_name": "PiX"
        }
    },
    "statement_descriptor_name": "joseph",
    "statement_descriptor_suffix": "JS",
    "metadata": {
        "udf1": "value1",
        "new_customer": "true",
        "login_date": "2019-09-10T10:11:12Z"
    },
    "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": "127.0.0.1"
    }
}

The response should be:

{
    "payment_id": "pay_kVLl3AjvBW52HBfjapdo",
    "merchant_id": "merchant_1727955369",
    "status": "requires_customer_action",
    "amount": 1000,
    "net_amount": 1000,
    "amount_capturable": 1000,
    "amount_received": null,
    "connector": "adyen",
    "client_secret": "pay_kVLl3AjvBW52HBfjapdo_secret_61luqZrIftUVAjEDnYgx",
    "created": "2024-10-03T11:41:19.679Z",
    "currency": "USD",
    "customer_id": "cus_6qF2pkFaGJeziVSXj8Un",
    "customer": {
        "id": "cus_6qF2pkFaGJeziVSXj8Un",
        "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": "9910",
            "card_type": null,
            "card_network": null,
            "card_issuer": null,
            "card_issuing_country": null,
            "card_isin": "487104",
            "card_extended_bin": null,
            "card_exp_month": "03",
            "card_exp_year": "2030",
            "card_holder_name": null,
            "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 Fransico",
            "country": "US",
            "line1": "1467",
            "line2": "Harrison Street",
            "line3": "Harrison Street",
            "zip": "94122",
            "state": "California",
            "first_name": "swangi",
            "last_name": "kumari"
        },
        "phone": null,
        "email": null
    },
    "order_details": null,
    "email": "guest@example.com",
    "name": "John Doe",
    "phone": "999999999",
    "return_url": "https://duck.com/",
    "authentication_type": "three_ds",
    "statement_descriptor_name": "joseph",
    "statement_descriptor_suffix": "JS",
    "next_action": {
        "type": "redirect_to_url",
        "redirect_to_url": "http://localhost:8080/payments/redirect/pay_kVLl3AjvBW52HBfjapdo/merchant_1727955369/pay_kVLl3AjvBW52HBfjapdo_1"
    },
    "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": "cus_6qF2pkFaGJeziVSXj8Un",
        "created_at": 1727955679,
        "expires": 1727959279,
        "secret": "epk_7412eb7fe3344af4b11d448a5eda7d43"
    },
    "manual_retry_allowed": null,
    "connector_transaction_id": "MWBV37K8QD82MV65",
    "frm_message": null,
    "metadata": {
        "udf1": "value1",
        "login_date": "2019-09-10T10:11:12Z",
        "new_customer": "true"
    },
    "connector_metadata": null,
    "feature_metadata": null,
    "reference_id": "MWBV37K8QD82MV65",
    "payment_link": null,
    "profile_id": "pro_kNsaNyd2WRlOiH8WHci9",
    "surcharge_details": null,
    "attempt_count": 1,
    "merchant_decision": null,
    "merchant_connector_id": "mca_G2RntfTUVhF4RbkRNTdG",
    "incremental_authorization_allowed": null,
    "authorization_count": null,
    "incremental_authorizations": null,
    "external_authentication_details": null,
    "external_3ds_authentication_attempted": false,
    "expires_on": "2024-10-03T11:56:19.679Z",
    "fingerprint": null,
    "browser_info": {
        "language": "nl-NL",
        "time_zone": 0,
        "ip_address": "127.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": "2024-10-03T11:41:20.057Z",
    "charges": null,
    "frm_metadata": null,
    "merchant_order_reference_id": null,
    "order_tax_amount": null,
    "connector_mandate_id": null
}

Complete the redirection, the status should be succeeded

Do a list call, the following should be the response:

{
    "customer_payment_methods": [
        {
            "payment_token": "token_IYU6ENPXCOakWgDVdzUN",
            "payment_method_id": "pm_DcSy5wqtj7ojMG24upwF",
            "customer_id": "cus_6qF2pkFaGJeziVSXj8Un",
            "payment_method": "card",
            "payment_method_type": "credit",
            "payment_method_issuer": null,
            "payment_method_issuer_code": null,
            "recurring_enabled": false,
            "installment_payment_enabled": false,
            "payment_experience": [
                "redirect_to_url"
            ],
            "card": {
                "scheme": "Visa",
                "issuer_country": null,
                "last4_digits": "9910",
                "expiry_month": "03",
                "expiry_year": "2030",
                "card_token": null,
                "card_holder_name": "swangi kumari",
                "card_fingerprint": null,
                "nick_name": null,
                "card_network": "Visa",
                "card_isin": "487104",
                "card_issuer": null,
                "card_type": null,
                "saved_to_locker": true
            },
            "metadata": null,
            "created": "2024-10-03T11:41:20.067Z",
            "bank": null,
            "surcharge_details": null,
            "requires_cvv": true,
            "last_used_at": "2024-10-03T11:41:20.067Z",
            "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": "swangi",
                    "last_name": "kumari"
                },
                "phone": null,
                "email": null
            }
        }
    ],
    "is_guest_customer": 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

@Sakilmostak Sakilmostak added A-core Area: Core flows C-bug Category: Bug A-payments Area: payments labels Oct 3, 2024
@Sakilmostak Sakilmostak added this to the October 2024 Release milestone Oct 3, 2024
@Sakilmostak Sakilmostak self-assigned this Oct 3, 2024
@Sakilmostak Sakilmostak requested review from a team as code owners October 3, 2024 11:32
Copy link

semanticdiff-com bot commented Oct 3, 2024

Review changes with SemanticDiff.

Analyzed 11 of 13 files.

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

1 files do not contain logic changes.

Filename Status
Cargo.lock Unsupported file format
✔️ crates/router/src/consts.rs No logic changes found
✔️ crates/router/src/core/payments/helpers.rs 71.72% smaller
✔️ crates/router/src/core/payments/operations/payment_confirm.rs Analyzed
✔️ crates/router/src/core/payments/operations/payment_create.rs 51.09% smaller
✔️ crates/router/src/core/payments/operations/payment_update.rs Analyzed
✔️ crates/router/src/connector/stripe/transformers.rs Analyzed
✔️ crates/router/src/connector/cybersource/transformers.rs 25.95% smaller
✔️ crates/router/src/connector/bankofamerica/transformers.rs 9.86% smaller
✔️ crates/router/src/connector/adyen/transformers.rs 4.76% smaller
crates/cards/Cargo.toml Unsupported file format
✔️ crates/cards/src/validate.rs 0.03% smaller
✔️ crates/api_models/src/payments.rs 57.41% smaller

@likhinbopanna likhinbopanna added this pull request to the merge queue Oct 4, 2024
Merged via the queue into main with commit 7564826 Oct 4, 2024
15 of 17 checks passed
@likhinbopanna likhinbopanna deleted the fix_co_badged_card branch October 4, 2024 10:02
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-core Area: Core flows A-payments Area: payments C-bug Category: Bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants