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
refactor(core): add support for expand attempt list in psync v2 (#7209)
chikke srujand09331701997
diff --git a/api-reference-v2/openapi_spec.json b/api-reference-v2/openapi_spec.jsonindex f7f1ca34a3..96294f56a9 100644--- a/api-reference-v2/openapi_spec.json+++ b/api-reference-v2/openapi_spec.json@@ -12815,71 +12815,92 @@}}},- "PaymentAttemptResponse": {+ "PaymentAttemptAmountDetails": {"type": "object","required": [- "attempt_id",- "status",- "amount",- "created_at",- "modified_at"+ "net_amount",+ "amount_capturable"],"properties": {- "attempt_id": {- "type": "string",- "description": "Unique identifier for the attempt"- },- "status": {- "$ref": "#/components/schemas/AttemptStatus"- },- "amount": {- "type": "integer",- "format": "int64",- "description": "The payment attempt amount. Amount for the payment in lowest denomination of the currency. (i.e) in cents for USD denomination, in paisa for INR denomination etc.,",- "example": 6540+ "net_amount": {+ "$ref": "#/components/schemas/MinorUnit"},- "order_tax_amount": {- "type": "integer",- "format": "int64",- "description": "The payment attempt tax_amount.",- "example": 6540,+ "amount_to_capture": {+ "allOf": [+ {+ "$ref": "#/components/schemas/MinorUnit"+ }+ ],"nullable": true},- "currency": {+ "surcharge_amount": {"allOf": [{- "$ref": "#/components/schemas/Currency"+ "$ref": "#/components/schemas/MinorUnit"}],"nullable": true},- "connector": {- "type": "string",- "description": "The connector used for the payment",+ "tax_on_surcharge": {+ "allOf": [+ {+ "$ref": "#/components/schemas/MinorUnit"+ }+ ],"nullable": true},- "error_message": {- "type": "string",- "description": "If there was an error while calling the connector, the error message is received here",+ "amount_capturable": {+ "$ref": "#/components/schemas/MinorUnit"+ },+ "shipping_cost": {+ "allOf": [+ {+ "$ref": "#/components/schemas/MinorUnit"+ }+ ],"nullable": true},- "payment_method": {+ "order_tax_amount": {"allOf": [{- "$ref": "#/components/schemas/PaymentMethod"+ "$ref": "#/components/schemas/MinorUnit"}],"nullable": true+ }+ }+ },+ "PaymentAttemptResponse": {+ "type": "object",+ "required": [+ "id",+ "status",+ "amount",+ "authentication_type",+ "created_at",+ "modified_at"+ ],+ "properties": {+ "id": {+ "type": "string",+ "description": "The global identifier for the payment attempt"},- "connector_transaction_id": {+ "status": {+ "$ref": "#/components/schemas/AttemptStatus"+ },+ "amount": {+ "$ref": "#/components/schemas/PaymentAttemptAmountDetails"+ },+ "connector": {"type": "string",- "description": "A unique identifier for a payment provided by the connector",+ "description": "Name of the connector that was used for the payment attempt.",+ "example": "stripe","nullable": true},- "capture_method": {+ "error": {"allOf": [{- "$ref": "#/components/schemas/CaptureMethod"+ "$ref": "#/components/schemas/ErrorDetails"}],"nullable": true@@ -12890,43 +12911,35 @@"$ref": "#/components/schemas/AuthenticationType"}],- "default": "three_ds",- "nullable": true+ "default": "three_ds"},"created_at": {"type": "string","format": "date-time",- "description": "Time at which the payment attempt was created",- "example": "2022-09-10T10:11:12Z"+ "description": "Date and time of Payment attempt creation"},"modified_at": {"type": "string","format": "date-time",- "description": "Time at which the payment attempt was last modified",- "example": "2022-09-10T10:11:12Z"+ "description": "Time at which the payment attempt was last modified"},"cancellation_reason": {"type": "string",- "description": "If the payment was cancelled the reason will be provided here",- "nullable": true- },- "mandate_id": {- "type": "string",- "description": "A unique identifier to link the payment to a mandate, can be use instead of payment_method_data",- "nullable": true- },- "error_code": {- "type": "string",- "description": "If there was an error while calling the connectors the error code is received here",+ "description": "The reason for the cancellation of the payment attempt. Some connectors will have strict rules regarding the values this can have\nCancellation reason will be validated at the connector level when building the request","nullable": true},"payment_token": {"type": "string",- "description": "Provide a reference to a stored payment method",+ "description": "Payment token is the token used for temporary use in case the payment method is stored in vault",+ "example": "187282ab-40ef-47a9-9206-5099ba31e432","nullable": true},"connector_metadata": {- "description": "Additional data related to some connectors",+ "allOf": [+ {+ "$ref": "#/components/schemas/ConnectorMetadata"+ }+ ],"nullable": true},"payment_experience": {@@ -12940,25 +12953,35 @@"payment_method_type": {"allOf": [{- "$ref": "#/components/schemas/PaymentMethodType"+ "$ref": "#/components/schemas/PaymentMethod"}],"nullable": true},- "reference_id": {+ "connector_reference_id": {"type": "string",- "description": "Reference to the payment at connector side",+ "description": "reference(Identifier) to the payment at connector side","example": "993672945374576J","nullable": true},- "unified_code": {+ "payment_method_subtype": {+ "allOf": [+ {+ "$ref": "#/components/schemas/PaymentMethodType"+ }+ ],+ "nullable": true+ },+ "connector_payment_id": {"type": "string",- "description": "(This field is not live yet)Error code unified across the connectors is received here if there was an error while calling connector",+ "description": "A unique identifier for a payment provided by the connector",+ "example": "993672945374576J","nullable": true},- "unified_message": {+ "payment_method_id": {"type": "string",- "description": "(This field is not live yet)Error message unified across the connectors is received here if there was an error while calling connector",+ "description": "Identifier for Payment Method used for the payment attempt",+ "example": "12345_pm_01926c58bc6e77c09e809964e72af8c8","nullable": true},"client_source": {@@ -15729,6 +15752,10 @@"type": "boolean","description": "A boolean used to indicate if the payment status should be fetched from the connector\nIf this is set to true, the status will be fetched from the connector"},+ "expand_attempts": {+ "type": "boolean",+ "description": "A boolean used to indicate if all the attempts needs to be fetched for the intent.\nIf this is set to true, attempts list will be available in the response."+ },"param": {"type": "string","description": "These are the query params that are sent in case of redirect response.\nThese can be ingested by the connector to take necessary actions.",@@ -15856,6 +15883,14 @@}],"nullable": true+ },+ "attempts": {+ "type": "array",+ "items": {+ "$ref": "#/components/schemas/PaymentAttemptResponse"+ },+ "description": "List of payment attempts associated with payment intent",+ "nullable": true}}},diff --git a/crates/api_models/src/payments.rs b/crates/api_models/src/payments.rsindex efd000d830..295b1979f1 100644--- a/crates/api_models/src/payments.rs+++ b/crates/api_models/src/payments.rs@@ -656,6 +656,30 @@ pub struct PaymentAmountDetailsResponse {pub amount_captured: Option<MinorUnit>,}+#[cfg(feature = "v2")]+#[derive(Clone, Debug, PartialEq, serde::Serialize, ToSchema)]++pub struct PaymentAttemptAmountDetails {+ /// The total amount of the order including tax, surcharge and shipping cost+ pub net_amount: MinorUnit,+ /// The amount that was requested to be captured for this payment+ pub amount_to_capture: Option<MinorUnit>,+ /// Surcharge amount for the payment attempt.+ /// This is either derived by surcharge rules, or sent by the merchant+ pub surcharge_amount: Option<MinorUnit>,+ /// Tax amount for the payment attempt+ /// This is either derived by surcharge rules, or sent by the merchant+ pub tax_on_surcharge: Option<MinorUnit>,+ /// The total amount that can be captured for this payment attempt.+ pub amount_capturable: MinorUnit,+ /// Shipping cost for the payment attempt.+ /// Shipping cost for the payment attempt.+ pub shipping_cost: Option<MinorUnit>,+ /// Tax amount for the order.+ /// This is either derived by calling an external tax processor, or sent by the merchant+ pub order_tax_amount: Option<MinorUnit>,+}+#[cfg(feature = "v2")]impl AmountDetails {pub fn new(amount_details_setter: AmountDetailsSetter) -> Self {@@ -1313,6 +1337,7 @@ impl RequestSurchargeDetails {}}+#[cfg(feature = "v1")]#[derive(Debug, serde::Serialize, Clone, PartialEq, ToSchema, router_derive::PolymorphicSchema)]pub struct PaymentAttemptResponse {/// Unique identifier for the attempt@@ -1381,6 +1406,78 @@ pub struct PaymentAttemptResponse {pub client_version: Option<String>,}+#[cfg(feature = "v2")]+#[derive(Debug, serde::Serialize, Clone, PartialEq, ToSchema, router_derive::PolymorphicSchema)]+pub struct PaymentAttemptResponse {+ /// The global identifier for the payment attempt+ #[schema(value_type = String)]+ pub id: id_type::GlobalAttemptId,+ /// /// The status of the attempt+ #[schema(value_type = AttemptStatus, example = "charged")]+ pub status: enums::AttemptStatus,+ /// Amount related information for this payment and attempt+ pub amount: PaymentAttemptAmountDetails,+ /// Name of the connector that was used for the payment attempt.+ #[schema(example = "stripe")]+ pub connector: Option<String>,++ /// Error details for the payment if any+ pub error: Option<ErrorDetails>,++ /// The transaction authentication can be set to undergo payer authentication. By default, the authentication will be marked as NO_THREE_DS, as the 3DS method helps with more robust payer authentication+ #[schema(value_type = AuthenticationType, example = "no_three_ds", default = "three_ds")]+ pub authentication_type: api_enums::AuthenticationType,++ /// Date and time of Payment attempt creation+ #[serde(with = "common_utils::custom_serde::iso8601")]+ pub created_at: PrimitiveDateTime,++ /// Time at which the payment attempt was last modified+ #[serde(with = "common_utils::custom_serde::iso8601")]+ pub modified_at: PrimitiveDateTime,++ /// The reason for the cancellation of the payment attempt. Some connectors will have strict rules regarding the values this can have+ /// Cancellation reason will be validated at the connector level when building the request+ pub cancellation_reason: Option<String>,++ /// Payment token is the token used for temporary use in case the payment method is stored in vault+ #[schema(example = "187282ab-40ef-47a9-9206-5099ba31e432")]+ pub payment_token: Option<String>,++ /// Additional data related to some connectors+ #[schema(value_type = Option<ConnectorMetadata>)]+ pub connector_metadata: Option<pii::SecretSerdeValue>,++ /// Payment Experience for the current payment+ #[schema(value_type = Option<PaymentExperience>, example = "redirect_to_url")]+ pub payment_experience: Option<enums::PaymentExperience>,++ /// Payment method type for the payment attempt+ #[schema(value_type = Option<PaymentMethod>, example = "wallet")]+ pub payment_method_type: common_enums::PaymentMethod,++ /// reference(Identifier) to the payment at connector side+ #[schema(value_type = Option<String>, example = "993672945374576J")]+ pub connector_reference_id: Option<String>,++ /// The payment method subtype for the payment attempt.+ #[schema(value_type = Option<PaymentMethodType>, example = "apple_pay")]+ pub payment_method_subtype: Option<api_enums::PaymentMethodType>,++ /// A unique identifier for a payment provided by the connector+ #[schema(value_type = Option<String>, example = "993672945374576J")]+ pub connector_payment_id: Option<String>,++ /// Identifier for Payment Method used for the payment attempt+ #[schema(value_type = Option<String>, example = "12345_pm_01926c58bc6e77c09e809964e72af8c8")]+ pub payment_method_id: Option<id_type::GlobalPaymentMethodId>,++ /// Value passed in X-CLIENT-SOURCE header during payments confirm request by the client+ pub client_source: Option<String>,+ /// Value passed in X-CLIENT-VERSION header during payments confirm request by the client+ pub client_version: Option<String>,+}+#[derive(Default, Debug, serde::Serialize, Clone, PartialEq, ToSchema, router_derive::PolymorphicSchema,)]@@ -5069,7 +5166,10 @@ pub struct PaymentsRetrieveRequest {/// If this is set to true, the status will be fetched from the connector#[serde(default)]pub force_sync: bool,-+ /// A boolean used to indicate if all the attempts needs to be fetched for the intent.+ /// If this is set to true, attempts list will be available in the response.+ #[serde(default)]+ pub expand_attempts: bool,/// These are the query params that are sent in case of redirect response./// These can be ingested by the connector to take necessary actions.pub param: Option<String>,@@ -5077,7 +5177,7 @@ pub struct PaymentsRetrieveRequest {/// Error details for the payment#[cfg(feature = "v2")]-#[derive(Debug, serde::Serialize, Clone, ToSchema)]+#[derive(Debug, serde::Serialize, Clone, PartialEq, ToSchema)]pub struct ErrorDetails {/// The error codepub code: String,@@ -5259,6 +5359,9 @@ pub struct PaymentsRetrieveResponse {/// The billing address associated with the payment intentpub billing: Option<Address>,++ /// List of payment attempts associated with payment intent+ pub attempts: Option<Vec<PaymentAttemptResponse>>,}#[derive(Debug, serde::Deserialize, serde::Serialize, Clone)]diff --git a/crates/diesel_models/src/query/payment_attempt.rs b/crates/diesel_models/src/query/payment_attempt.rsindex 9dd13e5b03..749ed41bcb 100644--- a/crates/diesel_models/src/query/payment_attempt.rs+++ b/crates/diesel_models/src/query/payment_attempt.rs@@ -242,6 +242,21 @@ impl PaymentAttempt {.await}+ #[cfg(feature = "v2")]+ pub async fn find_by_payment_id(+ conn: &PgPooledConn,+ payment_id: &common_utils::id_type::GlobalPaymentId,+ ) -> StorageResult<Vec<Self>> {+ generics::generic_filter::<<Self as HasTable>::Table, _, _, _>(+ conn,+ dsl::payment_id.eq(payment_id.to_owned()),+ None,+ None,+ Some(dsl::created_at.asc()),+ )+ .await+ }+#[cfg(feature = "v1")]pub async fn find_by_merchant_id_preprocessing_id(conn: &PgPooledConn,diff --git a/crates/hyperswitch_domain_models/src/payments.rs b/crates/hyperswitch_domain_models/src/payments.rsindex 095b4c33a4..939d9fee0e 100644--- a/crates/hyperswitch_domain_models/src/payments.rs+++ b/crates/hyperswitch_domain_models/src/payments.rs@@ -603,6 +603,7 @@ wherepub payment_intent: PaymentIntent,pub payment_attempt: Option<PaymentAttempt>,pub payment_address: payment_address::PaymentAddress,+ pub attempts: Option<Vec<PaymentAttempt>>,/// Should the payment status be synced with connector/// This will depend on the payment status and the force sync flag in the requestpub should_sync_with_connector: bool,diff --git a/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs b/crates/hyperswitch_domain_models/src/payments/payment_attempt.rsindex 361973daf9..e641ee63d2 100644--- a/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs+++ b/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs@@ -151,6 +151,15 @@ pub trait PaymentAttemptInterface {storage_scheme: storage_enums::MerchantStorageScheme,) -> error_stack::Result<PaymentAttempt, errors::StorageError>;+ #[cfg(feature = "v2")]+ async fn find_payment_attempts_by_payment_intent_id(+ &self,+ state: &KeyManagerState,+ payment_id: &id_type::GlobalPaymentId,+ merchant_key_store: &MerchantKeyStore,+ storage_scheme: common_enums::MerchantStorageScheme,+ ) -> error_stack::Result<Vec<PaymentAttempt>, errors::StorageError>;+#[cfg(feature = "v1")]async fn find_payment_attempt_by_preprocessing_id_merchant_id(&self,diff --git a/crates/openapi/src/openapi_v2.rs b/crates/openapi/src/openapi_v2.rsindex f2b692c27a..a4af7b1e13 100644--- a/crates/openapi/src/openapi_v2.rs+++ b/crates/openapi/src/openapi_v2.rs@@ -460,6 +460,7 @@ Never share your secret api keys. Keep them guarded and secure.api_models::payments::RedirectResponse,api_models::payments::RequestSurchargeDetails,api_models::payments::PaymentAttemptResponse,+ api_models::payments::PaymentAttemptAmountDetails,api_models::payments::CaptureResponse,api_models::payments::PaymentsIncrementalAuthorizationRequest,api_models::payments::IncrementalAuthorizationResponse,diff --git a/crates/router/src/core/payments.rs b/crates/router/src/core/payments.rsindex 592dda6017..1b4d00882a 100644--- a/crates/router/src/core/payments.rs+++ b/crates/router/src/core/payments.rs@@ -2327,6 +2327,7 @@ impl PaymentRedirectFlow for PaymentRedirectSync {let payment_sync_request = api::PaymentsRetrieveRequest {param: Some(req.query_params.clone()),force_sync: true,+ expand_attempts: false,};let operation = operations::PaymentGet;diff --git a/crates/router/src/core/payments/operations/payment_get.rs b/crates/router/src/core/payments/operations/payment_get.rsindex 6419376f09..189439ec96 100644--- a/crates/router/src/core/payments/operations/payment_get.rs+++ b/crates/router/src/core/payments/operations/payment_get.rs@@ -169,11 +169,32 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentStatusData<F>, PaymentsRetrievSome(true),);+ let attempts = match request.expand_attempts {+ true => payment_intent+ .active_attempt_id+ .as_ref()+ .async_map(|active_attempt| async {+ db.find_payment_attempts_by_payment_intent_id(+ key_manager_state,+ payment_id,+ key_store,+ storage_scheme,+ )+ .await+ .change_context(errors::ApiErrorResponse::InternalServerError)+ .attach_printable("Could not find payment attempts for the given the intent id")+ })+ .await+ .transpose()?,+ false => None,+ };+let payment_data = PaymentStatusData {flow: std::marker::PhantomData,payment_intent,payment_attempt,payment_address,+ attempts,should_sync_with_connector,};diff --git a/crates/router/src/core/payments/transformers.rs b/crates/router/src/core/payments/transformers.rsindex e2967e4ba5..5371afca93 100644--- a/crates/router/src/core/payments/transformers.rs+++ b/crates/router/src/core/payments/transformers.rs@@ -1687,6 +1687,12 @@ wherelet error = optional_payment_attempt.and_then(|payment_attempt| payment_attempt.error.clone()).map(api_models::payments::ErrorDetails::foreign_from);+ let attempts = self.attempts.as_ref().map(|attempts| {+ attempts+ .iter()+ .map(api_models::payments::PaymentAttemptResponse::foreign_from)+ .collect()+ });let payment_method_data =Some(api_models::payments::PaymentMethodDataResponseWithBilling {@@ -1729,6 +1735,7 @@ wheremerchant_connector_id,browser_info: None,error,+ attempts,};Ok(services::ApplicationResponse::JsonWithHeaders((@@ -4146,6 +4153,61 @@ impl}}+#[cfg(feature = "v2")]+impl ForeignFrom<&hyperswitch_domain_models::payments::payment_attempt::PaymentAttempt>+ for api_models::payments::PaymentAttemptResponse+{+ fn foreign_from(+ attempt: &hyperswitch_domain_models::payments::payment_attempt::PaymentAttempt,+ ) -> Self {+ Self {+ id: attempt.get_id().to_owned(),+ status: attempt.status,+ amount: api_models::payments::PaymentAttemptAmountDetails::foreign_from(+ &attempt.amount_details,+ ),+ connector: attempt.connector.clone(),+ error: attempt+ .error+ .clone()+ .map(api_models::payments::ErrorDetails::foreign_from),+ authentication_type: attempt.authentication_type,+ created_at: attempt.created_at,+ modified_at: attempt.modified_at,+ cancellation_reason: attempt.cancellation_reason.clone(),+ payment_token: attempt.payment_token.clone(),+ connector_metadata: attempt.connector_metadata.clone(),+ payment_experience: attempt.payment_experience,+ payment_method_type: attempt.payment_method_type,+ connector_reference_id: attempt.connector_response_reference_id.clone(),+ payment_method_subtype: attempt.get_payment_method_type(),+ connector_payment_id: attempt.get_connector_payment_id().map(ToString::to_string),+ payment_method_id: attempt.payment_method_id.clone(),+ client_source: attempt.client_source.clone(),+ client_version: attempt.client_version.clone(),+ }+ }+}++#[cfg(feature = "v2")]+impl ForeignFrom<&hyperswitch_domain_models::payments::payment_attempt::AttemptAmountDetails>+ for api_models::payments::PaymentAttemptAmountDetails+{+ fn foreign_from(+ amount: &hyperswitch_domain_models::payments::payment_attempt::AttemptAmountDetails,+ ) -> Self {+ Self {+ net_amount: amount.get_net_amount(),+ amount_to_capture: amount.get_amount_to_capture(),+ surcharge_amount: amount.get_surcharge_amount(),+ tax_on_surcharge: amount.get_tax_on_surcharge(),+ amount_capturable: amount.get_amount_capturable(),+ shipping_cost: amount.get_shipping_cost(),+ order_tax_amount: amount.get_order_tax_amount(),+ }+ }+}+#[cfg(feature = "v2")]impl ForeignFrom<hyperswitch_domain_models::payments::payment_attempt::ErrorDetails>for api_models::payments::ErrorDetailsdiff --git a/crates/router/src/core/webhooks/incoming_v2.rs b/crates/router/src/core/webhooks/incoming_v2.rsindex 6b01615778..900a455f99 100644--- a/crates/router/src/core/webhooks/incoming_v2.rs+++ b/crates/router/src/core/webhooks/incoming_v2.rs@@ -431,6 +431,7 @@ async fn payments_incoming_webhook_flow(payments::operations::PaymentGet,api::PaymentsRetrieveRequest {force_sync: true,+ expand_attempts: false,param: None,},get_trackers_response,@@ -630,6 +631,7 @@ whereflow: PhantomData,payment_intent,payment_attempt: Some(payment_attempt),+ attempts: None,should_sync_with_connector: true,payment_address,},diff --git a/crates/router/src/db/kafka_store.rs b/crates/router/src/db/kafka_store.rsindex b8ecb2eea8..3622695c9f 100644--- a/crates/router/src/db/kafka_store.rs+++ b/crates/router/src/db/kafka_store.rs@@ -1618,6 +1618,24 @@ impl PaymentAttemptInterface for KafkaStore {.await}+ #[cfg(feature = "v2")]+ async fn find_payment_attempts_by_payment_intent_id(+ &self,+ key_manager_state: &KeyManagerState,+ payment_id: &id_type::GlobalPaymentId,+ merchant_key_store: &domain::MerchantKeyStore,+ storage_scheme: MerchantStorageScheme,+ ) -> error_stack::Result<Vec<storage::PaymentAttempt>, errors::DataStorageError> {+ self.diesel_store+ .find_payment_attempts_by_payment_intent_id(+ key_manager_state,+ payment_id,+ merchant_key_store,+ storage_scheme,+ )+ .await+ }+#[cfg(feature = "v1")]async fn find_payment_attempt_last_successful_attempt_by_payment_id_merchant_id(&self,diff --git a/crates/storage_impl/src/mock_db/payment_attempt.rs b/crates/storage_impl/src/mock_db/payment_attempt.rsindex db210dbdbe..7bf4266bf5 100644--- a/crates/storage_impl/src/mock_db/payment_attempt.rs+++ b/crates/storage_impl/src/mock_db/payment_attempt.rs@@ -81,6 +81,18 @@ impl PaymentAttemptInterface for MockDb {Err(StorageError::MockDbError)?}+ #[cfg(feature = "v2")]+ async fn find_payment_attempts_by_payment_intent_id(+ &self,+ _key_manager_state: &KeyManagerState,+ _id: &id_type::GlobalPaymentId,+ _merchant_key_store: &MerchantKeyStore,+ _storage_scheme: common_enums::MerchantStorageScheme,+ ) -> error_stack::Result<Vec<PaymentAttempt>, StorageError> {+ // [#172]: Implement function for `MockDb`+ Err(StorageError::MockDbError)?+ }+#[cfg(feature = "v1")]async fn find_payment_attempt_by_preprocessing_id_merchant_id(&self,diff --git a/crates/storage_impl/src/payments/payment_attempt.rs b/crates/storage_impl/src/payments/payment_attempt.rsindex 8a8e8d4e4a..0c8b969e16 100644--- a/crates/storage_impl/src/payments/payment_attempt.rs+++ b/crates/storage_impl/src/payments/payment_attempt.rs@@ -425,6 +425,43 @@ impl<T: DatabaseStore> PaymentAttemptInterface for RouterStore<T> {.change_context(errors::StorageError::DecryptionError)}+ #[cfg(feature = "v2")]+ #[instrument(skip_all)]+ async fn find_payment_attempts_by_payment_intent_id(+ &self,+ key_manager_state: &KeyManagerState,+ payment_id: &common_utils::id_type::GlobalPaymentId,+ merchant_key_store: &MerchantKeyStore,+ _storage_scheme: MerchantStorageScheme,+ ) -> error_stack::Result<Vec<PaymentAttempt>, errors::StorageError> {+ use common_utils::ext_traits::AsyncExt;++ let conn = pg_connection_read(self).await?;+ DieselPaymentAttempt::find_by_payment_id(&conn, payment_id)+ .await+ .map_err(|er| {+ let new_err = diesel_error_to_data_error(*er.current_context());+ er.change_context(new_err)+ })+ .async_and_then(|payment_attempts| async {+ let mut domain_payment_attempts = Vec::with_capacity(payment_attempts.len());+ for attempt in payment_attempts.into_iter() {+ domain_payment_attempts.push(+ attempt+ .convert(+ key_manager_state,+ merchant_key_store.key.get_inner(),+ merchant_key_store.merchant_id.clone().into(),+ )+ .await+ .change_context(errors::StorageError::DecryptionError)?,+ );+ }+ Ok(domain_payment_attempts)+ })+ .await+ }+#[cfg(all(feature = "v1", feature = "olap"))]#[instrument(skip_all)]async fn get_total_count_of_filtered_payment_attempts(@@ -1200,6 +1237,25 @@ impl<T: DatabaseStore> PaymentAttemptInterface for KVRouterStore<T> {.await}+ #[cfg(feature = "v2")]+ #[instrument(skip_all)]+ async fn find_payment_attempts_by_payment_intent_id(+ &self,+ key_manager_state: &KeyManagerState,+ payment_id: &common_utils::id_type::GlobalPaymentId,+ merchant_key_store: &MerchantKeyStore,+ storage_scheme: MerchantStorageScheme,+ ) -> error_stack::Result<Vec<PaymentAttempt>, errors::StorageError> {+ self.router_store+ .find_payment_attempts_by_payment_intent_id(+ key_manager_state,+ payment_id,+ merchant_key_store,+ storage_scheme,+ )+ .await+ }+#[cfg(feature = "v1")]#[instrument(skip_all)]async fn find_payment_attempt_by_preprocessing_id_merchant_id(diff --git a/v2_migrations/2025-02-10-101458_create_index_payment_attempt_payment_id/down.sql b/v2_migrations/2025-02-10-101458_create_index_payment_attempt_payment_id/down.sqlnew file mode 100644index 0000000000..42c7d02ff2--- /dev/null+++ b/v2_migrations/2025-02-10-101458_create_index_payment_attempt_payment_id/down.sql@@ -0,0 +1,3 @@+-- This file should undo anything in `up.sql`+DROP INDEX IF EXISTS payment_attempt_payment_id_index;+CREATE INDEX IF NOT EXISTS payment_attempt_payment_id_merchant_id_index ON payment_attempt (payment_id, merchant_id);\ No newline at end of filediff --git a/v2_migrations/2025-02-10-101458_create_index_payment_attempt_payment_id/up.sql b/v2_migrations/2025-02-10-101458_create_index_payment_attempt_payment_id/up.sqlnew file mode 100644index 0000000000..9a9a9b077c--- /dev/null+++ b/v2_migrations/2025-02-10-101458_create_index_payment_attempt_payment_id/up.sql@@ -0,0 +1,3 @@+-- Your SQL goes here+DROP INDEX IF EXISTS payment_attempt_payment_id_merchant_id_index;+CREATE INDEX IF NOT EXISTS payment_attempt_payment_id_index ON payment_attempt (payment_id);\ No newline at end of file