mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-11-02 21:07:58 +08:00
refactor(RouterData): reorder fields in RouterData (#33)
This commit is contained in:
@ -213,13 +213,12 @@ impl<F, T>
|
|||||||
status: enums::AttemptStatus::from(AciPaymentStatus::from_str(
|
status: enums::AttemptStatus::from(AciPaymentStatus::from_str(
|
||||||
&item.response.result.code,
|
&item.response.result.code,
|
||||||
)?),
|
)?),
|
||||||
response: Some(types::PaymentsResponseData {
|
response: Ok(types::PaymentsResponseData {
|
||||||
connector_transaction_id: item.response.id,
|
connector_transaction_id: item.response.id,
|
||||||
//TODO: Add redirection details here
|
//TODO: Add redirection details here
|
||||||
redirection_data: None,
|
redirection_data: None,
|
||||||
redirect: false,
|
redirect: false,
|
||||||
}),
|
}),
|
||||||
error_response: None,
|
|
||||||
..item.data
|
..item.data
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -306,13 +305,12 @@ impl<F> TryFrom<types::RefundsResponseRouterData<F, AciRefundResponse>>
|
|||||||
item: types::RefundsResponseRouterData<F, AciRefundResponse>,
|
item: types::RefundsResponseRouterData<F, AciRefundResponse>,
|
||||||
) -> Result<Self, Self::Error> {
|
) -> Result<Self, Self::Error> {
|
||||||
Ok(types::RouterData {
|
Ok(types::RouterData {
|
||||||
response: Some(types::RefundsResponseData {
|
response: Ok(types::RefundsResponseData {
|
||||||
connector_refund_id: item.response.id,
|
connector_refund_id: item.response.id,
|
||||||
refund_status: enums::RefundStatus::from(AciRefundStatus::from_str(
|
refund_status: enums::RefundStatus::from(AciRefundStatus::from_str(
|
||||||
&item.response.result.code,
|
&item.response.result.code,
|
||||||
)?),
|
)?),
|
||||||
}),
|
}),
|
||||||
error_response: None,
|
|
||||||
..item.data
|
..item.data
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@ -340,7 +340,7 @@ impl TryFrom<types::PaymentsCancelResponseRouterData<AdyenCancelResponse>>
|
|||||||
};
|
};
|
||||||
Ok(types::RouterData {
|
Ok(types::RouterData {
|
||||||
status,
|
status,
|
||||||
response: Some(types::PaymentsResponseData {
|
response: Ok(types::PaymentsResponseData {
|
||||||
connector_transaction_id: item.response.psp_reference,
|
connector_transaction_id: item.response.psp_reference,
|
||||||
redirection_data: None,
|
redirection_data: None,
|
||||||
redirect: false,
|
redirect: false,
|
||||||
@ -457,8 +457,8 @@ impl<F, Req>
|
|||||||
|
|
||||||
Ok(types::RouterData {
|
Ok(types::RouterData {
|
||||||
status,
|
status,
|
||||||
error_response: error,
|
response: error.map_or_else(|| Ok(payment_response_data), Err),
|
||||||
response: Some(payment_response_data),
|
|
||||||
..item.data
|
..item.data
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -524,11 +524,10 @@ impl<F> TryFrom<types::RefundsResponseRouterData<F, AdyenRefundResponse>>
|
|||||||
_ => enums::RefundStatus::Pending,
|
_ => enums::RefundStatus::Pending,
|
||||||
};
|
};
|
||||||
Ok(types::RouterData {
|
Ok(types::RouterData {
|
||||||
response: Some(types::RefundsResponseData {
|
response: Ok(types::RefundsResponseData {
|
||||||
connector_refund_id: item.response.reference,
|
connector_refund_id: item.response.reference,
|
||||||
refund_status,
|
refund_status,
|
||||||
}),
|
}),
|
||||||
error_response: None,
|
|
||||||
..item.data
|
..item.data
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@ -295,13 +295,17 @@ impl<F, T>
|
|||||||
|
|
||||||
Ok(types::RouterData {
|
Ok(types::RouterData {
|
||||||
status,
|
status,
|
||||||
response: Some(types::PaymentsResponseData {
|
response: match error {
|
||||||
connector_transaction_id: item.response.transaction_response.transaction_id,
|
Some(err) => Err(err),
|
||||||
//TODO: Add redirection details here
|
None => {
|
||||||
redirection_data: None,
|
Ok(types::PaymentsResponseData {
|
||||||
redirect: false,
|
connector_transaction_id: item.response.transaction_response.transaction_id,
|
||||||
}),
|
//TODO: Add redirection details here
|
||||||
error_response: error,
|
redirection_data: None,
|
||||||
|
redirect: false,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
},
|
||||||
..item.data
|
..item.data
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -411,11 +415,13 @@ impl<F> TryFrom<types::RefundsResponseRouterData<F, AuthorizedotnetRefundRespons
|
|||||||
});
|
});
|
||||||
|
|
||||||
Ok(types::RouterData {
|
Ok(types::RouterData {
|
||||||
response: Some(types::RefundsResponseData {
|
response: match error {
|
||||||
connector_refund_id: transaction_response.transaction_id.clone(),
|
Some(err) => Err(err),
|
||||||
refund_status,
|
None => Ok(types::RefundsResponseData {
|
||||||
}),
|
connector_refund_id: transaction_response.transaction_id.clone(),
|
||||||
error_response: error,
|
refund_status,
|
||||||
|
}),
|
||||||
|
},
|
||||||
..item.data
|
..item.data
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -441,7 +447,8 @@ impl<F> TryFrom<&types::RefundsRouterData<F>> for AuthorizedotnetCreateSyncReque
|
|||||||
let transaction_id = item
|
let transaction_id = item
|
||||||
.response
|
.response
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map(|refund_response_data| refund_response_data.connector_refund_id.clone());
|
.map(|refund_response_data| refund_response_data.connector_refund_id.clone())
|
||||||
|
.ok();
|
||||||
let merchant_authentication = MerchantAuthentication::try_from(&item.connector_auth_type)?;
|
let merchant_authentication = MerchantAuthentication::try_from(&item.connector_auth_type)?;
|
||||||
|
|
||||||
let payload = AuthorizedotnetCreateSyncRequest {
|
let payload = AuthorizedotnetCreateSyncRequest {
|
||||||
@ -461,7 +468,8 @@ impl TryFrom<&types::PaymentsRouterSyncData> for AuthorizedotnetCreateSyncReques
|
|||||||
let transaction_id = item
|
let transaction_id = item
|
||||||
.response
|
.response
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map(|payment_response_data| payment_response_data.connector_transaction_id.clone());
|
.map(|payment_response_data| payment_response_data.connector_transaction_id.clone())
|
||||||
|
.ok();
|
||||||
let merchant_authentication = MerchantAuthentication::try_from(&item.connector_auth_type)?;
|
let merchant_authentication = MerchantAuthentication::try_from(&item.connector_auth_type)?;
|
||||||
|
|
||||||
let payload = AuthorizedotnetCreateSyncRequest {
|
let payload = AuthorizedotnetCreateSyncRequest {
|
||||||
@ -535,7 +543,7 @@ impl TryFrom<types::RefundsResponseRouterData<api::RSync, AuthorizedotnetSyncRes
|
|||||||
) -> Result<Self, Self::Error> {
|
) -> Result<Self, Self::Error> {
|
||||||
let refund_status = enums::RefundStatus::from(item.response.transaction.transaction_status);
|
let refund_status = enums::RefundStatus::from(item.response.transaction.transaction_status);
|
||||||
Ok(types::RouterData {
|
Ok(types::RouterData {
|
||||||
response: Some(types::RefundsResponseData {
|
response: Ok(types::RefundsResponseData {
|
||||||
connector_refund_id: item.response.transaction.transaction_id.clone(),
|
connector_refund_id: item.response.transaction.transaction_id.clone(),
|
||||||
refund_status,
|
refund_status,
|
||||||
}),
|
}),
|
||||||
@ -562,7 +570,7 @@ impl<F, Req>
|
|||||||
let payment_status =
|
let payment_status =
|
||||||
enums::AttemptStatus::from(item.response.transaction.transaction_status);
|
enums::AttemptStatus::from(item.response.transaction.transaction_status);
|
||||||
Ok(types::RouterData {
|
Ok(types::RouterData {
|
||||||
response: Some(types::PaymentsResponseData {
|
response: Ok(types::PaymentsResponseData {
|
||||||
connector_transaction_id: item.response.transaction.transaction_id,
|
connector_transaction_id: item.response.transaction.transaction_id,
|
||||||
redirection_data: None,
|
redirection_data: None,
|
||||||
redirect: false,
|
redirect: false,
|
||||||
|
|||||||
@ -526,11 +526,11 @@ impl
|
|||||||
) -> CustomResult<types::RefundsRouterData<api::RSync>, errors::ConnectorError> {
|
) -> CustomResult<types::RefundsRouterData<api::RSync>, errors::ConnectorError> {
|
||||||
let refund_action_id = data
|
let refund_action_id = data
|
||||||
.response
|
.response
|
||||||
.as_ref()
|
.clone()
|
||||||
|
.ok()
|
||||||
.get_required_value("response")
|
.get_required_value("response")
|
||||||
.change_context(errors::ConnectorError::FailedToObtainIntegrationUrl)?
|
.change_context(errors::ConnectorError::ResponseDeserializationFailed)?
|
||||||
.connector_refund_id
|
.connector_refund_id;
|
||||||
.clone();
|
|
||||||
|
|
||||||
let response: Vec<checkout::ActionResponse> = res
|
let response: Vec<checkout::ActionResponse> = res
|
||||||
.response
|
.response
|
||||||
|
|||||||
@ -189,12 +189,11 @@ impl<F, Req>
|
|||||||
});
|
});
|
||||||
Ok(types::RouterData {
|
Ok(types::RouterData {
|
||||||
status: enums::AttemptStatus::from(item.response.status),
|
status: enums::AttemptStatus::from(item.response.status),
|
||||||
response: Some(types::PaymentsResponseData {
|
response: Ok(types::PaymentsResponseData {
|
||||||
connector_transaction_id: item.response.id,
|
connector_transaction_id: item.response.id,
|
||||||
redirect: redirection_data.is_some(),
|
redirect: redirection_data.is_some(),
|
||||||
redirection_data,
|
redirection_data,
|
||||||
}),
|
}),
|
||||||
error_response: None,
|
|
||||||
..item.data
|
..item.data
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -249,11 +248,10 @@ impl TryFrom<types::RefundsResponseRouterData<api::Execute, CheckoutRefundRespon
|
|||||||
) -> Result<Self, Self::Error> {
|
) -> Result<Self, Self::Error> {
|
||||||
let refund_status = enums::RefundStatus::from(&item.response);
|
let refund_status = enums::RefundStatus::from(&item.response);
|
||||||
Ok(types::RouterData {
|
Ok(types::RouterData {
|
||||||
response: Some(types::RefundsResponseData {
|
response: Ok(types::RefundsResponseData {
|
||||||
connector_refund_id: item.response.response.action_id.clone(),
|
connector_refund_id: item.response.response.action_id.clone(),
|
||||||
refund_status,
|
refund_status,
|
||||||
}),
|
}),
|
||||||
error_response: None,
|
|
||||||
..item.data
|
..item.data
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -268,11 +266,10 @@ impl TryFrom<types::RefundsResponseRouterData<api::RSync, CheckoutRefundResponse
|
|||||||
) -> Result<Self, Self::Error> {
|
) -> Result<Self, Self::Error> {
|
||||||
let refund_status = enums::RefundStatus::from(&item.response);
|
let refund_status = enums::RefundStatus::from(&item.response);
|
||||||
Ok(types::RouterData {
|
Ok(types::RouterData {
|
||||||
response: Some(types::RefundsResponseData {
|
response: Ok(types::RefundsResponseData {
|
||||||
connector_refund_id: item.response.response.action_id.clone(),
|
connector_refund_id: item.response.response.action_id.clone(),
|
||||||
refund_status,
|
refund_status,
|
||||||
}),
|
}),
|
||||||
error_response: None,
|
|
||||||
..item.data
|
..item.data
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -342,11 +339,10 @@ impl TryFrom<types::RefundsResponseRouterData<api::Execute, &ActionResponse>>
|
|||||||
) -> Result<Self, Self::Error> {
|
) -> Result<Self, Self::Error> {
|
||||||
let refund_status = enums::RefundStatus::from(item.response);
|
let refund_status = enums::RefundStatus::from(item.response);
|
||||||
Ok(types::RouterData {
|
Ok(types::RouterData {
|
||||||
response: Some(types::RefundsResponseData {
|
response: Ok(types::RefundsResponseData {
|
||||||
connector_refund_id: item.response.action_id.clone(),
|
connector_refund_id: item.response.action_id.clone(),
|
||||||
refund_status,
|
refund_status,
|
||||||
}),
|
}),
|
||||||
error_response: None,
|
|
||||||
..item.data
|
..item.data
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -361,11 +357,10 @@ impl TryFrom<types::RefundsResponseRouterData<api::RSync, &ActionResponse>>
|
|||||||
) -> Result<Self, Self::Error> {
|
) -> Result<Self, Self::Error> {
|
||||||
let refund_status = enums::RefundStatus::from(item.response);
|
let refund_status = enums::RefundStatus::from(item.response);
|
||||||
Ok(types::RouterData {
|
Ok(types::RouterData {
|
||||||
response: Some(types::RefundsResponseData {
|
response: Ok(types::RefundsResponseData {
|
||||||
connector_refund_id: item.response.action_id.clone(),
|
connector_refund_id: item.response.action_id.clone(),
|
||||||
refund_status,
|
refund_status,
|
||||||
}),
|
}),
|
||||||
error_response: None,
|
|
||||||
..item.data
|
..item.data
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@ -669,6 +669,7 @@ impl
|
|||||||
let id = req
|
let id = req
|
||||||
.response
|
.response
|
||||||
.as_ref()
|
.as_ref()
|
||||||
|
.ok()
|
||||||
.get_required_value("response")
|
.get_required_value("response")
|
||||||
.change_context(errors::ConnectorError::FailedToObtainIntegrationUrl)?
|
.change_context(errors::ConnectorError::FailedToObtainIntegrationUrl)?
|
||||||
.connector_refund_id
|
.connector_refund_id
|
||||||
|
|||||||
@ -313,12 +313,11 @@ impl<F, T>
|
|||||||
// description: item.response.description.map(|x| x.as_str()),
|
// description: item.response.description.map(|x| x.as_str()),
|
||||||
// statement_descriptor_suffix: item.response.statement_descriptor_suffix.map(|x| x.as_str()),
|
// statement_descriptor_suffix: item.response.statement_descriptor_suffix.map(|x| x.as_str()),
|
||||||
// three_ds_form,
|
// three_ds_form,
|
||||||
response: Some(types::PaymentsResponseData {
|
response: Ok(types::PaymentsResponseData {
|
||||||
connector_transaction_id: item.response.id,
|
connector_transaction_id: item.response.id,
|
||||||
redirect: redirection_data.is_some(),
|
redirect: redirection_data.is_some(),
|
||||||
redirection_data,
|
redirection_data,
|
||||||
}),
|
}),
|
||||||
error_response: None,
|
|
||||||
..item.data
|
..item.data
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -435,11 +434,10 @@ impl TryFrom<types::RefundsResponseRouterData<api::Execute, RefundResponse>>
|
|||||||
item: types::RefundsResponseRouterData<api::Execute, RefundResponse>,
|
item: types::RefundsResponseRouterData<api::Execute, RefundResponse>,
|
||||||
) -> Result<Self, Self::Error> {
|
) -> Result<Self, Self::Error> {
|
||||||
Ok(types::RouterData {
|
Ok(types::RouterData {
|
||||||
response: Some(types::RefundsResponseData {
|
response: Ok(types::RefundsResponseData {
|
||||||
connector_refund_id: item.response.id,
|
connector_refund_id: item.response.id,
|
||||||
refund_status: enums::RefundStatus::from(item.response.status),
|
refund_status: enums::RefundStatus::from(item.response.status),
|
||||||
}),
|
}),
|
||||||
error_response: None,
|
|
||||||
..item.data
|
..item.data
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -453,11 +451,10 @@ impl TryFrom<types::RefundsResponseRouterData<api::RSync, RefundResponse>>
|
|||||||
item: types::RefundsResponseRouterData<api::RSync, RefundResponse>,
|
item: types::RefundsResponseRouterData<api::RSync, RefundResponse>,
|
||||||
) -> Result<Self, Self::Error> {
|
) -> Result<Self, Self::Error> {
|
||||||
Ok(types::RouterData {
|
Ok(types::RouterData {
|
||||||
response: Some(types::RefundsResponseData {
|
response: Ok(types::RefundsResponseData {
|
||||||
connector_refund_id: item.response.id,
|
connector_refund_id: item.response.id,
|
||||||
refund_status: enums::RefundStatus::from(item.response.status),
|
refund_status: enums::RefundStatus::from(item.response.status),
|
||||||
}),
|
}),
|
||||||
error_response: None,
|
|
||||||
..item.data
|
..item.data
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@ -14,7 +14,7 @@ use crate::{
|
|||||||
self, api,
|
self, api,
|
||||||
storage::{self, enums},
|
storage::{self, enums},
|
||||||
},
|
},
|
||||||
utils::{self, OptionExt},
|
utils,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, router_derive::PaymentOperation)]
|
#[derive(Debug, Clone, Copy, router_derive::PaymentOperation)]
|
||||||
@ -117,16 +117,12 @@ async fn payment_response_ut<F: Clone, T>(
|
|||||||
let router_data = response.ok_or(report!(errors::ApiErrorResponse::InternalServerError))?;
|
let router_data = response.ok_or(report!(errors::ApiErrorResponse::InternalServerError))?;
|
||||||
let mut connector_response_data = None;
|
let mut connector_response_data = None;
|
||||||
|
|
||||||
let payment_attempt_update = match router_data.error_response.as_ref() {
|
let payment_attempt_update = match router_data.response.clone() {
|
||||||
Some(err) => storage::PaymentAttemptUpdate::ErrorUpdate {
|
Err(err) => storage::PaymentAttemptUpdate::ErrorUpdate {
|
||||||
status: storage::enums::AttemptStatus::Failure,
|
status: storage::enums::AttemptStatus::Failure,
|
||||||
error_message: Some(err.message.to_owned()),
|
error_message: Some(err.message),
|
||||||
},
|
},
|
||||||
None => {
|
Ok(response) => {
|
||||||
let response = router_data
|
|
||||||
.response
|
|
||||||
.get_required_value("router_data.response")?;
|
|
||||||
|
|
||||||
connector_response_data = Some(response.clone());
|
connector_response_data = Some(response.clone());
|
||||||
|
|
||||||
storage::PaymentAttemptUpdate::ResponseUpdate {
|
storage::PaymentAttemptUpdate::ResponseUpdate {
|
||||||
@ -169,11 +165,11 @@ async fn payment_response_ut<F: Clone, T>(
|
|||||||
None => payment_data.connector_response,
|
None => payment_data.connector_response,
|
||||||
};
|
};
|
||||||
|
|
||||||
let payment_intent_update = match router_data.error_response {
|
let payment_intent_update = match router_data.response {
|
||||||
Some(_) => storage::PaymentIntentUpdate::PGStatusUpdate {
|
Err(_) => storage::PaymentIntentUpdate::PGStatusUpdate {
|
||||||
status: enums::IntentStatus::Failed,
|
status: enums::IntentStatus::Failed,
|
||||||
},
|
},
|
||||||
None => storage::PaymentIntentUpdate::ResponseUpdate {
|
Ok(_) => storage::PaymentIntentUpdate::ResponseUpdate {
|
||||||
status: router_data.status.into(),
|
status: router_data.status.into(),
|
||||||
return_url: router_data.return_url,
|
return_url: router_data.return_url,
|
||||||
amount_captured: None,
|
amount_captured: None,
|
||||||
|
|||||||
@ -101,9 +101,7 @@ where
|
|||||||
|
|
||||||
request: T::try_from(payment_data.clone())?,
|
request: T::try_from(payment_data.clone())?,
|
||||||
|
|
||||||
response,
|
response: response.map_or_else(|| Err(types::ErrorResponse::default()), Ok),
|
||||||
|
|
||||||
error_response: None,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok((payment_data, router_data))
|
Ok((payment_data, router_data))
|
||||||
|
|||||||
@ -129,21 +129,18 @@ pub async fn trigger_refund_to_gateway(
|
|||||||
.await
|
.await
|
||||||
.map_err(|error| error.to_refund_failed_response())?;
|
.map_err(|error| error.to_refund_failed_response())?;
|
||||||
|
|
||||||
let refund_update = match router_data.error_response {
|
let refund_update = match router_data.response {
|
||||||
Some(err) => storage::RefundUpdate::ErrorUpdate {
|
Err(err) => storage::RefundUpdate::ErrorUpdate {
|
||||||
refund_status: enums::RefundStatus::Failure,
|
refund_status: Some(enums::RefundStatus::Failure),
|
||||||
refund_error_message: Some(err.message),
|
refund_error_message: Some(err.message),
|
||||||
},
|
},
|
||||||
None => {
|
Ok(response) => storage::RefundUpdate::Update {
|
||||||
let response = router_data.response.get_required_value("response")?;
|
pg_refund_id: response.connector_refund_id,
|
||||||
storage::RefundUpdate::Update {
|
refund_status: response.refund_status,
|
||||||
pg_refund_id: response.connector_refund_id,
|
sent_to_gateway: true,
|
||||||
refund_status: response.refund_status,
|
refund_error_message: None,
|
||||||
sent_to_gateway: true,
|
refund_arn: "".to_string(),
|
||||||
refund_error_message: router_data.error_response.map(|error| error.message),
|
},
|
||||||
refund_arn: "".to_string(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let response = state
|
let response = state
|
||||||
@ -241,24 +238,18 @@ pub async fn sync_refund_with_gateway(
|
|||||||
.await
|
.await
|
||||||
.map_err(|error| error.to_refund_failed_response())?;
|
.map_err(|error| error.to_refund_failed_response())?;
|
||||||
|
|
||||||
let refund_update = match router_data.error_response {
|
let refund_update = match router_data.response {
|
||||||
Some(error_message) => {
|
Err(error_message) => storage::RefundUpdate::ErrorUpdate {
|
||||||
let response = router_data.response.get_required_value("response")?;
|
refund_status: None,
|
||||||
storage::RefundUpdate::ErrorUpdate {
|
refund_error_message: Some(error_message.message),
|
||||||
refund_status: response.refund_status,
|
},
|
||||||
refund_error_message: Some(error_message.message),
|
Ok(response) => storage::RefundUpdate::Update {
|
||||||
}
|
pg_refund_id: response.connector_refund_id,
|
||||||
}
|
refund_status: response.refund_status,
|
||||||
None => {
|
sent_to_gateway: true,
|
||||||
let response = router_data.response.get_required_value("response")?;
|
refund_error_message: None,
|
||||||
storage::RefundUpdate::Update {
|
refund_arn: "".to_string(),
|
||||||
pg_refund_id: response.connector_refund_id,
|
},
|
||||||
refund_status: response.refund_status,
|
|
||||||
sent_to_gateway: true,
|
|
||||||
refund_error_message: router_data.error_response.map(|error| error.message),
|
|
||||||
refund_arn: "".to_string(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let response = state
|
let response = state
|
||||||
@ -445,11 +436,13 @@ impl<F> TryFrom<types::RefundsRouterData<F>> for refunds::RefundResponse {
|
|||||||
type Error = error_stack::Report<errors::ApiErrorResponse>;
|
type Error = error_stack::Report<errors::ApiErrorResponse>;
|
||||||
fn try_from(data: types::RefundsRouterData<F>) -> RouterResult<Self> {
|
fn try_from(data: types::RefundsRouterData<F>) -> RouterResult<Self> {
|
||||||
let refund_id = data.request.refund_id.to_string();
|
let refund_id = data.request.refund_id.to_string();
|
||||||
let status = data
|
let response = data.response;
|
||||||
.response
|
|
||||||
.get_required_value("response")?
|
let (status, error_message) = match response {
|
||||||
.refund_status
|
Ok(response) => (response.refund_status.into(), None),
|
||||||
.into();
|
Err(error_response) => (api::RefundStatus::Pending, Some(error_response.message)),
|
||||||
|
};
|
||||||
|
|
||||||
Ok(refunds::RefundResponse {
|
Ok(refunds::RefundResponse {
|
||||||
payment_id: data.payment_id,
|
payment_id: data.payment_id,
|
||||||
refund_id,
|
refund_id,
|
||||||
@ -458,9 +451,7 @@ impl<F> TryFrom<types::RefundsRouterData<F>> for refunds::RefundResponse {
|
|||||||
reason: Some("TODO: Not propagated".to_string()), // TODO: Not propagated
|
reason: Some("TODO: Not propagated".to_string()), // TODO: Not propagated
|
||||||
status,
|
status,
|
||||||
metadata: None,
|
metadata: None,
|
||||||
error_message: data
|
error_message,
|
||||||
.error_response
|
|
||||||
.map(|error_response| error_response.message),
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -89,12 +89,10 @@ pub async fn construct_refund_router_data<'a, F>(
|
|||||||
refund_amount: refund.refund_amount,
|
refund_amount: refund.refund_amount,
|
||||||
},
|
},
|
||||||
|
|
||||||
response: Some(types::RefundsResponseData {
|
response: Ok(types::RefundsResponseData {
|
||||||
connector_refund_id: refund.pg_refund_id.clone().unwrap_or_default(),
|
connector_refund_id: refund.pg_refund_id.clone().unwrap_or_default(),
|
||||||
refund_status: refund.refund_status,
|
refund_status: refund.refund_status,
|
||||||
}),
|
}),
|
||||||
|
|
||||||
error_response: None,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(router_data)
|
Ok(router_data)
|
||||||
|
|||||||
@ -147,7 +147,7 @@ where
|
|||||||
Err(body) => {
|
Err(body) => {
|
||||||
let error =
|
let error =
|
||||||
connector_integration.get_error_response(body.response)?;
|
connector_integration.get_error_response(body.response)?;
|
||||||
router_data.error_response = Some(error);
|
router_data.response = Err(error);
|
||||||
|
|
||||||
router_data
|
router_data
|
||||||
}
|
}
|
||||||
|
|||||||
@ -54,11 +54,9 @@ pub struct RouterData<Flow, Request, Response> {
|
|||||||
pub request: Request,
|
pub request: Request,
|
||||||
|
|
||||||
/// Contains flow-specific data that the connector responds with.
|
/// Contains flow-specific data that the connector responds with.
|
||||||
pub response: Option<Response>,
|
pub response: Result<Response, ErrorResponse>,
|
||||||
|
|
||||||
/// Contains any error response that the connector returns.
|
/// Contains any error response that the connector returns.
|
||||||
pub error_response: Option<ErrorResponse>,
|
|
||||||
|
|
||||||
pub payment_method_id: Option<String>,
|
pub payment_method_id: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -197,3 +195,19 @@ impl ErrorResponse {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<ApiErrorResponse> for ErrorResponse {
|
||||||
|
fn from(error: ApiErrorResponse) -> Self {
|
||||||
|
Self {
|
||||||
|
code: error.error_code(),
|
||||||
|
message: error.error_message(),
|
||||||
|
reason: None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for ErrorResponse {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self::from(ApiErrorResponse::InternalServerError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@ -73,7 +73,7 @@ pub enum RefundUpdate {
|
|||||||
refund_status: enums::RefundStatus,
|
refund_status: enums::RefundStatus,
|
||||||
},
|
},
|
||||||
ErrorUpdate {
|
ErrorUpdate {
|
||||||
refund_status: enums::RefundStatus,
|
refund_status: Option<enums::RefundStatus>,
|
||||||
refund_error_message: Option<String>,
|
refund_error_message: Option<String>,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -124,7 +124,7 @@ impl From<RefundUpdate> for RefundUpdateInternal {
|
|||||||
refund_status,
|
refund_status,
|
||||||
refund_error_message,
|
refund_error_message,
|
||||||
} => Self {
|
} => Self {
|
||||||
refund_status: Some(refund_status),
|
refund_status,
|
||||||
refund_error_message,
|
refund_error_message,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
|
|||||||
@ -48,9 +48,8 @@ fn construct_payment_router_data() -> types::PaymentsRouterData {
|
|||||||
capture_method: None,
|
capture_method: None,
|
||||||
browser_info: None,
|
browser_info: None,
|
||||||
},
|
},
|
||||||
response: None,
|
response: Err(types::ErrorResponse::default()),
|
||||||
payment_method_id: None,
|
payment_method_id: None,
|
||||||
error_response: None,
|
|
||||||
address: PaymentAddress::default(),
|
address: PaymentAddress::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -87,8 +86,7 @@ fn construct_refund_router_data<F>() -> types::RefundsRouterData<F> {
|
|||||||
refund_amount: 100,
|
refund_amount: 100,
|
||||||
},
|
},
|
||||||
payment_method_id: None,
|
payment_method_id: None,
|
||||||
response: None,
|
response: Err(types::ErrorResponse::default()),
|
||||||
error_response: None,
|
|
||||||
address: PaymentAddress::default(),
|
address: PaymentAddress::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -49,8 +49,7 @@ fn construct_payment_router_data() -> types::PaymentsRouterData {
|
|||||||
browser_info: None,
|
browser_info: None,
|
||||||
},
|
},
|
||||||
payment_method_id: None,
|
payment_method_id: None,
|
||||||
response: None,
|
response: Err(types::ErrorResponse::default()),
|
||||||
error_response: None,
|
|
||||||
address: PaymentAddress::default(),
|
address: PaymentAddress::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -86,9 +85,8 @@ fn construct_refund_router_data<F>() -> types::RefundsRouterData<F> {
|
|||||||
connector_transaction_id: String::new(),
|
connector_transaction_id: String::new(),
|
||||||
refund_amount: 1,
|
refund_amount: 1,
|
||||||
},
|
},
|
||||||
response: None,
|
response: Err(types::ErrorResponse::default()),
|
||||||
payment_method_id: None,
|
payment_method_id: None,
|
||||||
error_response: None,
|
|
||||||
address: PaymentAddress::default(),
|
address: PaymentAddress::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -44,9 +44,8 @@ fn construct_payment_router_data() -> types::PaymentsRouterData {
|
|||||||
capture_method: None,
|
capture_method: None,
|
||||||
browser_info: None,
|
browser_info: None,
|
||||||
},
|
},
|
||||||
response: None,
|
response: Err(types::ErrorResponse::default()),
|
||||||
payment_method_id: None,
|
payment_method_id: None,
|
||||||
error_response: None,
|
|
||||||
address: PaymentAddress::default(),
|
address: PaymentAddress::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -82,9 +81,8 @@ fn construct_refund_router_data<F>() -> types::RefundsRouterData<F> {
|
|||||||
connector_transaction_id: String::new(),
|
connector_transaction_id: String::new(),
|
||||||
refund_amount: 10,
|
refund_amount: 10,
|
||||||
},
|
},
|
||||||
response: None,
|
response: Err(types::ErrorResponse::default()),
|
||||||
payment_method_id: None,
|
payment_method_id: None,
|
||||||
error_response: None,
|
|
||||||
address: PaymentAddress::default(),
|
address: PaymentAddress::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -284,8 +282,8 @@ async fn test_checkout_refund_failure() {
|
|||||||
|
|
||||||
println!("{response:?}");
|
println!("{response:?}");
|
||||||
let response = response.unwrap();
|
let response = response.unwrap();
|
||||||
assert!(response.error_response.is_some());
|
assert!(response.response.is_err());
|
||||||
|
|
||||||
let code = response.error_response.unwrap().code;
|
let code = response.response.unwrap_err().code;
|
||||||
assert_eq!(code, "refund_amount_exceeds_balance");
|
assert_eq!(code, "refund_amount_exceeds_balance");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user