Skip to content

Conversation

@Sakilmostak
Copy link
Contributor

@Sakilmostak Sakilmostak commented Mar 25, 2025

Type of Change

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

Description

An endpoint is added to fetch network token related to a payment method (specifically cards)

  • Add a GET call to fetch network token data with cryptogram
  • Cryptogram is generated for every api call
  • No DB changes made since cryptogram is single use

Additional Changes

  • This PR modifies the API contract
    Endpoint:
 {{baseUrl}}/v2/payment-methods/{id}/get-token
  • 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 Merchant Account
  • Cretae Organization
  • Create a Merchant Connector Account
  • Enable network tokenization in Business Profile
{
    "is_network_tokenization_enabled": true
}
  • Save a payment method with network token
curl --location '{{baseUrl}}/v2/payment-methods' \
--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}}",
    "payment_method_type": "card",
    "payment_method_subtype": "credit",
    "payment_method_data": {
        "card": {
            "card_number": "4761360080000093",
            "card_exp_month": "12",
            "card_exp_year": "2026",
            "card_holder_name": "joseph Doe"
        }
    },
    "network_tokenization":{
        "enable":"Enable"
    }
}'
  • Get cryptogram for the network token with payment_method_id:
curl --location --request GET '{{base_url}}/v2/payment-methods/{{payment_method_id}}/get-token' \
--header 'X-Profile-Id:{{profile_id}}' \
--header 'Content-Type: application/json' \
--header 'Authorization: api-key={{api_key}}' \
--data '{
    "token_type": "network_token"
}'

Following should be the response:

{
    "payment_method_id": "12345_pm_0195dc62e14d7102b2ee7be5d04fe853",
    "network_token": "4604000460040707",
    "network_token_exp_month": "12",
    "network_token_exp_year": "2026",
    "cryptogram": "AwAAAAABD5dXv0wAmbSeglsLAAA=",
    "card_issuer": "ICICI Bank",
    "card_network": "Visa",
    "card_type": null,
    "card_issuing_country": null,
    "bank_code": null,
    "card_holder_name": "joseph Doe",
    "nick_name": null,
    "eci": "07"
}

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 C-feature Category: Feature request or enhancement A-payment-methods Area: Payment Methods labels Mar 25, 2025
@Sakilmostak Sakilmostak added this to the March 2025 Release milestone Mar 25, 2025
@Sakilmostak Sakilmostak self-assigned this Mar 25, 2025
@semanticdiff-com
Copy link

semanticdiff-com bot commented Mar 25, 2025

@Sakilmostak Sakilmostak changed the title feat(payment_methods): add api for fetching cryptogram feat(payment_methods): add v2 api for fetching token data Mar 26, 2025
@Sakilmostak Sakilmostak marked this pull request as ready for review March 26, 2025 11:20
@Sakilmostak Sakilmostak requested review from a team as code owners March 26, 2025 11:20
@hyperswitch-bot hyperswitch-bot bot added the M-api-contract-changes Metadata: This PR involves API contract changes label Mar 26, 2025
@Sakilmostak Sakilmostak requested a review from a team as a code owner March 28, 2025 08:01
@Sakilmostak Sakilmostak removed request for a team April 21, 2025 08:18

/// Cryptogram generated by the Network
#[schema(value_type = Option<String>)]
pub cryptogram: Option<masking::Secret<String>>,
Copy link
Contributor

Choose a reason for hiding this comment

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

doesn't this have to be mandatory field?, since the aim of this api is to share cryptogram and network token

Copy link
Contributor Author

Choose a reason for hiding this comment

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

After discussion it seems cryptogram is not generated for all network token, it is a nullable value, thus couldn't be make mandatory.

@Sakilmostak Sakilmostak requested a review from a team as a code owner April 30, 2025 07:46
prasunna09
prasunna09 previously approved these changes May 5, 2025
Comment on lines +1411 to +1416
if !is_network_tokenization_enabled {
return Err(errors::ApiErrorResponse::UnprocessableEntity {
message: "Network tokenization is not enabled for this profile".to_string(),
}
.into());
}
Copy link
Contributor

Choose a reason for hiding this comment

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

you can use when method instead of if and early return.

@Gnanasundari24 Gnanasundari24 added this pull request to the merge queue May 12, 2025
Merged via the queue into main with commit 2cefac5 May 12, 2025
28 of 32 checks passed
@Gnanasundari24 Gnanasundari24 deleted the cyrptogram_api branch May 12, 2025 14:19
pixincreate added a commit that referenced this pull request May 12, 2025
…adyen-ideal

* 'main' of github.com:juspay/hyperswitch: (62 commits)
  fix(core): language consumption from locale in payment and payout links (#7993)
  feat(refunds_v2): Add refunds list flow in v2 apis (#7966)
  refactor(connector): [Noon] auth header (#7977)
  fix(connector): [Novalnet] send decoded token for apple pay payment (#7973)
  feat(business_profile): add business_profile config to enable external vault (#7876)
  feat(vsaas): integrate onboarding flow for vertical saas (#7884)
  feat(connector): Introduce connector template code for WorldpayXML  (#7968)
  feat(connector): [ADYEN, CHECKOUT] Added In Feature Matrix API (#7914)
  feat(core): add psync support for recovery external payments (#7855)
  refactor(open_router): call elimination routing of open router if enabled instead of dynamo (#7961)
  feat(payment_methods): add v2 api for fetching token data (#7629)
  ci(cypress): Fix Bank Redirects for stripe test (#8004)
  chore(version): 2025.05.12.0
  refactor(authentication): moved cavv storing from table to temp locker (#7978)
  chore(version): 2025.05.09.0
  feat(connector): [paypal, trustpay] add in feature matrix (#7911)
  fix(update_metadata): Update Metadata for any connectors other than stripe gives 500 error (#7984)
  fix(router): Fixed stack over flow for session call in authentication connectors (#7983)
  chore(version): 2025.05.08.0
  fix(payment): disable payment update via client config (#7970)
  ...
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-feature Category: Feature request or enhancement M-api-contract-changes Metadata: This PR involves API contract changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants