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
Rust adyenbeginner-friendlyfeaturedfinancefintechhacktoberfesthigh-performanceopen-sourceorchestrationpaymentpayment-gatewaypayment-integrationpayment-processingpaymentspayments-platformrestful-apirustsdkstripeworks-with-react
feat(core): add processor token details for proxy MIT flow (#14990)
Vani Gupta64d48d3422e9
diff --git a/api-reference/v1/openapi_spec_v1.json b/api-reference/v1/openapi_spec_v1.jsonindex 85c065eb15..d816909c36 100644--- a/api-reference/v1/openapi_spec_v1.json+++ b/api-reference/v1/openapi_spec_v1.json@@ -43203,6 +43203,42 @@"merchant_connector_id": {"type": "string","nullable": true+ },+ "processor_payment_token_details": {+ "allOf": [+ {+ "$ref": "#/components/schemas/ProcessorPaymentTokenDetails"+ }+ ],+ "nullable": true+ }+ }+ },+ "ProcessorPaymentTokenDetails": {+ "type": "object",+ "description": "Card and network reference details associated with a processor payment token.",+ "properties": {+ "card_exp_month": {+ "type": "string",+ "description": "The card's expiry month.",+ "example": "12",+ "nullable": true+ },+ "card_exp_year": {+ "type": "string",+ "description": "The card's expiry year.",+ "example": "2030",+ "nullable": true+ },+ "network_transaction_id": {+ "type": "string",+ "description": "The network transaction ID from the original customer initiated transaction.",+ "nullable": true+ },+ "transaction_link_id": {+ "type": "string",+ "description": "The Mastercard Transaction Link Identifier from the original transaction.",+ "nullable": true}}},diff --git a/api-reference/v2/openapi_spec_v2.json b/api-reference/v2/openapi_spec_v2.jsonindex cbbf8737f0..2916889ce0 100644--- a/api-reference/v2/openapi_spec_v2.json+++ b/api-reference/v2/openapi_spec_v2.json@@ -30650,6 +30650,42 @@"merchant_connector_id": {"type": "string","nullable": true+ },+ "processor_payment_token_details": {+ "allOf": [+ {+ "$ref": "#/components/schemas/ProcessorPaymentTokenDetails"+ }+ ],+ "nullable": true+ }+ }+ },+ "ProcessorPaymentTokenDetails": {+ "type": "object",+ "description": "Card and network reference details associated with a processor payment token.",+ "properties": {+ "card_exp_month": {+ "type": "string",+ "description": "The card's expiry month.",+ "example": "12",+ "nullable": true+ },+ "card_exp_year": {+ "type": "string",+ "description": "The card's expiry year.",+ "example": "2030",+ "nullable": true+ },+ "network_transaction_id": {+ "type": "string",+ "description": "The network transaction ID from the original customer initiated transaction.",+ "nullable": true+ },+ "transaction_link_id": {+ "type": "string",+ "description": "The Mastercard Transaction Link Identifier from the original transaction.",+ "nullable": true}}},diff --git a/crates/api_models/src/mandates.rs b/crates/api_models/src/mandates.rsindex 9047773731..4038ac9552 100644--- a/crates/api_models/src/mandates.rs+++ b/crates/api_models/src/mandates.rs@@ -239,6 +239,31 @@ pub struct ProcessorPaymentToken {#[schema(value_type = Option<String>)]#[smithy(value_type = "Option<String>")]pub merchant_connector_id: Option<common_utils::id_type::MerchantConnectorAccountId>,+ /// Additional card and network reference details associated with the processor token.+ #[smithy(value_type = "Option<ProcessorPaymentTokenDetails>")]+ pub processor_payment_token_details: Option<ProcessorPaymentTokenDetails>,+}++/// Card and network reference details associated with a processor payment token.+#[derive(+ Debug, Clone, serde::Serialize, serde::Deserialize, ToSchema, PartialEq, Eq, SmithyModel,+)]+#[smithy(namespace = "com.hyperswitch.smithy.types")]+pub struct ProcessorPaymentTokenDetails {+ /// The card's expiry month.+ #[schema(value_type = Option<String>, example = "12")]+ #[smithy(value_type = "Option<String>")]+ pub card_exp_month: Option<Secret<String>>,+ /// The card's expiry year.+ #[schema(value_type = Option<String>, example = "2030")]+ #[smithy(value_type = "Option<String>")]+ pub card_exp_year: Option<Secret<String>>,+ /// The network transaction ID from the original customer initiated transaction.+ #[smithy(value_type = "Option<String>")]+ pub network_transaction_id: Option<String>,+ /// The Mastercard Transaction Link Identifier from the original transaction.+ #[smithy(value_type = "Option<String>")]+ pub transaction_link_id: Option<String>,}#[derive(diff --git a/crates/hyperswitch_domain_models/src/mandates.rs b/crates/hyperswitch_domain_models/src/mandates.rsindex 6071a4fc52..fa58271164 100644--- a/crates/hyperswitch_domain_models/src/mandates.rs+++ b/crates/hyperswitch_domain_models/src/mandates.rs@@ -745,6 +745,7 @@ pub struct ConnectorMandateReferenceId {mandate_metadata: Option<pii::SecretSerdeValue>,connector_mandate_request_reference_id: Option<String>,updated_mandate_details: Option<UpdatedMandateDetails>,+ additional_mandate_details: Option<Box<api_models::mandates::ProcessorPaymentTokenDetails>>,}impl ConnectorMandateReferenceId {@@ -763,6 +764,7 @@ impl ConnectorMandateReferenceId {mandate_metadata,connector_mandate_request_reference_id,updated_mandate_details,+ additional_mandate_details: None,}}@@ -772,6 +774,11 @@ impl ConnectorMandateReferenceId {pub fn get_payment_method_id(&self) -> Option<String> {self.payment_method_id.clone()}+ pub fn get_additional_mandate_details(+ &self,+ ) -> Option<api_models::mandates::ProcessorPaymentTokenDetails> {+ self.additional_mandate_details.as_deref().cloned()+ }pub fn get_mandate_metadata(&self) -> Option<pii::SecretSerdeValue> {self.mandate_metadata.clone()}@@ -796,6 +803,20 @@ impl ConnectorMandateReferenceId {}}+impl From<&api_models::mandates::ProcessorPaymentToken> for ConnectorMandateReferenceId {+ fn from(token: &api_models::mandates::ProcessorPaymentToken) -> Self {+ Self {+ connector_mandate_id: Some(token.processor_payment_token.clone()),+ payment_method_id: None,+ update_history: None,+ mandate_metadata: None,+ connector_mandate_request_reference_id: None,+ updated_mandate_details: None,+ additional_mandate_details: token.processor_payment_token_details.clone().map(Box::new), // note: this is not persisted in payment_attempt table+ }+ }+}+#[derive(serde::Serialize, serde::Deserialize, Debug, Clone, Eq, PartialEq)]pub struct UpdatedMandateDetails {pub card_network: Option<common_enums::CardNetwork>,diff --git a/crates/hyperswitch_domain_models/src/payment_method_data.rs b/crates/hyperswitch_domain_models/src/payment_method_data.rsindex 31bcf8aefb..dacd5f2668 100644--- a/crates/hyperswitch_domain_models/src/payment_method_data.rs+++ b/crates/hyperswitch_domain_models/src/payment_method_data.rs@@ -154,6 +154,7 @@ pub enum RecurringDetails {pub struct ProcessorPaymentToken {pub processor_payment_token: String,pub merchant_connector_id: Option<id_type::MerchantConnectorAccountId>,+ pub processor_payment_token_details: Option<api_mandates::ProcessorPaymentTokenDetails>,}#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, PartialEq, Eq)]@@ -5057,6 +5058,7 @@ impl From<api_mandates::RecurringDetails> for RecurringDetails {Self::ProcessorPaymentToken(ProcessorPaymentToken {processor_payment_token: token.processor_payment_token,merchant_connector_id: token.merchant_connector_id,+ processor_payment_token_details: token.processor_payment_token_details,})}api_mandates::RecurringDetails::NetworkTransactionIdAndCardDetails(diff --git a/crates/openapi/src/openapi.rs b/crates/openapi/src/openapi.rsindex f089bddc40..b77f891c74 100644--- a/crates/openapi/src/openapi.rs+++ b/crates/openapi/src/openapi.rs@@ -919,6 +919,7 @@ Never share your secret api keys. Keep them guarded and secure.api_models::mandates::NetworkTokenWithVaultCardFallback,api_models::mandates::VaultCardData,api_models::mandates::ProcessorPaymentToken,+ api_models::mandates::ProcessorPaymentTokenDetails,api_models::payments::CustomerDetails,api_models::payments::GiftCardData,api_models::payments::GiftCardDetails,diff --git a/crates/openapi/src/openapi_v2.rs b/crates/openapi/src/openapi_v2.rsindex a0a46bea39..1d8a51dea0 100644--- a/crates/openapi/src/openapi_v2.rs+++ b/crates/openapi/src/openapi_v2.rs@@ -786,6 +786,7 @@ Never share your secret api keys. Keep them guarded and secure.api_models::mandates::MandateCardDetails,api_models::mandates::RecurringDetails,api_models::mandates::ProcessorPaymentToken,+ api_models::mandates::ProcessorPaymentTokenDetails,api_models::client_secret::ClientSecretResponse,api_models::payments::CustomerDetails,api_models::payments::GiftCardData,diff --git a/crates/router/src/core/payments/operations/payment_confirm.rs b/crates/router/src/core/payments/operations/payment_confirm.rsindex 14209c4b79..ab20d3d5e1 100644--- a/crates/router/src/core/payments/operations/payment_confirm.rs+++ b/crates/router/src/core/payments/operations/payment_confirm.rs@@ -931,14 +931,7 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, api::PaymentsRequest>mandate_id: None,mandate_reference_id: Some(mandates::MandateReferenceId::ConnectorMandateId(- ConnectorMandateReferenceId::new(- Some(token.processor_payment_token.clone()), // connector_mandate_id- None, // payment_method_id- None, // update_history- None, // mandate_metadata- None, // connector_mandate_request_reference_id- None,- ),+ ConnectorMandateReferenceId::from(token),),),})diff --git a/crates/router/src/core/payments/operations/payment_create.rs b/crates/router/src/core/payments/operations/payment_create.rsindex cd8929e5d5..59a0d1afd1 100644--- a/crates/router/src/core/payments/operations/payment_create.rs+++ b/crates/router/src/core/payments/operations/payment_create.rs@@ -504,14 +504,7 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, api::PaymentsRequest>mandate_id: None,mandate_reference_id: Some(mandates::MandateReferenceId::ConnectorMandateId(- mandates::ConnectorMandateReferenceId::new(- Some(token.processor_payment_token.clone()),- None,- None,- None,- None,- None,- ),+ mandates::ConnectorMandateReferenceId::from(token),),),}),diff --git a/crates/router/src/core/payments/operations/proxy_payments_intent.rs b/crates/router/src/core/payments/operations/proxy_payments_intent.rsindex 5a7d22b6b6..e6b3d89ec2 100644--- a/crates/router/src/core/payments/operations/proxy_payments_intent.rs+++ b/crates/router/src/core/payments/operations/proxy_payments_intent.rs@@ -230,8 +230,6 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentConfirmData<F>, ProxyPaymentsR}};- let processor_payment_token = request.recurring_details.processor_payment_token.clone();-let payment_address = hyperswitch_domain_models::payment_address::PaymentAddress::new(payment_intent.shipping_address@@ -250,14 +248,7 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentConfirmData<F>, ProxyPaymentsRlet mandate_data_input = mandates::MandateIds {mandate_id: None,mandate_reference_id: Some(mandates::MandateReferenceId::ConnectorMandateId(- mandates::ConnectorMandateReferenceId::new(- Some(processor_payment_token),- None,- None,- None,- None,- None,- ),+ mandates::ConnectorMandateReferenceId::from(&request.recurring_details),)),};diff --git a/crates/router/src/core/revenue_recovery/api.rs b/crates/router/src/core/revenue_recovery/api.rsindex 9be75f8422..fdfcb6c292 100644--- a/crates/router/src/core/revenue_recovery/api.rs+++ b/crates/router/src/core/revenue_recovery/api.rs@@ -109,6 +109,7 @@ pub async fn call_proxy_api(let recurring_details = api_models::mandates::ProcessorPaymentToken {processor_payment_token: payment_processor_token.to_string(),merchant_connector_id: Some(connector_accounts.payment_connector_id.clone()),+ processor_payment_token_details: None,};let req = payments_api::ProxyPaymentsRequest {return_url: None,diff --git a/crates/router/src/core/unified_connector_service/transformers.rs b/crates/router/src/core/unified_connector_service/transformers.rsindex 205a6e9a6a..6509e18b46 100644--- a/crates/router/src/core/unified_connector_service/transformers.rs+++ b/crates/router/src/core/unified_connector_service/transformers.rs@@ -58,8 +58,9 @@ use router_env::tracing;use time::Duration;use unified_connector_service_cards::{CardNumber, NetworkToken};use unified_connector_service_client::payments::{- self as payments_grpc, client_authentication_token_data,- recipient_account::AccountType as RecipientAccountType,+ self as payments_grpc,+ additional_payment_data::PaymentMethodData as AdditionalPaymentMethodData,+ client_authentication_token_data, recipient_account::AccountType as RecipientAccountType,recipient_bank_account::BankAccountType as RecipientBankAccountType, ConnectorState,EventServiceHandleRequest, EventServiceParseRequest,};@@ -1335,10 +1336,6 @@ impl)?;Ok(Self {- risk_assessment_data: None,- split_settlement: None,- split_payments: None,- domain_data: None,mit_category: None,surcharge_amount: None,amount: Some(payments_grpc::Money {@@ -1494,6 +1491,10 @@ implintegrity_specifications: Some(payments_grpc::IntegritySpecifications {allow_amount_mismatch: router_data.accept_amount_mismatch.map(|accept| *accept),}),+ domain_data: None,+ risk_assessment_data: None,+ split_payments: None,+ split_settlement: None,})}}@@ -1726,6 +1727,11 @@ impl ForeignFrom<&mandates::ConnectorMandateReferenceId>for payments_grpc::ConnectorMandateReferenceId{fn foreign_from(value: &mandates::ConnectorMandateReferenceId) -> Self {+ let (network_transaction_id, transaction_link_id) = value+ .get_additional_mandate_details()+ .map(|details| (details.network_transaction_id, details.transaction_link_id))+ .unwrap_or_default();+Self {connector_mandate_id: value.get_connector_mandate_id(),payment_method_id: value.get_payment_method_id(),@@ -1734,8 +1740,8 @@ impl ForeignFrom<&mandates::ConnectorMandateReferenceId>mandate_metadata: value.get_mandate_metadata().map(|mandate_metadata| {Secret::new(serde_json::to_string(&mandate_metadata.expose()).unwrap_or_default())}),- network_transaction_id: None,- transaction_link_id: None,+ network_transaction_id,+ transaction_link_id,}}}@@ -1760,10 +1766,16 @@ impl ForeignFrom<&RouterData<PSync, PaymentsSyncData, PaymentsResponseData>>let connector_mandate_request_reference_id = structured.and_then(|r| r.get_connector_mandate_request_reference_id()).or_else(|| router_data.connector_mandate_request_reference_id.clone());+ let (network_transaction_id, transaction_link_id) = structured+ .and_then(|r| r.get_additional_mandate_details())+ .map(|details| (details.network_transaction_id, details.transaction_link_id))+ .unwrap_or_default();if connector_mandate_id.is_none()&& payment_method_id.is_none()&& connector_mandate_request_reference_id.is_none()+ && network_transaction_id.is_none()+ && transaction_link_id.is_none(){return None;}@@ -1771,6 +1783,8 @@ impl ForeignFrom<&RouterData<PSync, PaymentsSyncData, PaymentsResponseData>>connector_mandate_id,payment_method_id,connector_mandate_request_reference_id,+ network_transaction_id,+ transaction_link_id,mandate_metadata: structured.and_then(|connector_mandate_reference_id| {connector_mandate_reference_id.get_mandate_metadata()@@ -1780,8 +1794,6 @@ impl ForeignFrom<&RouterData<PSync, PaymentsSyncData, PaymentsResponseData>>serde_json::to_string(&mandate_metadata.expose()).unwrap_or_default(),)}),- network_transaction_id: None,- transaction_link_id: None,})}}@@ -3839,6 +3851,40 @@ impl}}+// Processor-token expiry is carried internally in additional_mandate_details.+// Map it to UCS's existing AdditionalCardInfo fields to avoid duplicating expiry details. Explicit token expiry overrides stored card expiry.+fn merge_processor_token_expiry(+ additional_payment_data: &mut Option<payments_grpc::AdditionalPaymentData>,+ details: api_models::mandates::ProcessorPaymentTokenDetails,+) -> Result<(), error_stack::Report<UnifiedConnectorServiceError>> {+ if details.card_exp_month.is_some() || details.card_exp_year.is_some() {+ let payment_data = additional_payment_data.get_or_insert_with(Default::default);+ match payment_data+ .payment_method_data+ .get_or_insert_with(|| AdditionalPaymentMethodData::Card(Default::default()))+ {+ AdditionalPaymentMethodData::Card(card) => {+ if let Some(month) = details.card_exp_month {+ card.card_exp_month = Some(month);+ }+ if let Some(year) = details.card_exp_year {+ card.card_exp_year = Some(year);+ }+ Ok(())+ }+ AdditionalPaymentMethodData::Wallet(_) => Err(+ UnifiedConnectorServiceError::RequestEncodingFailedWithReason(+ "Processor token card expiry cannot be combined with wallet additional payment data"+ .to_string(),+ )+ .into(),+ ),+ }+ } else {+ Ok(())+ }+}+impltransformers::ForeignTryFrom<&RouterData<Authorize, PaymentsAuthorizeData, PaymentsResponseData>,@@ -3884,23 +3930,9 @@ implSome(payments_grpc::MandateReference {mandate_id_type: Some(payments_grpc::mandate_reference::MandateIdType::ConnectorMandateId(- payments_grpc::ConnectorMandateReferenceId {- connector_mandate_id: connector_mandate_id- .get_connector_mandate_id(),- payment_method_id: connector_mandate_id.get_payment_method_id(),- connector_mandate_request_reference_id: connector_mandate_id- .get_connector_mandate_request_reference_id(),- mandate_metadata: connector_mandate_id- .get_mandate_metadata()- .map(|mandate_metadata| {- Secret::new(- serde_json::to_string(&mandate_metadata.expose())- .unwrap_or_default(),- )- }),- network_transaction_id: None,- transaction_link_id: None,- },+ payments_grpc::ConnectorMandateReferenceId::foreign_from(+ connector_mandate_id,+ ),),),})@@ -3989,7 +4021,7 @@ impl.map(payments_grpc::AuthenticationData::foreign_try_from).transpose()?;- let additional_payment_data = router_data+ let mut additional_payment_data = router_data.request.additional_payment_method_data.clone()@@ -3997,6 +4029,17 @@ implpayments_grpc::AdditionalPaymentData::foreign_from(additional_payment_data)});+ if let Some(mandates::MandateReferenceId::ConnectorMandateId(reference)) = router_data+ .request+ .mandate_id+ .as_ref()+ .and_then(|mandate| mandate.mandate_reference_id.as_ref())+ {+ if let Some(details) = reference.get_additional_mandate_details() {+ merge_processor_token_expiry(&mut additional_payment_data, details)?;+ }+ }+let auth_type = payments_grpc::AuthenticationType::foreign_try_from(router_data.auth_type).attach_printable("Failed to convert authentication type")?;