Skip to content

feat(payments): add tokenization action handling to payment flow for braintree#9506

Merged
likhinbopanna merged 5 commits intomainfrom
feat/payments-tokenization
Sep 30, 2025
Merged

feat(payments): add tokenization action handling to payment flow for braintree#9506
likhinbopanna merged 5 commits intomainfrom
feat/payments-tokenization

Conversation

@ayush22667
Copy link
Contributor

@ayush22667 ayush22667 commented Sep 23, 2025

Type of Change

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

Description

This feature add connector-level tokenization to Hyperswitch V2, allowing secure storage of card data as tokens at payment connectors like Braintree.
Additionally Tokenization in router is not implemented, because of temp locker mechanism which is still pending.

For connector-level tokenization:
1.When a payment comes with raw card data and the connector supports tokenization, send the card details to the connector’s tokenization API.
2. Receive the tokenized payment method ID.
3. Use the token for the subsequent payment call.

Additional Changes

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

Motivation and Context

Closes #9501

How did you test it?

▶ Create and Confirm Request

Request:

curl --location 'http://localhost:8080/v2/payments' \
--header 'Content-Type: application/json' \
--header 'x-profile-id: pro_pYmCUDflXtfYghJEbwig' \
--header 'Authorization: api-key=dev_NJmZgHkdmFD5DC5ldyvqUObC7LgVZAkuNSsUCxlcwTYfdMb2zxsvKZQyFJ5AdIwI' \
--data-raw '{
    "amount_details": {
        "order_amount": 100,
        "currency": "USD"
    },
    "capture_method": "automatic",
    "authentication_type": "no_three_ds",
    "billing": {
        "address": {
            "first_name": "John",
            "last_name": "Dough"
        },
        "email": "example@example.com"
    },
    "payment_method_data": {
        "card": {
            "card_number": "4111111111111111",
            "card_exp_month": "01",
            "card_exp_year": "29",
            "card_holder_name": "John Doe",
            "card_cvc": "100"
        }
    },
    "payment_method_type": "card",
    "payment_method_subtype": "credit",
    "shipping": {
    "address": {
        "first_name": "John",
        "last_name": "Dough",
        "city": "Karwar",
        "zip": "581301",
        "state": "Karnataka"
    },
    "email": "example@example.com"
}
}'

Response:

{
    "id": "12345_pay_0199758923487c2380efbcb7a0480045",
    "status": "succeeded",
    "amount": {
        "order_amount": 100,
        "currency": "USD",
        "shipping_cost": null,
        "order_tax_amount": null,
        "external_tax_calculation": "skip",
        "surcharge_calculation": "skip",
        "surcharge_amount": null,
        "tax_on_surcharge": null,
        "net_amount": 100,
        "amount_to_capture": null,
        "amount_capturable": 0,
        "amount_captured": 100
    },
    "customer_id": null,
    "connector": "braintree",
    "created": "2025-09-23T07:45:45.801Z",
    "modified_at": "2025-09-23T07:45:46.773Z",
    "payment_method_data": {
        "billing": null
    },
    "payment_method_type": "card",
    "payment_method_subtype": "credit",
    "connector_transaction_id": "dHJhbnNhY3Rpb25fcWE0NGtmdHM",
    "connector_reference_id": null,
    "merchant_connector_id": "mca_15ue2HSPzmSPtuWvipkZ",
    "browser_info": null,
    "error": null,
    "shipping": null,
    "billing": null,
    "attempts": null,
    "connector_token_details": null,
    "payment_method_id": null,
    "next_action": null,
    "return_url": "https://google.com/success",
    "authentication_type": "no_three_ds",
    "authentication_type_applied": "no_three_ds",
    "is_iframe_redirection_enabled": null,
    "merchant_reference_id": null,
    "raw_connector_response": null,
    "feature_metadata": null,
    "metadata": null
}

▶ Create Intent

Request:

