diff --git a/connector-template/transformers.rs b/connector-template/transformers.rs index f379e016d7..34ac1e9589 100644 --- a/connector-template/transformers.rs +++ b/connector-template/transformers.rs @@ -90,12 +90,12 @@ impl Default for RefundStatus { } } -impl From for enums::RefundStatus { - fn from(item: self::RefundStatus) -> Self { +impl From for enums::RefundStatus { + fn from(item: RefundStatus) -> Self { match item { - self::RefundStatus::Succeeded => enums::RefundStatus::Success, - self::RefundStatus::Failed => enums::RefundStatus::Failure, - self::RefundStatus::Processing => enums::RefundStatus::Pending, + RefundStatus::Succeeded => Self::Success, + RefundStatus::Failed => Self::Failure, + RefundStatus::Processing => Self::Pending, //TODO: Review mapping } } diff --git a/crates/router/src/compatibility/stripe/errors.rs b/crates/router/src/compatibility/stripe/errors.rs index ba354754d7..cb545ed20f 100644 --- a/crates/router/src/compatibility/stripe/errors.rs +++ b/crates/router/src/compatibility/stripe/errors.rs @@ -314,11 +314,11 @@ impl From 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 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 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, }, diff --git a/crates/router/src/compatibility/stripe/payment_intents/types.rs b/crates/router/src/compatibility/stripe/payment_intents/types.rs index 0aa8bf0825..b817959444 100644 --- a/crates/router/src/compatibility/stripe/payment_intents/types.rs +++ b/crates/router/src/compatibility/stripe/payment_intents/types.rs @@ -42,7 +42,7 @@ pub(crate) enum StripePaymentMethodType { impl From 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 for payments::CCard { impl From 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 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 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, } } } diff --git a/crates/router/src/compatibility/stripe/setup_intents/types.rs b/crates/router/src/compatibility/stripe/setup_intents/types.rs index 71ecb7a1a7..7733353626 100644 --- a/crates/router/src/compatibility/stripe/setup_intents/types.rs +++ b/crates/router/src/compatibility/stripe/setup_intents/types.rs @@ -46,7 +46,7 @@ pub(crate) enum StripePaymentMethodType { impl From 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 for payments::CCard { impl From 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 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 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, } } } diff --git a/crates/router/src/connector/aci/transformers.rs b/crates/router/src/connector/aci/transformers.rs index 3ae38554b7..09a6e7b22b 100644 --- a/crates/router/src/connector/aci/transformers.rs +++ b/crates/router/src/connector/aci/transformers.rs @@ -19,7 +19,7 @@ impl TryFrom<&types::ConnectorAuthType> for AciAuthType { type Error = error_stack::Report; fn try_from(item: &types::ConnectorAuthType) -> Result { if let types::ConnectorAuthType::BodyKey { api_key, key1 } = item { - Ok(AciAuthType { + Ok(Self { api_key: api_key.to_string(), entity_id: key1.to_string(), }) @@ -117,7 +117,7 @@ impl TryFrom<&types::PaymentsAuthorizeRouterData> for AciPaymentsRequest { }; let auth = AciAuthType::try_from(&item.connector_auth_type)?; - let aci_payment_request = AciPaymentsRequest { + let aci_payment_request = Self { payment_method: payment_details, entity_id: auth.entity_id, amount: item.request.amount, @@ -132,7 +132,7 @@ impl TryFrom<&types::PaymentsCancelRouterData> for AciCancelRequest { type Error = error_stack::Report; fn try_from(item: &types::PaymentsCancelRouterData) -> Result { let auth = AciAuthType::try_from(&item.connector_auth_type)?; - let aci_payment_request = AciCancelRequest { + let aci_payment_request = Self { entity_id: auth.entity_id, payment_type: AciPaymentType::Reversal, }; @@ -152,9 +152,9 @@ pub enum AciPaymentStatus { impl From for enums::AttemptStatus { fn from(item: AciPaymentStatus) -> Self { match item { - AciPaymentStatus::Succeeded => enums::AttemptStatus::Charged, - AciPaymentStatus::Failed => enums::AttemptStatus::Failure, - AciPaymentStatus::Pending => enums::AttemptStatus::Authorizing, + AciPaymentStatus::Succeeded => Self::Charged, + AciPaymentStatus::Failed => Self::Failure, + AciPaymentStatus::Pending => Self::Authorizing, } } } @@ -209,7 +209,7 @@ impl fn try_from( item: types::ResponseRouterData, ) -> Result { - Ok(types::RouterData { + Ok(Self { status: enums::AttemptStatus::from(AciPaymentStatus::from_str( &item.response.result.code, )?), @@ -241,7 +241,7 @@ impl TryFrom<&types::RefundsRouterData> for AciRefundRequest { let payment_type = AciPaymentType::Refund; let auth = AciAuthType::try_from(&item.connector_auth_type)?; - Ok(AciRefundRequest { + Ok(Self { amount, currency: currency.to_string(), payment_type, @@ -275,12 +275,12 @@ impl FromStr for AciRefundStatus { } } -impl From for enums::RefundStatus { - fn from(item: self::AciRefundStatus) -> Self { +impl From for enums::RefundStatus { + fn from(item: AciRefundStatus) -> Self { match item { - self::AciRefundStatus::Succeeded => enums::RefundStatus::Success, - self::AciRefundStatus::Failed => enums::RefundStatus::Failure, - self::AciRefundStatus::Pending => enums::RefundStatus::Pending, + AciRefundStatus::Succeeded => Self::Success, + AciRefundStatus::Failed => Self::Failure, + AciRefundStatus::Pending => Self::Pending, } } } @@ -304,7 +304,7 @@ impl TryFrom> fn try_from( item: types::RefundsResponseRouterData, ) -> Result { - Ok(types::RouterData { + Ok(Self { response: Ok(types::RefundsResponseData { connector_refund_id: item.response.id, refund_status: enums::RefundStatus::from(AciRefundStatus::from_str( diff --git a/crates/router/src/connector/adyen/transformers.rs b/crates/router/src/connector/adyen/transformers.rs index 4c504d11bf..4474f2437d 100644 --- a/crates/router/src/connector/adyen/transformers.rs +++ b/crates/router/src/connector/adyen/transformers.rs @@ -363,7 +363,7 @@ impl TryFrom<&types::PaymentsAuthorizeRouterData> for AdyenPaymentRequest { None }; - Ok(AdyenPaymentRequest { + Ok(Self { amount, merchant_account: auth_type.merchant_account, payment_method, @@ -384,7 +384,7 @@ impl TryFrom<&types::PaymentsCancelRouterData> for AdyenCancelRequest { type Error = error_stack::Report; fn try_from(item: &types::PaymentsCancelRouterData) -> Result { let auth_type = AdyenAuthType::try_from(&item.connector_auth_type)?; - Ok(AdyenCancelRequest { + Ok(Self { merchant_account: auth_type.merchant_account, original_reference: item.request.connector_transaction_id.to_string(), reference: item.payment_id.to_string(), @@ -404,7 +404,7 @@ impl TryFrom> "processing" => storage_enums::AttemptStatus::Pending, _ => storage_enums::AttemptStatus::VoidFailed, }; - Ok(types::RouterData { + Ok(Self { status, response: Ok(types::PaymentsResponseData::TransactionResponse { resource_id: types::ResponseId::ConnectorTransactionId(item.response.psp_reference), @@ -536,7 +536,7 @@ impl } }; - Ok(types::RouterData { + Ok(Self { status, response: error.map_or_else(|| Ok(payment_response_data), Err), @@ -583,7 +583,7 @@ impl TryFrom<&types::RefundsRouterData> for AdyenRefundRequest { type Error = error_stack::Report; fn try_from(item: &types::RefundsRouterData) -> Result { let auth_type = AdyenAuthType::try_from(&item.connector_auth_type)?; - Ok(AdyenRefundRequest { + Ok(Self { merchant_account: auth_type.merchant_account, reference: item.request.refund_id.clone(), }) @@ -604,7 +604,7 @@ impl TryFrom> "received" => storage_enums::RefundStatus::Success, _ => storage_enums::RefundStatus::Pending, }; - Ok(types::RouterData { + Ok(Self { response: Ok(types::RefundsResponseData { connector_refund_id: item.response.reference, refund_status, diff --git a/crates/router/src/connector/applepay/transformers.rs b/crates/router/src/connector/applepay/transformers.rs index b9c506a805..e9b1eea274 100644 --- a/crates/router/src/connector/applepay/transformers.rs +++ b/crates/router/src/connector/applepay/transformers.rs @@ -76,7 +76,7 @@ impl fn try_from( item: types::ResponseRouterData, ) -> Result { - Ok(types::RouterData { + Ok(Self { response: Ok(types::PaymentsResponseData::SessionResponse { session_token: { api_models::payments::SessionToken::Applepay { diff --git a/crates/router/src/connector/authorizedotnet/transformers.rs b/crates/router/src/connector/authorizedotnet/transformers.rs index f2d5c7b2a5..a76a11b85c 100644 --- a/crates/router/src/connector/authorizedotnet/transformers.rs +++ b/crates/router/src/connector/authorizedotnet/transformers.rs @@ -28,7 +28,7 @@ impl TryFrom<&types::ConnectorAuthType> for MerchantAuthentication { fn try_from(auth_type: &types::ConnectorAuthType) -> Result { if let types::ConnectorAuthType::BodyKey { api_key, key1 } = auth_type { - Ok(MerchantAuthentication { + Ok(Self { name: api_key.clone(), transaction_key: key1.clone(), }) @@ -164,7 +164,7 @@ impl TryFrom<&types::PaymentsAuthorizeRouterData> for CreateTransactionRequest { let merchant_authentication = MerchantAuthentication::try_from(&item.connector_auth_type)?; - Ok(CreateTransactionRequest { + Ok(Self { create_transaction_request: AuthorizedotnetPaymentsRequest { merchant_authentication, transaction_request, @@ -209,11 +209,11 @@ pub type AuthorizedotnetRefundStatus = AuthorizedotnetPaymentStatus; impl From for enums::AttemptStatus { fn from(item: AuthorizedotnetPaymentStatus) -> Self { match item { - AuthorizedotnetPaymentStatus::Approved => enums::AttemptStatus::Charged, + AuthorizedotnetPaymentStatus::Approved => Self::Charged, AuthorizedotnetPaymentStatus::Declined | AuthorizedotnetPaymentStatus::Error => { - enums::AttemptStatus::Failure + Self::Failure } - AuthorizedotnetPaymentStatus::HeldForReview => enums::AttemptStatus::Pending, + AuthorizedotnetPaymentStatus::HeldForReview => Self::Pending, } } } @@ -293,7 +293,7 @@ impl }) }); - Ok(types::RouterData { + Ok(Self { status, response: match error { Some(err) => Err(err), @@ -369,7 +369,7 @@ impl TryFrom<&types::RefundsRouterData> for CreateRefundRequest { reference_transaction_id: item.request.connector_transaction_id.clone(), }; - Ok(CreateRefundRequest { + Ok(Self { create_transaction_request: AuthorizedotnetRefundRequest { merchant_authentication, transaction_request, @@ -381,11 +381,11 @@ impl TryFrom<&types::RefundsRouterData> for CreateRefundRequest { impl From for enums::RefundStatus { fn from(item: self::AuthorizedotnetRefundStatus) -> Self { match item { - AuthorizedotnetPaymentStatus::Approved => enums::RefundStatus::Success, + AuthorizedotnetPaymentStatus::Approved => Self::Success, AuthorizedotnetPaymentStatus::Declined | AuthorizedotnetPaymentStatus::Error => { - enums::RefundStatus::Failure + Self::Failure } - AuthorizedotnetPaymentStatus::HeldForReview => enums::RefundStatus::Pending, + AuthorizedotnetPaymentStatus::HeldForReview => Self::Pending, } } } @@ -414,7 +414,7 @@ impl TryFrom Err(err), None => Ok(types::RefundsResponseData { @@ -451,7 +451,7 @@ impl TryFrom<&types::RefundsRouterData> for AuthorizedotnetCreateSyncReque .ok(); let merchant_authentication = MerchantAuthentication::try_from(&item.connector_auth_type)?; - let payload = AuthorizedotnetCreateSyncRequest { + let payload = Self { get_transaction_details_request: TransactionDetails { merchant_authentication, transaction_id, @@ -484,7 +484,7 @@ impl TryFrom<&types::PaymentsSyncRouterData> for AuthorizedotnetCreateSyncReques let merchant_authentication = MerchantAuthentication::try_from(&item.connector_auth_type)?; - let payload = AuthorizedotnetCreateSyncRequest { + let payload = Self { get_transaction_details_request: TransactionDetails { merchant_authentication, transaction_id, @@ -523,9 +523,9 @@ pub struct AuthorizedotnetSyncResponse { impl From for enums::RefundStatus { fn from(transaction_status: SyncStatus) -> Self { match transaction_status { - SyncStatus::RefundSettledSuccessfully => enums::RefundStatus::Success, - SyncStatus::RefundPendingSettlement => enums::RefundStatus::Pending, - _ => enums::RefundStatus::Failure, + SyncStatus::RefundSettledSuccessfully => Self::Success, + SyncStatus::RefundPendingSettlement => Self::Pending, + _ => Self::Failure, } } } @@ -534,13 +534,13 @@ impl From for enums::AttemptStatus { fn from(transaction_status: SyncStatus) -> Self { match transaction_status { SyncStatus::SettledSuccessfully | SyncStatus::CapturedPendingSettlement => { - enums::AttemptStatus::Charged + Self::Charged } - SyncStatus::Declined => enums::AttemptStatus::AuthenticationFailed, - SyncStatus::Voided => enums::AttemptStatus::Voided, - SyncStatus::CouldNotVoid => enums::AttemptStatus::VoidFailed, - SyncStatus::GeneralError => enums::AttemptStatus::Failure, - _ => enums::AttemptStatus::Pending, + SyncStatus::Declined => Self::AuthenticationFailed, + SyncStatus::Voided => Self::Voided, + SyncStatus::CouldNotVoid => Self::VoidFailed, + SyncStatus::GeneralError => Self::Failure, + _ => Self::Pending, } } } @@ -554,7 +554,7 @@ impl TryFrom, ) -> Result { let refund_status = enums::RefundStatus::from(item.response.transaction.transaction_status); - Ok(types::RouterData { + Ok(Self { response: Ok(types::RefundsResponseData { connector_refund_id: item.response.transaction.transaction_id.clone(), refund_status, @@ -581,7 +581,7 @@ impl ) -> Result { let payment_status = enums::AttemptStatus::from(item.response.transaction.transaction_status); - Ok(types::RouterData { + Ok(Self { response: Ok(types::PaymentsResponseData::TransactionResponse { resource_id: types::ResponseId::ConnectorTransactionId( item.response.transaction.transaction_id, diff --git a/crates/router/src/connector/braintree/transformers.rs b/crates/router/src/connector/braintree/transformers.rs index df176f560d..3691adb974 100644 --- a/crates/router/src/connector/braintree/transformers.rs +++ b/crates/router/src/connector/braintree/transformers.rs @@ -121,7 +121,7 @@ impl TryFrom<&types::PaymentsAuthorizeRouterData> for BraintreePaymentsRequest { payment_method_data_type, kind, }; - Ok(BraintreePaymentsRequest { + Ok(Self { transaction: braintree_transaction_body, }) } @@ -146,7 +146,7 @@ impl TryFrom<&types::ConnectorAuthType> for BraintreeAuthType { } } -#[derive(Debug, Clone, Deserialize, Eq, PartialEq)] +#[derive(Debug, Default, Clone, Deserialize, Eq, PartialEq)] #[serde(rename_all = "snake_case")] pub enum BraintreePaymentStatus { Succeeded, @@ -157,6 +157,7 @@ pub enum BraintreePaymentStatus { GatewayRejected, Voided, SubmittedForSettlement, + #[default] Settling, Settled, SettlementPending, @@ -164,26 +165,20 @@ pub enum BraintreePaymentStatus { SettlementConfirmed, } -impl Default for BraintreePaymentStatus { - fn default() -> Self { - BraintreePaymentStatus::Settling - } -} - impl From for enums::AttemptStatus { fn from(item: BraintreePaymentStatus) -> Self { match item { BraintreePaymentStatus::Succeeded | BraintreePaymentStatus::SubmittedForSettlement => { - enums::AttemptStatus::Charged + Self::Charged } - BraintreePaymentStatus::AuthorizedExpired => enums::AttemptStatus::AuthorizationFailed, + BraintreePaymentStatus::AuthorizedExpired => Self::AuthorizationFailed, BraintreePaymentStatus::Failed | BraintreePaymentStatus::GatewayRejected | BraintreePaymentStatus::ProcessorDeclined - | BraintreePaymentStatus::SettlementDeclined => enums::AttemptStatus::Failure, - BraintreePaymentStatus::Authorized => enums::AttemptStatus::Authorized, - BraintreePaymentStatus::Voided => enums::AttemptStatus::Voided, - _ => enums::AttemptStatus::Pending, + | BraintreePaymentStatus::SettlementDeclined => Self::Failure, + BraintreePaymentStatus::Authorized => Self::Authorized, + BraintreePaymentStatus::Voided => Self::Voided, + _ => Self::Pending, } } } @@ -201,7 +196,7 @@ impl types::PaymentsResponseData, >, ) -> Result { - Ok(types::RouterData { + Ok(Self { status: enums::AttemptStatus::from(item.response.transaction.status), response: Ok(types::PaymentsResponseData::TransactionResponse { resource_id: types::ResponseId::ConnectorTransactionId( @@ -230,7 +225,7 @@ impl types::PaymentsResponseData, >, ) -> Result { - Ok(types::RouterData { + Ok(Self { response: Ok(types::PaymentsResponseData::SessionResponse { session_token: types::api::SessionToken::Paypal { session_token: item.response.client_token.value, @@ -292,32 +287,27 @@ pub struct Amount { impl TryFrom<&types::RefundsRouterData> for BraintreeRefundRequest { type Error = error_stack::Report; fn try_from(_item: &types::RefundsRouterData) -> Result { - Ok(BraintreeRefundRequest { + Ok(Self { transaction: Amount { amount: None }, }) } } #[allow(dead_code)] -#[derive(Debug, Deserialize, Clone)] +#[derive(Debug, Default, Deserialize, Clone)] pub enum RefundStatus { Succeeded, Failed, + #[default] Processing, } -impl Default for RefundStatus { - fn default() -> Self { - RefundStatus::Processing - } -} - -impl From for enums::RefundStatus { - fn from(item: self::RefundStatus) -> Self { +impl From for enums::RefundStatus { + fn from(item: RefundStatus) -> Self { match item { - self::RefundStatus::Succeeded => enums::RefundStatus::Success, - self::RefundStatus::Failed => enums::RefundStatus::Failure, - self::RefundStatus::Processing => enums::RefundStatus::Pending, + RefundStatus::Succeeded => Self::Success, + RefundStatus::Failed => Self::Failure, + RefundStatus::Processing => Self::Pending, } } } @@ -335,7 +325,7 @@ impl TryFrom> fn try_from( item: types::RefundsResponseRouterData, ) -> Result { - Ok(types::RouterData { + Ok(Self { response: Ok(types::RefundsResponseData { connector_refund_id: item.response.id, refund_status: enums::RefundStatus::from(item.response.status), @@ -352,7 +342,7 @@ impl TryFrom> fn try_from( item: types::RefundsResponseRouterData, ) -> Result { - Ok(types::RouterData { + Ok(Self { response: Ok(types::RefundsResponseData { connector_refund_id: item.response.id, refund_status: enums::RefundStatus::from(item.response.status), diff --git a/crates/router/src/connector/checkout/transformers.rs b/crates/router/src/connector/checkout/transformers.rs index e83ddffa62..c0aede0a29 100644 --- a/crates/router/src/connector/checkout/transformers.rs +++ b/crates/router/src/connector/checkout/transformers.rs @@ -117,7 +117,7 @@ impl TryFrom<&types::PaymentsAuthorizeRouterData> for PaymentsRequest { let connector_auth = &item.connector_auth_type; let auth_type: CheckoutAuthType = connector_auth.try_into()?; let processing_channel_id = auth_type.processing_channel_id; - Ok(PaymentsRequest { + Ok(Self { source: source_var, amount: item.request.amount, currency: item.request.currency.to_string(), @@ -210,7 +210,7 @@ impl TryFrom> .map(|(k, v)| (k.to_string(), v.to_string())), ), }); - Ok(types::RouterData { + Ok(Self { status: enums::AttemptStatus::foreign_from(( item.response.status, item.data.request.capture_method, @@ -252,7 +252,7 @@ impl TryFrom> ), }); - Ok(types::RouterData { + Ok(Self { status: enums::AttemptStatus::foreign_from((item.response.status, None)), response: Ok(types::PaymentsResponseData::TransactionResponse { resource_id: types::ResponseId::ConnectorTransactionId(item.response.id), @@ -277,7 +277,7 @@ pub struct PaymentVoidResponse { reference: String, } impl From<&PaymentVoidResponse> for enums::AttemptStatus { - fn from(item: &PaymentVoidResponse) -> enums::AttemptStatus { + fn from(item: &PaymentVoidResponse) -> Self { if item.status == 202 { Self::Voided } else { @@ -294,7 +294,7 @@ impl TryFrom> item: types::PaymentsCancelResponseRouterData, ) -> Result { let response = &item.response; - Ok(types::RouterData { + Ok(Self { response: Ok(types::PaymentsResponseData::TransactionResponse { resource_id: types::ResponseId::ConnectorTransactionId(response.action_id.clone()), redirect: false, @@ -364,7 +364,7 @@ impl TryFrom, ) -> Result { let refund_status = enums::RefundStatus::from(&item.response); - Ok(types::RouterData { + Ok(Self { response: Ok(types::RefundsResponseData { connector_refund_id: item.response.response.action_id.clone(), refund_status, @@ -382,7 +382,7 @@ impl TryFrom, ) -> Result { let refund_status = enums::RefundStatus::from(&item.response); - Ok(types::RouterData { + Ok(Self { response: Ok(types::RefundsResponseData { connector_refund_id: item.response.response.action_id.clone(), refund_status, @@ -455,7 +455,7 @@ impl TryFrom> item: types::RefundsResponseRouterData, ) -> Result { let refund_status = enums::RefundStatus::from(item.response); - Ok(types::RouterData { + Ok(Self { response: Ok(types::RefundsResponseData { connector_refund_id: item.response.action_id.clone(), refund_status, @@ -473,7 +473,7 @@ impl TryFrom> item: types::RefundsResponseRouterData, ) -> Result { let refund_status = enums::RefundStatus::from(item.response); - Ok(types::RouterData { + Ok(Self { response: Ok(types::RefundsResponseData { connector_refund_id: item.response.action_id.clone(), refund_status, @@ -486,13 +486,9 @@ impl TryFrom> impl From for enums::AttemptStatus { fn from(item: CheckoutRedirectResponseStatus) -> Self { match item { - CheckoutRedirectResponseStatus::Success => { - types::storage::enums::AttemptStatus::VbvSuccessful - } + CheckoutRedirectResponseStatus::Success => Self::VbvSuccessful, - CheckoutRedirectResponseStatus::Failure => { - types::storage::enums::AttemptStatus::Failure - } + CheckoutRedirectResponseStatus::Failure => Self::Failure, } } } diff --git a/crates/router/src/connector/klarna/transformers.rs b/crates/router/src/connector/klarna/transformers.rs index adedc49f42..295d11baf8 100644 --- a/crates/router/src/connector/klarna/transformers.rs +++ b/crates/router/src/connector/klarna/transformers.rs @@ -52,7 +52,7 @@ impl TryFrom> item: types::PaymentsSessionResponseRouterData, ) -> Result { let response = &item.response; - Ok(types::RouterData { + Ok(Self { response: Ok(types::PaymentsResponseData::SessionResponse { session_token: types::api::SessionToken::Klarna { session_token: response.client_token.clone(), @@ -109,9 +109,9 @@ pub enum KlarnaPaymentStatus { impl From for enums::AttemptStatus { fn from(item: KlarnaPaymentStatus) -> Self { match item { - KlarnaPaymentStatus::Succeeded => enums::AttemptStatus::Charged, - KlarnaPaymentStatus::Failed => enums::AttemptStatus::Failure, - KlarnaPaymentStatus::Processing => enums::AttemptStatus::Authorizing, + KlarnaPaymentStatus::Succeeded => Self::Charged, + KlarnaPaymentStatus::Failed => Self::Failure, + KlarnaPaymentStatus::Processing => Self::Authorizing, } } } diff --git a/crates/router/src/connector/stripe/transformers.rs b/crates/router/src/connector/stripe/transformers.rs index 0c7649e317..b59fe6867e 100644 --- a/crates/router/src/connector/stripe/transformers.rs +++ b/crates/router/src/connector/stripe/transformers.rs @@ -217,7 +217,7 @@ impl TryFrom<&types::PaymentsAuthorizeRouterData> for PaymentIntentRequest { None => Address::default(), }; - Ok(PaymentIntentRequest { + Ok(Self { amount: item.request.amount, //hopefully we don't loose some cents here currency: item.request.currency.to_string(), //we need to copy the value and not transfer ownership statement_descriptor_suffix: item.request.statement_descriptor_suffix.clone(), @@ -292,16 +292,14 @@ pub enum StripePaymentStatus { impl From for enums::AttemptStatus { fn from(item: StripePaymentStatus) -> Self { match item { - StripePaymentStatus::Succeeded => enums::AttemptStatus::Charged, - StripePaymentStatus::Failed => enums::AttemptStatus::Failure, - StripePaymentStatus::Processing => enums::AttemptStatus::Authorizing, - StripePaymentStatus::RequiresCustomerAction => enums::AttemptStatus::PendingVbv, - StripePaymentStatus::RequiresPaymentMethod => { - enums::AttemptStatus::PaymentMethodAwaited - } - StripePaymentStatus::RequiresConfirmation => enums::AttemptStatus::ConfirmationAwaited, - StripePaymentStatus::Canceled => enums::AttemptStatus::Voided, - StripePaymentStatus::RequiresCapture => enums::AttemptStatus::Authorized, + StripePaymentStatus::Succeeded => Self::Charged, + StripePaymentStatus::Failed => Self::Failure, + StripePaymentStatus::Processing => Self::Authorizing, + StripePaymentStatus::RequiresCustomerAction => Self::PendingVbv, + StripePaymentStatus::RequiresPaymentMethod => Self::PaymentMethodAwaited, + StripePaymentStatus::RequiresConfirmation => Self::ConfirmationAwaited, + StripePaymentStatus::Canceled => Self::Voided, + StripePaymentStatus::RequiresCapture => Self::Authorized, } } } @@ -375,7 +373,7 @@ impl StripePaymentMethodOptions::Klarna {} => None, }); - Ok(types::RouterData { + Ok(Self { status: enums::AttemptStatus::from(item.response.status), // client_secret: Some(item.response.client_secret.clone().as_str()), // description: item.response.description.map(|x| x.as_str()), @@ -427,7 +425,7 @@ impl StripePaymentMethodOptions::Klarna {} => None, }); - Ok(types::RouterData { + Ok(Self { status: enums::AttemptStatus::from(item.response.status), response: Ok(types::PaymentsResponseData::TransactionResponse { resource_id: types::ResponseId::ConnectorTransactionId(item.response.id), @@ -494,7 +492,7 @@ impl TryFrom<&types::RefundsRouterData> for RefundRequest { let metadata_txn_id = "Fetch txn_id from DB".to_string(); let metadata_txn_uuid = "Fetch txn_id from DB".to_string(); let payment_intent = item.request.connector_transaction_id.clone(); - Ok(RefundRequest { + Ok(Self { amount: Some(amount), payment_intent, metadata_order_id: item.payment_id.clone(), @@ -545,7 +543,7 @@ impl TryFrom> fn try_from( item: types::RefundsResponseRouterData, ) -> Result { - Ok(types::RouterData { + Ok(Self { response: Ok(types::RefundsResponseData { connector_refund_id: item.response.id, refund_status: enums::RefundStatus::from(item.response.status), @@ -562,7 +560,7 @@ impl TryFrom> fn try_from( item: types::RefundsResponseRouterData, ) -> Result { - Ok(types::RouterData { + Ok(Self { response: Ok(types::RefundsResponseData { connector_refund_id: item.response.id, refund_status: enums::RefundStatus::from(item.response.status), @@ -753,7 +751,7 @@ pub struct StripeWebhookObjectId { impl From<(api::PaymentMethod, enums::AuthenticationType)> for StripePaymentMethodData { fn from((pm_data, auth_type): (api::PaymentMethod, enums::AuthenticationType)) -> Self { match pm_data { - api::PaymentMethod::Card(ref ccard) => StripePaymentMethodData::Card({ + api::PaymentMethod::Card(ref ccard) => Self::Card({ let payment_method_auth_type = match auth_type { enums::AuthenticationType::ThreeDs => Auth3ds::Any, enums::AuthenticationType::NoThreeDs => Auth3ds::Automatic, @@ -768,17 +766,15 @@ impl From<(api::PaymentMethod, enums::AuthenticationType)> for StripePaymentMeth payment_method_auth_type, } }), - api::PaymentMethod::BankTransfer => StripePaymentMethodData::Bank, - api::PaymentMethod::PayLater(ref klarna_data) => { - StripePaymentMethodData::Klarna(StripeKlarnaData { - payment_method_types: "klarna".to_string(), - payment_method_data_type: "klarna".to_string(), - billing_email: klarna_data.billing_email.clone(), - billing_country: klarna_data.country.clone(), - }) - } - api::PaymentMethod::Wallet(_) => StripePaymentMethodData::Wallet, - api::PaymentMethod::Paypal => StripePaymentMethodData::Paypal, + api::PaymentMethod::BankTransfer => Self::Bank, + api::PaymentMethod::PayLater(ref klarna_data) => Self::Klarna(StripeKlarnaData { + payment_method_types: "klarna".to_string(), + payment_method_data_type: "klarna".to_string(), + billing_email: klarna_data.billing_email.clone(), + billing_country: klarna_data.country.clone(), + }), + api::PaymentMethod::Wallet(_) => Self::Wallet, + api::PaymentMethod::Paypal => Self::Paypal, } } } diff --git a/crates/router/src/core/errors.rs b/crates/router/src/core/errors.rs index b8fe1a0526..7d4c141949 100644 --- a/crates/router/src/core/errors.rs +++ b/crates/router/src/core/errors.rs @@ -205,17 +205,17 @@ fn error_response(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, } } diff --git a/crates/router/src/core/errors/api_error_response.rs b/crates/router/src/core/errors/api_error_response.rs index 95f631953e..213ee325b2 100644 --- a/crates/router/src/core/errors/api_error_response.rs +++ b/crates/router/src/core/errors/api_error_response.rs @@ -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 } } diff --git a/crates/router/src/core/payments/flows/authorize_flow.rs b/crates/router/src/core/payments/flows/authorize_flow.rs index 3071e5f5f7..f590c280e5 100644 --- a/crates/router/src/core/payments/flows/authorize_flow.rs +++ b/crates/router/src/core/payments/flows/authorize_flow.rs @@ -83,7 +83,7 @@ impl PaymentsAuthorizeRouterData { confirm: Option, call_connector_action: payments::CallConnectorAction, _storage_scheme: storage_enums::MerchantStorageScheme, - ) -> RouterResult { + ) -> RouterResult { match confirm { Some(true) => { let connector_integration: services::BoxedConnectorIntegration< diff --git a/crates/router/src/core/payments/flows/cancel_flow.rs b/crates/router/src/core/payments/flows/cancel_flow.rs index 4250cb9a7b..ad7458e94a 100644 --- a/crates/router/src/core/payments/flows/cancel_flow.rs +++ b/crates/router/src/core/payments/flows/cancel_flow.rs @@ -67,7 +67,7 @@ impl PaymentsCancelRouterData { _maybe_customer: &Option, _confirm: Option, call_connector_action: payments::CallConnectorAction, - ) -> RouterResult { + ) -> RouterResult { let connector_integration: services::BoxedConnectorIntegration< api::Void, types::PaymentsCancelData, diff --git a/crates/router/src/core/payments/flows/capture_flow.rs b/crates/router/src/core/payments/flows/capture_flow.rs index 6302bdb25b..469308e888 100644 --- a/crates/router/src/core/payments/flows/capture_flow.rs +++ b/crates/router/src/core/payments/flows/capture_flow.rs @@ -68,7 +68,7 @@ impl PaymentsCaptureRouterData { _maybe_customer: &Option, _confirm: Option, call_connector_action: payments::CallConnectorAction, - ) -> RouterResult { + ) -> RouterResult { let connector_integration: services::BoxedConnectorIntegration< api::Capture, PaymentsCaptureData, diff --git a/crates/router/src/core/payments/flows/psync_flow.rs b/crates/router/src/core/payments/flows/psync_flow.rs index 3e9d971219..e8240e5326 100644 --- a/crates/router/src/core/payments/flows/psync_flow.rs +++ b/crates/router/src/core/payments/flows/psync_flow.rs @@ -68,7 +68,7 @@ impl PaymentsSyncRouterData { _maybe_customer: &Option, _confirm: Option, call_connector_action: payments::CallConnectorAction, - ) -> RouterResult { + ) -> RouterResult { let connector_integration: services::BoxedConnectorIntegration< api::PSync, PaymentsSyncData, diff --git a/crates/router/src/core/payments/flows/session_flow.rs b/crates/router/src/core/payments/flows/session_flow.rs index 69aa47238f..52fea4646b 100644 --- a/crates/router/src/core/payments/flows/session_flow.rs +++ b/crates/router/src/core/payments/flows/session_flow.rs @@ -105,7 +105,7 @@ impl types::PaymentsSessionRouterData { _customer: &Option, _confirm: Option, call_connector_action: payments::CallConnectorAction, - ) -> RouterResult { + ) -> RouterResult { match connector.get_token { api::GetToken::Metadata => create_gpay_session_token(self), api::GetToken::Connector => { diff --git a/crates/router/src/core/refunds.rs b/crates/router/src/core/refunds.rs index 1d7eb7c941..fc77ddec2d 100644 --- a/crates/router/src/core/refunds.rs +++ b/crates/router/src/core/refunds.rs @@ -497,6 +497,7 @@ fn mk_new_refund( impl TryFrom> for refunds::RefundResponse { type Error = error_stack::Report; + fn try_from(data: types::RefundsRouterData) -> RouterResult { let refund_id = data.request.refund_id.to_string(); let response = data.response; @@ -506,7 +507,7 @@ impl TryFrom> 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, diff --git a/crates/router/src/lib.rs b/crates/router/src/lib.rs index aec94fa21a..da737e4ed1 100644 --- a/crates/router/src/lib.rs +++ b/crates/router/src/lib.rs @@ -16,7 +16,8 @@ clippy::todo, clippy::unreachable, clippy::unwrap_in_result, - clippy::unwrap_used + clippy::unwrap_used, + clippy::use_self )] #![recursion_limit = "256"] diff --git a/crates/router/src/routes/app.rs b/crates/router/src/routes/app.rs index 456c0c3a41..89ee368151 100644 --- a/crates/router/src/routes/app.rs +++ b/crates/router/src/routes/app.rs @@ -18,7 +18,7 @@ pub struct AppState { } impl AppState { - pub async fn with_storage(conf: Settings, storage_impl: StorageImpl) -> AppState { + pub async fn with_storage(conf: Settings, storage_impl: StorageImpl) -> Self { let testable = storage_impl == StorageImpl::PostgresqlTest; let store: Box = match storage_impl { StorageImpl::Postgresql | StorageImpl::PostgresqlTest => { @@ -27,7 +27,7 @@ impl AppState { StorageImpl::Mock => Box::new(MockDb::new(&conf).await), }; - AppState { + Self { flow_name: String::from("default"), store, conf, @@ -35,8 +35,8 @@ impl AppState { } #[allow(unused_variables)] - pub async fn new(conf: Settings) -> AppState { - AppState::with_storage(conf, StorageImpl::Postgresql).await + pub async fn new(conf: Settings) -> Self { + Self::with_storage(conf, StorageImpl::Postgresql).await } } diff --git a/crates/router/src/services/api/client.rs b/crates/router/src/services/api/client.rs index a96d9449c5..f2c7dc4a3b 100644 --- a/crates/router/src/services/api/client.rs +++ b/crates/router/src/services/api/client.rs @@ -20,10 +20,10 @@ impl ProxyType { use std::env::var; match self { - ProxyType::Http => var(HTTP_PROXY) + Self::Http => var(HTTP_PROXY) .or_else(|_| proxy.http_url.clone().ok_or(())) .ok(), - ProxyType::Https => var(HTTPS_PROXY) + Self::Https => var(HTTPS_PROXY) .or_else(|_| proxy.https_url.clone().ok_or(())) .ok(), } diff --git a/crates/router/src/services/api/request.rs b/crates/router/src/services/api/request.rs index 3470644618..f7f3e58532 100644 --- a/crates/router/src/services/api/request.rs +++ b/crates/router/src/services/api/request.rs @@ -42,8 +42,8 @@ pub struct Request { } impl Request { - pub fn new(method: Method, url: &str) -> Request { - Request { + pub fn new(method: Method, url: &str) -> Self { + Self { method, url: String::from(url), headers: Vec::new(), @@ -87,8 +87,8 @@ pub struct RequestBuilder { } impl RequestBuilder { - pub fn new() -> RequestBuilder { - RequestBuilder { + pub fn new() -> Self { + Self { method: Method::Get, url: String::with_capacity(1024), headers: Vec::new(), @@ -99,44 +99,44 @@ impl RequestBuilder { } } - pub fn url(mut self, url: &str) -> RequestBuilder { + pub fn url(mut self, url: &str) -> Self { self.url = url.into(); self } - pub fn method(mut self, method: Method) -> RequestBuilder { + pub fn method(mut self, method: Method) -> Self { self.method = method; self } - pub fn header(mut self, header: &str, value: &str) -> RequestBuilder { + pub fn header(mut self, header: &str, value: &str) -> Self { self.headers.push((header.into(), value.into())); self } - pub fn headers(mut self, headers: Vec<(String, String)>) -> RequestBuilder { + pub fn headers(mut self, headers: Vec<(String, String)>) -> Self { // Fixme add union property let mut h = headers.into_iter().map(|(h, v)| (h, v)).collect(); self.headers.append(&mut h); self } - pub fn body(mut self, body: Option) -> RequestBuilder { + pub fn body(mut self, body: Option) -> Self { self.payload = body.map(From::from); self } - pub fn content_type(mut self, content_type: ContentType) -> RequestBuilder { + pub fn content_type(mut self, content_type: ContentType) -> Self { self.content_type = Some(content_type); self } - pub fn add_certificate(mut self, certificate: Option) -> RequestBuilder { + pub fn add_certificate(mut self, certificate: Option) -> Self { self.certificate = certificate; self } - pub fn add_certificate_key(mut self, certificate_key: Option) -> RequestBuilder { + pub fn add_certificate_key(mut self, certificate_key: Option) -> Self { self.certificate_key = certificate_key; self } diff --git a/crates/router/src/types/api.rs b/crates/router/src/types/api.rs index e256cfe541..fb96a9d8a8 100644 --- a/crates/router/src/types/api.rs +++ b/crates/router/src/types/api.rs @@ -92,14 +92,14 @@ impl ConnectorData { connectors: &Connectors, name: &str, connector_type: GetToken, - ) -> CustomResult { + ) -> CustomResult { let connector = Self::convert_connector(connectors, name)?; let connector_name = api_enums::Connector::from_str(name) .into_report() .change_context(errors::ConnectorError::InvalidConnectorName) .attach_printable_lazy(|| format!("unable to parse connector name {connector:?}")) .change_context(errors::ApiErrorResponse::InternalServerError)?; - Ok(ConnectorData { + Ok(Self { connector, connector_name, get_token: connector_type, diff --git a/crates/router/src/types/storage/payment_intent.rs b/crates/router/src/types/storage/payment_intent.rs index 55739e9e87..e6545e8359 100644 --- a/crates/router/src/types/storage/payment_intent.rs +++ b/crates/router/src/types/storage/payment_intent.rs @@ -38,7 +38,7 @@ impl PaymentIntentDbExt for PaymentIntent { //TODO: Replace this with Boxable Expression and pass it into generic filter // when https://github.com/rust-lang/rust/issues/52662 becomes stable - let mut filter = ::table() + let mut filter = ::table() .filter(dsl::merchant_id.eq(merchant_id.to_owned())) .order_by(dsl::id) .into_boxed(); diff --git a/crates/router/src/types/transformers.rs b/crates/router/src/types/transformers.rs index 398f3c678c..99a930a6db 100644 --- a/crates/router/src/types/transformers.rs +++ b/crates/router/src/types/transformers.rs @@ -90,25 +90,25 @@ where impl From> for F { fn from(algo: F) -> Self { - Foreign(frunk::labelled_convert_from(algo.0)) + Self(frunk::labelled_convert_from(algo.0)) } } impl From> for F { fn from(algo: F) -> Self { - Foreign(frunk::labelled_convert_from(algo.0)) + Self(frunk::labelled_convert_from(algo.0)) } } impl From> for F { fn from(conn: F) -> Self { - Foreign(frunk::labelled_convert_from(conn.0)) + Self(frunk::labelled_convert_from(conn.0)) } } impl From> for F { fn from(conn: F) -> Self { - Foreign(frunk::labelled_convert_from(conn.0)) + Self(frunk::labelled_convert_from(conn.0)) } } @@ -124,49 +124,49 @@ impl From> for F { impl From> for F { fn from(status: F) -> Self { - Foreign(frunk::labelled_convert_from(status.0)) + Self(frunk::labelled_convert_from(status.0)) } } impl From> for F { fn from(pm_type: F) -> Self { - Foreign(frunk::labelled_convert_from(pm_type.0)) + Self(frunk::labelled_convert_from(pm_type.0)) } } impl From> for F { fn from(pm_type: F) -> Self { - Foreign(frunk::labelled_convert_from(pm_type.0)) + Self(frunk::labelled_convert_from(pm_type.0)) } } impl From> for F { fn from(pm_subtype: F) -> Self { - Foreign(frunk::labelled_convert_from(pm_subtype.0)) + Self(frunk::labelled_convert_from(pm_subtype.0)) } } impl From> for F { fn from(pm_subtype: F) -> Self { - Foreign(frunk::labelled_convert_from(pm_subtype.0)) + Self(frunk::labelled_convert_from(pm_subtype.0)) } } impl From> for F { fn from(issuer_code: F) -> Self { - Foreign(frunk::labelled_convert_from(issuer_code.0)) + Self(frunk::labelled_convert_from(issuer_code.0)) } } impl From> for F { fn from(status: F) -> Self { - Foreign(frunk::labelled_convert_from(status.0)) + Self(frunk::labelled_convert_from(status.0)) } } impl From> for F { fn from(status: F) -> Self { - Foreign(frunk::labelled_convert_from(status.0)) + Self(frunk::labelled_convert_from(status.0)) } } @@ -228,55 +228,55 @@ impl TryFrom> for F { impl From> for F { fn from(event_type: F) -> Self { - Foreign(frunk::labelled_convert_from(event_type.0)) + Self(frunk::labelled_convert_from(event_type.0)) } } impl From> for F { fn from(future_usage: F) -> Self { - Foreign(frunk::labelled_convert_from(future_usage.0)) + Self(frunk::labelled_convert_from(future_usage.0)) } } impl From> for F { fn from(future_usage: F) -> Self { - Foreign(frunk::labelled_convert_from(future_usage.0)) + Self(frunk::labelled_convert_from(future_usage.0)) } } impl From> for F { fn from(status: F) -> Self { - Foreign(frunk::labelled_convert_from(status.0)) + Self(frunk::labelled_convert_from(status.0)) } } impl From> for F { fn from(capture_method: F) -> Self { - Foreign(frunk::labelled_convert_from(capture_method.0)) + Self(frunk::labelled_convert_from(capture_method.0)) } } impl From> for F { fn from(capture_method: F) -> Self { - Foreign(frunk::labelled_convert_from(capture_method.0)) + Self(frunk::labelled_convert_from(capture_method.0)) } } impl From> for F { fn from(auth_type: F) -> Self { - Foreign(frunk::labelled_convert_from(auth_type.0)) + Self(frunk::labelled_convert_from(auth_type.0)) } } impl From> for F { fn from(auth_type: F) -> Self { - Foreign(frunk::labelled_convert_from(auth_type.0)) + Self(frunk::labelled_convert_from(auth_type.0)) } } impl From> for F { fn from(currency: F) -> Self { - Foreign(frunk::labelled_convert_from(currency.0)) + Self(frunk::labelled_convert_from(currency.0)) } } diff --git a/crates/router/src/utils/ext_traits.rs b/crates/router/src/utils/ext_traits.rs index e0cf6dea55..f708d8680a 100644 --- a/crates/router/src/utils/ext_traits.rs +++ b/crates/router/src/utils/ext_traits.rs @@ -77,7 +77,7 @@ where value.parse_value(type_name) } - fn update_value(&mut self, value: Option) { + fn update_value(&mut self, value: Self) { if let Some(a) = value { *self = Some(a) }