feat(router): Added amount conversion function in core for connector module (#4710)

Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
Co-authored-by: Hrithikesh <61539176+hrithikesh026@users.noreply.github.com>
Co-authored-by: Narayan Bhat <narayan.bhat@juspay.in>
This commit is contained in:
Sahkal Poddar
2024-05-30 19:21:33 +05:30
committed by GitHub
parent f7e99e1eda
commit 08eefdba4a
30 changed files with 577 additions and 150 deletions

View File

@ -26,15 +26,12 @@ pub trait OptionExt<T> {
fn update_value(&mut self, value: Option<T>);
}
impl<T> OptionExt<T> for Option<T>
where
T: std::fmt::Debug,
{
impl<T> OptionExt<T> for Option<T> {
fn check_value_present(&self, field_name: &'static str) -> RouterResult<()> {
when(self.is_none(), || {
Err(
Report::new(ApiErrorResponse::MissingRequiredField { field_name })
.attach_printable(format!("Missing required field {field_name} in {self:?}")),
.attach_printable(format!("Missing required field {field_name}")),
)
})
}
@ -46,7 +43,7 @@ where
Some(v) => Ok(v),
None => Err(
Report::new(ApiErrorResponse::MissingRequiredField { field_name })
.attach_printable(format!("Missing required field {field_name} in {self:?}")),
.attach_printable(format!("Missing required field {field_name}")),
),
}
}
@ -63,7 +60,7 @@ where
E::from_str(value.as_ref())
.change_context(errors::ParsingError::UnknownError)
.attach_printable_lazy(|| format!("Invalid {{ {enum_name}: {value:?} }} "))
.attach_printable_lazy(|| format!("Invalid {{ {enum_name} }} "))
}
fn parse_value<U>(self, type_name: &'static str) -> CustomResult<U, errors::ParsingError>

View File

@ -2,7 +2,7 @@ use api_models::{
enums::Connector::{DummyConnector4, DummyConnector7},
user::sample_data::SampleDataRequest,
};
use common_utils::id_type;
use common_utils::{id_type, types::MinorUnit};
use diesel_models::{user::sample_data::PaymentAttemptBatchNew, RefundNew};
use error_stack::ResultExt;
use hyperswitch_domain_models::payments::payment_intent::PaymentIntentNew;
@ -179,7 +179,7 @@ pub async fn generate_sample_data(
true => common_enums::IntentStatus::Failed,
_ => common_enums::IntentStatus::Succeeded,
},
amount: common_utils::types::MinorUnit::new(amount * 100),
amount: MinorUnit::new(amount * 100),
currency: Some(
*currency_vec
.get((num - 1) % currency_vec_len)
@ -197,7 +197,7 @@ pub async fn generate_sample_data(
),
attempt_count: 1,
customer_id: Some(dashboard_customer_id.clone()),
amount_captured: Some(common_utils::types::MinorUnit::new(amount * 100)),
amount_captured: Some(MinorUnit::new(amount * 100)),
profile_id: Some(profile_id.clone()),
return_url: Default::default(),
metadata: Default::default(),
@ -291,8 +291,8 @@ pub async fn generate_sample_data(
currency: *currency_vec
.get((num - 1) % currency_vec_len)
.unwrap_or(&common_enums::Currency::USD),
total_amount: amount * 100,
refund_amount: amount * 100,
total_amount: MinorUnit::new(amount * 100),
refund_amount: MinorUnit::new(amount * 100),
refund_status: common_enums::RefundStatus::Success,
sent_to_gateway: true,
refund_type: diesel_models::enums::RefundType::InstantRefund,