{
    "amount_details": {
        "order_amount": 10000,
        "currency": "USD"
    },
    "capture_method":"automatic",
    "authentication_type": "no_three_ds",
    "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"
        },
        "email": "example@example.com"
    },
    "shipping": {
        "address": {
            "line1": "1467",
            "line2": "Harrison Street",
            "line3": "Harrison Street",
            "city": "San Fransico",
            "state": "California",
            "zip": "94122",
            "country": "US",
            "first_name": "joseph",
            "last_name": "Doe"
        },
        "email": "example@example.com"
    }

}

Response:

{
    "id": "12345_pay_019975899d367c61ae62b88f1edde4e9",
    "status": "requires_payment_method",
    "amount_details": {
        "order_amount": 10000,
        "currency": "USD",
        "shipping_cost": null,
        "order_tax_amount": null,
        "external_tax_calculation": "skip",
        "surcharge_calculation": "skip",
        "surcharge_amount": null,
        "tax_on_surcharge": null
    },
    "client_secret": "cs_019975899d487c93a8bf823b41c05b44",
    "profile_id": "pro_pYmCUDflXtfYghJEbwig",
    "merchant_reference_id": null,
    "routing_algorithm_id": null,
    "capture_method": "automatic",
    "authentication_type": "no_three_ds",
    "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",
            "origin_zip": null
        },
        "phone": null,
        "email": "example@example.com"
    },
    "shipping": {
        "address": {
            "city": "San Fransico",
            "country": "US",
            "line1": "1467",
            "line2": "Harrison Street",
            "line3": "Harrison Street",
            "zip": "94122",
            "state": "California",
            "first_name": "joseph",
            "last_name": "Doe",
            "origin_zip": null
        },
        "phone": null,
        "email": "example@example.com"
    },
    "customer_id": null,
    "customer_present": "present",
    "description": null,
    "return_url": null,
    "setup_future_usage": "on_session",
    "apply_mit_exemption": "Skip",
    "statement_descriptor": null,
    "order_details": null,
    "allowed_payment_method_types": null,
    "metadata": null,
    "connector_metadata": null,
    "feature_metadata": null,
    "payment_link_enabled": "Skip",
    "payment_link_config": null,
    "request_incremental_authorization": "false",
    "split_txns_enabled": "skip",
    "expires_on": "2025-09-23T08:01:17.027Z",
    "frm_metadata": null,
    "request_external_three_ds_authentication": "Skip",
    "payment_type": "normal"
}

▶ Confirm Intent

Request:

curl --location 'http://localhost:8080/v2/payments/12345_pay_01997581b5657212a9e70f003b9d90b4/confirm-intent' \
--header 'x-profile-id: pro_k9nKKsBbyN4y6mOzfNe3' \
--header 'x-client-secret: cs_01997581b57e7683ae1c09b731afd73c' \
--header 'Authorization: api-key=dev_RDL3XpNVl4roIIGE1841URGxogUhALsFsxybasIi5yX62pvgFh4A3SNEWrKGvvBX' \
--header 'Content-Type: application/json' \
--header 'api-key: pk_dev_e02152d7d0c542dc934d95388df8a940' \
--data '{
    "payment_method_data": {
        "card": {
            "card_number": "4242424242424242",
            "card_exp_month": "01",
            "card_exp_year": "26",
            "card_holder_name": "John Doe",
            "card_cvc": "100"
        }
    },
    "payment_method_type": "card",
    "payment_method_subtype": "credit",
     "browser_info": {
        "user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36",
        "accept_header": "text\\/html,application\\/xhtml+xml,application\\/xml;q=0.9,image\\/webp,image\\/apng,*\\/*;q=0.8",
        "language": "en-GB",
        "color_depth": 24,
        "screen_height": 1440,
        "screen_width": 2560,
        "time_zone": -330,
        "java_enabled": true,
        "java_script_enabled": true,
        "ip_address": "0.0.0.0"
    }
}'

Response:

