Skip to content

Commit

Permalink
feat(core): add columns unified error code and error message in refun…
Browse files Browse the repository at this point in the history
…d table (#6933)
  • Loading branch information
cookieg13 authored Jan 7, 2025
1 parent 6b1e5b0 commit c4d36b5
Show file tree
Hide file tree
Showing 30 changed files with 237 additions and 166 deletions.
10 changes: 10 additions & 0 deletions api-reference/openapi_spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -23241,6 +23241,16 @@
"description": "The code for the error",
"nullable": true
},
"unified_code": {
"type": "string",
"description": "Error code unified across the connectors is received here if there was an error while calling connector",
"nullable": true
},
"unified_message": {
"type": "string",
"description": "Error message unified across the connectors is received here if there was an error while calling connector",
"nullable": true
},
"created_at": {
"type": "string",
"format": "date-time",
Expand Down
4 changes: 4 additions & 0 deletions crates/api_models/src/refunds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,10 @@ pub struct RefundResponse {
pub error_message: Option<String>,
/// The code for the error
pub error_code: Option<String>,
/// Error code unified across the connectors is received here if there was an error while calling connector
pub unified_code: Option<String>,
/// Error message unified across the connectors is received here if there was an error while calling connector
pub unified_message: Option<String>,
/// The timestamp at which refund is created
#[serde(with = "common_utils::custom_serde::iso8601::option")]
pub created_at: Option<PrimitiveDateTime>,
Expand Down
26 changes: 26 additions & 0 deletions crates/diesel_models/src/refund.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ pub struct Refund {
pub connector_refund_data: Option<String>,
pub connector_transaction_data: Option<String>,
pub split_refunds: Option<common_types::refunds::SplitRefund>,
pub unified_code: Option<String>,
pub unified_message: Option<String>,
}

#[derive(
Expand Down Expand Up @@ -132,6 +134,8 @@ pub enum RefundUpdate {
updated_by: String,
connector_refund_id: Option<ConnectorTransactionId>,
connector_refund_data: Option<String>,
unified_code: Option<String>,
unified_message: Option<String>,
},
ManualUpdate {
refund_status: Option<storage_enums::RefundStatus>,
Expand All @@ -155,6 +159,8 @@ pub struct RefundUpdateInternal {
updated_by: String,
modified_at: PrimitiveDateTime,
connector_refund_data: Option<String>,
unified_code: Option<String>,
unified_message: Option<String>,
}

impl RefundUpdateInternal {
Expand All @@ -171,6 +177,8 @@ impl RefundUpdateInternal {
updated_by: self.updated_by,
modified_at: self.modified_at,
connector_refund_data: self.connector_refund_data,
unified_code: self.unified_code,
unified_message: self.unified_message,
..source
}
}
Expand Down Expand Up @@ -199,6 +207,8 @@ impl From<RefundUpdate> for RefundUpdateInternal {
refund_reason: None,
refund_error_code: None,
modified_at: common_utils::date_time::now(),
unified_code: None,
unified_message: None,
},
RefundUpdate::MetadataAndReasonUpdate {
metadata,
Expand All @@ -216,6 +226,8 @@ impl From<RefundUpdate> for RefundUpdateInternal {
refund_error_code: None,
modified_at: common_utils::date_time::now(),
connector_refund_data: None,
unified_code: None,
unified_message: None,
},
RefundUpdate::StatusUpdate {
connector_refund_id,
Expand All @@ -235,11 +247,15 @@ impl From<RefundUpdate> for RefundUpdateInternal {
refund_reason: None,
refund_error_code: None,
modified_at: common_utils::date_time::now(),
unified_code: None,
unified_message: None,
},
RefundUpdate::ErrorUpdate {
refund_status,
refund_error_message,
refund_error_code,
unified_code,
unified_message,
updated_by,
connector_refund_id,
connector_refund_data,
Expand All @@ -255,6 +271,8 @@ impl From<RefundUpdate> for RefundUpdateInternal {
metadata: None,
refund_reason: None,
modified_at: common_utils::date_time::now(),
unified_code,
unified_message,
},
RefundUpdate::ManualUpdate {
refund_status,
Expand All @@ -273,6 +291,8 @@ impl From<RefundUpdate> for RefundUpdateInternal {
refund_reason: None,
modified_at: common_utils::date_time::now(),
connector_refund_data: None,
unified_code: None,
unified_message: None,
},
}
}
Expand All @@ -292,6 +312,8 @@ impl RefundUpdate {
updated_by,
modified_at: _,
connector_refund_data,
unified_code,
unified_message,
} = self.into();
Refund {
connector_refund_id: connector_refund_id.or(source.connector_refund_id),
Expand All @@ -305,6 +327,8 @@ impl RefundUpdate {
updated_by,
modified_at: common_utils::date_time::now(),
connector_refund_data: connector_refund_data.or(source.connector_refund_data),
unified_code: unified_code.or(source.unified_code),
unified_message: unified_message.or(source.unified_message),
..source
}
}
Expand Down Expand Up @@ -392,6 +416,8 @@ mod tests {
"merchant_connector_id": null,
"charges": null,
"connector_transaction_data": null
"unified_code": null,
"unified_message": null,
}"#;
let deserialized = serde_json::from_str::<super::Refund>(serialized_refund);

Expand Down
4 changes: 4 additions & 0 deletions crates/diesel_models/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1235,6 +1235,10 @@ diesel::table! {
#[max_length = 512]
connector_transaction_data -> Nullable<Varchar>,
split_refunds -> Nullable<Jsonb>,
#[max_length = 255]
unified_code -> Nullable<Varchar>,
#[max_length = 1024]
unified_message -> Nullable<Varchar>,
}
}

Expand Down
4 changes: 4 additions & 0 deletions crates/diesel_models/src/schema_v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1181,6 +1181,10 @@ diesel::table! {
#[max_length = 512]
connector_transaction_data -> Nullable<Varchar>,
split_refunds -> Nullable<Jsonb>,
#[max_length = 255]
unified_code -> Nullable<Varchar>,
#[max_length = 1024]
unified_message -> Nullable<Varchar>,
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,6 @@ pub struct Browser {
user_agent: String,
}

#[derive(Debug, Serialize)]
pub struct Location {
lat: String,
lon: String,
}

#[derive(Debug, Serialize)]
pub struct Mobile {
device_model: Option<String>,
Expand Down
4 changes: 2 additions & 2 deletions crates/router/src/bin/scheduler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ pub async fn deep_health_check(
let app_state = Arc::clone(&state.into_inner());
let service_name = service.into_inner();
for (tenant, _) in stores {
let session_state_res = app_state.clone().get_session_state(&tenant, || {
let session_state_res = app_state.clone().get_session_state(&tenant, None, || {
errors::ApiErrorResponse::MissingRequiredField {
field_name: "tenant_id",
}
Expand Down Expand Up @@ -397,7 +397,7 @@ async fn start_scheduler(
WorkflowRunner {},
|state, tenant| {
Arc::new(state.clone())
.get_session_state(tenant, || ProcessTrackerError::TenantNotFound.into())
.get_session_state(tenant, None, || ProcessTrackerError::TenantNotFound.into())
},
)
.await
Expand Down
3 changes: 3 additions & 0 deletions crates/router/src/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,3 +210,6 @@ pub const DYNAMIC_ROUTING_MAX_VOLUME: u8 = 100;

/// Click To Pay
pub const CLICK_TO_PAY: &str = "click_to_pay";

/// Refund flow identifier used for performing GSM operations
pub const REFUND_FLOW_STR: &str = "refund_flow";
67 changes: 19 additions & 48 deletions crates/router/src/core/payment_link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use api_models::{
};
use common_utils::{
consts::{DEFAULT_LOCALE, DEFAULT_SESSION_EXPIRY},
ext_traits::{AsyncExt, OptionExt, ValueExt},
ext_traits::{OptionExt, ValueExt},
types::{AmountConvertor, StringMajorUnitForCore},
};
use error_stack::{report, ResultExt};
Expand All @@ -28,9 +28,8 @@ use crate::{
},
errors::RouterResponse,
get_payment_link_config_value, get_payment_link_config_value_based_on_priority,
headers::ACCEPT_LANGUAGE,
routes::SessionState,
services::{self, authentication::get_header_value_by_key},
services,
types::{
api::payment_link::PaymentLinkResponseExt,
domain,
Expand Down Expand Up @@ -70,7 +69,6 @@ pub async fn form_payment_link_data(
key_store: domain::MerchantKeyStore,
merchant_id: common_utils::id_type::MerchantId,
payment_id: common_utils::id_type::PaymentId,
locale: Option<String>,
) -> RouterResult<(PaymentLink, PaymentLinkData, PaymentLinkConfig)> {
todo!()
}
Expand All @@ -82,7 +80,6 @@ pub async fn form_payment_link_data(
key_store: domain::MerchantKeyStore,
merchant_id: common_utils::id_type::MerchantId,
payment_id: common_utils::id_type::PaymentId,
locale: Option<String>,
) -> RouterResult<(PaymentLink, PaymentLinkData, PaymentLinkConfig)> {
let db = &*state.store;
let key_manager_state = &state.into();
Expand Down Expand Up @@ -242,7 +239,7 @@ pub async fn form_payment_link_data(
redirect: false,
theme: payment_link_config.theme.clone(),
return_url: return_url.clone(),
locale: locale.clone(),
locale: Some(state.clone().locale),
transaction_details: payment_link_config.transaction_details.clone(),
unified_code: payment_attempt.unified_code,
unified_message: payment_attempt.unified_message,
Expand Down Expand Up @@ -273,7 +270,7 @@ pub async fn form_payment_link_data(
display_sdk_only: payment_link_config.display_sdk_only,
hide_card_nickname_field: payment_link_config.hide_card_nickname_field,
show_card_form_by_default: payment_link_config.show_card_form_by_default,
locale,
locale: Some(state.clone().locale),
transaction_details: payment_link_config.transaction_details.clone(),
background_image: payment_link_config.background_image.clone(),
details_layout: payment_link_config.details_layout,
Expand All @@ -296,17 +293,9 @@ pub async fn initiate_secure_payment_link_flow(
payment_id: common_utils::id_type::PaymentId,
request_headers: &header::HeaderMap,
) -> RouterResponse<services::PaymentLinkFormData> {
let locale = get_header_value_by_key(ACCEPT_LANGUAGE.into(), request_headers)?
.map(|val| val.to_string());
let (payment_link, payment_link_details, payment_link_config) = form_payment_link_data(
&state,
merchant_account,
key_store,
merchant_id,
payment_id,
locale,
)
.await?;
let (payment_link, payment_link_details, payment_link_config) =
form_payment_link_data(&state, merchant_account, key_store, merchant_id, payment_id)
.await?;

validator::validate_secure_payment_link_render_request(
request_headers,
Expand Down Expand Up @@ -396,19 +385,10 @@ pub async fn initiate_payment_link_flow(
key_store: domain::MerchantKeyStore,
merchant_id: common_utils::id_type::MerchantId,
payment_id: common_utils::id_type::PaymentId,
request_headers: &header::HeaderMap,
) -> RouterResponse<services::PaymentLinkFormData> {
let locale = get_header_value_by_key(ACCEPT_LANGUAGE.into(), request_headers)?
.map(|val| val.to_string());
let (_, payment_details, payment_link_config) = form_payment_link_data(
&state,
merchant_account,
key_store,
merchant_id,
payment_id,
locale,
)
.await?;
let (_, payment_details, payment_link_config) =
form_payment_link_data(&state, merchant_account, key_store, merchant_id, payment_id)
.await?;

let css_script = get_color_scheme_css(&payment_link_config);
let js_script = get_js_script(&payment_details)?;
Expand Down Expand Up @@ -727,7 +707,6 @@ pub async fn get_payment_link_status(
_key_store: domain::MerchantKeyStore,
_merchant_id: common_utils::id_type::MerchantId,
_payment_id: common_utils::id_type::PaymentId,
_request_headers: &header::HeaderMap,
) -> RouterResponse<services::PaymentLinkFormData> {
todo!()
}
Expand All @@ -739,10 +718,7 @@ pub async fn get_payment_link_status(
key_store: domain::MerchantKeyStore,
merchant_id: common_utils::id_type::MerchantId,
payment_id: common_utils::id_type::PaymentId,
request_headers: &header::HeaderMap,
) -> RouterResponse<services::PaymentLinkFormData> {
let locale = get_header_value_by_key(ACCEPT_LANGUAGE.into(), request_headers)?
.map(|val| val.to_string());
let db = &*state.store;
let key_manager_state = &(&state).into();

Expand Down Expand Up @@ -858,19 +834,14 @@ pub async fn get_payment_link_status(
consts::DEFAULT_UNIFIED_ERROR_MESSAGE.to_owned(),
)
};
let unified_translated_message = locale
.as_ref()
.async_and_then(|locale_str| async {
helpers::get_unified_translation(
&state,
unified_code.to_owned(),
unified_message.to_owned(),
locale_str.to_owned(),
)
.await
})
.await
.or(Some(unified_message));
let unified_translated_message = helpers::get_unified_translation(
&state,
unified_code.to_owned(),
unified_message.to_owned(),
state.locale.clone(),
)
.await
.or(Some(unified_message));

let payment_details = api_models::payments::PaymentLinkStatusDetails {
amount,
Expand All @@ -885,7 +856,7 @@ pub async fn get_payment_link_status(
redirect: true,
theme: payment_link_config.theme.clone(),
return_url,
locale,
locale: Some(state.locale.clone()),
transaction_details: payment_link_config.transaction_details,
unified_code: Some(unified_code),
unified_message: unified_translated_message,
Expand Down
Loading

0 comments on commit c4d36b5

Please sign in to comment.