Skip to content

fix(core): language consumption from locale in payment and payout links#7993

Merged
Gnanasundari24 merged 3 commits intomainfrom
7981-bug-consider-only-the-language-for-locale-for-translations
May 12, 2025
Merged

fix(core): language consumption from locale in payment and payout links#7993
Gnanasundari24 merged 3 commits intomainfrom
7981-bug-consider-only-the-language-for-locale-for-translations

Conversation

@kashif-m
Copy link
Contributor

@kashif-m kashif-m commented May 9, 2025

Type of Change

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

Description

Fix the locale handling in the payment and payout links translation functionality to properly support language-location combinations like es-ES. Currently, the system is using the full locale value from the Accept-Language header without parsing it, causing translations for such locales to fail when the header includes region information.

The fix extracts the base language code from locale strings containing region identifiers to ensure proper translation mapping (e.g., es-ES will now correctly map to es translations).

Additional Changes

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

Motivation and Context

This PR fixes issue #7981 where the translation system fails to properly handle locale codes with region identifiers in the Accept-Language header.

When users send requests with headers like Accept-Language: es-ES, the system was using the full string (es-ES) for translation lookup instead of extracting the base language code (es). This caused Spanish translations to default to English because no exact match for es-ES was found in the translation data.

By parsing the locale string and extracting just the language part, we ensure that users receive translations in their requested language regardless of whether they include region information.

How did you test it?

1. Create a payment link with es-ES in Accept-Language header

cURL

curl --location --request POST 'http://localhost:8080/payments' \
    --header 'Content-Type: application/json' \
    --header 'Accept: application/json' \
    --header 'Accept-Language: es-ES' \
    --header 'api-key: dev_tizBo0XFMZBNZ3jWBlkrc6C81CiCdliXrLXFoAg2fTgoTmKvOIk2oAP43Gwb3AGK' \
    --data-raw '{"customer_id":"cus_Wz8ND2QMGUTQCZBgO4Jx_1","profile_id":"pro_DC4DZ899zblYKajNmd0K","customer_acceptance":{"acceptance_type":"online","accepted_at":"1963-05-03T04:07:52.723Z","online":{"ip_address":"127.0.0.1","user_agent":"amet irure esse"}},"amount":10,"currency":"EUR","confirm":false,"payment_link":true,"setup_future_usage":"off_session","capture_method":"automatic","billing":{"address":{},"email":"random@juspay.in"},"return_url":"https://example.com","payment_link_config":{"theme":"#111111","background_image":{"url":"https://img.freepik.com/free-photo/abstract-blue-geometric-shapes-background_24972-1841.jpg","position":"bottom","size":"cover"}}}'

Response

