chore(router): clippy::use_self (#203)

This commit is contained in:
kos-for-juspay
2022-12-22 06:50:53 +01:00
committed by GitHub
parent 939827da8f
commit e044451a4b
28 changed files with 336 additions and 380 deletions

View File

@ -205,17 +205,17 @@ fn error_response<T: Display>(err: &T) -> actix_web::HttpResponse {
impl ResponseError for BachError {
fn status_code(&self) -> StatusCode {
match self {
BachError::EParsingError(_)
| BachError::EAuthenticationError(_)
| BachError::EAuthorisationError(_) => StatusCode::BAD_REQUEST,
Self::EParsingError(_)
| Self::EAuthenticationError(_)
| Self::EAuthorisationError(_) => StatusCode::BAD_REQUEST,
BachError::EDatabaseError(_)
| BachError::NotImplementedByConnector(_)
| BachError::EMetrics(_)
| BachError::EIo(_)
| BachError::ConfigurationError(_)
| BachError::EEncryptionError(_)
| BachError::EUnexpectedError(_) => StatusCode::INTERNAL_SERVER_ERROR,
Self::EDatabaseError(_)
| Self::NotImplementedByConnector(_)
| Self::EMetrics(_)
| Self::EIo(_)
| Self::ConfigurationError(_)
| Self::EEncryptionError(_)
| Self::EUnexpectedError(_) => StatusCode::INTERNAL_SERVER_ERROR,
}
}

View File

@ -148,53 +148,55 @@ impl actix_web::ResponseError for ApiErrorResponse {
use reqwest::StatusCode;
match self {
ApiErrorResponse::Unauthorized
| ApiErrorResponse::BadCredentials
| ApiErrorResponse::InvalidEphermeralKey => StatusCode::UNAUTHORIZED, // 401
ApiErrorResponse::InvalidRequestUrl => StatusCode::NOT_FOUND, // 404
ApiErrorResponse::InvalidHttpMethod => StatusCode::METHOD_NOT_ALLOWED, // 405
ApiErrorResponse::MissingRequiredField { .. }
| ApiErrorResponse::InvalidDataValue { .. } => StatusCode::BAD_REQUEST, // 400
ApiErrorResponse::InvalidDataFormat { .. }
| ApiErrorResponse::InvalidRequestData { .. } => StatusCode::UNPROCESSABLE_ENTITY, // 422
ApiErrorResponse::RefundAmountExceedsPaymentAmount => StatusCode::BAD_REQUEST, // 400
ApiErrorResponse::MaximumRefundCount => StatusCode::BAD_REQUEST, // 400
ApiErrorResponse::PreconditionFailed { .. } => StatusCode::BAD_REQUEST, // 400
Self::Unauthorized | Self::BadCredentials | Self::InvalidEphermeralKey => {
StatusCode::UNAUTHORIZED
} // 401
Self::InvalidRequestUrl => StatusCode::NOT_FOUND, // 404
Self::InvalidHttpMethod => StatusCode::METHOD_NOT_ALLOWED, // 405
Self::MissingRequiredField { .. } | Self::InvalidDataValue { .. } => {
StatusCode::BAD_REQUEST
} // 400
Self::InvalidDataFormat { .. } | Self::InvalidRequestData { .. } => {
StatusCode::UNPROCESSABLE_ENTITY
} // 422
Self::RefundAmountExceedsPaymentAmount => StatusCode::BAD_REQUEST, // 400
Self::MaximumRefundCount => StatusCode::BAD_REQUEST, // 400
Self::PreconditionFailed { .. } => StatusCode::BAD_REQUEST, // 400
ApiErrorResponse::PaymentAuthorizationFailed { .. }
| ApiErrorResponse::PaymentAuthenticationFailed { .. }
| ApiErrorResponse::PaymentCaptureFailed { .. }
| ApiErrorResponse::InvalidCardData { .. }
| ApiErrorResponse::CardExpired { .. }
| ApiErrorResponse::RefundFailed { .. }
| ApiErrorResponse::VerificationFailed { .. }
| ApiErrorResponse::PaymentUnexpectedState { .. }
| ApiErrorResponse::MandateValidationFailed { .. } => StatusCode::BAD_REQUEST, // 400
Self::PaymentAuthorizationFailed { .. }
| Self::PaymentAuthenticationFailed { .. }
| Self::PaymentCaptureFailed { .. }
| Self::InvalidCardData { .. }
| Self::CardExpired { .. }
| Self::RefundFailed { .. }
| Self::VerificationFailed { .. }
| Self::PaymentUnexpectedState { .. }
| Self::MandateValidationFailed { .. } => StatusCode::BAD_REQUEST, // 400
ApiErrorResponse::InternalServerError => StatusCode::INTERNAL_SERVER_ERROR, // 500
ApiErrorResponse::DuplicateRefundRequest => StatusCode::BAD_REQUEST, // 400
ApiErrorResponse::RefundNotFound
| ApiErrorResponse::CustomerNotFound
| ApiErrorResponse::MandateActive
| ApiErrorResponse::CustomerRedacted
| ApiErrorResponse::PaymentNotFound
| ApiErrorResponse::PaymentMethodNotFound
| ApiErrorResponse::MerchantAccountNotFound
| ApiErrorResponse::MerchantConnectorAccountNotFound
| ApiErrorResponse::MandateNotFound
| ApiErrorResponse::ClientSecretNotGiven
| ApiErrorResponse::ClientSecretInvalid
| ApiErrorResponse::SuccessfulPaymentNotFound
| ApiErrorResponse::IncorrectConnectorNameGiven
| ApiErrorResponse::ResourceIdNotFound
| ApiErrorResponse::AddressNotFound => StatusCode::BAD_REQUEST, // 400
ApiErrorResponse::DuplicateMerchantAccount
| ApiErrorResponse::DuplicateMerchantConnectorAccount
| ApiErrorResponse::DuplicatePaymentMethod
| ApiErrorResponse::DuplicateMandate => StatusCode::BAD_REQUEST, // 400
ApiErrorResponse::ReturnUrlUnavailable => StatusCode::SERVICE_UNAVAILABLE, // 503
ApiErrorResponse::PaymentNotSucceeded => StatusCode::BAD_REQUEST, // 400
ApiErrorResponse::NotImplemented => StatusCode::NOT_IMPLEMENTED, // 501
Self::InternalServerError => StatusCode::INTERNAL_SERVER_ERROR, // 500
Self::DuplicateRefundRequest => StatusCode::BAD_REQUEST, // 400
Self::RefundNotFound
| Self::CustomerNotFound
| Self::MandateActive
| Self::CustomerRedacted
| Self::PaymentNotFound
| Self::PaymentMethodNotFound
| Self::MerchantAccountNotFound
| Self::MerchantConnectorAccountNotFound
| Self::MandateNotFound
| Self::ClientSecretNotGiven
| Self::ClientSecretInvalid
| Self::SuccessfulPaymentNotFound
| Self::IncorrectConnectorNameGiven
| Self::ResourceIdNotFound
| Self::AddressNotFound => StatusCode::BAD_REQUEST, // 400
Self::DuplicateMerchantAccount
| Self::DuplicateMerchantConnectorAccount
| Self::DuplicatePaymentMethod
| Self::DuplicateMandate => StatusCode::BAD_REQUEST, // 400
Self::ReturnUrlUnavailable => StatusCode::SERVICE_UNAVAILABLE, // 503
Self::PaymentNotSucceeded => StatusCode::BAD_REQUEST, // 400
Self::NotImplemented => StatusCode::NOT_IMPLEMENTED, // 501
}
}

View File

@ -83,7 +83,7 @@ impl PaymentsAuthorizeRouterData {
confirm: Option<bool>,
call_connector_action: payments::CallConnectorAction,
_storage_scheme: storage_enums::MerchantStorageScheme,
) -> RouterResult<PaymentsAuthorizeRouterData> {
) -> RouterResult<Self> {
match confirm {
Some(true) => {
let connector_integration: services::BoxedConnectorIntegration<

View File

@ -67,7 +67,7 @@ impl PaymentsCancelRouterData {
_maybe_customer: &Option<storage::Customer>,
_confirm: Option<bool>,
call_connector_action: payments::CallConnectorAction,
) -> RouterResult<PaymentsCancelRouterData> {
) -> RouterResult<Self> {
let connector_integration: services::BoxedConnectorIntegration<
api::Void,
types::PaymentsCancelData,

View File

@ -68,7 +68,7 @@ impl PaymentsCaptureRouterData {
_maybe_customer: &Option<storage::Customer>,
_confirm: Option<bool>,
call_connector_action: payments::CallConnectorAction,
) -> RouterResult<PaymentsCaptureRouterData> {
) -> RouterResult<Self> {
let connector_integration: services::BoxedConnectorIntegration<
api::Capture,
PaymentsCaptureData,

View File

@ -68,7 +68,7 @@ impl PaymentsSyncRouterData {
_maybe_customer: &Option<storage::Customer>,
_confirm: Option<bool>,
call_connector_action: payments::CallConnectorAction,
) -> RouterResult<PaymentsSyncRouterData> {
) -> RouterResult<Self> {
let connector_integration: services::BoxedConnectorIntegration<
api::PSync,
PaymentsSyncData,

View File

@ -105,7 +105,7 @@ impl types::PaymentsSessionRouterData {
_customer: &Option<storage::Customer>,
_confirm: Option<bool>,
call_connector_action: payments::CallConnectorAction,
) -> RouterResult<types::PaymentsSessionRouterData> {
) -> RouterResult<Self> {
match connector.get_token {
api::GetToken::Metadata => create_gpay_session_token(self),
api::GetToken::Connector => {

View File

@ -497,6 +497,7 @@ fn mk_new_refund(
impl<F> TryFrom<types::RefundsRouterData<F>> for refunds::RefundResponse {
type Error = error_stack::Report<errors::ApiErrorResponse>;
fn try_from(data: types::RefundsRouterData<F>) -> RouterResult<Self> {
let refund_id = data.request.refund_id.to_string();
let response = data.response;
@ -506,7 +507,7 @@ impl<F> TryFrom<types::RefundsRouterData<F>> for refunds::RefundResponse {
Err(error_response) => (api::RefundStatus::Pending, Some(error_response.message)),
};
Ok(refunds::RefundResponse {
Ok(Self {
payment_id: data.payment_id,
refund_id,
amount: data.request.amount / 100,