{
    "id": "12345_pay_019975899d367c61ae62b88f1edde4e9",
    "status": "succeeded",
    "amount": {
        "order_amount": 10000,
        "currency": "USD",
        "shipping_cost": null,
        "order_tax_amount": null,
        "external_tax_calculation": "skip",
        "surcharge_calculation": "skip",
        "surcharge_amount": null,
        "tax_on_surcharge": null,
        "net_amount": 10000,
        "amount_to_capture": null,
        "amount_capturable": 0,
        "amount_captured": 10000
    },
    "customer_id": null,
    "connector": "braintree",
    "created": "2025-09-23T07:46:17.027Z",
    "modified_at": "2025-09-23T07:47:00.359Z",
    "payment_method_data": {
        "billing": null
    },
    "payment_method_type": "card",
    "payment_method_subtype": "credit",
    "connector_transaction_id": "dHJhbnNhY3Rpb25fZnhxaDczNXY",
    "connector_reference_id": null,
    "merchant_connector_id": "mca_15ue2HSPzmSPtuWvipkZ",
    "browser_info": null,
    "error": null,
    "shipping": null,
    "billing": null,
    "attempts": null,
    "connector_token_details": null,
    "payment_method_id": null,
    "next_action": null,
    "return_url": "https://google.com/success",
    "authentication_type": "no_three_ds",
    "authentication_type_applied": "no_three_ds",
    "is_iframe_redirection_enabled": null,
    "merchant_reference_id": null,
    "raw_connector_response": null,
    "feature_metadata": null,
    "metadata": null
}
image 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

@ayush22667 ayush22667 self-assigned this Sep 23, 2025
@ayush22667 ayush22667 requested a review from a team as a code owner September 23, 2025 07:41
@ayush22667 ayush22667 added the C-feature Category: Feature request or enhancement label Sep 23, 2025
@semanticdiff-com
Copy link

semanticdiff-com bot commented Sep 23, 2025

Review changes with  SemanticDiff

Changed Files
File Status
  crates/router/src/core/payments.rs  33% smaller
  crates/router/src/core/payments/operations.rs  0% smaller
  crates/router/src/core/payments/operations/payment_confirm_intent.rs  0% smaller

@ayush22667 ayush22667 force-pushed the feat/payments-tokenization branch from 047977e to 20248c7 Compare September 23, 2025 10:06
hrithikesh026
hrithikesh026 previously approved these changes Sep 24, 2025
Copy link
Contributor

@hrithikesh026 hrithikesh026 left a comment

Choose a reason for hiding this comment

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

LGTM

@likhinbopanna likhinbopanna added this pull request to the merge queue Sep 29, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to no response for status checks Sep 29, 2025
@likhinbopanna likhinbopanna added this pull request to the merge queue Sep 30, 2025
Merged via the queue into main with commit efab34f Sep 30, 2025
25 of 29 checks passed
@likhinbopanna likhinbopanna deleted the feat/payments-tokenization branch September 30, 2025 08:07
pixincreate added a commit that referenced this pull request Sep 30, 2025
…pay-new-field

* 'main' of github.com:juspay/hyperswitch: (21 commits)
  feat(payments): add tokenization action handling to payment flow for braintree (#9506)
  feat(connector): [Loonio] Add template code (#9586)
  fix(connector): [paysafe] make `eci_indicator` field optional (#9591)
  fix(core): add should_call_connector_customer function to connector specification (#9569)
  feat(ucs): Add profile ID to lineage tracking in Unified Connector Service (#9559)
  feat(core): Add support for partial auth in proxy payments [V2] (#9503)
  chore(version): 2025.09.30.0
  fix(authorizedotnet): refund via ucs missing connector_metadata (#9581)
  feat(auth): add new authentication to communicate between microservices (#9547)
  Fix: Ideal Giropay Country Currency Config (#9552)
  feat(connector): [ACI] cypress added (#9502)
  feat(connector): Add Peachpayments Cypress (#9573)
  chore(version): 2025.09.29.0
  feat(finix): template code (#9557)
  feat(cypress): add cypress test-cases for manual retry (#9505)
  feat(core): update additional payment method data in psync response (#9519)
  feat(connector): [Checkout] Add Google Pay Predecrypt Flow (#9130)
  feat(framework): Added smithy, smithy-core and smithy-generator crates (#9249)
  fix(core): add request_extended_authorization in the payment attempt and populate it in the payment response (#9492)
  chore(version): 2025.09.26.0
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C-feature Category: Feature request or enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE] add tokenization action handling to payment flow in v2

4 participants