{"payment_id":"pay_zjyjvsTOPQKx0sYDzkzq","merchant_id":"merchant_1746522436","status":"requires_payment_method","amount":10,"net_amount":10,"shipping_cost":null,"amount_capturable":0,"amount_received":null,"connector":null,"client_secret":"pay_zjyjvsTOPQKx0sYDzkzq_secret_hD6KQpqlkWdk9wTPPDIB","created":"2025-05-09T08:09:43.323Z","currency":"EUR","customer_id":"cus_Wz8ND2QMGUTQCZBgO4Jx_1","customer":{"id":"cus_Wz8ND2QMGUTQCZBgO4Jx_1","name":null,"email":null,"phone":null,"phone_country_code":null},"description":null,"refunds":null,"disputes":null,"mandate_id":null,"mandate_data":null,"setup_future_usage":"off_session","off_session":null,"capture_on":null,"capture_method":"automatic","payment_method":null,"payment_method_data":null,"payment_token":null,"shipping":null,"billing":{"address":null,"phone":null,"email":"random@juspay.in"},"order_details":null,"email":null,"name":null,"phone":null,"return_url":"https://example.com/","authentication_type":null,"statement_descriptor_name":null,"statement_descriptor_suffix":null,"next_action":null,"cancellation_reason":null,"error_code":null,"error_message":null,"unified_code":null,"unified_message":null,"payment_experience":null,"payment_method_type":null,"connector_label":null,"business_country":null,"business_label":"default","business_sub_label":null,"allowed_payment_method_types":null,"ephemeral_key":{"customer_id":"cus_Wz8ND2QMGUTQCZBgO4Jx_1","created_at":1746778183,"expires":1746781783,"secret":"epk_f853d34ab7444310b3a54b0704e34867"},"manual_retry_allowed":null,"connector_transaction_id":null,"frm_message":null,"metadata":null,"connector_metadata":null,"feature_metadata":null,"reference_id":null,"payment_link":{"link":"http://localhost:8080/payment_link/merchant_1746522436/pay_zjyjvsTOPQKx0sYDzkzq?locale=es-ES","secure_link":null,"payment_link_id":"plink_FAtpjPaeg4T5UjMsVBeg"},"profile_id":"pro_DC4DZ899zblYKajNmd0K","surcharge_details":null,"attempt_count":1,"merchant_decision":null,"merchant_connector_id":null,"incremental_authorization_allowed":null,"authorization_count":null,"incremental_authorizations":null,"external_authentication_details":null,"external_3ds_authentication_attempted":false,"expires_on":"2025-05-09T08:24:43.318Z","fingerprint":null,"browser_info":null,"payment_method_id":null,"payment_method_status":null,"updated":"2025-05-09T08:09:43.343Z","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}
Screenshot 2025-05-09 at 1 51 02 PM
2. Create a payout link

cURL

curl --location --request POST 'http://localhost:8080/payouts/create' \
    --header 'Content-Type: application/json' \
    --header 'api-key: dev_tizBo0XFMZBNZ3jWBlkrc6C81CiCdliXrLXFoAg2fTgoTmKvOIk2oAP43Gwb3AGK' \
    --data '{"amount":1,"currency":"EUR","customer_id":"cus_Wz8ND2QMGUTQCZBgO4Jx","description":"Its my first payout request","entity_type":"Individual","confirm":false,"auto_fulfill":true,"session_expiry":1000000,"priority":"instant","profile_id":"pro_DC4DZ899zblYKajNmd0K","payout_link":true,"return_url":"https://www.google.com","payout_link_config":{"form_layout":"journey","theme":"#0066ff","logo":"https://hyperswitch.io/favicon.ico","merchant_name":"HyperSwitch Inc.","test_mode":true}}'

Response

{"payout_id":"93d4cfee-cfcd-4be0-b750-049c98a1f220","merchant_id":"merchant_1746522436","amount":1,"currency":"EUR","connector":null,"payout_type":null,"payout_method_data":null,"billing":null,"auto_fulfill":true,"customer_id":"cus_Wz8ND2QMGUTQCZBgO4Jx","customer":{"id":"cus_Wz8ND2QMGUTQCZBgO4Jx","name":null,"email":"abc@example.com","phone":null,"phone_country_code":null},"client_secret":"payout_93d4cfee-cfcd-4be0-b750-049c98a1f220_secret_UllSmh3B4jG5IMkov2ft","return_url":"https://www.google.com","business_country":null,"business_label":null,"description":"Its my first payout request","entity_type":"Individual","recurring":false,"metadata":{},"merchant_connector_id":null,"status":"requires_payout_method_data","error_message":null,"error_code":null,"profile_id":"pro_DC4DZ899zblYKajNmd0K","created":"2025-05-09T08:11:21.214Z","connector_transaction_id":null,"priority":"instant","payout_link":{"payout_link_id":"payout_link_DkmRGHGOrm12ZZRvYH5o","link":"http://localhost:8080/payout_link/merchant_1746522436/93d4cfee-cfcd-4be0-b750-049c98a1f220?locale=en"},"email":"abc@example.com","name":null,"phone":null,"phone_country_code":null,"unified_code":null,"unified_message":null,"payout_method_id":null}
Screenshot 2025-05-09 at 1 50 16 PM

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

@kashif-m kashif-m self-assigned this May 9, 2025
@kashif-m kashif-m requested review from a team as code owners May 9, 2025 08:21
@kashif-m kashif-m linked an issue May 9, 2025 that may be closed by this pull request
2 tasks
@semanticdiff-com
Copy link

semanticdiff-com bot commented May 9, 2025

Review changes with  SemanticDiff

Changed Files
File Status
  crates/router/src/core/payment_link/locale.js  28% smaller
  crates/router/locales/en_gb.yml  0% smaller
  crates/router/locales/fr_be.yml  0% smaller
  crates/router/src/services/api/generic_link_response/context.rs  0% smaller

sahkal
sahkal previously approved these changes May 9, 2025
@Gnanasundari24 Gnanasundari24 added this pull request to the merge queue May 12, 2025
Merged via the queue into main with commit 04da2dd May 12, 2025
15 of 20 checks passed
@Gnanasundari24 Gnanasundari24 deleted the 7981-bug-consider-only-the-language-for-locale-for-translations branch May 12, 2025 15:38
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)
  ...
kashif-m added a commit that referenced this pull request May 13, 2025
…ks (#7993)

Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
(cherry picked from commit 04da2dd)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] consider only the language for locale for translations

4 participants