Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core): add columns unified error code and error message in refund table #6933

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions api-reference/openapi_spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -23239,6 +23239,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)]
Copy link
Contributor Author

@cookieg13 cookieg13 Dec 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Screenshot 2024-12-27 at 12 12 45

Location is not used anywhere, so removing it

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";
42 changes: 15 additions & 27 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 @@ -296,15 +295,13 @@ 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,
Some(state.clone().locale),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need not pass locale here since form_payment_link_data() already accepts SessionState, the function can be updated to access state.locale as needed.

)
.await?;

Expand Down Expand Up @@ -396,17 +393,15 @@ 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,
_request_headers: &header::HeaderMap,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can remove the unused request_headers argument here and in get_payment_link_status() (both v1 and v2 features).

) -> 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,
Some(state.clone().locale),
)
.await?;

Expand Down Expand Up @@ -739,10 +734,8 @@ 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,
_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 +851,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 +873,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
11 changes: 5 additions & 6 deletions crates/router/src/core/payout_link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ pub async fn initiate_payout_link(
key_store: domain::MerchantKeyStore,
req: payouts::PayoutLinkInitiateRequest,
request_headers: &header::HeaderMap,
locale: String,
) -> RouterResponse<services::GenericLinkFormData> {
let db: &dyn StorageInterface = &*state.store;
let merchant_id = merchant_account.get_id();
Expand Down Expand Up @@ -128,7 +127,7 @@ pub async fn initiate_payout_link(
GenericLinks {
allowed_domains,
data: GenericLinksData::ExpiredLink(expired_link_data),
locale,
locale: state.locale,
},
)))
}
Expand Down Expand Up @@ -245,7 +244,7 @@ pub async fn initiate_payout_link(
enabled_payment_methods_with_required_fields,
amount,
currency: payout.destination_currency,
locale: locale.clone(),
locale: state.locale.clone(),
form_layout: link_data.form_layout,
test_mode: link_data.test_mode.unwrap_or(false),
};
Expand All @@ -270,7 +269,7 @@ pub async fn initiate_payout_link(
GenericLinks {
allowed_domains,
data: GenericLinksData::PayoutLink(generic_form_data),
locale,
locale: state.locale.clone(),
},
)))
}
Expand All @@ -282,7 +281,7 @@ pub async fn initiate_payout_link(
&state,
payout_attempt.unified_code.as_ref(),
payout_attempt.unified_message.as_ref(),
&locale,
&state.locale.clone(),
)
.await?;
let js_data = payouts::PayoutLinkStatusDetails {
Expand Down Expand Up @@ -322,7 +321,7 @@ pub async fn initiate_payout_link(
GenericLinks {
allowed_domains,
data: GenericLinksData::PayoutLinkStatus(generic_status_data),
locale,
locale: state.locale.clone(),
},
)))
}
Expand Down
Loading
Loading