diff --git a/.github/workflows/CI-pr.yml b/.github/workflows/CI-pr.yml index e43af03ec6..220c4f2577 100644 --- a/.github/workflows/CI-pr.yml +++ b/.github/workflows/CI-pr.yml @@ -307,6 +307,7 @@ jobs: uses: dtolnay/rust-toolchain@master with: toolchain: stable 2 weeks ago + components: clippy - name: Install Protoc uses: arduino/setup-protoc@v3 @@ -322,14 +323,9 @@ jobs: tool: just checksum: true - - name: Run cargo check with v2 features enabled + - name: Run cargo clippy with v2 features enabled shell: bash - env: - RUSTFLAGS: "-A warnings" - # Not denying warnings for now. - # We only want to ensure successful compilation for now. - # RUSTFLAGS: "-D warnings -A clippy::todo" - run: just check_v2 + run: just clippy_v2 -- -D warnings -Aunused -Aclippy::todo -Aclippy::diverging_sub_expression - name: Run cargo check enabling only the release and v2 features shell: bash diff --git a/crates/common_utils/src/id_type/global_id.rs b/crates/common_utils/src/id_type/global_id.rs index c0b6384abc..0709ce84d5 100644 --- a/crates/common_utils/src/id_type/global_id.rs +++ b/crates/common_utils/src/id_type/global_id.rs @@ -63,13 +63,24 @@ impl From for CellIdError { impl CellId { /// Create a new cell id from a string - pub fn from_str(cell_id_string: impl AsRef) -> Result { + fn from_str(cell_id_string: impl AsRef) -> Result { let trimmed_input_string = cell_id_string.as_ref().trim().to_string(); let alphanumeric_id = AlphaNumericId::from(trimmed_input_string.into())?; let length_id = LengthId::from_alphanumeric_id(alphanumeric_id)?; Ok(Self(length_id)) } + /// Create a new cell id from a string + pub fn from_string( + input_string: impl AsRef, + ) -> error_stack::Result { + Self::from_str(input_string).change_context( + errors::ValidationError::IncorrectValueProvided { + field_name: "cell_id", + }, + ) + } + /// Get the string representation of the cell id fn get_string_repr(&self) -> &str { &self.0 .0 .0 @@ -115,7 +126,7 @@ impl GlobalId { pub(crate) fn from_string( input_string: std::borrow::Cow<'static, str>, ) -> Result { - let length_id = LengthId::from(input_string.into())?; + let length_id = LengthId::from(input_string)?; let input_string = &length_id.0 .0; let (cell_id, remaining) = input_string .split_once("_") diff --git a/crates/common_utils/src/id_type/global_id/payment_methods.rs b/crates/common_utils/src/id_type/global_id/payment_methods.rs index 3929efd09b..f6f394242c 100644 --- a/crates/common_utils/src/id_type/global_id/payment_methods.rs +++ b/crates/common_utils/src/id_type/global_id/payment_methods.rs @@ -1,4 +1,3 @@ -use diesel::{backend::Backend, deserialize::FromSql, serialize::ToSql, sql_types}; use error_stack::ResultExt; use crate::{ @@ -7,6 +6,7 @@ use crate::{ id_type::global_id::{CellId, GlobalEntity, GlobalId, GlobalIdError}, }; +/// A global id that can be used to identify a payment method #[derive( Debug, Clone, @@ -27,7 +27,7 @@ pub enum GlobalPaymentMethodIdError { } impl GlobalPaymentMethodId { - /// Create a new GlobalPaymentMethodId from celll id information + /// Create a new GlobalPaymentMethodId from cell id information pub fn generate(cell_id: &str) -> error_stack::Result { let cell_id = CellId::from_str(cell_id) .change_context(GlobalPaymentMethodIdError::ConstructionError) @@ -36,10 +36,12 @@ impl GlobalPaymentMethodId { Ok(Self(global_id)) } + /// Get string representation of the id pub fn get_string_repr(&self) -> &str { self.0.get_string_repr() } + /// Construct a new GlobalPaymentMethodId from a string pub fn generate_from_string(value: String) -> CustomResult { let id = GlobalId::from_string(value.into()) .change_context(GlobalPaymentMethodIdError::ConstructionError)?; @@ -47,7 +49,7 @@ impl GlobalPaymentMethodId { } } -impl diesel::Queryable for GlobalPaymentMethodId +impl diesel::Queryable for GlobalPaymentMethodId where DB: diesel::backend::Backend, Self: diesel::deserialize::FromSql, @@ -58,10 +60,10 @@ where } } -impl ToSql for GlobalPaymentMethodId +impl diesel::serialize::ToSql for GlobalPaymentMethodId where - DB: Backend, - GlobalId: ToSql, + DB: diesel::backend::Backend, + GlobalId: diesel::serialize::ToSql, { fn to_sql<'b>( &'b self, @@ -71,10 +73,10 @@ where } } -impl FromSql for GlobalPaymentMethodId +impl diesel::deserialize::FromSql for GlobalPaymentMethodId where - DB: Backend, - GlobalId: FromSql, + DB: diesel::backend::Backend, + GlobalId: diesel::deserialize::FromSql, { fn from_sql(value: DB::RawValue<'_>) -> diesel::deserialize::Result { let global_id = GlobalId::from_sql(value)?; diff --git a/crates/hyperswitch_domain_models/src/payments.rs b/crates/hyperswitch_domain_models/src/payments.rs index da56a1dc30..c59fb9b12f 100644 --- a/crates/hyperswitch_domain_models/src/payments.rs +++ b/crates/hyperswitch_domain_models/src/payments.rs @@ -109,8 +109,8 @@ pub enum SurchargeCalculationOverride { impl From> for TaxCalculationOverride { fn from(value: Option) -> Self { match value { - Some(true) => TaxCalculationOverride::Calculate, - _ => TaxCalculationOverride::Skip, + Some(true) => Self::Calculate, + _ => Self::Skip, } } } @@ -119,8 +119,8 @@ impl From> for TaxCalculationOverride { impl From> for SurchargeCalculationOverride { fn from(value: Option) -> Self { match value { - Some(true) => SurchargeCalculationOverride::Calculate, - _ => SurchargeCalculationOverride::Skip, + Some(true) => Self::Calculate, + _ => Self::Skip, } } } @@ -235,7 +235,7 @@ pub struct PaymentIntent { /// The details of the customer in a denormalized form. Only a subset of fields are stored. pub customer_details: Option>>, /// The reference id for the order in the merchant's system. This value can be passed by the merchant. - pub merchant_reference_id: Option, + pub merchant_reference_id: Option, /// The billing address for the order in a denormalized form. pub billing_address: Option>>, /// The shipping address for the order in a denormalized form. diff --git a/crates/hyperswitch_domain_models/src/payments/payment_intent.rs b/crates/hyperswitch_domain_models/src/payments/payment_intent.rs index eb207a1950..381a84ce82 100644 --- a/crates/hyperswitch_domain_models/src/payments/payment_intent.rs +++ b/crates/hyperswitch_domain_models/src/payments/payment_intent.rs @@ -1481,7 +1481,7 @@ impl behaviour::Conversion for PaymentIntent { type NewDstType = DieselPaymentIntentNew; async fn convert(self) -> CustomResult { - let PaymentIntent { + let Self { merchant_id, amount_details, status, @@ -1585,7 +1585,7 @@ impl behaviour::Conversion for PaymentIntent { async fn convert_back( state: &KeyManagerState, storage_model: Self::DstType, - key: &masking::Secret>, + key: &Secret>, key_manager_identifier: keymanager::Identifier, ) -> CustomResult where diff --git a/crates/router/src/configs/settings.rs b/crates/router/src/configs/settings.rs index 0a7defc406..e59dd73cd3 100644 --- a/crates/router/src/configs/settings.rs +++ b/crates/router/src/configs/settings.rs @@ -958,7 +958,7 @@ impl Default for CellInformation { // around the time of deserializing application settings. // And a panic at application startup is considered acceptable. #[allow(clippy::expect_used)] - let cell_id = common_utils::id_type::CellId::from_str("defid") + let cell_id = common_utils::id_type::CellId::from_string("defid") .expect("Failed to create a default for Cell Id"); Self { id: cell_id } } diff --git a/crates/router/src/configs/validations.rs b/crates/router/src/configs/validations.rs index 7736d7b3f3..bfea4eee42 100644 --- a/crates/router/src/configs/validations.rs +++ b/crates/router/src/configs/validations.rs @@ -198,7 +198,7 @@ impl super::settings::CellInformation { pub fn validate(&self) -> Result<(), ApplicationError> { use common_utils::{fp_utils::when, id_type}; - when(self == &super::settings::CellInformation::default(), || { + when(self == &Self::default(), || { Err(ApplicationError::InvalidConfigurationValueError( "CellId cannot be set to a default".into(), )) diff --git a/crates/router/src/core/payment_methods.rs b/crates/router/src/core/payment_methods.rs index e51771a280..cb26494b70 100644 --- a/crates/router/src/core/payment_methods.rs +++ b/crates/router/src/core/payment_methods.rs @@ -21,13 +21,13 @@ use api_models::payment_methods; pub use api_models::{enums::PayoutConnectors, payouts as payout_types}; #[cfg(all(any(feature = "v1", feature = "v2"), not(feature = "customer_v2")))] use common_utils::ext_traits::Encode; -use common_utils::{consts::DEFAULT_LOCALE, id_type::CustomerId}; +use common_utils::{consts::DEFAULT_LOCALE, id_type}; #[cfg(all(feature = "v2", feature = "payment_methods_v2"))] use common_utils::{ crypto::{self, Encryptable}, ext_traits::{AsyncExt, Encode, ValueExt}, fp_utils::when, - generate_id, id_type, + generate_id, request::RequestContent, types as util_types, }; @@ -40,9 +40,7 @@ use hyperswitch_domain_models::api::{GenericLinks, GenericLinksData}; use hyperswitch_domain_models::payments::{payment_attempt::PaymentAttempt, PaymentIntent}; #[cfg(all(feature = "v2", feature = "payment_methods_v2"))] use masking::ExposeInterface; -use masking::PeekInterface; -#[cfg(all(feature = "v2", feature = "payment_methods_v2"))] -use masking::Secret; +use masking::{PeekInterface, Secret}; use router_env::{instrument, tracing}; use time::Duration; @@ -198,10 +196,10 @@ pub async fn initiate_pm_collect_link( req.return_url.clone(), ) .await?; - let customer_id = CustomerId::try_from(Cow::from(pm_collect_link.primary_reference)) + let customer_id = id_type::CustomerId::try_from(Cow::from(pm_collect_link.primary_reference)) .change_context(errors::ApiErrorResponse::InvalidDataValue { - field_name: "customer_id", - })?; + field_name: "customer_id", + })?; // Return response let url = pm_collect_link.url.peek(); @@ -321,11 +319,12 @@ pub async fn render_pm_collect_link( // else, send back form link } else { - let customer_id = - CustomerId::try_from(Cow::from(pm_collect_link.primary_reference.clone())) - .change_context(errors::ApiErrorResponse::InvalidDataValue { - field_name: "customer_id", - })?; + let customer_id = id_type::CustomerId::try_from(Cow::from( + pm_collect_link.primary_reference.clone(), + )) + .change_context(errors::ApiErrorResponse::InvalidDataValue { + field_name: "customer_id", + })?; // Fetch customer let customer = db @@ -349,7 +348,7 @@ pub async fn render_pm_collect_link( ))?; let js_data = payment_methods::PaymentMethodCollectLinkDetails { - publishable_key: masking::Secret::new(merchant_account.publishable_key), + publishable_key: Secret::new(merchant_account.publishable_key), client_secret: link_data.client_secret.clone(), pm_collect_link_id: pm_collect_link.link_id, customer_id: customer.customer_id, @@ -448,7 +447,7 @@ pub async fn add_payment_method_status_update_task( payment_method: &domain::PaymentMethod, prev_status: enums::PaymentMethodStatus, curr_status: enums::PaymentMethodStatus, - merchant_id: &common_utils::id_type::MerchantId, + merchant_id: &id_type::MerchantId, ) -> Result<(), errors::ProcessTrackerError> { let created_at = payment_method.created_at; let schedule_time = @@ -496,6 +495,7 @@ pub async fn add_payment_method_status_update_task( } #[cfg(feature = "v2")] +#[allow(clippy::too_many_arguments)] #[instrument(skip_all)] pub async fn retrieve_payment_method_with_token( _state: &SessionState, @@ -671,8 +671,8 @@ pub(crate) async fn get_payment_method_create_request( payment_method_data: Option<&domain::PaymentMethodData>, payment_method: Option, payment_method_type: Option, - customer_id: &Option, - billing_name: Option>, + customer_id: &Option, + billing_name: Option>, ) -> RouterResult { match payment_method_data { Some(pm_data) => match payment_method { @@ -748,8 +748,8 @@ pub(crate) async fn get_payment_method_create_request( payment_method_data: Option<&domain::PaymentMethodData>, payment_method: Option, payment_method_type: Option, - customer_id: &Option, - billing_name: Option>, + customer_id: &Option, + billing_name: Option>, ) -> RouterResult { match payment_method_data { Some(pm_data) => match payment_method { @@ -833,7 +833,7 @@ pub async fn create_payment_method( req: api::PaymentMethodCreate, merchant_account: &domain::MerchantAccount, key_store: &domain::MerchantKeyStore, -) -> errors::RouterResponse { +) -> RouterResponse { req.validate()?; let db = &*state.store; @@ -844,7 +844,7 @@ pub async fn create_payment_method( &(state.into()), &customer_id, merchant_account.get_id(), - &key_store, + key_store, merchant_account.storage_scheme, ) .await @@ -860,10 +860,9 @@ pub async fn create_payment_method( .attach_printable("Unable to encrypt Payment method billing address")?; // create pm - let payment_method_id = - common_utils::id_type::GlobalPaymentMethodId::generate("random_cell_id") - .change_context(errors::ApiErrorResponse::InternalServerError) - .attach_printable("Unable to generate GlobalPaymentMethodId")?; + let payment_method_id = id_type::GlobalPaymentMethodId::generate("random_cell_id") + .change_context(errors::ApiErrorResponse::InternalServerError) + .attach_printable("Unable to generate GlobalPaymentMethodId")?; let payment_method = create_payment_method_for_intent( state, @@ -897,7 +896,7 @@ pub async fn create_payment_method( let payment_method = db .update_payment_method( &(state.into()), - &key_store, + key_store, payment_method, pm_update, merchant_account.storage_scheme, @@ -917,7 +916,7 @@ pub async fn create_payment_method( db.update_payment_method( &(state.into()), - &key_store, + key_store, payment_method, pm_update, merchant_account.storage_scheme, @@ -940,7 +939,7 @@ pub async fn payment_method_intent_create( req: api::PaymentMethodIntentCreate, merchant_account: &domain::MerchantAccount, key_store: &domain::MerchantKeyStore, -) -> errors::RouterResponse { +) -> RouterResponse { let db = &*state.store; let merchant_id = merchant_account.get_id(); let customer_id = req.customer_id.to_owned(); @@ -949,7 +948,7 @@ pub async fn payment_method_intent_create( &(state.into()), &customer_id, merchant_account.get_id(), - &key_store, + key_store, merchant_account.storage_scheme, ) .await @@ -966,10 +965,9 @@ pub async fn payment_method_intent_create( // create pm entry - let payment_method_id = - common_utils::id_type::GlobalPaymentMethodId::generate("random_cell_id") - .change_context(errors::ApiErrorResponse::InternalServerError) - .attach_printable("Unable to generate GlobalPaymentMethodId")?; + let payment_method_id = id_type::GlobalPaymentMethodId::generate("random_cell_id") + .change_context(errors::ApiErrorResponse::InternalServerError) + .attach_printable("Unable to generate GlobalPaymentMethodId")?; let payment_method = create_payment_method_for_intent( state, @@ -997,19 +995,19 @@ pub async fn payment_method_intent_confirm( merchant_account: &domain::MerchantAccount, key_store: &domain::MerchantKeyStore, pm_id: String, -) -> errors::RouterResponse { +) -> RouterResponse { req.validate()?; let db = &*state.store; let client_secret = req.client_secret.clone(); - let pm_id = common_utils::id_type::GlobalPaymentMethodId::generate_from_string(pm_id) + let pm_id = id_type::GlobalPaymentMethodId::generate_from_string(pm_id) .change_context(errors::ApiErrorResponse::InternalServerError) .attach_printable("Unable to generate GlobalPaymentMethodId")?; let payment_method = db .find_payment_method( &(state.into()), - &key_store, + key_store, &pm_id, merchant_account.storage_scheme, ) @@ -1037,7 +1035,7 @@ pub async fn payment_method_intent_confirm( &(state.into()), &customer_id, merchant_account.get_id(), - &key_store, + key_store, merchant_account.storage_scheme, ) .await @@ -1062,7 +1060,7 @@ pub async fn payment_method_intent_confirm( let payment_method = db .update_payment_method( &(state.into()), - &key_store, + key_store, payment_method, pm_update, merchant_account.storage_scheme, @@ -1082,7 +1080,7 @@ pub async fn payment_method_intent_confirm( db.update_payment_method( &(state.into()), - &key_store, + key_store, payment_method, pm_update, merchant_account.storage_scheme, @@ -1228,7 +1226,7 @@ pub async fn create_pm_additional_data_update( vault_id: Option, payment_method: Option, payment_method_type: Option, -) -> errors::RouterResult { +) -> RouterResult { let card = match pmd.clone() { api::PaymentMethodCreateData::Card(card) => api::PaymentMethodsData::Card(card.into()), }; @@ -1244,7 +1242,7 @@ pub async fn create_pm_additional_data_update( locker_id: vault_id, payment_method, payment_method_type, - payment_method_data: Some(pmd).map(Into::into), + payment_method_data: Some(pmd.into()), network_token_requestor_reference_id: None, network_token_locker_id: None, network_token_payment_method_data: None, @@ -1260,7 +1258,7 @@ pub async fn vault_payment_method( pmd: &api::PaymentMethodCreateData, merchant_account: &domain::MerchantAccount, key_store: &domain::MerchantKeyStore, -) -> errors::RouterResult { +) -> RouterResult { let db = &*state.store; // get fingerprint_id from locker @@ -1377,7 +1375,7 @@ pub async fn list_customer_payment_method_util( req: Option, customer_id: Option, is_payment_associated: bool, -) -> errors::RouterResponse { +) -> RouterResponse { let limit = req.as_ref().and_then(|pml_req| pml_req.limit); let (customer_id, payment_intent) = if is_payment_associated { @@ -1431,11 +1429,11 @@ pub async fn list_customer_payment_method( state: &SessionState, merchant_account: domain::MerchantAccount, key_store: domain::MerchantKeyStore, - payment_intent: Option, + payment_intent: Option, customer_id: &id_type::CustomerId, limit: Option, is_payment_associated: bool, -) -> errors::RouterResponse { +) -> RouterResponse { let db = &*state.store; let key_manager_state = &(state).into(); // let key = key_store.key.get_inner().peek(); @@ -1661,12 +1659,12 @@ async fn generate_saved_pm_response( #[cfg(all(feature = "v2", feature = "payment_methods_v2"))] impl pm_types::SavedPMLPaymentsInfo { pub async fn form_payments_info( - payment_intent: storage::PaymentIntent, + payment_intent: PaymentIntent, merchant_account: &domain::MerchantAccount, db: &dyn StorageInterface, key_manager_state: &util_types::keymanager::KeyManagerState, key_store: &domain::MerchantKeyStore, - ) -> errors::RouterResult { + ) -> RouterResult { let requires_cvv = db .find_config_by_key_unwrap_or( format!( @@ -1718,7 +1716,7 @@ impl pm_types::SavedPMLPaymentsInfo { parent_payment_method_token: Option, pma: &api::CustomerPaymentMethod, pm_list_context: PaymentMethodListContext, - ) -> errors::RouterResult<()> { + ) -> RouterResult<()> { let token = parent_payment_method_token .as_ref() .get_required_value("parent_payment_method_token")?; diff --git a/crates/router/src/core/payment_methods/cards.rs b/crates/router/src/core/payment_methods/cards.rs index 6e3d89195d..a7ae7f9ca5 100644 --- a/crates/router/src/core/payment_methods/cards.rs +++ b/crates/router/src/core/payment_methods/cards.rs @@ -226,7 +226,7 @@ async fn create_vault_request( jwekey: &settings::Jwekey, locker: &settings::Locker, payload: Vec, -) -> errors::CustomResult { +) -> errors::CustomResult { let private_key = jwekey.vault_private_key.peek().as_bytes(); let jws = services::encryption::jws_sign_payload( @@ -241,7 +241,7 @@ async fn create_vault_request( let mut url = locker.host.to_owned(); url.push_str(R::get_vaulting_request_url()); - let mut request = services::Request::new(services::Method::Post, &url); + let mut request = Request::new(services::Method::Post, &url); request.add_header( headers::CONTENT_TYPE, router_consts::VAULT_HEADER_CONTENT_TYPE.into(), diff --git a/crates/router/src/core/payment_methods/transformers.rs b/crates/router/src/core/payment_methods/transformers.rs index 6583d109d5..ab21add60a 100644 --- a/crates/router/src/core/payment_methods/transformers.rs +++ b/crates/router/src/core/payment_methods/transformers.rs @@ -310,15 +310,11 @@ pub async fn create_jwe_body_for_vault( let public_key = jwekey.vault_encryption_key.peek().as_bytes(); - let jwe_encrypted = encryption::encrypt_jwe( - &payload, - public_key, - encryption::EncryptionAlgorithm::A256GCM, - None, - ) - .await - .change_context(errors::VaultError::SaveCardFailed) - .attach_printable("Error on jwe encrypt")?; + let jwe_encrypted = + encryption::encrypt_jwe(&payload, public_key, EncryptionAlgorithm::A256GCM, None) + .await + .change_context(errors::VaultError::SaveCardFailed) + .attach_printable("Error on jwe encrypt")?; let jwe_payload: Vec<&str> = jwe_encrypted.split('.').collect(); let generate_jwe_body = |payload: Vec<&str>| -> Option { diff --git a/crates/router/src/core/payments/helpers.rs b/crates/router/src/core/payments/helpers.rs index ded12b781d..23ac67c910 100644 --- a/crates/router/src/core/payments/helpers.rs +++ b/crates/router/src/core/payments/helpers.rs @@ -1788,7 +1788,7 @@ pub async fn retrieve_payment_method_with_temporary_token( pub async fn retrieve_card_with_permanent_token( state: &SessionState, locker_id: &str, - _payment_method_id: &common_utils::id_type::GlobalPaymentMethodId, + _payment_method_id: &id_type::GlobalPaymentMethodId, payment_intent: &PaymentIntent, card_token_data: Option<&domain::CardToken>, _merchant_key_store: &domain::MerchantKeyStore, diff --git a/crates/router/src/db/merchant_connector_account.rs b/crates/router/src/db/merchant_connector_account.rs index b51e7afb34..be2c25d476 100644 --- a/crates/router/src/db/merchant_connector_account.rs +++ b/crates/router/src/db/merchant_connector_account.rs @@ -785,7 +785,7 @@ impl MerchantConnectorAccountInterface for Store { format!("{}_{}", _profile_id.get_string_repr(), _connector_name).into(), ), cache::CacheKind::Accounts( - format!("{}", _merchant_connector_id.get_string_repr()).into(), + _merchant_connector_id.get_string_repr().to_string().into(), ), cache::CacheKind::CGraph( format!( diff --git a/crates/router/src/types/api/admin.rs b/crates/router/src/types/api/admin.rs index cb75fe6a9b..c7b76d1780 100644 --- a/crates/router/src/types/api/admin.rs +++ b/crates/router/src/types/api/admin.rs @@ -173,7 +173,7 @@ impl ForeignTryFrom for ProfileResponse { } #[cfg(feature = "v2")] -impl ForeignTryFrom for admin::ProfileResponse { +impl ForeignTryFrom for ProfileResponse { type Error = error_stack::Report; fn foreign_try_from(item: domain::Profile) -> Result { @@ -193,7 +193,7 @@ impl ForeignTryFrom for admin::ProfileResponse { let order_fulfillment_time = item .order_fulfillment_time - .map(api_models::admin::OrderFulfillmentTime::try_new) + .map(admin::OrderFulfillmentTime::try_new) .transpose() .change_context(errors::ParsingError::IntegerOverflow)?; diff --git a/crates/router/src/types/api/payment_methods.rs b/crates/router/src/types/api/payment_methods.rs index 65111815b5..28d387771b 100644 --- a/crates/router/src/types/api/payment_methods.rs +++ b/crates/router/src/types/api/payment_methods.rs @@ -69,25 +69,25 @@ impl PaymentMethodCreateExt for PaymentMethodCreate { self.payment_method_type, ), || { - return Err(report!(errors::ApiErrorResponse::InvalidRequestData { + Err(report!(errors::ApiErrorResponse::InvalidRequestData { message: "Invalid 'payment_method_type' provided".to_string() }) - .attach_printable("Invalid payment method type")); + .attach_printable("Invalid payment method type")) }, - ); + )?; utils::when( - !PaymentMethodCreate::validate_payment_method_data_against_payment_method( + !Self::validate_payment_method_data_against_payment_method( self.payment_method, self.payment_method_data.clone(), ), || { - return Err(report!(errors::ApiErrorResponse::InvalidRequestData { + Err(report!(errors::ApiErrorResponse::InvalidRequestData { message: "Invalid 'payment_method_data' provided".to_string() }) - .attach_printable("Invalid payment method data")); + .attach_printable("Invalid payment method data")) }, - ); + )?; Ok(()) } } @@ -101,25 +101,25 @@ impl PaymentMethodCreateExt for PaymentMethodIntentConfirm { self.payment_method_type, ), || { - return Err(report!(errors::ApiErrorResponse::InvalidRequestData { + Err(report!(errors::ApiErrorResponse::InvalidRequestData { message: "Invalid 'payment_method_type' provided".to_string() }) - .attach_printable("Invalid payment method type")); + .attach_printable("Invalid payment method type")) }, - ); + )?; utils::when( - !PaymentMethodIntentConfirm::validate_payment_method_data_against_payment_method( + !Self::validate_payment_method_data_against_payment_method( self.payment_method, self.payment_method_data.clone(), ), || { - return Err(report!(errors::ApiErrorResponse::InvalidRequestData { + Err(report!(errors::ApiErrorResponse::InvalidRequestData { message: "Invalid 'payment_method_data' provided".to_string() }) - .attach_printable("Invalid payment method data")); + .attach_printable("Invalid payment method data")) }, - ); + )?; Ok(()) } } diff --git a/crates/router/src/types/payment_methods.rs b/crates/router/src/types/payment_methods.rs index 9b8d17db42..e55516fc3a 100644 --- a/crates/router/src/types/payment_methods.rs +++ b/crates/router/src/types/payment_methods.rs @@ -78,7 +78,7 @@ impl VaultingInterface for GetVaultFingerprint { impl VaultingDataInterface for api::PaymentMethodCreateData { fn get_vaulting_data_key(&self) -> String { match &self { - api::PaymentMethodCreateData::Card(card) => card.card_number.to_string(), + Self::Card(card) => card.card_number.to_string(), } } } diff --git a/justfile b/justfile index 4cbaf38efe..e1b9c25935 100644 --- a/justfile +++ b/justfile @@ -19,7 +19,7 @@ clippy *FLAGS: #! /usr/bin/env bash set -euo pipefail - FEATURES="$(cargo metadata --all-features --format-version 1 | \ + FEATURES="$(cargo metadata --all-features --format-version 1 --no-deps | \ jq -r ' [ ( .workspace_members | sort ) as $package_ids # Store workspace crate package IDs in `package_ids` array | .packages[] | select( IN(.id; $package_ids[]) ) | .features | keys[] ] | unique # Select all unique features from all workspace crates @@ -35,7 +35,7 @@ clippy_v2 *FLAGS: #! /usr/bin/env bash set -euo pipefail - FEATURES="$(cargo metadata --all-features --format-version 1 | \ + FEATURES="$(cargo metadata --all-features --format-version 1 --no-deps | \ jq -r ' [ ( .workspace_members | sort ) as $package_ids # Store workspace crate package IDs in `package_ids` array | .packages[] | select( IN(.id; $package_ids[]) ) | .features | keys[] ] | unique # Select all unique features from all workspace crates @@ -44,14 +44,14 @@ clippy_v2 *FLAGS: ')" set -x - cargo clippy {{ check_flags }} --no-default-features --features "${FEATURES}" {{ FLAGS }} + cargo clippy {{ check_flags }} --no-default-features --features "${FEATURES}" {{ FLAGS }} set +x check_v2 *FLAGS: #! /usr/bin/env bash set -euo pipefail - FEATURES="$(cargo metadata --all-features --format-version 1 | \ + FEATURES="$(cargo metadata --all-features --format-version 1 --no-deps | \ jq -r ' [ ( .workspace_members | sort ) as $package_ids # Store workspace crate package IDs in `package_ids` array | .packages[] | select( IN(.id; $package_ids[]) ) | .features | keys[] ] | unique # Select all unique features from all workspace crates @@ -60,7 +60,7 @@ check_v2 *FLAGS: ')" set -x - cargo check {{ check_flags }} --no-default-features --features "${FEATURES}" {{ FLAGS }} + cargo check {{ check_flags }} --no-default-features --features "${FEATURES}" {{ FLAGS }} set +x run_v2: @@ -82,7 +82,7 @@ check *FLAGS: #! /usr/bin/env bash set -euo pipefail - FEATURES="$(cargo metadata --all-features --format-version 1 | \ + FEATURES="$(cargo metadata --all-features --format-version 1 --no-deps | \ jq -r ' [ ( .workspace_members | sort ) as $package_ids # Store workspace crate package IDs in `package_ids` array | .packages[] | select( IN(.id; $package_ids[]) ) | .features | keys[] ] | unique # Select all unique features from all workspace crates @@ -91,7 +91,7 @@ check *FLAGS: ')" set -x - cargo check {{ check_flags }} --features "${FEATURES}" {{ FLAGS }} + cargo check {{ check_flags }} --features "${FEATURES}" {{ FLAGS }} set +x alias cl := clippy