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

@ -314,11 +314,11 @@ impl From<errors::ApiErrorResponse> for StripeErrorCode {
fn from(value: errors::ApiErrorResponse) -> Self {
match value {
errors::ApiErrorResponse::Unauthorized
| errors::ApiErrorResponse::InvalidEphermeralKey => StripeErrorCode::Unauthorized,
| errors::ApiErrorResponse::InvalidEphermeralKey => Self::Unauthorized,
errors::ApiErrorResponse::InvalidRequestUrl
| errors::ApiErrorResponse::InvalidHttpMethod => StripeErrorCode::InvalidRequestUrl,
| errors::ApiErrorResponse::InvalidHttpMethod => Self::InvalidRequestUrl,
errors::ApiErrorResponse::MissingRequiredField { field_name } => {
StripeErrorCode::ParameterMissing {
Self::ParameterMissing {
field_name: field_name.to_owned(),
param: field_name,
}
@ -327,98 +327,80 @@ impl From<errors::ApiErrorResponse> for StripeErrorCode {
errors::ApiErrorResponse::InvalidDataFormat {
field_name,
expected_format,
} => StripeErrorCode::ParameterUnknown {
} => Self::ParameterUnknown {
field_name,
expected_format,
},
errors::ApiErrorResponse::RefundAmountExceedsPaymentAmount => {
StripeErrorCode::RefundAmountExceedsPaymentAmount {
Self::RefundAmountExceedsPaymentAmount {
param: "amount".to_owned(),
}
}
errors::ApiErrorResponse::PaymentAuthorizationFailed { data }
| errors::ApiErrorResponse::PaymentAuthenticationFailed { data } => {
StripeErrorCode::PaymentIntentAuthenticationFailure { data }
Self::PaymentIntentAuthenticationFailure { data }
}
errors::ApiErrorResponse::VerificationFailed { data } => {
StripeErrorCode::VerificationFailed { data }
Self::VerificationFailed { data }
}
errors::ApiErrorResponse::PaymentCaptureFailed { data } => {
StripeErrorCode::PaymentIntentPaymentAttemptFailed { data }
Self::PaymentIntentPaymentAttemptFailed { data }
}
errors::ApiErrorResponse::InvalidCardData { data } => StripeErrorCode::InvalidCardType, // Maybe it is better to de generalize this router error
errors::ApiErrorResponse::CardExpired { data } => StripeErrorCode::ExpiredCard,
errors::ApiErrorResponse::RefundFailed { data } => StripeErrorCode::RefundFailed, // Nothing at stripe to map
errors::ApiErrorResponse::InvalidCardData { data } => Self::InvalidCardType, // Maybe it is better to de generalize this router error
errors::ApiErrorResponse::CardExpired { data } => Self::ExpiredCard,
errors::ApiErrorResponse::RefundFailed { data } => Self::RefundFailed, // Nothing at stripe to map
errors::ApiErrorResponse::InternalServerError => StripeErrorCode::InternalServerError, // not a stripe code
errors::ApiErrorResponse::IncorrectConnectorNameGiven => {
StripeErrorCode::InternalServerError
}
errors::ApiErrorResponse::MandateActive => StripeErrorCode::MandateActive, //not a stripe code
errors::ApiErrorResponse::CustomerRedacted => StripeErrorCode::CustomerRedacted, //not a stripe code
errors::ApiErrorResponse::DuplicateRefundRequest => {
StripeErrorCode::DuplicateRefundRequest
}
errors::ApiErrorResponse::RefundNotFound => StripeErrorCode::RefundNotFound,
errors::ApiErrorResponse::CustomerNotFound => StripeErrorCode::CustomerNotFound,
errors::ApiErrorResponse::PaymentNotFound => StripeErrorCode::PaymentNotFound,
errors::ApiErrorResponse::PaymentMethodNotFound => {
StripeErrorCode::PaymentMethodNotFound
}
errors::ApiErrorResponse::ClientSecretNotGiven => StripeErrorCode::ClientSecretNotFound,
errors::ApiErrorResponse::MerchantAccountNotFound => {
StripeErrorCode::MerchantAccountNotFound
}
errors::ApiErrorResponse::ResourceIdNotFound => StripeErrorCode::ResourceIdNotFound,
errors::ApiErrorResponse::InternalServerError => Self::InternalServerError, // not a stripe code
errors::ApiErrorResponse::IncorrectConnectorNameGiven => Self::InternalServerError,
errors::ApiErrorResponse::MandateActive => Self::MandateActive, //not a stripe code
errors::ApiErrorResponse::CustomerRedacted => Self::CustomerRedacted, //not a stripe code
errors::ApiErrorResponse::DuplicateRefundRequest => Self::DuplicateRefundRequest,
errors::ApiErrorResponse::RefundNotFound => Self::RefundNotFound,
errors::ApiErrorResponse::CustomerNotFound => Self::CustomerNotFound,
errors::ApiErrorResponse::PaymentNotFound => Self::PaymentNotFound,
errors::ApiErrorResponse::PaymentMethodNotFound => Self::PaymentMethodNotFound,
errors::ApiErrorResponse::ClientSecretNotGiven => Self::ClientSecretNotFound,
errors::ApiErrorResponse::MerchantAccountNotFound => Self::MerchantAccountNotFound,
errors::ApiErrorResponse::ResourceIdNotFound => Self::ResourceIdNotFound,
errors::ApiErrorResponse::MerchantConnectorAccountNotFound => {
StripeErrorCode::MerchantConnectorAccountNotFound
Self::MerchantConnectorAccountNotFound
}
errors::ApiErrorResponse::MandateNotFound => StripeErrorCode::MandateNotFound,
errors::ApiErrorResponse::MandateNotFound => Self::MandateNotFound,
errors::ApiErrorResponse::MandateValidationFailed { reason } => {
StripeErrorCode::PaymentIntentMandateInvalid { message: reason }
}
errors::ApiErrorResponse::ReturnUrlUnavailable => StripeErrorCode::ReturnUrlUnavailable,
errors::ApiErrorResponse::DuplicateMerchantAccount => {
StripeErrorCode::DuplicateMerchantAccount
Self::PaymentIntentMandateInvalid { message: reason }
}
errors::ApiErrorResponse::ReturnUrlUnavailable => Self::ReturnUrlUnavailable,
errors::ApiErrorResponse::DuplicateMerchantAccount => Self::DuplicateMerchantAccount,
errors::ApiErrorResponse::DuplicateMerchantConnectorAccount => {
StripeErrorCode::DuplicateMerchantConnectorAccount
}
errors::ApiErrorResponse::DuplicatePaymentMethod => {
StripeErrorCode::DuplicatePaymentMethod
}
errors::ApiErrorResponse::ClientSecretInvalid => {
StripeErrorCode::PaymentIntentInvalidParameter {
param: "client_secret".to_owned(),
}
Self::DuplicateMerchantConnectorAccount
}
errors::ApiErrorResponse::DuplicatePaymentMethod => Self::DuplicatePaymentMethod,
errors::ApiErrorResponse::ClientSecretInvalid => Self::PaymentIntentInvalidParameter {
param: "client_secret".to_owned(),
},
errors::ApiErrorResponse::InvalidRequestData { message } => {
StripeErrorCode::InvalidRequestData { message }
Self::InvalidRequestData { message }
}
errors::ApiErrorResponse::PreconditionFailed { message } => {
StripeErrorCode::PreconditionFailed { message }
Self::PreconditionFailed { message }
}
errors::ApiErrorResponse::BadCredentials => StripeErrorCode::Unauthorized,
errors::ApiErrorResponse::InvalidDataValue { field_name } => {
StripeErrorCode::ParameterMissing {
field_name: field_name.to_owned(),
param: field_name.to_owned(),
}
}
errors::ApiErrorResponse::MaximumRefundCount => StripeErrorCode::MaximumRefundCount,
errors::ApiErrorResponse::PaymentNotSucceeded => StripeErrorCode::PaymentFailed,
errors::ApiErrorResponse::DuplicateMandate => StripeErrorCode::DuplicateMandate,
errors::ApiErrorResponse::SuccessfulPaymentNotFound => {
StripeErrorCode::SuccessfulPaymentNotFound
}
errors::ApiErrorResponse::AddressNotFound => StripeErrorCode::AddressNotFound,
errors::ApiErrorResponse::NotImplemented => StripeErrorCode::Unauthorized,
errors::ApiErrorResponse::BadCredentials => Self::Unauthorized,
errors::ApiErrorResponse::InvalidDataValue { field_name } => Self::ParameterMissing {
field_name: field_name.to_owned(),
param: field_name.to_owned(),
},
errors::ApiErrorResponse::MaximumRefundCount => Self::MaximumRefundCount,
errors::ApiErrorResponse::PaymentNotSucceeded => Self::PaymentFailed,
errors::ApiErrorResponse::DuplicateMandate => Self::DuplicateMandate,
errors::ApiErrorResponse::SuccessfulPaymentNotFound => Self::SuccessfulPaymentNotFound,
errors::ApiErrorResponse::AddressNotFound => Self::AddressNotFound,
errors::ApiErrorResponse::NotImplemented => Self::Unauthorized,
errors::ApiErrorResponse::PaymentUnexpectedState {
current_flow,
field_name,
current_value,
states,
} => StripeErrorCode::PaymentIntentUnexpectedState {
} => Self::PaymentIntentUnexpectedState {
current_flow,
field_name,
current_value,
@ -433,45 +415,45 @@ impl actix_web::ResponseError for StripeErrorCode {
use reqwest::StatusCode;
match self {
StripeErrorCode::Unauthorized => StatusCode::UNAUTHORIZED,
StripeErrorCode::InvalidRequestUrl => StatusCode::NOT_FOUND,
StripeErrorCode::ParameterUnknown { .. } => StatusCode::UNPROCESSABLE_ENTITY,
StripeErrorCode::ParameterMissing { .. }
| StripeErrorCode::RefundAmountExceedsPaymentAmount { .. }
| StripeErrorCode::PaymentIntentAuthenticationFailure { .. }
| StripeErrorCode::PaymentIntentPaymentAttemptFailed { .. }
| StripeErrorCode::ExpiredCard
| StripeErrorCode::InvalidCardType
| StripeErrorCode::DuplicateRefundRequest
| StripeErrorCode::RefundNotFound
| StripeErrorCode::CustomerNotFound
| StripeErrorCode::ClientSecretNotFound
| StripeErrorCode::PaymentNotFound
| StripeErrorCode::PaymentMethodNotFound
| StripeErrorCode::MerchantAccountNotFound
| StripeErrorCode::MerchantConnectorAccountNotFound
| StripeErrorCode::MandateNotFound
| StripeErrorCode::DuplicateMerchantAccount
| StripeErrorCode::DuplicateMerchantConnectorAccount
| StripeErrorCode::DuplicatePaymentMethod
| StripeErrorCode::PaymentFailed
| StripeErrorCode::VerificationFailed { .. }
| StripeErrorCode::MaximumRefundCount
| StripeErrorCode::PaymentIntentInvalidParameter { .. }
| StripeErrorCode::SerdeQsError { .. }
| StripeErrorCode::InvalidRequestData { .. }
| StripeErrorCode::PreconditionFailed { .. }
| StripeErrorCode::DuplicateMandate
| StripeErrorCode::SuccessfulPaymentNotFound
| StripeErrorCode::AddressNotFound
| StripeErrorCode::ResourceIdNotFound
| StripeErrorCode::PaymentIntentMandateInvalid { .. }
| StripeErrorCode::PaymentIntentUnexpectedState { .. } => StatusCode::BAD_REQUEST,
StripeErrorCode::RefundFailed
| StripeErrorCode::InternalServerError
| StripeErrorCode::MandateActive
| StripeErrorCode::CustomerRedacted => StatusCode::INTERNAL_SERVER_ERROR,
StripeErrorCode::ReturnUrlUnavailable => StatusCode::SERVICE_UNAVAILABLE,
Self::Unauthorized => StatusCode::UNAUTHORIZED,
Self::InvalidRequestUrl => StatusCode::NOT_FOUND,
Self::ParameterUnknown { .. } => StatusCode::UNPROCESSABLE_ENTITY,
Self::ParameterMissing { .. }
| Self::RefundAmountExceedsPaymentAmount { .. }
| Self::PaymentIntentAuthenticationFailure { .. }
| Self::PaymentIntentPaymentAttemptFailed { .. }
| Self::ExpiredCard
| Self::InvalidCardType
| Self::DuplicateRefundRequest
| Self::RefundNotFound
| Self::CustomerNotFound
| Self::ClientSecretNotFound
| Self::PaymentNotFound
| Self::PaymentMethodNotFound
| Self::MerchantAccountNotFound
| Self::MerchantConnectorAccountNotFound
| Self::MandateNotFound
| Self::DuplicateMerchantAccount
| Self::DuplicateMerchantConnectorAccount
| Self::DuplicatePaymentMethod
| Self::PaymentFailed
| Self::VerificationFailed { .. }
| Self::MaximumRefundCount
| Self::PaymentIntentInvalidParameter { .. }
| Self::SerdeQsError { .. }
| Self::InvalidRequestData { .. }
| Self::PreconditionFailed { .. }
| Self::DuplicateMandate
| Self::SuccessfulPaymentNotFound
| Self::AddressNotFound
| Self::ResourceIdNotFound
| Self::PaymentIntentMandateInvalid { .. }
| Self::PaymentIntentUnexpectedState { .. } => StatusCode::BAD_REQUEST,
Self::RefundFailed
| Self::InternalServerError
| Self::MandateActive
| Self::CustomerRedacted => StatusCode::INTERNAL_SERVER_ERROR,
Self::ReturnUrlUnavailable => StatusCode::SERVICE_UNAVAILABLE,
}
}
@ -488,33 +470,33 @@ impl actix_web::ResponseError for StripeErrorCode {
impl From<serde_qs::Error> for StripeErrorCode {
fn from(item: serde_qs::Error) -> Self {
match item {
serde_qs::Error::Custom(s) => StripeErrorCode::SerdeQsError {
serde_qs::Error::Custom(s) => Self::SerdeQsError {
error_message: s,
param: None,
},
serde_qs::Error::Parse(param, position) => StripeErrorCode::SerdeQsError {
serde_qs::Error::Parse(param, position) => Self::SerdeQsError {
error_message: format!(
"parsing failed with error: '{param}' at position: {position}"
),
param: Some(param),
},
serde_qs::Error::Unsupported => StripeErrorCode::SerdeQsError {
serde_qs::Error::Unsupported => Self::SerdeQsError {
error_message: "Given request format is not supported".to_owned(),
param: None,
},
serde_qs::Error::FromUtf8(_) => StripeErrorCode::SerdeQsError {
serde_qs::Error::FromUtf8(_) => Self::SerdeQsError {
error_message: "Failed to parse request to from utf-8".to_owned(),
param: None,
},
serde_qs::Error::Io(_) => StripeErrorCode::SerdeQsError {
serde_qs::Error::Io(_) => Self::SerdeQsError {
error_message: "Failed to parse request".to_owned(),
param: None,
},
serde_qs::Error::ParseInt(_) => StripeErrorCode::SerdeQsError {
serde_qs::Error::ParseInt(_) => Self::SerdeQsError {
error_message: "Failed to parse integer in request".to_owned(),
param: None,
},
serde_qs::Error::Utf8(_) => StripeErrorCode::SerdeQsError {
serde_qs::Error::Utf8(_) => Self::SerdeQsError {
error_message: "Failed to convert utf8 to string".to_owned(),
param: None,
},

View File

@ -42,7 +42,7 @@ pub(crate) enum StripePaymentMethodType {
impl From<StripePaymentMethodType> for api_enums::PaymentMethodType {
fn from(item: StripePaymentMethodType) -> Self {
match item {
StripePaymentMethodType::Card => api_enums::PaymentMethodType::Card,
StripePaymentMethodType::Card => Self::Card,
}
}
}
@ -78,10 +78,8 @@ impl From<StripeCard> for payments::CCard {
impl From<StripePaymentMethodDetails> for payments::PaymentMethod {
fn from(item: StripePaymentMethodDetails) -> Self {
match item {
StripePaymentMethodDetails::Card(card) => {
payments::PaymentMethod::Card(payments::CCard::from(card))
}
StripePaymentMethodDetails::BankTransfer => payments::PaymentMethod::BankTransfer,
StripePaymentMethodDetails::Card(card) => Self::Card(payments::CCard::from(card)),
StripePaymentMethodDetails::BankTransfer => Self::BankTransfer,
}
}
}
@ -131,7 +129,7 @@ pub(crate) struct StripePaymentIntentRequest {
impl From<StripePaymentIntentRequest> for payments::PaymentsRequest {
fn from(item: StripePaymentIntentRequest) -> Self {
payments::PaymentsRequest {
Self {
amount: item.amount.map(|amount| amount.into()),
connector: item.connector,
currency: item.currency.as_ref().map(|c| c.to_uppercase()),
@ -193,18 +191,14 @@ pub(crate) enum StripePaymentStatus {
impl From<api_enums::IntentStatus> for StripePaymentStatus {
fn from(item: api_enums::IntentStatus) -> Self {
match item {
api_enums::IntentStatus::Succeeded => StripePaymentStatus::Succeeded,
api_enums::IntentStatus::Failed => StripePaymentStatus::Canceled, // TODO: should we show canceled or processing
api_enums::IntentStatus::Processing => StripePaymentStatus::Processing,
api_enums::IntentStatus::RequiresCustomerAction => StripePaymentStatus::RequiresAction,
api_enums::IntentStatus::RequiresPaymentMethod => {
StripePaymentStatus::RequiresPaymentMethod
}
api_enums::IntentStatus::RequiresConfirmation => {
StripePaymentStatus::RequiresConfirmation
}
api_enums::IntentStatus::RequiresCapture => StripePaymentStatus::RequiresCapture,
api_enums::IntentStatus::Cancelled => StripePaymentStatus::Canceled,
api_enums::IntentStatus::Succeeded => Self::Succeeded,
api_enums::IntentStatus::Failed => Self::Canceled, // TODO: should we show canceled or processing
api_enums::IntentStatus::Processing => Self::Processing,
api_enums::IntentStatus::RequiresCustomerAction => Self::RequiresAction,
api_enums::IntentStatus::RequiresPaymentMethod => Self::RequiresPaymentMethod,
api_enums::IntentStatus::RequiresConfirmation => Self::RequiresConfirmation,
api_enums::IntentStatus::RequiresCapture => Self::RequiresCapture,
api_enums::IntentStatus::Cancelled => Self::Canceled,
}
}
}

View File

@ -46,7 +46,7 @@ pub(crate) enum StripePaymentMethodType {
impl From<StripePaymentMethodType> for api_enums::PaymentMethodType {
fn from(item: StripePaymentMethodType) -> Self {
match item {
StripePaymentMethodType::Card => api_enums::PaymentMethodType::Card,
StripePaymentMethodType::Card => Self::Card,
}
}
}
@ -82,10 +82,8 @@ impl From<StripeCard> for payments::CCard {
impl From<StripePaymentMethodDetails> for payments::PaymentMethod {
fn from(item: StripePaymentMethodDetails) -> Self {
match item {
StripePaymentMethodDetails::Card(card) => {
payments::PaymentMethod::Card(payments::CCard::from(card))
}
StripePaymentMethodDetails::BankTransfer => payments::PaymentMethod::BankTransfer,
StripePaymentMethodDetails::Card(card) => Self::Card(payments::CCard::from(card)),
StripePaymentMethodDetails::BankTransfer => Self::BankTransfer,
}
}
}
@ -129,7 +127,7 @@ pub(crate) struct StripeSetupIntentRequest {
impl From<StripeSetupIntentRequest> for payments::PaymentsRequest {
fn from(item: StripeSetupIntentRequest) -> Self {
payments::PaymentsRequest {
Self {
amount: Some(api_types::Amount::Zero),
currency: Some(api_enums::Currency::default().to_string()),
capture_method: None,
@ -189,21 +187,17 @@ pub(crate) enum StripeSetupStatus {
impl From<api_enums::IntentStatus> for StripeSetupStatus {
fn from(item: api_enums::IntentStatus) -> Self {
match item {
api_enums::IntentStatus::Succeeded => StripeSetupStatus::Succeeded,
api_enums::IntentStatus::Failed => StripeSetupStatus::Canceled, // TODO: should we show canceled or processing
api_enums::IntentStatus::Processing => StripeSetupStatus::Processing,
api_enums::IntentStatus::RequiresCustomerAction => StripeSetupStatus::RequiresAction,
api_enums::IntentStatus::RequiresPaymentMethod => {
StripeSetupStatus::RequiresPaymentMethod
}
api_enums::IntentStatus::RequiresConfirmation => {
StripeSetupStatus::RequiresConfirmation
}
api_enums::IntentStatus::Succeeded => Self::Succeeded,
api_enums::IntentStatus::Failed => Self::Canceled, // TODO: should we show canceled or processing
api_enums::IntentStatus::Processing => Self::Processing,
api_enums::IntentStatus::RequiresCustomerAction => Self::RequiresAction,
api_enums::IntentStatus::RequiresPaymentMethod => Self::RequiresPaymentMethod,
api_enums::IntentStatus::RequiresConfirmation => Self::RequiresConfirmation,
api_enums::IntentStatus::RequiresCapture => {
logger::error!("Invalid status change");
StripeSetupStatus::Canceled
Self::Canceled
}
api_enums::IntentStatus::Cancelled => StripeSetupStatus::Canceled,
api_enums::IntentStatus::Cancelled => Self::Canceled,
}
}
}