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

feat(router): silence vault failures for setup_future_usage `off_session` payments in the confirm flow (#10406)

Sai Harsha Vardhanc232c208d5d0
diff --git a/api-reference/v1/openapi_spec_v1.json b/api-reference/v1/openapi_spec_v1.json
index 127cddc2f8..ccd89e9883 100644
--- a/api-reference/v1/openapi_spec_v1.json
+++ b/api-reference/v1/openapi_spec_v1.json
@@ -25953,6 +25953,46 @@
"awaiting_data"
]
},
+ "PaymentMethodTokenizationDetails": {
+ "type": "object",
+ "required": [
+ "payment_method_id",
+ "psp_tokenization",
+ "network_tokenization",
+ "is_eligible_for_mit_payment"
+ ],
+ "properties": {
+ "payment_method_id": {
+ "type": "string",
+ "description": "The unique identifier for the payment method"
+ },
+ "payment_method_status": {
+ "allOf": [
+ {
+ "$ref": "#/components/schemas/PaymentMethodStatus"
+ }
+ ],
+ "nullable": true
+ },
+ "psp_tokenization": {
+ "type": "boolean",
+ "description": "This indicates whether there is at least one active PSP token available"
+ },
+ "network_tokenization": {
+ "type": "boolean",
+ "description": "This indicates whether a payment method is tokenized with card network"
+ },
+ "network_transaction_id": {
+ "type": "string",
+ "description": "This is the transaction id generated by the network",
+ "nullable": true
+ },
+ "is_eligible_for_mit_payment": {
+ "type": "boolean",
+ "description": "This indicates whether a payment method is eligible for performing a mit transaction"
+ }
+ }
+ },
"PaymentMethodType": {
"type": "string",
"description": "Indicates the sub type of payment method. Eg: 'google_pay' & 'apple_pay' for wallets.",
@@ -27980,12 +28020,12 @@
},
"payment_method_id": {
"type": "string",
- "description": "A unique identifier for the payment method used in this payment. If the payment method was saved or tokenized, this ID can be used to reference it for future transactions or recurring payments.",
+ "description": "A unique identifier for the payment method used in this payment. If the payment method was saved or tokenized, this ID can be used to reference it for future transactions or recurring payments.\nRefer `payment_method_tokenization_details` for detailed view of payment method tokenization",
"nullable": true
},
"network_transaction_id": {
"type": "string",
- "description": "The network transaction ID is a unique identifier for the transaction as recognized by the payment network (e.g., Visa, Mastercard), this ID can be used to reference it for future transactions or recurring payments.",
+ "description": "The network transaction ID is a unique identifier for the transaction as recognized by the payment network (e.g., Visa, Mastercard), this ID can be used to reference it for future transactions or recurring payments.\nRefer `payment_method_tokenization_details` for detailed view of payment method tokenization",
"nullable": true
},
"payment_method_status": {
@@ -28159,6 +28199,14 @@
}
],
"nullable": true
+ },
+ "payment_method_tokenization_details": {
+ "allOf": [
+ {
+ "$ref": "#/components/schemas/PaymentMethodTokenizationDetails"
+ }
+ ],
+ "nullable": true
}
}
},
@@ -29563,12 +29611,12 @@
},
"payment_method_id": {
"type": "string",
- "description": "A unique identifier for the payment method used in this payment. If the payment method was saved or tokenized, this ID can be used to reference it for future transactions or recurring payments.",
+ "description": "A unique identifier for the payment method used in this payment. If the payment method was saved or tokenized, this ID can be used to reference it for future transactions or recurring payments.\nRefer `payment_method_tokenization_details` for detailed view of payment method tokenization",
"nullable": true
},
"network_transaction_id": {
"type": "string",
- "description": "The network transaction ID is a unique identifier for the transaction as recognized by the payment network (e.g., Visa, Mastercard), this ID can be used to reference it for future transactions or recurring payments.",
+ "description": "The network transaction ID is a unique identifier for the transaction as recognized by the payment network (e.g., Visa, Mastercard), this ID can be used to reference it for future transactions or recurring payments.\nRefer `payment_method_tokenization_details` for detailed view of payment method tokenization",
"nullable": true
},
"payment_method_status": {
@@ -29742,6 +29790,14 @@
}
],
"nullable": true
+ },
+ "payment_method_tokenization_details": {
+ "allOf": [
+ {
+ "$ref": "#/components/schemas/PaymentMethodTokenizationDetails"
+ }
+ ],
+ "nullable": true
}
}
},
diff --git a/crates/api_models/src/payments.rs b/crates/api_models/src/payments.rs
index ad952c1c16..80f4944825 100644
--- a/crates/api_models/src/payments.rs
+++ b/crates/api_models/src/payments.rs
@@ -7218,14 +7218,17 @@ pub struct PaymentsResponse {
pub payment_channel: Option<common_enums::PaymentChannel>,
/// A unique identifier for the payment method used in this payment. If the payment method was saved or tokenized, this ID can be used to reference it for future transactions or recurring payments.
+ /// Refer `payment_method_tokenization_details` for detailed view of payment method tokenization
#[smithy(value_type = "Option<String>")]
pub payment_method_id: Option<String>,
/// The network transaction ID is a unique identifier for the transaction as recognized by the payment network (e.g., Visa, Mastercard), this ID can be used to reference it for future transactions or recurring payments.
+ /// Refer `payment_method_tokenization_details` for detailed view of payment method tokenization
#[smithy(value_type = "Option<String>")]
pub network_transaction_id: Option<String>,
/// Payment Method Status, refers to the status of the payment method used for this payment.
+ /// Refer `payment_method_tokenization_details` for detailed view of payment method tokenization
#[schema(value_type = Option<PaymentMethodStatus>)]
#[smithy(value_type = "Option<PaymentMethodStatus>")]
pub payment_method_status: Option<common_enums::PaymentMethodStatus>,
@@ -7358,6 +7361,28 @@ pub struct PaymentsResponse {
#[schema(value_type = Option<PartnerMerchantIdentifierDetails>)]
pub partner_merchant_identifier_details:
Option<common_types::payments::PartnerMerchantIdentifierDetails>,
+
+ /// Tokenization details of the payment method data
+ pub payment_method_tokenization_details: Option<PaymentMethodTokenizationDetails>,
+}
+
+#[cfg(feature = "v1")]
+#[derive(Clone, Debug, PartialEq, serde::Serialize, ToSchema, SmithyModel)]
+#[smithy(namespace = "com.hyperswitch.smithy.types")]
+pub struct PaymentMethodTokenizationDetails {
+ /// The unique identifier for the payment method
+ pub payment_method_id: String,
+ /// The status of the payment method
+ #[schema(value_type = Option<PaymentMethodStatus>)]
+ pub payment_method_status: enums::PaymentMethodStatus,
+ /// This indicates whether there is at least one active PSP token available
+ pub psp_tokenization: bool,
+ /// This indicates whether a payment method is tokenized with card network
+ pub network_tokenization: bool,
+ /// This is the transaction id generated by the network
+ pub network_transaction_id: Option<String>,
+ /// This indicates whether a payment method is eligible for performing a mit transaction
+ pub is_eligible_for_mit_payment: bool,
}
#[cfg(feature = "v2")]
diff --git a/crates/common_enums/src/enums.rs b/crates/common_enums/src/enums.rs
index fb4c126bdd..3cedcdc10f 100644
--- a/crates/common_enums/src/enums.rs
+++ b/crates/common_enums/src/enums.rs
@@ -9433,6 +9433,12 @@ pub enum ConnectorMandateStatus {
Inactive,
}
+impl ConnectorMandateStatus {
+ pub fn is_active(&self) -> bool {
+ self == &Self::Active
+ }
+}
+
/// Connector Mandate Status
#[derive(
Clone, Copy, Debug, Eq, PartialEq, serde::Deserialize, serde::Serialize, strum::Display,
diff --git a/crates/diesel_models/src/payment_attempt.rs b/crates/diesel_models/src/payment_attempt.rs
index 7f4f668a39..20f49c2d34 100644
--- a/crates/diesel_models/src/payment_attempt.rs
+++ b/crates/diesel_models/src/payment_attempt.rs
@@ -33,6 +33,10 @@ impl ConnectorMandateReferenceId {
pub fn get_connector_mandate_request_reference_id(&self) -> Option<String> {
self.connector_mandate_request_reference_id.clone()
}
+
+ pub fn is_connector_mandate_id_present(&self) -> bool {
+ self.connector_mandate_id.is_some()
+ }
}
common_utils::impl_to_sql_from_sql_json!(NetworkDetails);
#[derive(
diff --git a/crates/hyperswitch_domain_models/src/mandates.rs b/crates/hyperswitch_domain_models/src/mandates.rs
index 4260b7d8b5..e56138f531 100644
--- a/crates/hyperswitch_domain_models/src/mandates.rs
+++ b/crates/hyperswitch_domain_models/src/mandates.rs
@@ -241,6 +241,19 @@ pub struct PaymentsMandateReference(
pub HashMap<common_utils::id_type::MerchantConnectorAccountId, PaymentsMandateReferenceRecord>,
);
+#[cfg(feature = "v1")]
+impl PaymentsMandateReference {
+ pub fn is_active_connector_mandate_available(&self) -> bool {
+ self.clone().0.into_iter().any(|detail| {
+ detail
+ .1
+ .connector_mandate_status
+ .map(|connector_mandate_status| connector_mandate_status.is_active())
+ .unwrap_or(false)
+ })
+ }
+}
+
#[cfg(feature = "v1")]
impl std::ops::Deref for PaymentsMandateReference {
type Target =
diff --git a/crates/openapi/src/openapi.rs b/crates/openapi/src/openapi.rs
index a8b89253f4..a27e53fcd8 100644
--- a/crates/openapi/src/openapi.rs
+++ b/crates/openapi/src/openapi.rs
@@ -308,6 +308,7 @@ Never share your secret api keys. Keep them guarded and secure.
api_models::payments::NetworkParams,
api_models::payments::Cryptogram,
api_models::payments::ExternalThreeDsData,
+ api_models::payments::PaymentMethodTokenizationDetails,
api_models::refunds::RefundRequest,
api_models::refunds::RefundType,
api_models::refunds::RefundResponse,
diff --git a/crates/router/src/core/payments/operations/payment_response.rs b/crates/router/src/core/payments/operations/payment_response.rs
index b8a4c8a7ce..c118f2ce51 100644
--- a/crates/router/src/core/payments/operations/payment_response.rs
+++ b/crates/router/src/core/payments/operations/payment_response.rs
@@ -246,48 +246,62 @@ impl<F: Send + Clone> PostUpdateTracker<F, PaymentData<F>, types::PaymentsAuthor
Ok(())
} else if is_connector_mandate {
// The mandate is created on connector's end.
- let tokenization::SavePaymentMethodDataResponse {
- payment_method_id,
- connector_mandate_reference_id,
- ..
- } = save_payment_call_future.await?;
- payment_data.payment_method_info = if let Some(payment_method_id) = &payment_method_id {
- match state
- .store
- .find_payment_method(
- platform.get_processor().get_key_store(),
- payment_method_id,
- storage_scheme,
- )
- .await
- {
- Ok(payment_method) => Some(payment_method),
- Err(error) => {
- if error.current_context().is_db_not_found() {
- logger::info!("Payment Method not found in db {:?}", error);
- None
- } else {
- Err(error)
- .change_context(errors::ApiErrorResponse::InternalServerError)
- .attach_printable("Error retrieving payment method from db")
- .map_err(|err| logger::error!(payment_method_retrieve=?err))
- .ok()
+ let save_payment_call_response = save_payment_call_future.await;
+ match save_payment_call_response {
+ Ok(tokenization::SavePaymentMethodDataResponse {
+ payment_method_id,
+ connector_mandate_reference_id,
+ ..
+ }) => {
+ payment_data.payment_method_info = if let Some(payment_method_id) =
+ &payment_method_id
+ {
+ match state
+ .store
+ .find_payment_method(
+ platform.get_processor().get_key_store(),
+ payment_method_id,
+ storage_scheme,
+ )
+ .await
+ {
+ Ok(payment_method) => Some(payment_method),
+ Err(error) => {
+ if error.current_context().is_db_not_found() {
+ logger::info!("Payment Method not found in db {:?}", error);
+ None
+ } else {
+ Err(error)
+ .change_context(
+ errors::ApiErrorResponse::InternalServerError,
+ )
+ .attach_printable("Error retrieving payment method from db")
+ .map_err(|err| logger::error!(payment_method_retrieve=?err))
+ .ok()
+ }
+ }
}
- }
+ } else {
+ None
+ };
+ payment_data.payment_attempt.payment_method_id = payment_method_id;
+ payment_data.payment_attempt.connector_mandate_detail =
+ connector_mandate_reference_id
+ .clone()
+ .map(ForeignFrom::foreign_from);
+ payment_data.set_mandate_id(api_models::payments::MandateIds {
+ mandate_id: None,
+ mandate_reference_id: connector_mandate_reference_id.map(
+ |connector_mandate_id| {
+ MandateReferenceId::ConnectorMandateId(connector_mandate_id)
+ },
+ ),
+ })
}
- } else {
- None
- };
- payment_data.payment_attempt.payment_method_id = payment_method_id;
- payment_data.payment_attempt.connector_mandate_detail = connector_mandate_reference_id
- .clone()
- .map(ForeignFrom::foreign_from);
- payment_data.set_mandate_id(api_models::payments::MandateIds {
- mandate_id: None,
- mandate_reference_id: connector_mandate_reference_id.map(|connector_mandate_id| {
- MandateReferenceId::ConnectorMandateId(connector_mandate_id)
- }),
- });
+ Err(err) => {
+ logger::error!("Error while storing the payment method in locker {:?}", err);
+ }
+ }
Ok(())
} else if should_avoid_saving {
if let Some(pm_info) = &payment_data.payment_method_info {
diff --git a/crates/router/src/core/payments/transformers.rs b/crates/router/src/core/payments/transformers.rs
index 425b2f74c2..f1c4537a66 100644
--- a/crates/router/src/core/payments/transformers.rs
+++ b/crates/router/src/core/payments/transformers.rs
@@ -2,6 +2,8 @@ use std::{fmt::Debug, marker::PhantomData, str::FromStr};
#[cfg(feature = "v2")]
use api_models::enums as api_enums;
+#[cfg(feature = "v1")]
+use api_models::payments::PaymentMethodTokenizationDetails;
#[cfg(feature = "v2")]
use api_models::payments::RevenueRecoveryGetIntentResponse;
use api_models::payments::{
@@ -3867,6 +3869,11 @@ where
Some(false) | None => None,
};
+ let payment_method_tokenization_details = payment_data
+ .get_payment_method_info()
+ .map(PaymentMethodTokenizationDetails::foreign_try_from)
+ .transpose()?;
+
let payments_response = api::PaymentsResponse {
payment_id: payment_intent.payment_id,
merchant_id: payment_intent.merchant_id,
@@ -4000,6 +4007,7 @@ where
request_extended_authorization: payment_attempt.request_extended_authorization,
billing_descriptor: payment_intent.billing_descriptor,
partner_merchant_identifier_details: payment_intent.partner_merchant_identifier_details,
+ payment_method_tokenization_details,
};
services::ApplicationResponse::JsonWithHeaders((payments_response, headers))
@@ -4308,10 +4316,36 @@ impl ForeignFrom<(storage::PaymentIntent, storage::PaymentAttempt)> for api::Pay
request_extended_authorization: pa.request_extended_authorization,
billing_descriptor: pi.billing_descriptor,
partner_merchant_identifier_details: pi.partner_merchant_identifier_details,
+ payment_method_tokenization_details: None,
}
}
}
+#[cfg(feature = "v1")]
+impl ForeignTryFrom<&domain::PaymentMethod> for PaymentMethodTokenizationDetails {
+ type Error = error_stack::Report<errors::ApiErrorResponse>;
+ fn foreign_try_from(payment_method: &domain::PaymentMethod) -> Result<Self, Self::Error> {
+ let connector_common_mandate_details = payment_method
+ .get_common_mandate_reference()
+ .change_context(errors::ApiErrorResponse::InternalServerError)
+ .attach_printable("Failed to get the common mandate reference")?;
+ let psp_tokenization = connector_common_mandate_details
+ .payments
+ .map(|payments| payments.is_active_connector_mandate_available())
+ .unwrap_or(false);
+ let network_tokenization = payment_method.network_token_locker_id.is_some();
+ let is_network_transaction_id_present = payment_method.network_transaction_id.is_some();
+ Ok(Self {
+ payment_method_id: payment_method.payment_method_id.clone(),
+ payment_method_status: payment_method.status,
+ psp_tokenization,
+ network_tokenization,
+ network_transaction_id: payment_method.network_transaction_id.clone(),
+ is_eligible_for_mit_payment: psp_tokenization || is_network_transaction_id_present,
+ })
+ }
+}
+
#[cfg(feature = "v2")]
impl ForeignFrom<(storage::PaymentIntent, Option<storage::PaymentAttempt>)>
for api_models::payments::PaymentsListResponseItem
diff --git a/crates/router/src/db/events.rs b/crates/router/src/db/events.rs
index e41e29f1ae..88eda68bae 100644
--- a/crates/router/src/db/events.rs
+++ b/crates/router/src/db/events.rs
@@ -1406,6 +1406,7 @@ mod tests {
request_extended_authorization: None,
billing_descriptor: None,
partner_merchant_identifier_details: None,
+ payment_method_tokenization_details: None,
};
let content =
api_webhooks::OutgoingWebhookContent::PaymentDetails(Box::new(expected_response));
diff --git a/crates/router/tests/payments.rs b/crates/router/tests/payments.rs
index d0378802be..0d5d408c8a 100644
--- a/crates/router/tests/payments.rs
+++ b/crates/router/tests/payments.rs
@@ -474,6 +474,7 @@ async fn payments_create_core() {
request_extended_authorization: None,
billing_descriptor: None,
partner_merchant_identifier_details: None,
+ payment_method_tokenization_details: None,
};
let expected_response =
services::ApplicationResponse::JsonWithHeaders((expected_response, vec![]));
@@ -766,6 +767,7 @@ async fn payments_create_core_adyen_no_redirect() {
request_extended_authorization: None,
billing_descriptor: None,
partner_merchant_identifier_details: None,
+ payment_method_tokenization_details: None,
},
vec![],
));
diff --git a/crates/router/tests/payments2.rs b/crates/router/tests/payments2.rs
index a571b9dbe8..c7564a5c50 100644
--- a/crates/router/tests/payments2.rs
+++ b/crates/router/tests/payments2.rs
@@ -234,6 +234,7 @@ async fn payments_create_core() {
request_extended_authorization: None,
billing_descriptor: None,
partner_merchant_identifier_details: None,
+ payment_method_tokenization_details: None,
};
let expected_response =
@@ -535,6 +536,7 @@ async fn payments_create_core_adyen_no_redirect() {
request_extended_authorization: None,
billing_descriptor: None,
partner_merchant_identifier_details: None,
+ payment_method_tokenization_details: None,
},
vec![],
));