diff --git a/crates/router/src/compatibility/stripe/payment_intents/types.rs b/crates/router/src/compatibility/stripe/payment_intents/types.rs index abdff48df7..9e38b65343 100644 --- a/crates/router/src/compatibility/stripe/payment_intents/types.rs +++ b/crates/router/src/compatibility/stripe/payment_intents/types.rs @@ -1,10 +1,11 @@ use api_models::payments; -use common_utils::{ext_traits::StringExt, pii as secret}; +use common_utils::{date_time, ext_traits::StringExt, pii as secret}; use error_stack::ResultExt; use serde::{Deserialize, Serialize}; use crate::{ compatibility::stripe::refunds::types as stripe_refunds, + consts, core::errors, pii::{self, PeekInterface}, types::{ @@ -295,12 +296,23 @@ pub struct StripePaymentIntentResponse { pub payment_token: Option, pub email: Option>, pub phone: Option>, - pub error_code: Option, - pub error_message: Option, pub statement_descriptor_suffix: Option, pub statement_descriptor_name: Option, pub capture_method: Option, pub name: Option>, + pub last_payment_error: Option, +} + +#[derive(Default, Eq, PartialEq, Serialize)] +pub struct LastPaymentError { + charge: Option, + code: Option, + decline_code: Option, + message: String, + param: Option, + payment_method: StripePaymentMethod, + #[serde(rename = "type")] + error_type: String, } impl From for StripePaymentIntentResponse { @@ -328,7 +340,7 @@ impl From for StripePaymentIntentResponse { capture_on: resp.capture_on, capture_method: resp.capture_method, payment_method: resp.payment_method, - payment_method_data: resp.payment_method_data, + payment_method_data: resp.payment_method_data.clone(), payment_token: resp.payment_token, shipping: resp.shipping, billing: resp.billing, @@ -340,14 +352,43 @@ impl From for StripePaymentIntentResponse { statement_descriptor_suffix: resp.statement_descriptor_suffix, next_action: into_stripe_next_action(resp.next_action, resp.return_url), cancellation_reason: resp.cancellation_reason, - error_code: resp.error_code, - error_message: resp.error_message, metadata: resp.metadata, charges: Charges::new(), + last_payment_error: resp.error_code.map(|code| LastPaymentError { + charge: None, + code: Some(code.to_owned()), + decline_code: None, + message: resp + .error_message + .unwrap_or_else(|| consts::NO_ERROR_MESSAGE.to_string()), + param: None, + payment_method: StripePaymentMethod { + payment_method_id: "place_holder_id".to_string(), + object: "payment_method", + card: None, + created: u64::try_from(date_time::now().assume_utc().unix_timestamp()) + .unwrap_or_default(), + method_type: "card".to_string(), + live_mode: false, + }, + error_type: code, + }), } } } +#[derive(Default, Eq, PartialEq, Serialize)] +pub struct StripePaymentMethod { + #[serde(rename = "id")] + payment_method_id: String, + object: &'static str, + card: Option, + created: u64, + #[serde(rename = "type")] + method_type: String, + live_mode: bool, +} + #[derive(Default, Eq, PartialEq, Serialize)] pub struct Charges { object: &'static str,