refactor(common_utils): move serde implementations and date-time utils to common_utils crate (#40)

This commit is contained in:
Sanchith Hegde
2022-11-30 12:23:04 +05:30
committed by GitHub
parent 595f34e20f
commit 863e53c0d1
32 changed files with 189 additions and 192 deletions

View File

@ -82,7 +82,7 @@ pub async fn add_payment_method(
payment_method_issuer: req.payment_method_issuer,
card: None,
metadata: req.metadata,
created: Some(crate::utils::date_time::now()),
created: Some(common_utils::date_time::now()),
payment_method_issuer_code: req.payment_method_issuer_code,
recurring_enabled: false, //TODO
installment_payment_enabled: false, //TODO
@ -504,7 +504,7 @@ pub async fn get_tempcard_from_payment_method(
let card_info_val = get_card_info_value(&state.conf.keys, card_info).await?;
let temp_card = storage::TempCard {
card_info: Some(card_info_val),
date_created: crate::utils::date_time::now(),
date_created: common_utils::date_time::now(),
txn_id: None,
id: payment_token,
};

View File

@ -112,7 +112,7 @@ pub fn mk_add_card_response(
payment_method_issuer: req.payment_method_issuer,
card: Some(card),
metadata: req.metadata,
created: Some(crate::utils::date_time::now()),
created: Some(common_utils::date_time::now()),
payment_method_issuer_code: req.payment_method_issuer_code,
recurring_enabled: false, //TODO
installment_payment_enabled: false, //TODO

View File

@ -678,7 +678,7 @@ pub async fn create_temp_card(
let card_info_val = cards::get_card_info_value(&state.conf.keys, card_info).await?;
temp_card = storage::TempCardNew {
card_info: Some(card_info_val),
date_created: crate::utils::date_time::now(),
date_created: common_utils::date_time::now(),
txn_id: Some(txn_id.to_string()),
id: None,
};

View File

@ -299,7 +299,7 @@ impl PaymentCreate {
request: &api::PaymentsRequest,
browser_info: Option<serde_json::Value>,
) -> storage::PaymentAttemptNew {
let created_at @ modified_at @ last_synced = Some(crate::utils::date_time::now());
let created_at @ modified_at @ last_synced = Some(common_utils::date_time::now());
let status =
helpers::payment_attempt_status_fsm(&request.payment_method_data, request.confirm);
let (amount, currency) = (money.0, Some(money.1));
@ -334,7 +334,7 @@ impl PaymentCreate {
shipping_address_id: Option<String>,
billing_address_id: Option<String>,
) -> storage::PaymentIntentNew {
let created_at @ modified_at @ last_synced = Some(crate::utils::date_time::now());
let created_at @ modified_at @ last_synced = Some(common_utils::date_time::now());
let status =
helpers::payment_intent_status_fsm(&request.payment_method_data, request.confirm);
let client_secret =

View File

@ -414,7 +414,7 @@ fn mk_new_refund(
merchant_id: &str,
refund_amount: i32,
) -> storage::RefundNew {
let current_time = crate::utils::date_time::now();
let current_time = common_utils::date_time::now();
let connecter_transaction_id = match &payment_attempt.connector_transaction_id {
Some(id) => id,
None => "",
@ -681,7 +681,7 @@ pub async fn add_refund_sync_task(
refund: &storage::Refund,
runner: &str,
) -> RouterResult<storage::ProcessTracker> {
let current_time = crate::utils::date_time::now();
let current_time = common_utils::date_time::now();
let refund_workflow_model = serde_json::to_value(refund_to_refund_core_workflow_model(refund))
.into_report()
.change_context(errors::ApiErrorResponse::InternalServerError)
@ -693,7 +693,7 @@ pub async fn add_refund_sync_task(
tag: vec![String::from("REFUND")],
runner: Some(String::from(runner)),
retry_count: 0,
schedule_time: Some(crate::utils::date_time::now()),
schedule_time: Some(common_utils::date_time::now()),
rule: String::new(),
tracking_data: refund_workflow_model,
business_status: String::from("Pending"),
@ -717,7 +717,7 @@ pub async fn add_refund_execute_task(
runner: &str,
) -> RouterResult<storage::ProcessTracker> {
let task = "EXECUTE_REFUND";
let current_time = crate::utils::date_time::now();
let current_time = common_utils::date_time::now();
let refund_workflow_model = serde_json::to_value(refund_to_refund_core_workflow_model(refund))
.into_report()
.change_context(errors::ApiErrorResponse::InternalServerError)
@ -728,7 +728,7 @@ pub async fn add_refund_execute_task(
tag: vec![String::from("REFUND")],
runner: Some(String::from(runner)),
retry_count: 0,
schedule_time: Some(crate::utils::date_time::now()),
schedule_time: Some(common_utils::date_time::now()),
rule: String::new(),
tracking_data: refund_workflow_model,
business_status: String::from("Pending"),

View File

@ -70,7 +70,7 @@ pub fn validate_refund_amount(
pub fn validate_payment_order_age(
created_at: &PrimitiveDateTime,
) -> CustomResult<(), RefundValidationError> {
let current_time = utils::date_time::now();
let current_time = common_utils::date_time::now();
utils::when(
(current_time - *created_at).whole_days() > REFUND_MAX_AGE,