Skip to content

Conversation

ShankarSinghC
Copy link
Contributor

@ShankarSinghC ShankarSinghC commented Jul 17, 2025

Type of Change

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

Description

This pull request adds debit routing support for Apple Pay. In the Apple Pay decryption flow, if debit routing is enabled by the merchant and the card type is debit, a call will be made to the decision engine to retrieve the supported card networks and the potential debit routing savings. Among these networks, the lowest-cost network will be selected to process the Apple Pay payment.

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?

-> enable debit routing and make a apple pay payment

curl --location 'http://localhost:8080/payments' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: dev_tT5kUVUp7uaQHR2Z824Iy7393nL5sEWLxAvJblCxxmttLizAkJbWtsdgoIjdGQE2' \
--data-raw '{
    "amount": 650,
    "currency": "USD",
    "confirm": true,
    "business_country": "US",
    "business_label": "default",
    "amount_to_capture": 650,
    "customer_id": "cu_1752747625",
    "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": "[email protected]",
    "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_O0EoroDslloH3cVj5Xc5",
    "merchant_id": "merchant_1752747413",
    "status": "succeeded",
    "amount": 650,
    "net_amount": 650,
    "shipping_cost": null,
    "amount_capturable": 0,
    "amount_received": 650,
    "connector": "adyen",
    "client_secret": "pay_O0EoroDslloH3cVj5Xc5_secret_mEciQ25Sjl46cuShfITO",
    "created": "2025-07-17T10:18:35.495Z",
    "currency": "USD",
    "customer_id": "cu_1752747515",
    "customer": {
        "id": "cu_1752747515",
        "name": "Joseph 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": "on_session",
    "off_session": null,
    "capture_on": null,
    "capture_method": "automatic",
    "payment_method": "wallet",
    "payment_method_data": {
        "wallet": {
            "apple_pay": {
                "last4": "9319",
                "card_network": "Accel",
                "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": "[email protected]",
    "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": "adyen_US_default",
    "business_country": "US",
    "business_label": "default",
    "business_sub_label": null,
    "allowed_payment_method_types": null,
    "ephemeral_key": {
        "customer_id": "cu_1752747515",
        "created_at": 1752747515,
        "expires": 1752751115,
        "secret": "epk_e7dc207a6f124b47a191ba2daf803e6b"
    },
    "manual_retry_allowed": false,
    "connector_transaction_id": "P3TQQMQMMQ6M5375",
    "frm_message": null,
    "metadata": null,
    "connector_metadata": null,
    "feature_metadata": null,
    "reference_id": "pay_O0EoroDslloH3cVj5Xc5_1",
    "payment_link": null,
    "profile_id": "pro_0BT05CUisTpwMzBcK4wf",
    "surcharge_details": null,
    "attempt_count": 1,
    "merchant_decision": null,
    "merchant_connector_id": "mca_dITrhiR4JCNaaJFsaPGH",
    "incremental_authorization_allowed": null,
    "authorization_count": null,
    "incremental_authorizations": null,
    "external_authentication_details": null,
    "external_3ds_authentication_attempted": false,
    "expires_on": "2025-07-17T10:33:35.495Z",
    "fingerprint": null,
    "browser_info": null,
    "payment_method_id": null,
    "payment_method_status": null,
    "updated": "2025-07-17T10:18:40.793Z",
    "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
}

-> Decision engine lookup using 8 digits bin with padded 0s for lookup
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 self-assigned this Jul 17, 2025
@ShankarSinghC ShankarSinghC requested review from a team as code owners July 17, 2025 07:05
@ShankarSinghC ShankarSinghC added A-core Area: Core flows A-payment-methods Area: Payment Methods A-routing Area: Routing labels Jul 17, 2025
Copy link

semanticdiff-com bot commented Jul 17, 2025

Review changes with  SemanticDiff

Changed Files
File Status
  crates/router/src/core/payments/tokenization.rs  73% smaller
  crates/router/src/core/debit_routing.rs  24% smaller
  crates/router/src/core/payments.rs  20% smaller
  crates/common_enums/src/enums.rs  0% smaller
  crates/hyperswitch_connectors/src/connectors/adyen/transformers.rs  0% smaller
  crates/hyperswitch_domain_models/src/payment_method_data.rs  0% smaller
  crates/router/src/core/payments/operations/payment_approve.rs  0% smaller
  crates/router/src/core/payments/operations/payment_cancel.rs  0% smaller
  crates/router/src/core/payments/operations/payment_capture.rs  0% smaller
  crates/router/src/core/payments/operations/payment_complete_authorize.rs  0% smaller
  crates/router/src/core/payments/operations/payment_confirm.rs  0% smaller
  crates/router/src/core/payments/operations/payment_create.rs  0% smaller
  crates/router/src/core/payments/operations/payment_post_session_tokens.rs  0% smaller
  crates/router/src/core/payments/operations/payment_reject.rs  0% smaller
  crates/router/src/core/payments/operations/payment_session.rs  0% smaller
  crates/router/src/core/payments/operations/payment_start.rs  0% smaller
  crates/router/src/core/payments/operations/payment_status.rs  0% smaller
  crates/router/src/core/payments/operations/payment_update.rs  0% smaller
  crates/router/src/core/payments/operations/payment_update_metadata.rs  0% smaller
  crates/router/src/core/payments/operations/payments_incremental_authorization.rs  0% smaller
  crates/router/src/core/payments/operations/tax_calculation.rs  0% smaller


let is_currency_supported = is_currency_supported(payment_intent, debit_routing_config);

let payment_method_validation = validate_payment_method_for_debit_routing(payment_data);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
let payment_method_validation = validate_payment_method_for_debit_routing(payment_data);
let is_valid_payment_method = validate_payment_method_for_debit_routing(payment_data);

&& payment_attempt.payment_method_type == Some(enums::PaymentMethodType::Debit)
&& is_currency_supported
&& payment_attempt.authentication_type == Some(enums::AuthenticationType::NoThreeDs)
&& payment_method_validation
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
&& payment_method_validation
&& is_valid_payment_method

@ShankarSinghC ShankarSinghC requested a review from jagan-jaya July 17, 2025 10:45
@ShankarSinghC ShankarSinghC linked an issue Jul 17, 2025 that may be closed by this pull request
jagan-jaya
jagan-jaya previously approved these changes Jul 17, 2025
Chethan-rao
Chethan-rao previously approved these changes Jul 17, 2025
Comment on lines +475 to +476
.parse_enum("ApplePayPaymentMethodType")
.ok()
Copy link
Contributor

Choose a reason for hiding this comment

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

should the error be logged at least instead of ignoring it?

AkshayaFoiger
AkshayaFoiger previously approved these changes Jul 17, 2025
Base automatically changed from debit-routing/wallets/refactor-tokenization to main July 18, 2025 12:55
@likhinbopanna likhinbopanna dismissed stale reviews from AkshayaFoiger, Chethan-rao, and jagan-jaya July 18, 2025 12:55

The base branch was changed.

@ShankarSinghC ShankarSinghC requested a review from a team as a code owner July 18, 2025 12:55
@likhinbopanna likhinbopanna enabled auto-merge July 18, 2025 14:01
@likhinbopanna likhinbopanna added this pull request to the merge queue Jul 18, 2025
Merged via the queue into main with commit d42fad7 Jul 18, 2025
23 of 31 checks passed
@likhinbopanna likhinbopanna deleted the debit-routing/wallets/apple-pay branch July 18, 2025 14:54
pixincreate added a commit that referenced this pull request Jul 22, 2025
…ayload-recurring

* 'main' of github.com:juspay/hyperswitch: (48 commits)
  fix(connector): Add Trustpay in Authentication Providers Config (#8622)
  refactor(connector): [Adyen] map ssn and session validity for Pix (#8702)
  feat(core): Implement UCS kill switch for emergency fallback (#8651)
  fix(openapi): Added Error Response Schema for Status Code 400 (#8684)
  feat(connector): Add template code for breadpay (#8655)
  chore(version): 2025.07.21.1
  refactor(payments): fetch payment method information in attempts list api v2 and add custom billing connector template (#8681)
  fix(router): Make v2 endpoints follow standard naming conventions (#8630)
  fix(connector): [Cybersource] Add type_selection_indicator as 1 for all cards  (#8663)
  feat(routing): Add API key auth for decision engine endpoints (#8640)
  feat(authentication): Added eligibility flow for modular authentication (#8431)
  feat(connector): [BLACKHAWKNETWORK] Add Template Code  (#8632)
  fix: remove straight through routing from routing approach (#8695)
  fix(connector): [Access Worldpay] correct enum deserialization for payment responses for (#8689)
  chore(version): 2025.07.21.0
  feat(debit_routing): add debit routing support for apple pay (#8673)
  refactor(router): decrypt the wallet token before the debit routing call (#8598)
  chore: update org retrieve api response to include org type (#8660)
  feat(routing): Add routing evaluation rule endpoint and related flow (#8656)
  fix(connector): [AUTHORIZEDOTNET] Added Invoice Number Fix (#8685)
  ...
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-routing Area: Routing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add debit routing support for apple pay
5 participants