Skip to content

Open source, composable payments platform | PCI compliant | SaaS and Self-host options | Enables connectivity to multiple payment, payout, fraud, vault and tokenization providers | Uplifts authorization with intelligent routing and revenue recovery | Reduce payment processing costs with cost observability | Reduces payment ops with reconciliation

fix(connector): [Checkout] pad NetworkToken expiry_year to 4 digits (#12386)

awasthi21289685fa1221
diff --git a/crates/hyperswitch_connectors/src/connectors/checkout/transformers.rs b/crates/hyperswitch_connectors/src/connectors/checkout/transformers.rs
index 04f61229ab..ecedc73022 100644
--- a/crates/hyperswitch_connectors/src/connectors/checkout/transformers.rs
+++ b/crates/hyperswitch_connectors/src/connectors/checkout/transformers.rs
@@ -542,6 +542,23 @@ fn build_metadata(
Some(Secret::new(metadata_json))
}
+/// Pad a 2-digit "YY" expiry year to 4-digit "20YY", pass-through if already 4-digit.
+///
+/// `CardData::get_expiry_year_4_digit` (in `crates/hyperswitch_connectors/src/utils.rs`)
+/// covers `Card`, `CardDetailsForNetworkTransactionId`, `DecryptedWalletTokenDetailsForNetworkTransactionId`,
+/// and `ApplePayDecrypt` — but not `NetworkTokenData` or
+/// `NetworkTokenDetailsForNetworkTransactionId`. The PaymentSource::NetworkToken
+/// paths below need the same YY → YYYY coercion, since Checkout's API expects
+/// a 4-digit `expiry_year`.
+fn pad_expiry_year_to_4_digit(year: Secret<String>) -> Secret<String> {
+ let raw = year.expose();
+ if raw.len() == 2 {
+ Secret::new(format!("20{raw}"))
+ } else {
+ Secret::new(raw)
+ }
+}
+
fn is_metadata_empty(val: &Option<Secret<serde_json::Value>>) -> bool {
match val {
None => true,
@@ -863,7 +880,7 @@ impl TryFrom<&CheckoutRouterData<&PaymentsAuthorizeRouterData>> for PaymentsRequ
source_type: "network_token".to_string(),
token: cards::CardNumber::from(token),
expiry_month,
- expiry_year,
+ expiry_year: pad_expiry_year_to_4_digit(expiry_year),
token_type,
cryptogram,
eci: token_data.eci,
@@ -908,7 +925,7 @@ impl TryFrom<&CheckoutRouterData<&PaymentsAuthorizeRouterData>> for PaymentsRequ
source_type: "network_token".to_string(),
token: cards::CardNumber::from(token_data.network_token),
expiry_month: token_data.token_exp_month,
- expiry_year: token_data.token_exp_year,
+ expiry_year: pad_expiry_year_to_4_digit(token_data.token_exp_year),
token_type,
cryptogram: None,
eci: token_data.eci,