Skip to content

feat(router): Add tokenization support for proxy and update the route for proxy #8530

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

Merged
merged 11 commits into from
Aug 8, 2025

Conversation

prasunna09
Copy link
Contributor

@prasunna09 prasunna09 commented Jul 2, 2025

Type of Change

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

Description

Add tokenization support for proxy and update the route for proxy to /v2/proxy

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?

test case -

  1. create customer
  2. Create payment method
  3. use the same payment method id in proxy api
    request -
curl --location 'http://localhost:8080/v2/proxy' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'X-Profile-Id: profile id' \
--header 'Authorization: api-key=api key' \
--data '{
    "request_body": {
        "source": {
            "type": "card",
            "number": "{{$card_number}}",
            "expiry_month": "{{$card_exp_month}}",
            "expiry_year": "{{$card_exp_year}}",
        },
        "processing_channel_id": "< processing_channel_id >",
        "amount": 6540,
        "currency": "USD",
        "payment_type": "Regular",
        "reference": "ORD-5023-4E89",
        "description": "Set of 3 masks",
        "capture": true,
        "capture_on": "2019-09-10T10:11:12Z",
        "billing_descriptor": {
            "name": "Withdrawal",
            "city": "London"
        }
    },
    "destination_url": "https://api.sandbox.checkout.com/payments",
    "headers": {
        "Content-Type": "application/json",
        "Authorization": "Bearer <api key for checkout> "
    },
"token": "pm_0197ca91742f72d3bac45e1f8cdf9836",
    "token_type": "payment_method_id",
    "method": "POST"
}'

response -

{
    "response": {
        "id": "pay_onvfpnamhmnujkins23jzzyn6m",
        "action_id": "act_cllav3k4bveuvippsxvn3p3tim",
        "amount": 6540,
        "currency": "USD",
        "approved": true,
        "status": "Authorized",
        "auth_code": "727844",
        "response_code": "10000",
        "response_summary": "Approved",
        "balances": {
            "total_authorized": 6540,
            "total_voided": 0,
            "available_to_void": 6540,
            "total_captured": 0,
            "available_to_capture": 6540,
            "total_refunded": 0,
            "available_to_refund": 0
        },
        "risk": {
            "flagged": false,
            "score": 0.0
        },
        "source": {
            "id": "src_vtwe6mnu6pvepcnfhj337v2kk4",
            "type": "card",
            "expiry_month": 9,
            "expiry_year": 2025,
            "scheme": "Visa",
            "last4": "4242",
            "fingerprint": "0E532896E00C0A15DBE880E5BABF25A2F8080D577C4B37EFC391C2BC3629A3E4",
            "bin": "42424242",
            "card_type": "CREDIT",
            "card_category": "CONSUMER",
            "issuer": "CKO, WHERE THE WORLD CHECKS OUT",
            "issuer_country": "GB",
            "product_id": "F",
            "product_type": "Visa Classic",
            "avs_check": "G",
            "payment_account_reference": "V001827870003119243",
            "regulated_indicator": false
        },
        "processed_on": "2025-07-02T10:12:04.7916639Z",
        "reference": "ORD-5023-4E89",
        "scheme_id": "251583969481470",
        "processing": {
            "acquirer_transaction_id": "622040732846408761184",
            "retrieval_reference_number": "931975963629",
            "merchant_category_code": "5815",
            "scheme_merchant_id": "75155",
            "scheme": "VISA",
            "aft": false,
            "pan_type_processed": "fpan",
            "cko_network_token_available": false,
            "provision_network_token": false
        },
        "expires_on": "2025-08-01T10:12:04.7916639Z",
    },
    "status_code": 201,
    "response_headers": {
        "cko-version": "1.1129.0+0e5d53d72",
        "content-length": "1901",
        "cko-request-id": "e4919142-dd65-4b0f-8125-70e41d62076e",
        "content-type": "application/json; charset=utf-8",
        "connection": "keep-alive",
        "location": "https://api.sandbox.checkout.com/payments/pay_onvfpnamhmnujkins23jzzyn6m",
        "strict-transport-security": "max-age=16000000; includeSubDomains; preload;",
        "date": "Wed, 02 Jul 2025 10:12:04 GMT"
    }
}
  1. Create tokenization entry with card data -
    request -
