Skip to content

Commit

Permalink
refactor: use separate update enums for sync update
Browse files Browse the repository at this point in the history
  • Loading branch information
Narayanbhat166 committed Oct 30, 2024
1 parent ef71de3 commit e50a071
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 8 deletions.
28 changes: 24 additions & 4 deletions crates/hyperswitch_domain_models/src/payments/payment_attempt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1277,7 +1277,6 @@ impl PaymentAttemptUpdate {
}
}

// TODO: Add fields as necessary
#[cfg(feature = "v2")]
#[derive(Debug, Clone, Serialize)]
pub enum PaymentAttemptUpdate {
Expand All @@ -1294,11 +1293,17 @@ pub enum PaymentAttemptUpdate {
connector_payment_id: Option<String>,
updated_by: String,
},
/// Update the payment attempt after force syncing with the connector
SyncUpdate {
status: storage_enums::AttemptStatus,
updated_by: String,
},
/// Update the payment attempt on confirming the intent, after calling the connector on error response
ConfirmIntentError {
ErrorUpdate {
status: storage_enums::AttemptStatus,
error: ErrorDetails,
updated_by: String,
connector_payment_id: Option<String>,
},
}

Expand Down Expand Up @@ -1921,9 +1926,10 @@ impl From<PaymentAttemptUpdate> for diesel_models::PaymentAttemptUpdateInternal
connector_payment_id: None,
connector: Some(connector),
},
PaymentAttemptUpdate::ConfirmIntentError {
PaymentAttemptUpdate::ErrorUpdate {
status,
error,
connector_payment_id,
updated_by,
} => Self {
status: Some(status),
Expand All @@ -1936,7 +1942,7 @@ impl From<PaymentAttemptUpdate> for diesel_models::PaymentAttemptUpdateInternal
merchant_connector_id: None,
unified_code: None,
unified_message: None,
connector_payment_id: None,
connector_payment_id,
connector: None,
},
PaymentAttemptUpdate::ConfirmIntentResponse {
Expand All @@ -1957,6 +1963,20 @@ impl From<PaymentAttemptUpdate> for diesel_models::PaymentAttemptUpdateInternal
connector_payment_id,
connector: None,
},
PaymentAttemptUpdate::SyncUpdate { status, updated_by } => Self {
status: Some(status),
error_message: None,
error_code: None,
modified_at: common_utils::date_time::now(),
browser_info: None,
error_reason: None,
updated_by,
merchant_connector_id: None,
unified_code: None,
unified_message: None,
connector_payment_id: None,
connector: None,
},
}
}
}
15 changes: 15 additions & 0 deletions crates/hyperswitch_domain_models/src/payments/payment_intent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,10 @@ pub enum PaymentIntentUpdate {
status: storage_enums::IntentStatus,
updated_by: String,
},
SyncUpdate {
status: storage_enums::IntentStatus,
updated_by: String,
},
}

#[cfg(feature = "v2")]
Expand Down Expand Up @@ -378,6 +382,12 @@ impl From<PaymentIntentUpdate> for diesel_models::PaymentIntentUpdateInternal {
modified_at: common_utils::date_time::now(),
updated_by,
},
PaymentIntentUpdate::SyncUpdate { status, updated_by } => Self {
status: Some(status),
active_attempt_id: None,
modified_at: common_utils::date_time::now(),
updated_by,
},
}
}
}
Expand All @@ -402,6 +412,11 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
updated_by,
..Default::default()
},
PaymentIntentUpdate::SyncUpdate { status, updated_by } => Self {
status: Some(status),
updated_by,
..Default::default()
},
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2293,7 +2293,7 @@ impl<F: Clone> PostUpdateTracker<F, PaymentConfirmData<F>, types::PaymentsAuthor
unified_message: None,
};

let payment_attempt_update = hyperswitch_domain_models::payments::payment_attempt::PaymentAttemptUpdate::ConfirmIntentError { status: attempt_status, error: error_details,updated_by: storage_scheme.to_string() };
let payment_attempt_update = hyperswitch_domain_models::payments::payment_attempt::PaymentAttemptUpdate::ErrorUpdate { status: attempt_status, error: error_details, connector_payment_id: connector_transaction_id, updated_by: storage_scheme.to_string() };
let updated_payment_attempt = db
.update_payment_attempt(
key_manager_state,
Expand Down Expand Up @@ -2379,7 +2379,7 @@ impl<F: Clone> PostUpdateTracker<F, PaymentStatusData<F>, types::PaymentsSyncDat
| types::ResponseId::EncodedData(id) => Some(id),
};

let payment_intent_update = hyperswitch_domain_models::payments::payment_intent::PaymentIntentUpdate::ConfirmIntentPostUpdate { status: intent_status, updated_by: storage_scheme.to_string() };
let payment_intent_update = hyperswitch_domain_models::payments::payment_intent::PaymentIntentUpdate::SyncUpdate { status: intent_status, updated_by: storage_scheme.to_string() };
let updated_payment_intent = db
.update_payment_intent(
key_manager_state,
Expand All @@ -2393,7 +2393,7 @@ impl<F: Clone> PostUpdateTracker<F, PaymentStatusData<F>, types::PaymentsSyncDat
.attach_printable("Unable to update payment intent")?;
payment_data.payment_intent = updated_payment_intent;

let payment_attempt_update = hyperswitch_domain_models::payments::payment_attempt::PaymentAttemptUpdate::ConfirmIntentResponse { status: attempt_status, connector_payment_id, updated_by: storage_scheme.to_string() };
let payment_attempt_update = hyperswitch_domain_models::payments::payment_attempt::PaymentAttemptUpdate::SyncUpdate { status: attempt_status, updated_by: storage_scheme.to_string() };
let updated_payment_attempt = db
.update_payment_attempt(
key_manager_state,
Expand Down Expand Up @@ -2476,7 +2476,7 @@ impl<F: Clone> PostUpdateTracker<F, PaymentStatusData<F>, types::PaymentsSyncDat
unified_message: None,
};

let payment_attempt_update = hyperswitch_domain_models::payments::payment_attempt::PaymentAttemptUpdate::ConfirmIntentError { status: attempt_status, error: error_details,updated_by: storage_scheme.to_string() };
let payment_attempt_update = hyperswitch_domain_models::payments::payment_attempt::PaymentAttemptUpdate::ErrorUpdate { status: attempt_status, error: error_details, connector_payment_id: connector_transaction_id, updated_by: storage_scheme.to_string() };
let updated_payment_attempt = db
.update_payment_attempt(
key_manager_state,
Expand Down

0 comments on commit e50a071

Please sign in to comment.