Skip to content

Commit

Permalink
refactor: rsync status
Browse files Browse the repository at this point in the history
  • Loading branch information
swangi-kumari committed Feb 28, 2024
1 parent a909aeb commit 2cb0bf8
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 16 deletions.
4 changes: 2 additions & 2 deletions crates/router/src/connector/authorizedotnet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -685,8 +685,8 @@ impl ConnectorIntegration<api::RSync, types::RefundsData, types::RefundsResponse
let intermediate_response =
bytes::Bytes::copy_from_slice(intermediate_response.0.as_bytes());

let response: authorizedotnet::AuthorizedotnetSyncResponse = intermediate_response
.parse_struct("AuthorizedotnetSyncResponse")
let response: authorizedotnet::AuthorizedotnetRSyncResponse = intermediate_response
.parse_struct("AuthorizedotnetRSyncResponse")
.change_context(errors::ConnectorError::ResponseDeserializationFailed)?;
event_builder.map(|i| i.set_response_body(&response));
router_env::logger::info!(connector_response=?response);
Expand Down
42 changes: 28 additions & 14 deletions crates/router/src/connector/authorizedotnet/transformers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -932,6 +932,14 @@ pub enum SyncStatus {
#[serde(rename = "FDSPendingReview")]
FDSPendingReview,
}

#[derive(Debug, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub enum RSyncStatus {
RefundSettledSuccessfully,
RefundPendingSettlement,
}

#[derive(Debug, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct SyncTransactionResponse {
Expand All @@ -946,19 +954,25 @@ pub struct AuthorizedotnetSyncResponse {
messages: ResponseMessages,
}

impl From<SyncStatus> for enums::RefundStatus {
fn from(transaction_status: SyncStatus) -> Self {
#[derive(Debug, Deserialize, Serialize)]
pub struct AuthorizedotnetRSyncResponse {
transaction: Option<RSyncTransactionResponse>,
messages: ResponseMessages,
}

#[derive(Debug, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct RSyncTransactionResponse {
#[serde(rename = "transId")]
transaction_id: String,
transaction_status: RSyncStatus,
}

impl From<RSyncStatus> for enums::RefundStatus {
fn from(transaction_status: RSyncStatus) -> Self {
match transaction_status {
SyncStatus::RefundSettledSuccessfully => Self::Success,
SyncStatus::RefundPendingSettlement => Self::Pending,
SyncStatus::AuthorizedPendingCapture
| SyncStatus::CapturedPendingSettlement
| SyncStatus::SettledSuccessfully
| SyncStatus::Declined
| SyncStatus::Voided
| SyncStatus::CouldNotVoid
| SyncStatus::GeneralError
| SyncStatus::FDSPendingReview => Self::Failure,
RSyncStatus::RefundSettledSuccessfully => Self::Success,
RSyncStatus::RefundPendingSettlement => Self::Pending,
}
}
}
Expand All @@ -980,13 +994,13 @@ impl From<SyncStatus> for enums::AttemptStatus {
}
}

impl TryFrom<types::RefundsResponseRouterData<api::RSync, AuthorizedotnetSyncResponse>>
impl TryFrom<types::RefundsResponseRouterData<api::RSync, AuthorizedotnetRSyncResponse>>
for types::RefundsRouterData<api::RSync>
{
type Error = error_stack::Report<errors::ConnectorError>;

fn try_from(
item: types::RefundsResponseRouterData<api::RSync, AuthorizedotnetSyncResponse>,
item: types::RefundsResponseRouterData<api::RSync, AuthorizedotnetRSyncResponse>,
) -> Result<Self, Self::Error> {
match item.response.transaction {
Some(transaction) => {
Expand Down

0 comments on commit 2cb0bf8

Please sign in to comment.