curl --location 'http://localhost:8080/v2/tokenize' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'X-Profile-Id: profile id' \
--header 'Authorization: api-key=api key' \
--data '{
    "customer_id": "<customer_id>",
    "token_request":{
    "card_number":"<card number>",
    "card_exp_month": "09",
    "card_exp_year": "2025"
    }
}'

response -

{
    "id": "12345_tok_0197ca91742f72d3bac45e1f8cdf9836",
    "created_at": "2025-07-02 09:56:59.567795",
    "flag": "enabled"
}
  1. use this tokenization id in proxy
    request -
curl --location 'http://localhost:8080/v2/proxy' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'X-Profile-Id: profile id' \
--header 'Authorization: api-key=api key' \
--data '{
    "request_body": {
        "source": {
            "type": "card",
            "number": "{{$card_number}}",
            "expiry_month": "{{$card_exp_month}}",
            "expiry_year": "{{$card_exp_year}}",
        },
        "processing_channel_id": "processing_channel_id",
        "amount": 6540,
        "currency": "USD",
        "payment_type": "Regular",
        "reference": "ORD-5023-4E89",
        "description": "Set of 3 masks",
        "capture": true,
        "capture_on": "2019-09-10T10:11:12Z",
        "billing_descriptor": {
            "name": "Withdrawal",
            "city": "London"
        }
    },
    "destination_url": "https://api.sandbox.checkout.com/payments",
    "headers": {
        "Content-Type": "application/json",
        "Authorization": "Bearer <api key for checkout>"
    },
"token": "12345_tok_0197ca91742f72d3bac45e1f8cdf9836",
    "token_type": "tokenization_id",
    "method": "POST"

}'

response will be same when we used payment method id for proxy.

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

@prasunna09 prasunna09 requested review from a team as code owners July 2, 2025 10:26
Copy link

semanticdiff-com bot commented Jul 2, 2025

Review changes with  SemanticDiff

Changed Files
File Status
  crates/router/src/core/proxy.rs  35% smaller
  crates/router/src/core/proxy/utils.rs  11% smaller
  crates/common_utils/src/id_type/global_id/token.rs  0% smaller
  crates/router/src/routes/app.rs  0% smaller

@prasunna09 prasunna09 self-assigned this Jul 2, 2025
@prasunna09 prasunna09 added the A-core Area: Core flows label Jul 2, 2025
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("Unable to generate GlobalPaymentMethodId")?;
let token_id = id_type::GlobalTokenId::from_string(token.clone().as_str())
.change_context(errors::ApiErrorResponse::InternalServerError)?;
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add an attach_printable here

"Proxy flow using tokenization id".to_string(),
),
}))
.change_context(errors::ApiErrorResponse::InternalServerError)?;
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here

@likhinbopanna likhinbopanna added this pull request to the merge queue Aug 8, 2025
Merged via the queue into main with commit 767dee9 Aug 8, 2025
18 of 22 checks passed
@likhinbopanna likhinbopanna deleted the add-tokenization-support-for-proxy branch August 8, 2025 13:19
pixincreate added a commit that referenced this pull request Aug 8, 2025
…ordea-sepa

* 'main' of github.com:juspay/hyperswitch:
  feat(core): Adding integration for webhooks through UCS (#8814)
  refactor(euclid): refactor logs for evaluation of equality for dynamic routing evaluate response (#8834)
  feat(connector): [SIFT] add Connector Template Code  (#8488)
  feat(router): Add tokenization support for proxy and update the route for proxy (#8530)
  fix(ci): Fix Spell Check For CI Pull Request (#8857)
  feat(checkbook_io): connector integrate ACH (#8730)
  fix(connector): Change Refund Reason Type in Adyen (#8849)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-core Area: Core flows
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants