From e951a74a82347d60852885a7d6e0eb1503a70655 Mon Sep 17 00:00:00 2001 From: prajjwalkumar17 Date: Sat, 22 Jun 2024 15:49:25 +0530 Subject: [PATCH 01/15] feat(core): Constraint Graph for Payment Methods List --- crates/euclid/src/enums.rs | 2 + crates/router/src/core/payment_methods.rs | 1 + .../router/src/core/payment_methods/cards.rs | 667 ++++++------------ .../router/src/core/payment_methods/utils.rs | 8 +- .../src/db/merchant_connector_account.rs | 6 + .../routes/metrics/bg_metrics_collector.rs | 1 + crates/storage_impl/src/redis/cache.rs | 18 + crates/storage_impl/src/redis/pub_sub.rs | 17 +- 8 files changed, 259 insertions(+), 461 deletions(-) diff --git a/crates/euclid/src/enums.rs b/crates/euclid/src/enums.rs index 1aba6338d9d2..8e65d23d5ea9 100644 --- a/crates/euclid/src/enums.rs +++ b/crates/euclid/src/enums.rs @@ -79,6 +79,8 @@ pub enum MandateAcceptanceType { pub enum PaymentType { SetupMandate, NonMandate, + NewMandate, + UpdateMandate, } #[derive( diff --git a/crates/router/src/core/payment_methods.rs b/crates/router/src/core/payment_methods.rs index a4d4f38bfaf0..c7a6ff76a993 100644 --- a/crates/router/src/core/payment_methods.rs +++ b/crates/router/src/core/payment_methods.rs @@ -1,6 +1,7 @@ pub mod cards; pub mod surcharge_decision_configs; pub mod transformers; +pub mod utils; pub mod vault; pub use api_models::enums::Connector; diff --git a/crates/router/src/core/payment_methods/cards.rs b/crates/router/src/core/payment_methods/cards.rs index 204d7eb2439a..9562be188696 100644 --- a/crates/router/src/core/payment_methods/cards.rs +++ b/crates/router/src/core/payment_methods/cards.rs @@ -5,8 +5,8 @@ use std::{ }; use api_models::{ - admin::{self, PaymentMethodsEnabled}, - enums::{self as api_enums}, + admin::PaymentMethodsEnabled, + enums as api_enums, payment_methods::{ BankAccountTokenData, Card, CardDetailUpdate, CardDetailsPaymentMethod, CardNetworkTypes, CountryCodeWithName, CustomerDefaultPaymentMethodResponse, ListCountriesCurrenciesRequest, @@ -26,11 +26,17 @@ use common_utils::{ generate_id, id_type, }; use diesel_models::{ - business_profile::BusinessProfile, encryption::Encryption, enums as storage_enums, + business_profile::BusinessProfile, encryption::Encryption, payment_method, }; use domain::CustomerUpdate; use error_stack::{report, ResultExt}; +use euclid::{ + dssa::graph::{AnalysisContext, CgraphExt}, + frontend::dir, +}; +use hyperswitch_constraint_graph as cgraph; +use kgraph_utils::transformers::IntoDirValue; use masking::Secret; use router_env::{instrument, metrics::add_attributes, tracing}; use strum::IntoEnumIterator; @@ -46,7 +52,9 @@ use crate::{ core::{ errors::{self, StorageErrorExt}, payment_methods::{ - add_payment_method_status_update_task, transformers as payment_methods, vault, + add_payment_method_status_update_task, transformers as payment_methods, + utils::{get_merchant_pm_filter_graph, make_pm_graph, refresh_pm_filters_cache}, + vault, }, payments::{ helpers, @@ -1894,31 +1902,92 @@ pub async fn list_payment_methods( .await?; // filter out connectors based on the business country - let filtered_mcas = helpers::filter_mca_based_on_business_profile(all_mcas, profile_id); + let filtered_mcas = helpers::filter_mca_based_on_business_profile(all_mcas, profile_id.clone()); logger::debug!(mca_before_filtering=?filtered_mcas); let mut response: Vec = vec![]; - for mca in &filtered_mcas { - let payment_methods = match &mca.payment_methods_enabled { - Some(pm) => pm.clone(), - None => continue, - }; - - filter_payment_methods( - payment_methods, - &mut req, - &mut response, - payment_intent.as_ref(), - payment_attempt.as_ref(), - billing_address.as_ref(), - mca.connector_name.clone(), - pm_config_mapping, - &state.conf.mandates.supported_payment_methods, - &state.conf.mandates.update_mandate_supported, - &state.conf.saved_payment_methods, + // Key creation for storing PM_FILTER_CGRAPH + #[cfg(feature = "business_profile_routing")] + let key = { + let profile_id = profile_id + .clone() + .get_required_value("profile_id") + .change_context(errors::ApiErrorResponse::GenericNotFoundError { + message: "Profile id not found".to_string(), + })?; + format!( + "pm_filters_cgraph_{}_{}", + &merchant_account.merchant_id, profile_id ) - .await?; + }; + + #[cfg(not(feature = "business_profile_routing"))] + let key = { format!("pm_filters_cgraph_{}", &merchant_account.merchant_id) }; + + if let Some(graph) = get_merchant_pm_filter_graph(&state, &key).await { + // Derivation of PM_FILTER_CGRAPH from MokaCache successful + for mca in &filtered_mcas { + let payment_methods = match &mca.payment_methods_enabled { + Some(pm) => pm, + None => continue, + }; + filter_payment_methods( + &graph, + payment_methods, + &mut req, + &mut response, + payment_intent.as_ref(), + payment_attempt.as_ref(), + billing_address.as_ref(), + mca.connector_name.clone(), + &state.conf.saved_payment_methods, + ) + .await?; + } + } else { + // No PM_FILTER_CGRAPH Cache present in MokaCache + let mut builder = cgraph::ConstraintGraphBuilder::<'static, _>::new(); + for mca in &filtered_mcas { + let payment_methods = match &mca.payment_methods_enabled { + Some(pm) => pm, + None => continue, + }; + if let Err(e) = make_pm_graph( + &mut builder, + payment_methods, + mca.connector_name.clone(), + pm_config_mapping, + &state.conf.mandates.supported_payment_methods, + &state.conf.mandates.update_mandate_supported, + ) { + logger::error!( + "Failed to construct constraint graph for list payment methods {e:?}" + ); + } + } + + // Refreshing our CGraph cache + let graph = refresh_pm_filters_cache(&state, &key, builder.build()).await; + + for mca in &filtered_mcas { + let payment_methods = match &mca.payment_methods_enabled { + Some(pm) => pm, + None => continue, + }; + filter_payment_methods( + &graph, + payment_methods, + &mut req, + &mut response, + payment_intent.as_ref(), + payment_attempt.as_ref(), + billing_address.as_ref(), + mca.connector_name.clone(), + &state.conf.saved_payment_methods, + ) + .await?; + } } // Filter out wallet payment method from mca if customer has already saved it @@ -2813,20 +2882,18 @@ pub async fn call_surcharge_decision_management_for_saved_card( #[allow(clippy::too_many_arguments)] pub async fn filter_payment_methods( - payment_methods: Vec, + graph: &cgraph::ConstraintGraph<'_, dir::DirValue>, + payment_methods: &[serde_json::Value], req: &mut api::PaymentMethodListRequest, resp: &mut Vec, payment_intent: Option<&storage::PaymentIntent>, payment_attempt: Option<&storage::PaymentAttempt>, address: Option<&domain::Address>, connector: String, - config: &settings::ConnectorFilters, - supported_payment_methods_for_mandate: &settings::SupportedPaymentMethodsForMandate, - supported_payment_methods_for_update_mandate: &settings::SupportedPaymentMethodsForMandate, saved_payment_methods: &settings::EligiblePaymentMethods, ) -> errors::CustomResult<(), errors::ApiErrorResponse> { - for payment_method in payment_methods.into_iter() { - let parse_result = serde_json::from_value::(payment_method); + for payment_method in payment_methods.iter() { + let parse_result = serde_json::from_value::(payment_method.clone()); if let Ok(payment_methods_enabled) = parse_result { let payment_method = payment_methods_enabled.payment_method; @@ -2857,57 +2924,13 @@ pub async fn filter_payment_methods( .map(|minor_amount| minor_amount.get_amount_as_i64()), ) { - let mut payment_method_object = payment_method_type_info; - - let filter; - ( - payment_method_object.accepted_countries, - req.accepted_countries, - filter, - ) = filter_pm_country_based( - &payment_method_object.accepted_countries, - &req.accepted_countries, - ); - let filter2; - ( - payment_method_object.accepted_currencies, - req.accepted_currencies, - filter2, - ) = filter_pm_currencies_based( - &payment_method_object.accepted_currencies, - &req.accepted_currencies, - ); - - let filter4 = filter_pm_card_network_based( - payment_method_object.card_networks.as_ref(), - req.card_networks.as_ref(), - &payment_method_object.payment_method_type, - ); - - let filter3 = if let Some(payment_intent) = payment_intent { - filter_payment_country_based(&payment_method_object, address).await? - && filter_payment_currency_based(payment_intent, &payment_method_object) - && filter_payment_amount_based(payment_intent, &payment_method_object) - && filter_payment_mandate_based(payment_attempt, &payment_method_object) - .await? - } else { - true - }; + let payment_method_object = payment_method_type_info.clone(); - let filter5 = filter_pm_based_on_config( - config, - &connector, - &payment_method_object.payment_method_type, - payment_attempt, - &mut payment_method_object.card_networks, - &address.and_then(|inner| inner.country), - payment_attempt.and_then(|value| value.currency), - ); - - let filter6 = filter_pm_based_on_allowed_types( - allowed_payment_method_types.as_ref(), - &payment_method_object.payment_method_type, - ); + let pm_dir_value: dir::DirValue = + (payment_method_type_info.payment_method_type, payment_method) + .into_dir_value() + .change_context(errors::ApiErrorResponse::InternalServerError) + .attach_printable("pm_value_node not created")?; let connector_variant = api_enums::Connector::from_str(connector.as_str()) .change_context(errors::ConnectorError::InvalidConnectorName) @@ -2917,35 +2940,85 @@ pub async fn filter_payment_methods( .attach_printable_lazy(|| { format!("unable to parse connector name {connector:?}") })?; - let filter7 = payment_attempt - .and_then(|attempt| attempt.mandate_details.as_ref()) - .map(|_mandate_details| { - filter_pm_based_on_supported_payments_for_mandate( - supported_payment_methods_for_mandate, - &payment_method, - &payment_method_object.payment_method_type, - connector_variant, - ) + + let mut context_values: Vec = Vec::new(); + context_values.push(pm_dir_value.clone()); + + payment_intent.map(|intent| { + intent.currency.map(|currency| { + context_values.push(dir::DirValue::PaymentCurrency(currency)) }) - .unwrap_or(true); + }); + address.map(|address| { + address.country.map(|country| { + context_values.push(dir::DirValue::BillingCountry( + common_enums::Country::from_alpha2(country), + )) + }) + }); + + // Addition of Connector to context + if let Ok(connector) = api_enums::RoutableConnectors::from_str( + connector_variant.to_string().as_str(), + ) { + context_values.push(dir::DirValue::Connector(Box::new( + api_models::routing::ast::ConnectorChoice { + connector, + #[cfg(not(feature = "connector_choice_mca_id"))] + sub_label: None, + }, + ))); + }; + + let filter_pm_based_on_allowed_types = filter_pm_based_on_allowed_types( + allowed_payment_method_types.as_ref(), + &payment_method_object.payment_method_type, + ); - let filter8 = payment_attempt + if payment_attempt + .and_then(|attempt| attempt.mandate_details.as_ref()) + .is_some() + { + context_values.push(dir::DirValue::PaymentType( + euclid::enums::PaymentType::NewMandate, + )); + }; + + payment_attempt .and_then(|attempt| attempt.mandate_data.as_ref()) .map(|mandate_detail| { if mandate_detail.update_mandate_id.is_some() { - filter_pm_based_on_update_mandate_support_for_connector( - supported_payment_methods_for_update_mandate, - &payment_method, - &payment_method_object.payment_method_type, - connector_variant, - ) - } else { - true + context_values.push(dir::DirValue::PaymentType( + euclid::enums::PaymentType::UpdateMandate, + )); } + }); + + payment_attempt + .map(|attempt| { + attempt.mandate_data.is_none() && attempt.mandate_details.is_none() }) - .unwrap_or(true); + .and_then(|res| { + res.then(|| { + context_values.push(dir::DirValue::PaymentType( + euclid::enums::PaymentType::NonMandate, + )) + }) + }); + + payment_attempt + .and_then(|inner| inner.capture_method) + .map(|capture_method| { + context_values.push(dir::DirValue::CaptureMethod(capture_method)); + }); + + let filter_pm_card_network_based = filter_pm_card_network_based( + payment_method_object.card_networks.as_ref(), + req.card_networks.as_ref(), + &payment_method_object.payment_method_type, + ); - let filter9 = req + let saved_payment_methods_filter = req .client_secret .as_ref() .map(|cs| { @@ -2959,25 +3032,28 @@ pub async fn filter_payment_methods( }) .unwrap_or(true); - let connector = connector.clone(); + let context = AnalysisContext::from_dir_values(context_values.clone()); - let response_pm_type = ResponsePaymentMethodIntermediate::new( - payment_method_object, - connector, - payment_method, + let result = graph.key_value_analysis( + pm_dir_value.clone(), + &context, + &mut cgraph::Memoization::new(), + &mut cgraph::CycleCheck::new(), + None, ); - - if filter - && filter2 - && filter3 - && filter4 - && filter5 - && filter6 - && filter7 - && filter8 - && filter9 + if filter_pm_based_on_allowed_types + && filter_pm_card_network_based + && saved_payment_methods_filter + && matches!(result, Ok(())) { + let response_pm_type = ResponsePaymentMethodIntermediate::new( + payment_method_object, + connector.clone(), + payment_method, + ); resp.push(response_pm_type); + } else { + logger::error!("Filtering Payment Methods Failed"); } } } @@ -2985,287 +3061,12 @@ pub async fn filter_payment_methods( } Ok(()) } -pub fn filter_pm_based_on_update_mandate_support_for_connector( - supported_payment_methods_for_mandate: &settings::SupportedPaymentMethodsForMandate, - payment_method: &api_enums::PaymentMethod, - payment_method_type: &api_enums::PaymentMethodType, - connector: api_enums::Connector, -) -> bool { - if payment_method == &api_enums::PaymentMethod::Card { - supported_payment_methods_for_mandate - .0 - .get(payment_method) - .map(|payment_method_type_hm| { - let pm_credit = payment_method_type_hm - .0 - .get(&api_enums::PaymentMethodType::Credit) - .map(|conn| conn.connector_list.clone()) - .unwrap_or_default(); - let pm_debit = payment_method_type_hm - .0 - .get(&api_enums::PaymentMethodType::Debit) - .map(|conn| conn.connector_list.clone()) - .unwrap_or_default(); - &pm_credit | &pm_debit - }) - .map(|supported_connectors| supported_connectors.contains(&connector)) - .unwrap_or(false) - } else { - supported_payment_methods_for_mandate - .0 - .get(payment_method) - .and_then(|payment_method_type_hm| payment_method_type_hm.0.get(payment_method_type)) - .map(|supported_connectors| supported_connectors.connector_list.contains(&connector)) - .unwrap_or(false) - } -} - -fn filter_pm_based_on_supported_payments_for_mandate( - supported_payment_methods_for_mandate: &settings::SupportedPaymentMethodsForMandate, - payment_method: &api_enums::PaymentMethod, - payment_method_type: &api_enums::PaymentMethodType, - connector: api_enums::Connector, -) -> bool { - supported_payment_methods_for_mandate - .0 - .get(payment_method) - .and_then(|payment_method_type_hm| payment_method_type_hm.0.get(payment_method_type)) - .map(|supported_connectors| supported_connectors.connector_list.contains(&connector)) - .unwrap_or(false) -} -fn filter_pm_based_on_config<'a>( - config: &'a settings::ConnectorFilters, - connector: &'a str, - payment_method_type: &'a api_enums::PaymentMethodType, - payment_attempt: Option<&storage::PaymentAttempt>, - card_network: &mut Option>, - country: &Option, - currency: Option, -) -> bool { - config - .0 - .get(connector) - .or_else(|| config.0.get("default")) - .and_then(|inner| match payment_method_type { - api_enums::PaymentMethodType::Credit | api_enums::PaymentMethodType::Debit => { - let country_currency_filter = inner - .0 - .get(&settings::PaymentMethodFilterKey::PaymentMethodType( - *payment_method_type, - )) - .map(|value| global_country_currency_filter(value, country, currency)); - - card_network_filter(country, currency, card_network, inner); - - let capture_method_filter = payment_attempt - .and_then(|inner| inner.capture_method) - .and_then(|capture_method| { - (capture_method == storage_enums::CaptureMethod::Manual).then(|| { - filter_pm_based_on_capture_method_used(inner, payment_method_type) - }) - }); - - Some( - country_currency_filter.unwrap_or(true) - && capture_method_filter.unwrap_or(true), - ) - } - payment_method_type => inner - .0 - .get(&settings::PaymentMethodFilterKey::PaymentMethodType( - *payment_method_type, - )) - .map(|value| global_country_currency_filter(value, country, currency)), - }) - .unwrap_or(true) -} - -///Filters the payment method list on basis of Capture methods, checks whether the connector issues Manual payments using cards or not if not it won't be visible in payment methods list -fn filter_pm_based_on_capture_method_used( - payment_method_filters: &settings::PaymentMethodFilters, +fn filter_pm_based_on_allowed_types( + allowed_types: Option<&Vec>, payment_method_type: &api_enums::PaymentMethodType, ) -> bool { - payment_method_filters - .0 - .get(&settings::PaymentMethodFilterKey::PaymentMethodType( - *payment_method_type, - )) - .and_then(|v| v.not_available_flows) - .and_then(|v| v.capture_method) - .map(|v| !matches!(v, api_enums::CaptureMethod::Manual)) - .unwrap_or(true) -} - -fn card_network_filter( - country: &Option, - currency: Option, - card_network: &mut Option>, - payment_method_filters: &settings::PaymentMethodFilters, -) { - if let Some(value) = card_network.as_mut() { - let filtered_card_networks = value - .iter() - .filter(|&element| { - let key = settings::PaymentMethodFilterKey::CardNetwork(element.clone()); - payment_method_filters - .0 - .get(&key) - .map(|value| global_country_currency_filter(value, country, currency)) - .unwrap_or(true) - }) - .cloned() - .collect::>(); - *value = filtered_card_networks; - } -} - -fn global_country_currency_filter( - item: &settings::CurrencyCountryFlowFilter, - country: &Option, - currency: Option, -) -> bool { - let country_condition = item - .country - .as_ref() - .zip(country.as_ref()) - .map(|(lhs, rhs)| lhs.contains(rhs)); - let currency_condition = item - .currency - .as_ref() - .zip(currency) - .map(|(lhs, rhs)| lhs.contains(&rhs)); - country_condition.unwrap_or(true) && currency_condition.unwrap_or(true) -} - -fn filter_pm_card_network_based( - pm_card_networks: Option<&Vec>, - request_card_networks: Option<&Vec>, - pm_type: &api_enums::PaymentMethodType, -) -> bool { - match pm_type { - api_enums::PaymentMethodType::Credit | api_enums::PaymentMethodType::Debit => { - match (pm_card_networks, request_card_networks) { - (Some(pm_card_networks), Some(request_card_networks)) => request_card_networks - .iter() - .all(|card_network| pm_card_networks.contains(card_network)), - (None, Some(_)) => false, - _ => true, - } - } - _ => true, - } -} -fn filter_pm_country_based( - accepted_countries: &Option, - req_country_list: &Option>, -) -> ( - Option, - Option>, - bool, -) { - match (accepted_countries, req_country_list) { - (None, None) => (None, None, true), - (None, Some(ref r)) => ( - Some(admin::AcceptedCountries::EnableOnly(r.to_vec())), - Some(r.to_vec()), - true, - ), - (Some(l), None) => (Some(l.to_owned()), None, true), - (Some(l), Some(ref r)) => { - let updated = match l { - admin::AcceptedCountries::EnableOnly(acc) => { - filter_accepted_enum_based(&Some(acc.clone()), &Some(r.to_owned())) - .map(admin::AcceptedCountries::EnableOnly) - } - - admin::AcceptedCountries::DisableOnly(den) => { - filter_disabled_enum_based(&Some(den.clone()), &Some(r.to_owned())) - .map(admin::AcceptedCountries::DisableOnly) - } - - admin::AcceptedCountries::AllAccepted => { - Some(admin::AcceptedCountries::AllAccepted) - } - }; - - (updated, Some(r.to_vec()), true) - } - } -} - -fn filter_pm_currencies_based( - accepted_currency: &Option, - req_currency_list: &Option>, -) -> ( - Option, - Option>, - bool, -) { - match (accepted_currency, req_currency_list) { - (None, None) => (None, None, true), - (None, Some(ref r)) => ( - Some(admin::AcceptedCurrencies::EnableOnly(r.to_vec())), - Some(r.to_vec()), - true, - ), - (Some(l), None) => (Some(l.to_owned()), None, true), - (Some(l), Some(ref r)) => { - let updated = match l { - admin::AcceptedCurrencies::EnableOnly(acc) => { - filter_accepted_enum_based(&Some(acc.clone()), &Some(r.to_owned())) - .map(admin::AcceptedCurrencies::EnableOnly) - } - - admin::AcceptedCurrencies::DisableOnly(den) => { - filter_disabled_enum_based(&Some(den.clone()), &Some(r.to_owned())) - .map(admin::AcceptedCurrencies::DisableOnly) - } - - admin::AcceptedCurrencies::AllAccepted => { - Some(admin::AcceptedCurrencies::AllAccepted) - } - }; - - (updated, Some(r.to_vec()), true) - } - } -} - -fn filter_accepted_enum_based( - left: &Option>, - right: &Option>, -) -> Option> { - match (left, right) { - (Some(ref l), Some(ref r)) => { - let a: HashSet<&T> = HashSet::from_iter(l.iter()); - let b: HashSet<&T> = HashSet::from_iter(r.iter()); - - let y: Vec = a.intersection(&b).map(|&i| i.to_owned()).collect(); - Some(y) - } - (Some(ref l), None) => Some(l.to_vec()), - (_, _) => None, - } -} - -fn filter_disabled_enum_based( - left: &Option>, - right: &Option>, -) -> Option> { - match (left, right) { - (Some(ref l), Some(ref r)) => { - let mut enabled = Vec::new(); - for element in r { - if !l.contains(element) { - enabled.push(element.to_owned()); - } - } - Some(enabled) - } - (None, Some(r)) => Some(r.to_vec()), - (_, _) => None, - } + allowed_types.map_or(true, |pm| pm.contains(payment_method_type)) } fn filter_amount_based(payment_method: &RequestPaymentMethodTypes, amount: Option) -> bool { @@ -3283,24 +3084,9 @@ fn filter_amount_based(payment_method: &RequestPaymentMethodTypes, amount: Optio .map(|max_amt| amt <= max_amt.into()) }) .unwrap_or(true); - // let min_check = match (amount, payment_method.minimum_amount) { - // (Some(amt), Some(min_amt)) => amt >= min_amt, - // (_, _) => true, - // }; - // let max_check = match (amount, payment_method.maximum_amount) { - // (Some(amt), Some(max_amt)) => amt <= max_amt, - // (_, _) => true, - // }; (min_check && max_check) || amount == Some(0) } -fn filter_pm_based_on_allowed_types( - allowed_types: Option<&Vec>, - payment_method_type: &api_enums::PaymentMethodType, -) -> bool { - allowed_types.map_or(true, |pm| pm.contains(payment_method_type)) -} - fn filter_recurring_based( payment_method: &RequestPaymentMethodTypes, recurring_enabled: Option, @@ -3317,54 +3103,23 @@ fn filter_installment_based( }) } -async fn filter_payment_country_based( - pm: &RequestPaymentMethodTypes, - address: Option<&domain::Address>, -) -> errors::CustomResult { - Ok(address.map_or(true, |address| { - address.country.as_ref().map_or(true, |country| { - pm.accepted_countries.as_ref().map_or(true, |ac| match ac { - admin::AcceptedCountries::EnableOnly(acc) => acc.contains(country), - admin::AcceptedCountries::DisableOnly(den) => !den.contains(country), - admin::AcceptedCountries::AllAccepted => true, - }) - }) - })) -} - -fn filter_payment_currency_based( - payment_intent: &storage::PaymentIntent, - pm: &RequestPaymentMethodTypes, -) -> bool { - payment_intent.currency.map_or(true, |currency| { - pm.accepted_currencies.as_ref().map_or(true, |ac| match ac { - admin::AcceptedCurrencies::EnableOnly(acc) => acc.contains(¤cy), - admin::AcceptedCurrencies::DisableOnly(den) => !den.contains(¤cy), - admin::AcceptedCurrencies::AllAccepted => true, - }) - }) -} - -fn filter_payment_amount_based( - payment_intent: &storage::PaymentIntent, - pm: &RequestPaymentMethodTypes, +fn filter_pm_card_network_based( + pm_card_networks: Option<&Vec>, + request_card_networks: Option<&Vec>, + pm_type: &api_enums::PaymentMethodType, ) -> bool { - let amount = payment_intent.amount.get_amount_as_i64(); - (pm.maximum_amount.map_or(true, |amt| amount <= amt.into()) - && pm.minimum_amount.map_or(true, |amt| amount >= amt.into())) - || payment_intent.amount.get_amount_as_i64() == 0 -} - -async fn filter_payment_mandate_based( - payment_attempt: Option<&storage::PaymentAttempt>, - pm: &RequestPaymentMethodTypes, -) -> errors::CustomResult { - let recurring_filter = if !pm.recurring_enabled { - payment_attempt.map_or(true, |pa| pa.mandate_id.is_none()) - } else { - true - }; - Ok(recurring_filter) + match pm_type { + api_enums::PaymentMethodType::Credit | api_enums::PaymentMethodType::Debit => { + match (pm_card_networks, request_card_networks) { + (Some(pm_card_networks), Some(request_card_networks)) => request_card_networks + .iter() + .all(|card_network| pm_card_networks.contains(card_network)), + (None, Some(_)) => false, + _ => true, + } + } + _ => true, + } } pub async fn do_list_customer_pm_fetch_customer_if_not_passed( diff --git a/crates/router/src/core/payment_methods/utils.rs b/crates/router/src/core/payment_methods/utils.rs index 1b9897f9f050..3a32d3a741dd 100644 --- a/crates/router/src/core/payment_methods/utils.rs +++ b/crates/router/src/core/payment_methods/utils.rs @@ -1,5 +1,5 @@ use std::{str::FromStr, sync::Arc}; -: + use api_models::{ admin::{self, PaymentMethodsEnabled}, enums as api_enums, @@ -571,7 +571,7 @@ fn compile_accepted_countries_for_mca( agg_nodes.push(( pm_object_country_value_node, cgraph::Relation::Positive, - cgraph::Strength::Strong, + cgraph::Strength::Weak, )); } admin::AcceptedCountries::DisableOnly(countries) => { @@ -592,7 +592,7 @@ fn compile_accepted_countries_for_mca( agg_nodes.push(( pm_object_country_value_node, cgraph::Relation::Positive, - cgraph::Strength::Strong, + cgraph::Strength::Weak, )); } admin::AcceptedCountries::AllAccepted => return Ok(None), @@ -628,7 +628,7 @@ fn compile_accepted_countries_for_mca( agg_nodes.push(( config_country_agg_node, cgraph::Relation::Positive, - cgraph::Strength::Strong, + cgraph::Strength::Weak, )); } } diff --git a/crates/router/src/db/merchant_connector_account.rs b/crates/router/src/db/merchant_connector_account.rs index ab66b52c32d0..a176db265495 100644 --- a/crates/router/src/db/merchant_connector_account.rs +++ b/crates/router/src/db/merchant_connector_account.rs @@ -538,6 +538,9 @@ impl MerchantConnectorAccountInterface for Store { cache::CacheKind::CGraph( format!("cgraph_{}_{_profile_id}", _merchant_id).into(), ), + cache::CacheKind::PmFiltersCGraph( + format!("pm_filters_cgraph_{}_{_profile_id}", _merchant_id).into(), + ), ], update_call, ) @@ -595,6 +598,9 @@ impl MerchantConnectorAccountInterface for Store { cache::CacheKind::CGraph( format!("cgraph_{}_{_profile_id}", mca.merchant_id).into(), ), + cache::CacheKind::PmFiltersCGraph( + format!("pm_filters_cgraph_{}_{_profile_id}", mca.merchant_id).into(), + ), ], delete_call, ) diff --git a/crates/router/src/routes/metrics/bg_metrics_collector.rs b/crates/router/src/routes/metrics/bg_metrics_collector.rs index 681b523db137..52d7777f5aa8 100644 --- a/crates/router/src/routes/metrics/bg_metrics_collector.rs +++ b/crates/router/src/routes/metrics/bg_metrics_collector.rs @@ -11,6 +11,7 @@ pub fn spawn_metrics_collector(metrics_collection_interval_in_secs: &Option &cache::ACCOUNTS_CACHE, &cache::ROUTING_CACHE, &cache::CGRAPH_CACHE, + &cache::PM_FILTERS_CGRAPH_CACHE, &cache::DECISION_MANAGER_CACHE, &cache::SURCHARGE_CACHE, ]; diff --git a/crates/storage_impl/src/redis/cache.rs b/crates/storage_impl/src/redis/cache.rs index 036a8902bc38..6cfadbcb256f 100644 --- a/crates/storage_impl/src/redis/cache.rs +++ b/crates/storage_impl/src/redis/cache.rs @@ -44,6 +44,9 @@ const CGRAPH_CACHE_PREFIX: &str = "cgraph"; /// Prefix for all kinds of cache key const ALL_CACHE_PREFIX: &str = "all_cache_kind"; +/// Prefix for PM Filter cgraph cache key +const PM_FILTERS_CGRAPH_CACHE_PREFIX: &str = "pm_filters_cgraph"; + /// Time to live 30 mins const CACHE_TTL: u64 = 30 * 60; @@ -83,6 +86,16 @@ pub static SURCHARGE_CACHE: Lazy = pub static CGRAPH_CACHE: Lazy = Lazy::new(|| Cache::new("CGRAPH_CACHE", CACHE_TTL, CACHE_TTI, Some(MAX_CAPACITY))); +/// PM Filter CGraph Cache +pub static PM_FILTERS_CGRAPH_CACHE: Lazy = Lazy::new(|| { + Cache::new( + "PM_FILTERS_CGRAPH_CACHE", + CACHE_TTL, + CACHE_TTI, + Some(MAX_CAPACITY), + ) +}); + /// Trait which defines the behaviour of types that's gonna be stored in Cache pub trait Cacheable: Any + Send + Sync + DynClone { fn as_any(&self) -> &dyn Any; @@ -95,6 +108,7 @@ pub enum CacheKind<'a> { DecisionManager(Cow<'a, str>), Surcharge(Cow<'a, str>), CGraph(Cow<'a, str>), + PmFiltersCGraph(Cow<'a, str>), All(Cow<'a, str>), } @@ -107,6 +121,7 @@ impl<'a> From> for RedisValue { CacheKind::DecisionManager(s) => format!("{DECISION_MANAGER_CACHE_PREFIX},{s}"), CacheKind::Surcharge(s) => format!("{SURCHARGE_CACHE_PREFIX},{s}"), CacheKind::CGraph(s) => format!("{CGRAPH_CACHE_PREFIX},{s}"), + CacheKind::PmFiltersCGraph(s) => format!("{PM_FILTERS_CGRAPH_CACHE_PREFIX},{s}"), CacheKind::All(s) => format!("{ALL_CACHE_PREFIX},{s}"), }; Self::from_string(value) @@ -130,6 +145,9 @@ impl<'a> TryFrom for CacheKind<'a> { } SURCHARGE_CACHE_PREFIX => Ok(Self::Surcharge(Cow::Owned(split.1.to_string()))), CGRAPH_CACHE_PREFIX => Ok(Self::CGraph(Cow::Owned(split.1.to_string()))), + PM_FILTERS_CGRAPH_CACHE_PREFIX => { + Ok(Self::PmFiltersCGraph(Cow::Owned(split.1.to_string()))) + } ALL_CACHE_PREFIX => Ok(Self::All(Cow::Owned(split.1.to_string()))), _ => Err(validation_err.into()), } diff --git a/crates/storage_impl/src/redis/pub_sub.rs b/crates/storage_impl/src/redis/pub_sub.rs index 670ffbb54e17..89877f7e8dd9 100644 --- a/crates/storage_impl/src/redis/pub_sub.rs +++ b/crates/storage_impl/src/redis/pub_sub.rs @@ -6,7 +6,7 @@ use router_env::{logger, tracing::Instrument}; use crate::redis::cache::{ CacheKey, CacheKind, ACCOUNTS_CACHE, CGRAPH_CACHE, CONFIG_CACHE, DECISION_MANAGER_CACHE, - ROUTING_CACHE, SURCHARGE_CACHE, + PM_FILTERS_CGRAPH_CACHE, ROUTING_CACHE, SURCHARGE_CACHE, }; #[async_trait::async_trait] @@ -120,6 +120,15 @@ impl PubSubInterface for std::sync::Arc { .await; key } + CacheKind::PmFiltersCGraph(key) => { + PM_FILTERS_CGRAPH_CACHE + .remove(CacheKey { + key: key.to_string(), + prefix: self.key_prefix.clone(), + }) + .await; + key + } CacheKind::Routing(key) => { ROUTING_CACHE .remove(CacheKey { @@ -166,6 +175,12 @@ impl PubSubInterface for std::sync::Arc { prefix: self.key_prefix.clone(), }) .await; + PM_FILTERS_CGRAPH_CACHE + .remove(CacheKey { + key: key.to_string(), + prefix: self.key_prefix.clone(), + }) + .await; ROUTING_CACHE .remove(CacheKey { key: key.to_string(), From 03dbc0ece384a49dc1a24e6e2e75c954142da353 Mon Sep 17 00:00:00 2001 From: "hyperswitch-bot[bot]" <148525504+hyperswitch-bot[bot]@users.noreply.github.com> Date: Sat, 22 Jun 2024 10:21:43 +0000 Subject: [PATCH 02/15] chore: run formatter --- crates/router/src/core/payment_methods/cards.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/crates/router/src/core/payment_methods/cards.rs b/crates/router/src/core/payment_methods/cards.rs index 9562be188696..1c5ef7806965 100644 --- a/crates/router/src/core/payment_methods/cards.rs +++ b/crates/router/src/core/payment_methods/cards.rs @@ -25,10 +25,7 @@ use common_utils::{ ext_traits::{AsyncExt, Encode, StringExt, ValueExt}, generate_id, id_type, }; -use diesel_models::{ - business_profile::BusinessProfile, encryption::Encryption, - payment_method, -}; +use diesel_models::{business_profile::BusinessProfile, encryption::Encryption, payment_method}; use domain::CustomerUpdate; use error_stack::{report, ResultExt}; use euclid::{ From 1e6132fef44878d22876e6a0378be99abcac7738 Mon Sep 17 00:00:00 2001 From: prajjwalkumar17 Date: Wed, 26 Jun 2024 09:21:57 +0530 Subject: [PATCH 03/15] chore: refactor for cgraph --- crates/router/src/core/payment_methods/utils.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/router/src/core/payment_methods/utils.rs b/crates/router/src/core/payment_methods/utils.rs index 3a32d3a741dd..b7ac0fc208c1 100644 --- a/crates/router/src/core/payment_methods/utils.rs +++ b/crates/router/src/core/payment_methods/utils.rs @@ -247,7 +247,7 @@ fn compile_pm_graph( .make_edge( and_node_for_all_the_filters, payment_method_type_value_node, - cgraph::Strength::Strong, + cgraph::Strength::Normal, cgraph::Relation::Positive, None::, ) @@ -665,7 +665,7 @@ fn compile_accepted_currency_for_mca( agg_nodes.push(( pm_object_currency_value_node, cgraph::Relation::Positive, - cgraph::Strength::Strong, + cgraph::Strength::Weak, )); } admin::AcceptedCurrencies::DisableOnly(currency) => { @@ -682,7 +682,7 @@ fn compile_accepted_currency_for_mca( agg_nodes.push(( pm_object_currency_value_node, cgraph::Relation::Positive, - cgraph::Strength::Strong, + cgraph::Strength::Weak, )); } admin::AcceptedCurrencies::AllAccepted => return Ok(None), @@ -720,7 +720,7 @@ fn compile_accepted_currency_for_mca( agg_nodes.push(( config_currency_agg_node, cgraph::Relation::Positive, - cgraph::Strength::Strong, + cgraph::Strength::Weak, )); } } From 9f03b0a0d50635248b785066b5b0730cda2214f6 Mon Sep 17 00:00:00 2001 From: "hyperswitch-bot[bot]" <148525504+hyperswitch-bot[bot]@users.noreply.github.com> Date: Fri, 28 Jun 2024 10:32:04 +0000 Subject: [PATCH 04/15] chore: run formatter --- crates/router/src/core/payment_methods/utils.rs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/crates/router/src/core/payment_methods/utils.rs b/crates/router/src/core/payment_methods/utils.rs index 9d2ea5b71a75..8562359cb6c5 100644 --- a/crates/router/src/core/payment_methods/utils.rs +++ b/crates/router/src/core/payment_methods/utils.rs @@ -42,12 +42,10 @@ pub async fn get_merchant_pm_filter_graph<'a>( key: &str, ) -> Option>> { PM_FILTERS_CGRAPH_CACHE - .get_val::>>( - CacheKey { - key: key.to_string(), - prefix: state.tenant.redis_key_prefix.clone(), - }, - ) + .get_val::>>(CacheKey { + key: key.to_string(), + prefix: state.tenant.redis_key_prefix.clone(), + }) .await } From 8adccdb508975bc10b89689bf2d90492364674f9 Mon Sep 17 00:00:00 2001 From: prajjwalkumar17 Date: Fri, 28 Jun 2024 16:49:02 +0530 Subject: [PATCH 05/15] chore: merge conflicts --- .../router/src/core/payment_methods/cards.rs | 322 +++++++++--------- 1 file changed, 161 insertions(+), 161 deletions(-) diff --git a/crates/router/src/core/payment_methods/cards.rs b/crates/router/src/core/payment_methods/cards.rs index ff66ff250bb5..b4a69d9927e7 100644 --- a/crates/router/src/core/payment_methods/cards.rs +++ b/crates/router/src/core/payment_methods/cards.rs @@ -5,7 +5,7 @@ use std::{ }; use api_models::{ - admin::{self, PaymentMethodsEnabled}, + admin::PaymentMethodsEnabled, enums as api_enums, payment_methods::{ BankAccountTokenData, Card, CardDetailUpdate, CardDetailsPaymentMethod, CardNetworkTypes, @@ -3130,117 +3130,117 @@ fn filter_pm_card_network_based( _ => true, } } -fn filter_pm_country_based( - accepted_countries: &Option, - req_country_list: &Option>, -) -> ( - Option, - Option>, - bool, -) { - match (accepted_countries, req_country_list) { - (None, None) => (None, None, true), - (None, Some(ref r)) => ( - Some(admin::AcceptedCountries::EnableOnly(r.to_vec())), - Some(r.to_vec()), - true, - ), - (Some(l), None) => (Some(l.to_owned()), None, true), - (Some(l), Some(ref r)) => { - let updated = match l { - admin::AcceptedCountries::EnableOnly(acc) => { - filter_accepted_enum_based(&Some(acc.clone()), &Some(r.to_owned())) - .map(admin::AcceptedCountries::EnableOnly) - } - - admin::AcceptedCountries::DisableOnly(den) => { - filter_disabled_enum_based(&Some(den.clone()), &Some(r.to_owned())) - .map(admin::AcceptedCountries::DisableOnly) - } - - admin::AcceptedCountries::AllAccepted => { - Some(admin::AcceptedCountries::AllAccepted) - } - }; - - (updated, Some(r.to_vec()), true) - } - } -} - -fn filter_pm_currencies_based( - accepted_currency: &Option, - req_currency_list: &Option>, -) -> ( - Option, - Option>, - bool, -) { - match (accepted_currency, req_currency_list) { - (None, None) => (None, None, true), - (None, Some(ref r)) => ( - Some(admin::AcceptedCurrencies::EnableOnly(r.to_vec())), - Some(r.to_vec()), - true, - ), - (Some(l), None) => (Some(l.to_owned()), None, true), - (Some(l), Some(ref r)) => { - let updated = match l { - admin::AcceptedCurrencies::EnableOnly(acc) => { - filter_accepted_enum_based(&Some(acc.clone()), &Some(r.to_owned())) - .map(admin::AcceptedCurrencies::EnableOnly) - } - - admin::AcceptedCurrencies::DisableOnly(den) => { - filter_disabled_enum_based(&Some(den.clone()), &Some(r.to_owned())) - .map(admin::AcceptedCurrencies::DisableOnly) - } - - admin::AcceptedCurrencies::AllAccepted => { - Some(admin::AcceptedCurrencies::AllAccepted) - } - }; - - (updated, Some(r.to_vec()), true) - } - } -} - -fn filter_accepted_enum_based( - left: &Option>, - right: &Option>, -) -> Option> { - match (left, right) { - (Some(ref l), Some(ref r)) => { - let a: HashSet<&T> = HashSet::from_iter(l.iter()); - let b: HashSet<&T> = HashSet::from_iter(r.iter()); - - let y: Vec = a.intersection(&b).map(|&i| i.to_owned()).collect(); - Some(y) - } - (Some(ref l), None) => Some(l.to_vec()), - (_, _) => None, - } -} - -fn filter_disabled_enum_based( - left: &Option>, - right: &Option>, -) -> Option> { - match (left, right) { - (Some(ref l), Some(ref r)) => { - let mut enabled = Vec::new(); - for element in r { - if !l.contains(element) { - enabled.push(element.to_owned()); - } - } - Some(enabled) - } - (None, Some(r)) => Some(r.to_vec()), - (_, _) => None, - } -} +// fn filter_pm_country_based( +// accepted_countries: &Option, +// req_country_list: &Option>, +// ) -> ( +// Option, +// Option>, +// bool, +// ) { +// match (accepted_countries, req_country_list) { +// (None, None) => (None, None, true), +// (None, Some(ref r)) => ( +// Some(admin::AcceptedCountries::EnableOnly(r.to_vec())), +// Some(r.to_vec()), +// true, +// ), +// (Some(l), None) => (Some(l.to_owned()), None, true), +// (Some(l), Some(ref r)) => { +// let updated = match l { +// admin::AcceptedCountries::EnableOnly(acc) => { +// filter_accepted_enum_based(&Some(acc.clone()), &Some(r.to_owned())) +// .map(admin::AcceptedCountries::EnableOnly) +// } +// +// admin::AcceptedCountries::DisableOnly(den) => { +// filter_disabled_enum_based(&Some(den.clone()), &Some(r.to_owned())) +// .map(admin::AcceptedCountries::DisableOnly) +// } +// +// admin::AcceptedCountries::AllAccepted => { +// Some(admin::AcceptedCountries::AllAccepted) +// } +// }; +// +// (updated, Some(r.to_vec()), true) +// } +// } +// } +// +// fn filter_pm_currencies_based( +// accepted_currency: &Option, +// req_currency_list: &Option>, +// ) -> ( +// Option, +// Option>, +// bool, +// ) { +// match (accepted_currency, req_currency_list) { +// (None, None) => (None, None, true), +// (None, Some(ref r)) => ( +// Some(admin::AcceptedCurrencies::EnableOnly(r.to_vec())), +// Some(r.to_vec()), +// true, +// ), +// (Some(l), None) => (Some(l.to_owned()), None, true), +// (Some(l), Some(ref r)) => { +// let updated = match l { +// admin::AcceptedCurrencies::EnableOnly(acc) => { +// filter_accepted_enum_based(&Some(acc.clone()), &Some(r.to_owned())) +// .map(admin::AcceptedCurrencies::EnableOnly) +// } +// +// admin::AcceptedCurrencies::DisableOnly(den) => { +// filter_disabled_enum_based(&Some(den.clone()), &Some(r.to_owned())) +// .map(admin::AcceptedCurrencies::DisableOnly) +// } +// +// admin::AcceptedCurrencies::AllAccepted => { +// Some(admin::AcceptedCurrencies::AllAccepted) +// } +// }; +// +// (updated, Some(r.to_vec()), true) +// } +// } +// } +// +// fn filter_accepted_enum_based( +// left: &Option>, +// right: &Option>, +// ) -> Option> { +// match (left, right) { +// (Some(ref l), Some(ref r)) => { +// let a: HashSet<&T> = HashSet::from_iter(l.iter()); +// let b: HashSet<&T> = HashSet::from_iter(r.iter()); +// +// let y: Vec = a.intersection(&b).map(|&i| i.to_owned()).collect(); +// Some(y) +// } +// (Some(ref l), None) => Some(l.to_vec()), +// (_, _) => None, +// } +// } +// +// fn filter_disabled_enum_based( +// left: &Option>, +// right: &Option>, +// ) -> Option> { +// match (left, right) { +// (Some(ref l), Some(ref r)) => { +// let mut enabled = Vec::new(); +// for element in r { +// if !l.contains(element) { +// enabled.push(element.to_owned()); +// } +// } +// Some(enabled) +// } +// (None, Some(r)) => Some(r.to_vec()), +// (_, _) => None, +// } +// } fn filter_pm_based_on_allowed_types( allowed_types: Option<&Vec>, @@ -3256,55 +3256,55 @@ fn filter_recurring_based( recurring_enabled.map_or(true, |enabled| payment_method.recurring_enabled == enabled) } -async fn filter_payment_country_based( - pm: &RequestPaymentMethodTypes, - address: Option<&domain::Address>, -) -> errors::CustomResult { - Ok(address.map_or(true, |address| { - address.country.as_ref().map_or(true, |country| { - pm.accepted_countries.as_ref().map_or(true, |ac| match ac { - admin::AcceptedCountries::EnableOnly(acc) => acc.contains(country), - admin::AcceptedCountries::DisableOnly(den) => !den.contains(country), - admin::AcceptedCountries::AllAccepted => true, - }) - }) - })) -} - -fn filter_payment_currency_based( - payment_intent: &storage::PaymentIntent, - pm: &RequestPaymentMethodTypes, -) -> bool { - payment_intent.currency.map_or(true, |currency| { - pm.accepted_currencies.as_ref().map_or(true, |ac| match ac { - admin::AcceptedCurrencies::EnableOnly(acc) => acc.contains(¤cy), - admin::AcceptedCurrencies::DisableOnly(den) => !den.contains(¤cy), - admin::AcceptedCurrencies::AllAccepted => true, - }) - }) -} - -fn filter_payment_amount_based( - payment_intent: &storage::PaymentIntent, - pm: &RequestPaymentMethodTypes, -) -> bool { - let amount = payment_intent.amount; - (pm.maximum_amount.map_or(true, |amt| amount <= amt) - && pm.minimum_amount.map_or(true, |amt| amount >= amt)) - || payment_intent.amount == MinorUnit::zero() -} - -async fn filter_payment_mandate_based( - payment_attempt: Option<&storage::PaymentAttempt>, - pm: &RequestPaymentMethodTypes, -) -> errors::CustomResult { - let recurring_filter = if !pm.recurring_enabled { - payment_attempt.map_or(true, |pa| pa.mandate_id.is_none()) - } else { - true - }; - Ok(recurring_filter) -} +// async fn filter_payment_country_based( +// pm: &RequestPaymentMethodTypes, +// address: Option<&domain::Address>, +// ) -> errors::CustomResult { +// Ok(address.map_or(true, |address| { +// address.country.as_ref().map_or(true, |country| { +// pm.accepted_countries.as_ref().map_or(true, |ac| match ac { +// admin::AcceptedCountries::EnableOnly(acc) => acc.contains(country), +// admin::AcceptedCountries::DisableOnly(den) => !den.contains(country), +// admin::AcceptedCountries::AllAccepted => true, +// }) +// }) +// })) +// } +// +// fn filter_payment_currency_based( +// payment_intent: &storage::PaymentIntent, +// pm: &RequestPaymentMethodTypes, +// ) -> bool { +// payment_intent.currency.map_or(true, |currency| { +// pm.accepted_currencies.as_ref().map_or(true, |ac| match ac { +// admin::AcceptedCurrencies::EnableOnly(acc) => acc.contains(¤cy), +// admin::AcceptedCurrencies::DisableOnly(den) => !den.contains(¤cy), +// admin::AcceptedCurrencies::AllAccepted => true, +// }) +// }) +// } +// +// fn filter_payment_amount_based( +// payment_intent: &storage::PaymentIntent, +// pm: &RequestPaymentMethodTypes, +// ) -> bool { +// let amount = payment_intent.amount; +// (pm.maximum_amount.map_or(true, |amt| amount <= amt) +// && pm.minimum_amount.map_or(true, |amt| amount >= amt)) +// || payment_intent.amount == MinorUnit::zero() +// } +// +// async fn filter_payment_mandate_based( +// payment_attempt: Option<&storage::PaymentAttempt>, +// pm: &RequestPaymentMethodTypes, +// ) -> errors::CustomResult { +// let recurring_filter = if !pm.recurring_enabled { +// payment_attempt.map_or(true, |pa| pa.mandate_id.is_none()) +// } else { +// true +// }; +// Ok(recurring_filter) +// } pub async fn do_list_customer_pm_fetch_customer_if_not_passed( state: routes::SessionState, From cbf1ec5febe0c9db656acd490f182b059cba64f5 Mon Sep 17 00:00:00 2001 From: prajjwalkumar17 Date: Thu, 4 Jul 2024 02:02:41 +0530 Subject: [PATCH 06/15] chore: cypress tests with bug fix for not reading the default paymentmethods in case of connector found in configs --- config/development.toml | 2 + .../src/builder.rs | 20 +- .../hyperswitch_constraint_graph/src/types.rs | 8 - crates/kgraph_utils/src/error.rs | 2 + .../router/src/core/payment_methods/cards.rs | 23 +- .../router/src/core/payment_methods/utils.rs | 171 ++-- ...0000-PaymentMethodListConfigCurrency.cy.js | 81 ++ ...01-PaymentMethodListMcaWrongCurrency.cy.js | 82 ++ .../00002-PaymentMethodListMcaCountry.cy.js | 82 ++ ...-PaymentMethodListConfigWrongCountry.cy.js | 82 ++ ...entMethodListNoConfigCurrencyCountry.cy.js | 85 ++ .../e2e/PaymentMethodListUtils/Common.js | 391 +++++++++ .../e2e/PaymentMethodListUtils/Cybersource.js | 470 +++++++++++ .../e2e/PaymentMethodListUtils/Stripe.js | 754 ++++++++++++++++++ .../e2e/PaymentMethodListUtils/utils.js | 43 + cypress-tests/cypress/support/commands.js | 134 ++++ cypress-tests/package-lock.json | 8 +- cypress-tests/package.json | 2 +- 18 files changed, 2362 insertions(+), 78 deletions(-) create mode 100644 cypress-tests/cypress/e2e/PaymentMethodListTest/00000-PaymentMethodListConfigCurrency.cy.js create mode 100644 cypress-tests/cypress/e2e/PaymentMethodListTest/00001-PaymentMethodListMcaWrongCurrency.cy.js create mode 100644 cypress-tests/cypress/e2e/PaymentMethodListTest/00002-PaymentMethodListMcaCountry.cy.js create mode 100644 cypress-tests/cypress/e2e/PaymentMethodListTest/00003-PaymentMethodListConfigWrongCountry.cy.js create mode 100644 cypress-tests/cypress/e2e/PaymentMethodListTest/00004-PaymentMethodListNoConfigCurrencyCountry.cy.js create mode 100644 cypress-tests/cypress/e2e/PaymentMethodListUtils/Common.js create mode 100644 cypress-tests/cypress/e2e/PaymentMethodListUtils/Cybersource.js create mode 100644 cypress-tests/cypress/e2e/PaymentMethodListUtils/Stripe.js create mode 100644 cypress-tests/cypress/e2e/PaymentMethodListUtils/utils.js diff --git a/config/development.toml b/config/development.toml index ecece79a696d..2aaf0e699220 100644 --- a/config/development.toml +++ b/config/development.toml @@ -99,6 +99,7 @@ cards = [ "airwallex", "authorizedotnet", "bambora", + "bamboraapac", "bankofamerica", "billwerk", "bitpay", @@ -175,6 +176,7 @@ airwallex.base_url = "https://api-demo.airwallex.com/" applepay.base_url = "https://apple-pay-gateway.apple.com/" authorizedotnet.base_url = "https://apitest.authorize.net/xml/v1/request.api" bambora.base_url = "https://api.na.bambora.com" +bamboraapac.base_url = "https://demo.bambora.co.nz/interface/api/dts.asmx" bankofamerica.base_url = "https://apitest.merchant-services.bankofamerica.com/" billwerk.base_url = "https://api.reepay.com/" billwerk.secondary_base_url = "https://card.reepay.com/" diff --git a/crates/hyperswitch_constraint_graph/src/builder.rs b/crates/hyperswitch_constraint_graph/src/builder.rs index ad28375616f7..96b7ff9671eb 100644 --- a/crates/hyperswitch_constraint_graph/src/builder.rs +++ b/crates/hyperswitch_constraint_graph/src/builder.rs @@ -194,7 +194,7 @@ where nodes: &[(NodeId, Relation, Strength)], info: Option<&'static str>, metadata: Option, - domain: Option, + domain_id: Option, ) -> Result> { nodes .iter() @@ -208,13 +208,7 @@ where .push(metadata.map(|meta| -> Arc { Arc::new(meta) })); for (node_id, relation, strength) in nodes { - self.make_edge( - *node_id, - aggregator_id, - *strength, - *relation, - domain.clone(), - )?; + self.make_edge(*node_id, aggregator_id, *strength, *relation, domain_id)?; } Ok(aggregator_id) @@ -225,7 +219,7 @@ where nodes: &[(NodeId, Relation, Strength)], info: Option<&'static str>, metadata: Option, - domain: Option, + domain_id: Option, ) -> Result> { nodes .iter() @@ -239,13 +233,7 @@ where .push(metadata.map(|meta| -> Arc { Arc::new(meta) })); for (node_id, relation, strength) in nodes { - self.make_edge( - *node_id, - aggregator_id, - *strength, - *relation, - domain.clone(), - )?; + self.make_edge(*node_id, aggregator_id, *strength, *relation, domain_id)?; } Ok(aggregator_id) diff --git a/crates/hyperswitch_constraint_graph/src/types.rs b/crates/hyperswitch_constraint_graph/src/types.rs index 174a7cdaeaa7..0cbecc28f281 100644 --- a/crates/hyperswitch_constraint_graph/src/types.rs +++ b/crates/hyperswitch_constraint_graph/src/types.rs @@ -158,14 +158,6 @@ impl From for DomainIdentifier { } } -// impl Deref for DomainIdentifier { -// type Target = &String; -// -// fn deref(&self) -> Self::Target { -// self.0 -// } -// } - #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct DomainInfo { pub domain_identifier: DomainIdentifier, diff --git a/crates/kgraph_utils/src/error.rs b/crates/kgraph_utils/src/error.rs index 95450fbe3502..ef9e3fd506b7 100644 --- a/crates/kgraph_utils/src/error.rs +++ b/crates/kgraph_utils/src/error.rs @@ -5,6 +5,8 @@ use euclid::{dssa::types::AnalysisErrorType, frontend::dir}; pub enum KgraphError { #[error("Invalid connector name encountered: '{0}'")] InvalidConnectorName(String), + #[error("Error in domain creation")] + DomainCreationError, #[error("There was an error constructing the graph: {0}")] GraphConstructionError(hyperswitch_constraint_graph::GraphError), #[error("There was an error constructing the context")] diff --git a/crates/router/src/core/payment_methods/cards.rs b/crates/router/src/core/payment_methods/cards.rs index b4a69d9927e7..827d1cd07c2c 100644 --- a/crates/router/src/core/payment_methods/cards.rs +++ b/crates/router/src/core/payment_methods/cards.rs @@ -1965,6 +1965,7 @@ pub async fn list_payment_methods( }; filter_payment_methods( &graph, + mca.merchant_connector_id.clone(), payment_methods, &mut req, &mut response, @@ -1980,12 +1981,26 @@ pub async fn list_payment_methods( // No PM_FILTER_CGRAPH Cache present in MokaCache let mut builder = cgraph::ConstraintGraphBuilder::new(); for mca in &filtered_mcas { + let domain_id = builder + .make_domain( + mca.merchant_connector_id.clone(), + mca.connector_name.as_str(), + ); + + let Ok(domain_id) = domain_id else { + logger::error!( + "Failed to construct domain for list payment methods" + ); + return Err(errors::ApiErrorResponse::InternalServerError.into()); + }; + let payment_methods = match &mca.payment_methods_enabled { Some(pm) => pm, None => continue, }; if let Err(e) = make_pm_graph( &mut builder, + domain_id, payment_methods, mca.connector_name.clone(), pm_config_mapping, @@ -1999,7 +2014,8 @@ pub async fn list_payment_methods( } // Refreshing our CGraph cache - let graph = refresh_pm_filters_cache(&state, &key, builder.build()).await; + let graph = + refresh_pm_filters_cache(&state, &key, builder.build()).await; for mca in &filtered_mcas { let payment_methods = match &mca.payment_methods_enabled { @@ -2008,6 +2024,7 @@ pub async fn list_payment_methods( }; filter_payment_methods( &graph, + mca.merchant_connector_id.clone(), payment_methods, &mut req, &mut response, @@ -2915,6 +2932,7 @@ pub async fn call_surcharge_decision_management_for_saved_card( #[allow(clippy::too_many_arguments)] pub async fn filter_payment_methods( graph: &cgraph::ConstraintGraph, + mca_id: String, payment_methods: &[serde_json::Value], req: &mut api::PaymentMethodListRequest, resp: &mut Vec, @@ -3062,12 +3080,13 @@ pub async fn filter_payment_methods( let context = AnalysisContext::from_dir_values(context_values.clone()); + let domain_ident: &[String] = &[mca_id.clone()]; let result = graph.key_value_analysis( pm_dir_value.clone(), &context, &mut cgraph::Memoization::new(), &mut cgraph::CycleCheck::new(), - None, + Some(domain_ident), ); if filter_pm_based_on_allowed_types && filter_pm_card_network_based diff --git a/crates/router/src/core/payment_methods/utils.rs b/crates/router/src/core/payment_methods/utils.rs index 8562359cb6c5..4a295c042343 100644 --- a/crates/router/src/core/payment_methods/utils.rs +++ b/crates/router/src/core/payment_methods/utils.rs @@ -15,6 +15,7 @@ use crate::{configs::settings, routes::SessionState}; pub fn make_pm_graph( builder: &mut cgraph::ConstraintGraphBuilder, + domain_id: cgraph::DomainId, payment_methods: &[serde_json::value::Value], connector: String, pm_config_mapping: &settings::ConnectorFilters, @@ -26,6 +27,7 @@ pub fn make_pm_graph( if let Ok(payment_methods_enabled) = pm_enabled { compile_pm_graph( builder, + domain_id, payment_methods_enabled.clone(), connector.clone(), pm_config_mapping, @@ -40,9 +42,15 @@ pub fn make_pm_graph( pub async fn get_merchant_pm_filter_graph<'a>( state: &SessionState, key: &str, -) -> Option>> { +) -> Option< + Arc< + hyperswitch_constraint_graph::ConstraintGraph + >, +> { PM_FILTERS_CGRAPH_CACHE - .get_val::>>(CacheKey { + .get_val::, + >>(CacheKey { key: key.to_string(), prefix: state.tenant.redis_key_prefix.clone(), }) @@ -69,6 +77,7 @@ pub async fn refresh_pm_filters_cache( fn compile_pm_graph( builder: &mut cgraph::ConstraintGraphBuilder, + domain_id: cgraph::DomainId, pm_enabled: PaymentMethodsEnabled, connector: String, config: &settings::ConnectorFilters, @@ -88,6 +97,7 @@ fn compile_pm_graph( // Connector supported for Update mandate filter let res = construct_supported_connectors_for_update_mandate_node( builder, + domain_id, supported_payment_methods_for_update_mandate, pmt.clone(), &pm_enabled.payment_method, @@ -117,6 +127,7 @@ fn compile_pm_graph( if let Ok(Some(connector_eligible_for_mandates_node)) = construct_supported_connectors_for_mandate_node( builder, + domain_id, supported_connectors, ) { @@ -161,7 +172,7 @@ fn compile_pm_graph( ], None, None::<()>, - None, + Some(domain_id), ) .map_err(KgraphError::GraphConstructionError)?; @@ -172,7 +183,12 @@ fn compile_pm_graph( )); let agg_or_node = builder - .make_any_aggregator(&agg_or_nodes_for_mandate_filters, None, None::<()>, None) + .make_any_aggregator( + &agg_or_nodes_for_mandate_filters, + None, + None::<()>, + Some(domain_id), + ) .map_err(KgraphError::GraphConstructionError)?; agg_nodes.push(( @@ -201,6 +217,7 @@ fn compile_pm_graph( // Country filter if let Ok(Some(country_node)) = compile_accepted_countries_for_mca( builder, + domain_id, &pmt.payment_method_type, pmt.accepted_countries, config, @@ -216,6 +233,7 @@ fn compile_pm_graph( // Currency filter if let Ok(Some(currency_node)) = compile_accepted_currency_for_mca( builder, + domain_id, &pmt.payment_method_type, pmt.accepted_currencies, config, @@ -229,7 +247,7 @@ fn compile_pm_graph( } let and_node_for_all_the_filters = builder - .make_all_aggregator(&agg_nodes, None, None::<()>, None) + .make_all_aggregator(&agg_nodes, None, None::<()>, Some(domain_id)) .map_err(KgraphError::GraphConstructionError)?; // Making our output node @@ -247,7 +265,7 @@ fn compile_pm_graph( payment_method_type_value_node, cgraph::Strength::Normal, cgraph::Relation::Positive, - None::, + Some(domain_id), ) .map_err(KgraphError::GraphConstructionError)?; } @@ -255,34 +273,9 @@ fn compile_pm_graph( Ok(()) } -fn construct_capture_method_node( - builder: &mut cgraph::ConstraintGraphBuilder, - payment_method_filters: &settings::PaymentMethodFilters, - payment_method_type: &api_enums::PaymentMethodType, -) -> Result, KgraphError> { - if !payment_method_filters - .0 - .get(&settings::PaymentMethodFilterKey::PaymentMethodType( - *payment_method_type, - )) - .and_then(|v| v.not_available_flows) - .and_then(|v| v.capture_method) - .map(|v| !matches!(v, api_enums::CaptureMethod::Manual)) - .unwrap_or(true) - { - return Ok(Some(builder.make_value_node( - cgraph::NodeValue::Value(dir::DirValue::CaptureMethod( - common_enums::CaptureMethod::Manual, - )), - None, - None::<()>, - ))); - } - Ok(None) -} - fn construct_supported_connectors_for_update_mandate_node( builder: &mut cgraph::ConstraintGraphBuilder, + domain_id: cgraph::DomainId, supported_payment_methods_for_update_mandate: &settings::SupportedPaymentMethodsForMandate, pmt: RequestPaymentMethodTypes, payment_method: &enums::PaymentMethod, @@ -384,7 +377,7 @@ fn construct_supported_connectors_for_update_mandate_node( ], None, None::<()>, - None, + Some(domain_id), ) .map_err(KgraphError::GraphConstructionError)?; @@ -440,7 +433,7 @@ fn construct_supported_connectors_for_update_mandate_node( ], None, None::<()>, - None, + Some(domain_id), ) .map_err(KgraphError::GraphConstructionError)?; @@ -458,7 +451,7 @@ fn construct_supported_connectors_for_update_mandate_node( &agg_nodes, Some("any node for card and non card pm"), None::<()>, - None, + Some(domain_id), ) .map_err(KgraphError::GraphConstructionError)?, )) @@ -466,6 +459,7 @@ fn construct_supported_connectors_for_update_mandate_node( fn construct_supported_connectors_for_mandate_node( builder: &mut cgraph::ConstraintGraphBuilder, + domain_id: cgraph::DomainId, eligible_connectors: Vec, ) -> Result, KgraphError> { let payment_type_value_node = builder.make_value_node( @@ -514,13 +508,39 @@ fn construct_supported_connectors_for_mandate_node( ], None, None::<()>, - None, + Some(domain_id), ) .map_err(KgraphError::GraphConstructionError)?, )) } } +fn construct_capture_method_node( + builder: &mut cgraph::ConstraintGraphBuilder, + payment_method_filters: &settings::PaymentMethodFilters, + payment_method_type: &api_enums::PaymentMethodType, +) -> Result, KgraphError> { + if !payment_method_filters + .0 + .get(&settings::PaymentMethodFilterKey::PaymentMethodType( + *payment_method_type, + )) + .and_then(|v| v.not_available_flows) + .and_then(|v| v.capture_method) + .map(|v| !matches!(v, api_enums::CaptureMethod::Manual)) + .unwrap_or(true) + { + return Ok(Some(builder.make_value_node( + cgraph::NodeValue::Value(dir::DirValue::CaptureMethod( + common_enums::CaptureMethod::Manual, + )), + None, + None::<()>, + ))); + } + Ok(None) +} + // fn construct_card_network_nodes( // builder: &mut cgraph::ConstraintGraphBuilder, // mca_card_networks: Vec, @@ -541,6 +561,7 @@ fn construct_supported_connectors_for_mandate_node( fn compile_accepted_countries_for_mca( builder: &mut cgraph::ConstraintGraphBuilder, + domain_id: cgraph::DomainId, payment_method_type: &enums::PaymentMethodType, pm_countries: Option, config: &settings::ConnectorFilters, @@ -598,12 +619,12 @@ fn compile_accepted_countries_for_mca( } // country from config - if let Some(config) = config + if let Some(derived_config) = config .0 .get(connector.as_str()) .or_else(|| config.0.get("default")) { - if let Some(value) = config + if let Some(value) = derived_config .0 .get(&settings::PaymentMethodFilterKey::PaymentMethodType( *payment_method_type, @@ -630,16 +651,43 @@ fn compile_accepted_countries_for_mca( )); } } + else if let Some(default_derived_config) = config.0.get("default") { + if let Some(value) = default_derived_config.0.get( + &settings::PaymentMethodFilterKey::PaymentMethodType(*payment_method_type), + ) { + if let Some(config_countries) = value.country.as_ref() { + let config_countries: Vec = Vec::from_iter(config_countries) + .into_iter() + .map(|country| common_enums::Country::from_alpha2(*country)) + .collect(); + let dir_countries: Vec = config_countries + .into_iter() + .map(dir::DirValue::BillingCountry) + .collect(); + + let config_country_agg_node = builder + .make_in_aggregator(dir_countries, None, None::<()>) + .map_err(KgraphError::GraphConstructionError)?; + + agg_nodes.push(( + config_country_agg_node, + cgraph::Relation::Positive, + cgraph::Strength::Weak, + )); + } + } + }; } Ok(Some( builder - .make_all_aggregator(&agg_nodes, None, None::<()>, None) + .make_all_aggregator(&agg_nodes, None, None::<()>, Some(domain_id)) .map_err(KgraphError::GraphConstructionError)?, )) } fn compile_accepted_currency_for_mca( builder: &mut cgraph::ConstraintGraphBuilder, + domain_id: cgraph::DomainId, payment_method_type: &enums::PaymentMethodType, pm_currency: Option, config: &settings::ConnectorFilters, @@ -687,17 +735,18 @@ fn compile_accepted_currency_for_mca( } } - // country from config - if let Some(config) = config + // currency from config + if let Some(derived_config) = config .0 .get(connector.as_str()) .or_else(|| config.0.get("default")) { - if let Some(value) = config - .0 - .get(&settings::PaymentMethodFilterKey::PaymentMethodType( - *payment_method_type, - )) + if let Some(value) = + derived_config + .0 + .get(&settings::PaymentMethodFilterKey::PaymentMethodType( + *payment_method_type, + )) { if let Some(config_currencies) = value.currency.as_ref() { let config_currency: Vec = @@ -722,10 +771,38 @@ fn compile_accepted_currency_for_mca( )); } } + else if let Some(default_derived_config) = config.0.get("default") { + if let Some(value) = default_derived_config.0.get( + &settings::PaymentMethodFilterKey::PaymentMethodType(*payment_method_type), + ) { + if let Some(config_currencies) = value.currency.as_ref() { + let config_currency: Vec = + Vec::from_iter(config_currencies) + .into_iter() + .cloned() + .collect(); + + let dir_currencies: Vec = config_currency + .into_iter() + .map(dir::DirValue::PaymentCurrency) + .collect(); + + let config_currency_agg_node = builder + .make_in_aggregator(dir_currencies, None, None::<()>) + .map_err(KgraphError::GraphConstructionError)?; + + agg_nodes.push(( + config_currency_agg_node, + cgraph::Relation::Positive, + cgraph::Strength::Weak, + )) + } + } + }; } Ok(Some( builder - .make_all_aggregator(&agg_nodes, None, None::<()>, None) + .make_all_aggregator(&agg_nodes, None, None::<()>, Some(domain_id)) .map_err(KgraphError::GraphConstructionError)?, )) } diff --git a/cypress-tests/cypress/e2e/PaymentMethodListTest/00000-PaymentMethodListConfigCurrency.cy.js b/cypress-tests/cypress/e2e/PaymentMethodListTest/00000-PaymentMethodListConfigCurrency.cy.js new file mode 100644 index 000000000000..8b98ef2e6916 --- /dev/null +++ b/cypress-tests/cypress/e2e/PaymentMethodListTest/00000-PaymentMethodListConfigCurrency.cy.js @@ -0,0 +1,81 @@ +import apiKeyCreateBody from "../../fixtures/create-api-key-body.json"; +import createConnectorBody from "../../fixtures/create-connector-body.json"; +import getConnectorDetails from "../PaymentMethodListUtils/utils"; +import merchantCreateBody from "../../fixtures/merchant-create-body.json"; +import * as utils from "../PaymentMethodListUtils/utils"; +import { + card_credit_enabled, + bank_redirect_ideal_enabled, + create_payment_body_in_EUR, +} from "../PaymentMethodListUtils/Common"; +import State from "../../utils/State"; + +// Testing for scenario: +// MCA1 -> Stripe configured with ideal = { country = "NL", currency = "EUR" } +// MCA2 -> Cybersource configured with credit = { currency = "USD" } +// Payment is done with currency as EUR and no billing address +// The resultant Payment Method list should only have ideal with stripe + +let globalState; +describe("Account Create flow test", () => { + before("seed global state", () => { + cy.task("getGlobalState").then((state) => { + globalState = new State(state); + }); + }); + + after("flush global state", () => { + cy.task("setGlobalState", globalState.data); + }); + + it("merchant-create-call-test", () => { + cy.merchantCreateCallTest(merchantCreateBody, globalState); + }); + + it("api-key-create-call-test", () => { + cy.apiKeyCreateTest(apiKeyCreateBody, globalState); + }); + + // stripe connector create with ideal enabled + it("connector-create-call-test", () => { + cy.createConnectorCallTest( + createConnectorBody, + bank_redirect_ideal_enabled, + globalState + ); + }); + + // cybersource connector create with card credit enabled + it("connector-create-call-test", () => { + cy.createNamedConnectorCallTest( + createConnectorBody, + card_credit_enabled, + globalState, + "cybersource" + ); + }); + + // creating payment with currency as EUR and no billing address + it("create-payment-call-test", () => { + let data = getConnectorDetails("stripe")["pm_list"]["PaymentIntent"]; + let req_data = data["RequestCurrencyEUR"]; + let res_data = data["Response"]; + + cy.createPaymentIntentTest( + create_payment_body_in_EUR, + req_data, + res_data, + "no_three_ds", + "automatic", + globalState + ); + }); + + // payment method list which should only have ideal with stripe + it("payment-method-list-call-test", () => { + let data = getConnectorDetails(globalState.get("connectorId"))["pm_list"][ + "PmListResponse" + ]["PmListWithStripeForIdeal"]; + cy.paymentMethodListTestLessThanEqualToOneConnector(data, globalState); + }); +}); diff --git a/cypress-tests/cypress/e2e/PaymentMethodListTest/00001-PaymentMethodListMcaWrongCurrency.cy.js b/cypress-tests/cypress/e2e/PaymentMethodListTest/00001-PaymentMethodListMcaWrongCurrency.cy.js new file mode 100644 index 000000000000..968060ed7502 --- /dev/null +++ b/cypress-tests/cypress/e2e/PaymentMethodListTest/00001-PaymentMethodListMcaWrongCurrency.cy.js @@ -0,0 +1,82 @@ +import apiKeyCreateBody from "../../fixtures/create-api-key-body.json"; +import createConnectorBody from "../../fixtures/create-connector-body.json"; +import getConnectorDetails from "../PaymentMethodListUtils/utils"; +import merchantCreateBody from "../../fixtures/merchant-create-body.json"; +import * as utils from "../PaymentMethodListUtils/utils"; +import { + card_credit_enabled, + card_credit_enabled_in_USD, + bank_redirect_ideal_enabled, + create_payment_body_in_INR, +} from "../PaymentMethodListUtils/Common"; +import State from "../../utils/State"; + +// Testing for scenario: +// MCA1 -> Stripe configured with ideal = { country = "NL", currency = "EUR" } +// MCA2 -> Cybersource configured with credit = { currency = "USD" } +// Payment is done with currency as INR and no billing address +// The resultant Payment Method list shouldn't have + +let globalState; +describe("Account Create flow test", () => { + before("seed global state", () => { + cy.task("getGlobalState").then((state) => { + globalState = new State(state); + }); + }); + + after("flush global state", () => { + cy.task("setGlobalState", globalState.data); + }); + + it("merchant-create-call-test", () => { + cy.merchantCreateCallTest(merchantCreateBody, globalState); + }); + + it("api-key-create-call-test", () => { + cy.apiKeyCreateTest(apiKeyCreateBody, globalState); + }); + + // stripe connector create with ideal enabled + it("connector-create-call-test", () => { + cy.createConnectorCallTest( + createConnectorBody, + bank_redirect_ideal_enabled, + globalState + ); + }); + + // cybersource connector create with card credit enabled in USD + it("connector-create-call-test", () => { + cy.createNamedConnectorCallTest( + createConnectorBody, + card_credit_enabled_in_USD, + globalState, + "cybersource" + ); + }); + + // creating payment with currency as INR and no billing address + it("create-payment-call-test", () => { + let data = getConnectorDetails("stripe")["pm_list"]["PaymentIntent"]; + let req_data = data["RequestCurrencyINR"]; + let res_data = data["Response"]; + + cy.createPaymentIntentTest( + create_payment_body_in_INR, + req_data, + res_data, + "no_three_ds", + "automatic", + globalState + ); + }); + + // payment method list which should only have ideal with stripe + it("payment-method-list-call-test", () => { + let data = getConnectorDetails(globalState.get("connectorId"))["pm_list"][ + "PmListResponse" + ]["PmListNull"]; + cy.paymentMethodListTestLessThanEqualToOneConnector(data, globalState); + }); +}); diff --git a/cypress-tests/cypress/e2e/PaymentMethodListTest/00002-PaymentMethodListMcaCountry.cy.js b/cypress-tests/cypress/e2e/PaymentMethodListTest/00002-PaymentMethodListMcaCountry.cy.js new file mode 100644 index 000000000000..860b79a55ddc --- /dev/null +++ b/cypress-tests/cypress/e2e/PaymentMethodListTest/00002-PaymentMethodListMcaCountry.cy.js @@ -0,0 +1,82 @@ +import apiKeyCreateBody from "../../fixtures/create-api-key-body.json"; +import createConnectorBody from "../../fixtures/create-connector-body.json"; +import getConnectorDetails from "../PaymentMethodListUtils/utils"; +import merchantCreateBody from "../../fixtures/merchant-create-body.json"; +import * as utils from "../PaymentMethodListUtils/utils"; +import { + card_credit_enabled, + card_credit_enabled_in_US, + bank_redirect_ideal_enabled, + create_payment_body_in_USD, +} from "../PaymentMethodListUtils/Common"; +import State from "../../utils/State"; + +// Testing for scenario: +// MCA1 -> Stripe configured with credit = { country = "US" } +// MCA2 -> Cybersource configured with credit = { country = "US" } +// Payment is done with country as US and currency as USD +// The resultant Payment Method list should have both Stripe and cybersource + +let globalState; +describe("Account Create flow test", () => { + before("seed global state", () => { + cy.task("getGlobalState").then((state) => { + globalState = new State(state); + }); + }); + + after("flush global state", () => { + cy.task("setGlobalState", globalState.data); + }); + + it("merchant-create-call-test", () => { + cy.merchantCreateCallTest(merchantCreateBody, globalState); + }); + + it("api-key-create-call-test", () => { + cy.apiKeyCreateTest(apiKeyCreateBody, globalState); + }); + + // stripe connector create with credit enabled for US + it("connector-create-call-test", () => { + cy.createConnectorCallTest( + createConnectorBody, + card_credit_enabled_in_US, + globalState + ); + }); + + // cybersource connector create with card credit enabled in US + it("connector-create-call-test", () => { + cy.createNamedConnectorCallTest( + createConnectorBody, + card_credit_enabled_in_US, + globalState, + "cybersource" + ); + }); + + // creating payment with currency as USD and billing address as US + it("create-payment-call-test", () => { + let data = getConnectorDetails("stripe")["pm_list"]["PaymentIntent"]; + let req_data = data["RequestCurrencyUSD"]; + let res_data = data["Response"]; + + cy.createPaymentIntentTest( + create_payment_body_in_USD, + req_data, + res_data, + "no_three_ds", + "automatic", + globalState + ); + }); + + // payment method list which should only have credit with Stripe and Cybersource + it("payment-method-list-call-test", () => { + let data = getConnectorDetails(globalState.get("connectorId"))["pm_list"][ + "PmListResponse" + ]["PmListWithCreditTwoConnector"]; + cy.paymentMethodListTestLessThanEqualToOneConnector(data, globalState); + }); +}); diff --git a/cypress-tests/cypress/e2e/PaymentMethodListTest/00003-PaymentMethodListConfigWrongCountry.cy.js b/cypress-tests/cypress/e2e/PaymentMethodListTest/00003-PaymentMethodListConfigWrongCountry.cy.js new file mode 100644 index 000000000000..c27b44a71b6b --- /dev/null +++ b/cypress-tests/cypress/e2e/PaymentMethodListTest/00003-PaymentMethodListConfigWrongCountry.cy.js @@ -0,0 +1,82 @@ +import apiKeyCreateBody from "../../fixtures/create-api-key-body.json"; +import createConnectorBody from "../../fixtures/create-connector-body.json"; +import getConnectorDetails from "../PaymentMethodListUtils/utils"; +import merchantCreateBody from "../../fixtures/merchant-create-body.json"; +import * as utils from "../PaymentMethodListUtils/utils"; +import { + card_credit_enabled, + card_credit_enabled_in_US, + bank_redirect_ideal_enabled, + create_payment_body_in_EUR_US, +} from "../PaymentMethodListUtils/Common"; +import State from "../../utils/State"; + +// Testing for scenario: +// MCA1 -> Stripe configured with ideal = { country = "NL", currency = "EUR" } +// MCA2 -> Cybersource configured with ideal = { country = "NL", currency = "EUR" } +// Payment is done with country as US and currency as EUR +// The resultant Payment Method list shouldn't have anything + +let globalState; +describe("Account Create flow test", () => { + before("seed global state", () => { + cy.task("getGlobalState").then((state) => { + globalState = new State(state); + }); + }); + + after("flush global state", () => { + cy.task("setGlobalState", globalState.data); + }); + + it("merchant-create-call-test", () => { + cy.merchantCreateCallTest(merchantCreateBody, globalState); + }); + + it("api-key-create-call-test", () => { + cy.apiKeyCreateTest(apiKeyCreateBody, globalState); + }); + + // stripe connector create with ideal enabled + it("connector-create-call-test", () => { + cy.createConnectorCallTest( + createConnectorBody, + bank_redirect_ideal_enabled, + globalState + ); + }); + + // cybersource connector create with ideal enabled + it("connector-create-call-test", () => { + cy.createNamedConnectorCallTest( + createConnectorBody, + bank_redirect_ideal_enabled, + globalState, + "cybersource" + ); + }); + + // creating payment with currency as EUR and billing address as US + it("create-payment-call-test", () => { + let data = getConnectorDetails("stripe")["pm_list"]["PaymentIntent"]; + let req_data = data["RequestCurrencyEUR"]; + let res_data = data["Response"]; + + cy.createPaymentIntentTest( + create_payment_body_in_EUR_US, + req_data, + res_data, + "no_three_ds", + "automatic", + globalState + ); + }); + + // payment method list which shouldn't have anything + it("payment-method-list-call-test", () => { + let data = getConnectorDetails(globalState.get("connectorId"))["pm_list"][ + "PmListResponse" + ]["PmListNull"]; + cy.paymentMethodListTestLessThanEqualToOneConnector(data, globalState); + }); +}); diff --git a/cypress-tests/cypress/e2e/PaymentMethodListTest/00004-PaymentMethodListNoConfigCurrencyCountry.cy.js b/cypress-tests/cypress/e2e/PaymentMethodListTest/00004-PaymentMethodListNoConfigCurrencyCountry.cy.js new file mode 100644 index 000000000000..7fd72328991a --- /dev/null +++ b/cypress-tests/cypress/e2e/PaymentMethodListTest/00004-PaymentMethodListNoConfigCurrencyCountry.cy.js @@ -0,0 +1,85 @@ +import apiKeyCreateBody from "../../fixtures/create-api-key-body.json"; +import createConnectorBody from "../../fixtures/create-connector-body.json"; +import getConnectorDetails from "../PaymentMethodListUtils/utils"; +import merchantCreateBody from "../../fixtures/merchant-create-body.json"; +import * as utils from "../PaymentMethodListUtils/utils"; +import { + card_credit_enabled, + card_credit_enabled_in_US, + bank_redirect_ideal_and_credit_enabled, + create_payment_body_in_USD_IN, +} from "../PaymentMethodListUtils/Common"; +import State from "../../utils/State"; + +// Testing for scenario: +// MCA1 -> Stripe configured with card credit no configs present +// MCA1 -> Cybersource configured with card credit = { currency = "USD" } +// and ideal (default config present as = { country = "NL", currency = "EUR" } ) +// Payment is done with country as IN and currency as USD +// The resultant Payment Method list should have +// Stripe and cybersource both for credit and none for ideal + +let globalState; +describe("Account Create flow test", () => { + before("seed global state", () => { + cy.task("getGlobalState").then((state) => { + globalState = new State(state); + }); + }); + + after("flush global state", () => { + cy.task("setGlobalState", globalState.data); + }); + + it("merchant-create-call-test", () => { + cy.merchantCreateCallTest(merchantCreateBody, globalState); + }); + + it("api-key-create-call-test", () => { + cy.apiKeyCreateTest(apiKeyCreateBody, globalState); + }); + + // stripe connector create with card credit enabled + it("connector-create-call-test", () => { + cy.createConnectorCallTest( + createConnectorBody, + card_credit_enabled, + globalState + ); + }); + + // cybersource connector create with card credit and ideal enabled + it("connector-create-call-test", () => { + cy.createNamedConnectorCallTest( + createConnectorBody, + // card_credit_enabled, + card_credit_enabled, + globalState, + "cybersource" + ); + }); + + // creating payment with currency as USD and billing address as IN + it("create-payment-call-test", () => { + let data = getConnectorDetails("stripe")["pm_list"]["PaymentIntent"]; + let req_data = data["RequestCurrencyUSD"]; + let res_data = data["Response"]; + + cy.createPaymentIntentTest( + create_payment_body_in_USD_IN, + req_data, + res_data, + "no_three_ds", + "automatic", + globalState + ); + }); + + // payment method list which should have credit with stripe and cybersource and no ideal + it("payment-method-list-call-test", () => { + let data = getConnectorDetails(globalState.get("connectorId"))["pm_list"][ + "PmListResponse" + ]["PmListWithCreditTwoConnector"]; + cy.paymentMethodListTestTwoConnectorsForCredit(data, globalState); + }); +}); diff --git a/cypress-tests/cypress/e2e/PaymentMethodListUtils/Common.js b/cypress-tests/cypress/e2e/PaymentMethodListUtils/Common.js new file mode 100644 index 000000000000..01573179e642 --- /dev/null +++ b/cypress-tests/cypress/e2e/PaymentMethodListUtils/Common.js @@ -0,0 +1,391 @@ +import State from "../../utils/State"; + +const globalState = new State({ + connectorId: Cypress.env("CONNECTOR"), + baseUrl: Cypress.env("BASEURL"), + adminApiKey: Cypress.env("ADMINAPIKEY"), + connectorAuthFilePath: Cypress.env("CONNECTOR_AUTH_FILE_PATH"), +}); + +export const card_credit_enabled = [ + { + payment_method: "card", + payment_method_types: [ + { + payment_method_type: "credit", + card_networks: ["Visa"], + minimum_amount: 0, + maximum_amount: 68607706, + recurring_enabled: false, + installment_payment_enabled: true, + }, + ], + }, +]; + +export const card_credit_enabled_in_USD = [ + { + payment_method: "card", + payment_method_types: [ + { + payment_method_type: "credit", + card_networks: ["Visa"], + minimum_amount: 0, + accepted_currencies: { + type: "enable_only", + list: ["USD"], + }, + maximum_amount: 68607706, + recurring_enabled: false, + installment_payment_enabled: true, + }, + ], + }, +]; + +export const card_credit_enabled_in_US = [ + { + payment_method: "card", + payment_method_types: [ + { + payment_method_type: "credit", + card_networks: ["Visa"], + minimum_amount: 0, + accepted_countries: { + type: "enable_only", + list: ["US"], + }, + maximum_amount: 68607706, + recurring_enabled: false, + installment_payment_enabled: true, + }, + ], + }, +]; + +export const bank_redirect_ideal_enabled = [ + { + payment_method: "bank_redirect", + payment_method_types: [ + { + payment_method_type: "ideal", + payment_experience: null, + card_networks: null, + accepted_countries: null, + minimum_amount: 0, + maximum_amount: 68607706, + recurring_enabled: true, + installment_payment_enabled: false, + }, + ], + }, +]; + +export const bank_redirect_ideal_and_credit_enabled = [ + { + payment_method: "card", + payment_method_types: [ + { + payment_method_type: "credit", + card_networks: ["Visa"], + minimum_amount: 0, + maximum_amount: 68607706, + recurring_enabled: false, + installment_payment_enabled: true, + }, + ], + }, + { + payment_method: "bank_redirect", + payment_method_types: [ + { + payment_method_type: "ideal", + payment_experience: null, + card_networks: null, + accepted_countries: null, + minimum_amount: 0, + maximum_amount: 68607706, + recurring_enabled: true, + installment_payment_enabled: false, + }, + ], + }, +]; + +export const create_payment_body_in_EUR = { + currency: "EUR", + amount: 6500, + authentication_type: "three_ds", + description: "Joseph First Crypto", + email: "hyperswitch_sdk_demo_id@gmail.com", + setup_future_usage: "", + metadata: { + udf1: "value1", + new_customer: "true", + login_date: "2019-09-10T10:11:12Z", + }, + business_label: "default", +}; + +export const create_payment_body_in_EUR_US = { + currency: "EUR", + amount: 6500, + authentication_type: "three_ds", + description: "Joseph First Crypto", + email: "hyperswitch_sdk_demo_id@gmail.com", + setup_future_usage: "", + metadata: { + udf1: "value1", + new_customer: "true", + login_date: "2019-09-10T10:11:12Z", + }, + business_label: "default", + billing: { + address: { + line1: "1467", + line2: "Harrison Street", + line3: "Harrison Street", + city: "San Fransico", + state: "California", + zip: "94122", + country: "US", + first_name: "joseph", + last_name: "Doe", + }, + phone: { + number: "8056594427", + country_code: "+91", + }, + email: "example@example.com", + }, +}; + +export const create_payment_body_in_USD_IN = { + currency: "USD", + amount: 6500, + authentication_type: "three_ds", + description: "Ramesh First Crypto", + email: "hyperswitch_sdk_demo_id@gmail.com", + setup_future_usage: "", + metadata: { + udf1: "value1", + new_customer: "true", + login_date: "2019-09-10T10:11:12Z", + }, + business_label: "default", + billing: { + address: { + line1: "1946", + line2: "Gandhi Nagar", + line3: "Ramnagar", + city: "Ranchi", + state: "Jharkhand", + zip: "827013", + country: "IN", + first_name: "Ramesh", + last_name: "Kumar", + }, + phone: { + number: "8056594427", + country_code: "+91", + }, + email: "example@example.com", + }, +}; + +export const create_payment_body_in_INR = { + currency: "INR", + amount: 6500, + authentication_type: "three_ds", + description: "Joseph First Crypto", + email: "hyperswitch_sdk_demo_id@gmail.com", + setup_future_usage: "", + metadata: { + udf1: "value1", + new_customer: "true", + login_date: "2019-09-10T10:11:12Z", + }, + business_label: "default", +}; + +export const create_payment_body_in_USD = { + currency: "USD", + amount: 6500, + authentication_type: "three_ds", + description: "Joseph First Crypto", + email: "hyperswitch_sdk_demo_id@gmail.com", + setup_future_usage: "", + metadata: { + udf1: "value1", + new_customer: "true", + login_date: "2019-09-10T10:11:12Z", + }, + business_label: "default", +}; + +/* +`getDefaultExchange` contains the default Request and Response to be considered if none provided. +`getCustomExchange` takes in 2 optional fields named as Request and Response. +with `getCustomExchange`, if 501 response is expected, there is no need to pass Response as it considers default values. +*/ + +// Const to get default PaymentExchange object +const getDefaultExchange = () => ({ + Request: { + currency: "EUR", + }, + Response: { + status: 501, + body: { + error: { + type: "invalid_request", + message: `Selected payment method is not implemented`, + code: "IR_00", + }, + }, + }, +}); + +// Const to get PaymentExchange with overridden properties +export const getCustomExchange = (overrides) => { + const defaultExchange = getDefaultExchange(); + + return { + ...defaultExchange, + Request: { + ...defaultExchange.Request, + ...(overrides.Request || {}), + }, + Response: { + ...defaultExchange.Response, + ...(overrides.Response || {}), + }, + }; +}; + +export const payment_methods_enabled = [ + { + payment_method: "card", + payment_method_types: [ + { + payment_method_type: "credit", + card_networks: [ + "AmericanExpress", + "Discover", + "Interac", + "JCB", + "Mastercard", + "Visa", + "DinersClub", + "UnionPay", + "RuPay", + ], + minimum_amount: 0, + maximum_amount: 68607706, + recurring_enabled: false, + installment_payment_enabled: true, + }, + { + payment_method_type: "debit", + card_networks: [ + "AmericanExpress", + "Discover", + "Interac", + "JCB", + "Mastercard", + "Visa", + "DinersClub", + "UnionPay", + "RuPay", + ], + minimum_amount: 0, + maximum_amount: 68607706, + recurring_enabled: false, + installment_payment_enabled: true, + }, + ], + }, + { + payment_method: "bank_transfer", + payment_method_types: [ + { + payment_method_type: "pix", + minimum_amount: 0, + maximum_amount: 68607706, + recurring_enabled: false, + installment_payment_enabled: true, + }, + ], + }, + { + payment_method: "bank_redirect", + payment_method_types: [ + { + payment_method_type: "ideal", + payment_experience: null, + card_networks: null, + accepted_currencies: null, + accepted_countries: null, + minimum_amount: 1, + maximum_amount: 68607706, + recurring_enabled: true, + installment_payment_enabled: true, + }, + { + payment_method_type: "giropay", + payment_experience: null, + card_networks: null, + accepted_currencies: null, + accepted_countries: null, + minimum_amount: 1, + maximum_amount: 68607706, + recurring_enabled: true, + installment_payment_enabled: true, + }, + { + payment_method_type: "sofort", + payment_experience: null, + card_networks: null, + accepted_currencies: null, + accepted_countries: null, + minimum_amount: 1, + maximum_amount: 68607706, + recurring_enabled: true, + installment_payment_enabled: true, + }, + { + payment_method_type: "eps", + payment_experience: null, + card_networks: null, + accepted_currencies: null, + accepted_countries: null, + minimum_amount: 1, + maximum_amount: 68607706, + recurring_enabled: true, + installment_payment_enabled: true, + }, + { + payment_method_type: "blik", + payment_experience: null, + card_networks: null, + accepted_currencies: null, + accepted_countries: null, + minimum_amount: 1, + maximum_amount: 68607706, + recurring_enabled: true, + installment_payment_enabled: true, + }, + { + payment_method_type: "przelewy24", + payment_experience: null, + card_networks: null, + accepted_currencies: null, + accepted_countries: null, + minimum_amount: 1, + maximum_amount: 68607706, + recurring_enabled: true, + installment_payment_enabled: true, + }, + ], + }, +]; diff --git a/cypress-tests/cypress/e2e/PaymentMethodListUtils/Cybersource.js b/cypress-tests/cypress/e2e/PaymentMethodListUtils/Cybersource.js new file mode 100644 index 000000000000..0ed998e74e4b --- /dev/null +++ b/cypress-tests/cypress/e2e/PaymentMethodListUtils/Cybersource.js @@ -0,0 +1,470 @@ +const successfulNo3DSCardDetails = { + card_number: "4242424242424242", + card_exp_month: "01", + card_exp_year: "25", + card_holder_name: "joseph Doe", + card_cvc: "123", +}; + +const successfulThreeDSTestCardDetails = { + card_number: "4000000000001091", + card_exp_month: "01", + card_exp_year: "25", + card_holder_name: "joseph Doe", + card_cvc: "123", +}; + +const singleUseMandateData = { + customer_acceptance: { + acceptance_type: "offline", + accepted_at: "1963-05-03T04:07:52.723Z", + online: { + ip_address: "125.0.0.1", + user_agent: "amet irure esse", + }, + }, + mandate_type: { + single_use: { + amount: 8000, + currency: "USD", + }, + }, +}; + +const multiUseMandateData = { + customer_acceptance: { + acceptance_type: "offline", + accepted_at: "1963-05-03T04:07:52.723Z", + online: { + ip_address: "125.0.0.1", + user_agent: "amet irure esse", + }, + }, + mandate_type: { + multi_use: { + amount: 8000, + currency: "USD", + }, + }, +}; + +export const connectorDetails = { + card_pm: { + PaymentIntent: { + Request: { + card: successfulNo3DSCardDetails, + currency: "USD", + customer_acceptance: null, + setup_future_usage: "on_session", + }, + Response: { + status: 200, + body: { + status: "requires_payment_method", + }, + }, + }, + "3DSManualCapture": { + Request: { + card: successfulThreeDSTestCardDetails, + currency: "USD", + customer_acceptance: null, + setup_future_usage: "on_session", + }, + Response: { + status: 200, + body: { + status: "requires_capture", + }, + }, + }, + "3DSAutoCapture": { + Request: { + card: successfulThreeDSTestCardDetails, + currency: "USD", + customer_acceptance: null, + setup_future_usage: "on_session", + }, + Response: { + status: 200, + body: { + status: "succeeded", + }, + }, + }, + No3DSManualCapture: { + Request: { + card: successfulNo3DSCardDetails, + currency: "USD", + customer_acceptance: null, + setup_future_usage: "on_session", + }, + Response: { + status: 200, + body: { + status: "requires_capture", + }, + }, + }, + No3DSAutoCapture: { + Request: { + card: successfulNo3DSCardDetails, + currency: "USD", + customer_acceptance: null, + setup_future_usage: "on_session", + }, + Response: { + status: 200, + body: { + status: "succeeded", + }, + }, + }, + Capture: { + Request: { + card: successfulNo3DSCardDetails, + currency: "USD", + customer_acceptance: null, + }, + Response: { + status: 200, + body: { + status: "succeeded", + amount: 6500, + amount_capturable: 0, + amount_received: 6500, + }, + }, + }, + PartialCapture: { + Request: {}, + Response: { + status: 200, + body: { + status: "partially_captured", + amount: 6500, + amount_capturable: 0, + amount_received: 100, + }, + }, + }, + Void: { + Request: {}, + Response: { + status: 200, + body: { + status: "cancelled", + }, + }, + }, + Refund: { + Request: { + card: successfulNo3DSCardDetails, + currency: "USD", + customer_acceptance: null, + }, + Response: { + status: 200, + body: { + status: "pending", + }, + }, + }, + PartialRefund: { + Request: { + card: successfulNo3DSCardDetails, + currency: "USD", + customer_acceptance: null, + }, + Response: { + status: 200, + body: { + status: "pending", + }, + }, + }, + SyncRefund: { + Request: { + card: successfulNo3DSCardDetails, + currency: "USD", + customer_acceptance: null, + }, + Response: { + status: 200, + body: { + status: "pending", + }, + }, + }, + MandateSingleUse3DSAutoCapture: { + Request: { + payment_method_data: { + card: successfulThreeDSTestCardDetails, + }, + currency: "USD", + mandate_data: singleUseMandateData, + }, + Response: { + status: 200, + body: { + status: "succeeded", + }, + }, + }, + MandateSingleUse3DSManualCapture: { + Request: { + payment_method_data: { + card: successfulThreeDSTestCardDetails, + }, + currency: "USD", + mandate_data: singleUseMandateData, + }, + Response: { + status: 200, + body: { + status: "requires_customer_action", + }, + }, + }, + MandateSingleUseNo3DSAutoCapture: { + Request: { + payment_method_data: { + card: successfulNo3DSCardDetails, + }, + currency: "USD", + mandate_data: singleUseMandateData, + }, + Response: { + status: 200, + body: { + status: "succeeded", + }, + }, + }, + MandateSingleUseNo3DSManualCapture: { + Request: { + payment_method_data: { + card: successfulNo3DSCardDetails, + }, + currency: "USD", + mandate_data: singleUseMandateData, + }, + Response: { + status: 200, + body: { + status: "requires_capture", + }, + }, + }, + MandateMultiUseNo3DSAutoCapture: { + Request: { + payment_method_data: { + card: successfulNo3DSCardDetails, + }, + currency: "USD", + mandate_data: multiUseMandateData, + }, + Response: { + status: 200, + body: { + status: "succeeded", + }, + }, + }, + MandateMultiUseNo3DSManualCapture: { + Request: { + payment_method_data: { + card: successfulNo3DSCardDetails, + }, + currency: "USD", + mandate_data: multiUseMandateData, + }, + Response: { + status: 200, + body: { + status: "requires_capture", + }, + }, + }, + MandateMultiUse3DSAutoCapture: { + Request: { + payment_method_data: { + card: successfulThreeDSTestCardDetails, + }, + currency: "USD", + mandate_data: multiUseMandateData, + }, + Response: { + status: 200, + body: { + status: "requires_capture", + }, + }, + }, + MandateMultiUse3DSManualCapture: { + Request: { + payment_method_data: { + card: successfulThreeDSTestCardDetails, + }, + currency: "USD", + mandate_data: multiUseMandateData, + }, + Response: { + status: 200, + body: { + status: "requires_capture", + }, + }, + }, + ZeroAuthMandate: { + Request: { + payment_method_data: { + card: successfulNo3DSCardDetails, + }, + currency: "USD", + mandate_data: singleUseMandateData + }, + Response: { + status: 200, + body: { + status: "succeeded", + }, + }, + }, + SaveCardUseNo3DSAutoCapture: { + Request: { + card: successfulNo3DSCardDetails, + currency: "USD", + setup_future_usage: "on_session", + customer_acceptance: { + acceptance_type: "offline", + accepted_at: "1963-05-03T04:07:52.723Z", + online: { + ip_address: "127.0.0.1", + user_agent: "amet irure esse", + }, + }, + }, + Response: { + status: 200, + body: { + status: "succeeded", + }, + }, + }, + SaveCardUseNo3DSManualCapture: { + Request: { + card: successfulNo3DSCardDetails, + currency: "USD", + setup_future_usage: "on_session", + customer_acceptance: { + acceptance_type: "offline", + accepted_at: "1963-05-03T04:07:52.723Z", + online: { + ip_address: "127.0.0.1", + user_agent: "amet irure esse", + }, + }, + }, + Response: { + status: 200, + body: { + status: "requires_capture", + }, + }, + }, + PaymentMethodIdMandateNo3DSAutoCapture: { + Request: { + payment_method_data: { + card: successfulNo3DSCardDetails, + }, + currency: "USD", + mandate_data: null, + customer_acceptance: { + acceptance_type: "offline", + accepted_at: "1963-05-03T04:07:52.723Z", + online: { + ip_address: "125.0.0.1", + user_agent: "amet irure esse", + }, + }, + }, + Response: { + status: 200, + body: { + status: "succeeded", + }, + }, + }, + PaymentMethodIdMandateNo3DSManualCapture: { + Request: { + payment_method_data: { + card: successfulNo3DSCardDetails, + }, + currency: "USD", + mandate_data: null, + customer_acceptance: { + acceptance_type: "offline", + accepted_at: "1963-05-03T04:07:52.723Z", + online: { + ip_address: "125.0.0.1", + user_agent: "amet irure esse", + }, + }, + }, + Response: { + status: 200, + body: { + status: "requires_capture", + }, + }, + }, + PaymentMethodIdMandate3DSAutoCapture: { + Request: { + payment_method_data: { + card: successfulThreeDSTestCardDetails, + }, + currency: "USD", + mandate_data: null, + authentication_type: "three_ds", + customer_acceptance: { + acceptance_type: "offline", + accepted_at: "1963-05-03T04:07:52.723Z", + online: { + ip_address: "125.0.0.1", + user_agent: "amet irure esse", + }, + }, + }, + Response: { + status: 200, + body: { + status: "requires_customer_action", + }, + }, + }, + PaymentMethodIdMandate3DSManualCapture: { + Request: { + payment_method_data: { + card: successfulThreeDSTestCardDetails, + }, + mandate_data: null, + authentication_type: "three_ds", + customer_acceptance: { + acceptance_type: "offline", + accepted_at: "1963-05-03T04:07:52.723Z", + online: { + ip_address: "125.0.0.1", + user_agent: "amet irure esse", + }, + }, + }, + Response: { + status: 200, + body: { + status: "requires_customer_action", + }, + }, + }, + }, +}; diff --git a/cypress-tests/cypress/e2e/PaymentMethodListUtils/Stripe.js b/cypress-tests/cypress/e2e/PaymentMethodListUtils/Stripe.js new file mode 100644 index 000000000000..bf29f6897821 --- /dev/null +++ b/cypress-tests/cypress/e2e/PaymentMethodListUtils/Stripe.js @@ -0,0 +1,754 @@ +import { getCustomExchange } from "./Common"; + +const successfulTestCard = "4242424242424242"; +const successful3DSCard = "4000002500003155"; + +const successfulNo3DSCardDetails = { + card_number: "4242424242424242", + card_exp_month: "10", + card_exp_year: "25", + card_holder_name: "morino", + card_cvc: "737", +}; + +const successfulThreeDSTestCardDetails = { + card_number: "4000002500003155", + card_exp_month: "10", + card_exp_year: "25", + card_holder_name: "morino", + card_cvc: "737", +}; + +const singleUseMandateData = { + customer_acceptance: { + acceptance_type: "offline", + accepted_at: "1963-05-03T04:07:52.723Z", + online: { + ip_address: "125.0.0.1", + user_agent: "amet irure esse", + }, + }, + mandate_type: { + single_use: { + amount: 8000, + currency: "USD", + }, + }, +}; + +const multiUseMandateData = { + customer_acceptance: { + acceptance_type: "offline", + accepted_at: "1963-05-03T04:07:52.723Z", + online: { + ip_address: "125.0.0.1", + user_agent: "amet irure esse", + }, + }, + mandate_type: { + multi_use: { + amount: 8000, + currency: "USD", + }, + }, +}; + +export const connectorDetails = { + pm_list: { + PaymentIntent: { + RequestCurrencyUSD: { + card: successfulNo3DSCardDetails, + currency: "USD", + customer_acceptance: null, + setup_future_usage: "off_session", + authentication_type: "no_three_ds", + }, + RequestCurrencyEUR: { + card: successfulNo3DSCardDetails, + currency: "EUR", + customer_acceptance: null, + setup_future_usage: "off_session", + authentication_type: "no_three_ds", + }, + RequestCurrencyINR: { + card: successfulNo3DSCardDetails, + currency: "INR", + customer_acceptance: null, + setup_future_usage: "off_session", + authentication_type: "no_three_ds", + }, + Response: { + status: 200, + body: { + status: "requires_payment_method", + }, + }, + }, + PmListResponse: { + PmListNull: { + payment_methods: [], + }, + PmListWithStripeForIdeal: { + status: "requires_payment_method", + payment_methods: [ + { + payment_method: "bank_redirect", + payment_method_types: [ + { + payment_method_type: "ideal", + bank_names: [ + { + eligible_connectors: ["stripe"], + }, + ], + }, + ], + }, + ], + }, + PmListWithCreditOneConnector: { + payment_methods: [ + { + payment_method: "card", + payment_method_types: [ + { + payment_method_type: "credit", + }, + ], + }, + ], + }, + PmListWithCreditTwoConnector: { + payment_methods: [ + { + payment_method: "card", + payment_method_types: [ + { + payment_method_type: "credit", + card_networks: [ + { + eligible_connectors: ["stripe", "cybersource"], + }, + ], + }, + ], + }, + ], + }, + }, + }, + + card_pm: { + PaymentIntent: { + Request: { + card: successfulNo3DSCardDetails, + currency: "USD", + customer_acceptance: null, + setup_future_usage: "on_session", + }, + Response: { + status: 200, + body: { + status: "requires_payment_method", + }, + }, + }, + "3DSManualCapture": { + Request: { + card: successfulThreeDSTestCardDetails, + currency: "USD", + customer_acceptance: null, + setup_future_usage: "on_session", + }, + Response: { + status: 200, + body: { + status: "requires_capture", + }, + }, + }, + "3DSAutoCapture": { + Request: { + card: successfulThreeDSTestCardDetails, + currency: "USD", + customer_acceptance: null, + setup_future_usage: "on_session", + }, + Response: { + status: 200, + body: { + status: "succeeded", + }, + }, + }, + No3DSManualCapture: { + Request: { + card: successfulNo3DSCardDetails, + currency: "USD", + customer_acceptance: null, + setup_future_usage: "on_session", + }, + Response: { + status: 200, + body: { + status: "requires_capture", + }, + }, + }, + No3DSAutoCapture: { + Request: { + card: successfulNo3DSCardDetails, + currency: "USD", + customer_acceptance: null, + setup_future_usage: "on_session", + }, + Response: { + status: 200, + body: { + status: "succeeded", + }, + }, + }, + Capture: { + Request: { + card: successfulNo3DSCardDetails, + currency: "USD", + customer_acceptance: null, + }, + Response: { + status: 200, + body: { + status: "succeeded", + amount: 6500, + amount_capturable: 0, + amount_received: 6500, + }, + }, + }, + PartialCapture: { + Request: {}, + Response: { + status: 200, + body: { + status: "partially_captured", + amount: 6500, + amount_capturable: 0, + amount_received: 100, + }, + }, + }, + Void: { + Request: {}, + Response: { + status: 200, + body: { + status: "cancelled", + }, + }, + }, + Refund: { + Request: { + card: successfulNo3DSCardDetails, + currency: "USD", + customer_acceptance: null, + }, + Response: { + status: 200, + body: { + status: "succeeded", + }, + }, + }, + PartialRefund: { + Request: { + card: successfulNo3DSCardDetails, + currency: "USD", + customer_acceptance: null, + }, + Response: { + status: 200, + body: { + status: "succeeded", + }, + }, + }, + SyncRefund: { + Request: { + card: successfulNo3DSCardDetails, + currency: "USD", + customer_acceptance: null, + }, + Response: { + status: 200, + body: { + status: "succeeded", + }, + }, + }, + MandateSingleUse3DSAutoCapture: { + Request: { + payment_method_data: { + card: successfulThreeDSTestCardDetails, + }, + currency: "USD", + mandate_data: singleUseMandateData, + }, + Response: { + status: 200, + body: { + status: "succeeded", + }, + }, + }, + MandateSingleUse3DSManualCapture: { + Request: { + payment_method_data: { + card: successfulThreeDSTestCardDetails, + }, + currency: "USD", + mandate_data: singleUseMandateData, + }, + Response: { + status: 200, + body: { + status: "requires_customer_action", + }, + }, + }, + MandateSingleUseNo3DSAutoCapture: { + Request: { + payment_method_data: { + card: successfulNo3DSCardDetails, + }, + currency: "USD", + mandate_data: singleUseMandateData, + }, + Response: { + status: 200, + body: { + status: "succeeded", + }, + }, + }, + MandateSingleUseNo3DSManualCapture: { + Request: { + payment_method_data: { + card: successfulNo3DSCardDetails, + }, + currency: "USD", + mandate_data: singleUseMandateData, + }, + Response: { + status: 200, + body: { + status: "requires_capture", + }, + }, + }, + MandateMultiUseNo3DSAutoCapture: { + Request: { + payment_method_data: { + card: successfulNo3DSCardDetails, + }, + currency: "USD", + mandate_data: multiUseMandateData, + }, + Response: { + status: 200, + body: { + status: "succeeded", + }, + }, + }, + MandateMultiUseNo3DSManualCapture: { + Request: { + payment_method_data: { + card: successfulNo3DSCardDetails, + }, + currency: "USD", + mandate_data: multiUseMandateData, + }, + Response: { + status: 200, + body: { + status: "requires_capture", + }, + }, + }, + MandateMultiUse3DSAutoCapture: { + Request: { + payment_method_data: { + card: successfulThreeDSTestCardDetails, + }, + currency: "USD", + mandate_data: multiUseMandateData, + }, + Response: { + status: 200, + body: { + status: "requires_capture", + }, + }, + }, + MandateMultiUse3DSManualCapture: { + Request: { + payment_method_data: { + card: successfulThreeDSTestCardDetails, + }, + currency: "USD", + mandate_data: multiUseMandateData, + }, + Response: { + status: 200, + body: { + status: "requires_capture", + }, + }, + }, + ZeroAuthMandate: { + Request: { + payment_method_data: { + card: successfulNo3DSCardDetails, + }, + currency: "USD", + mandate_data: singleUseMandateData, + }, + Response: { + status: 200, + body: { + status: "succeeded", + }, + }, + }, + SaveCardUseNo3DSAutoCapture: { + Request: { + card: successfulNo3DSCardDetails, + currency: "USD", + setup_future_usage: "on_session", + customer_acceptance: { + acceptance_type: "offline", + accepted_at: "1963-05-03T04:07:52.723Z", + online: { + ip_address: "127.0.0.1", + user_agent: "amet irure esse", + }, + }, + }, + Response: { + status: 200, + body: { + status: "succeeded", + }, + }, + }, + SaveCardUseNo3DSManualCapture: { + Request: { + card: successfulNo3DSCardDetails, + currency: "USD", + setup_future_usage: "on_session", + customer_acceptance: { + acceptance_type: "offline", + accepted_at: "1963-05-03T04:07:52.723Z", + online: { + ip_address: "127.0.0.1", + user_agent: "amet irure esse", + }, + }, + }, + Response: { + status: 200, + body: { + status: "requires_capture", + }, + }, + }, + PaymentMethodIdMandateNo3DSAutoCapture: { + Request: { + payment_method_data: { + card: successfulNo3DSCardDetails, + }, + currency: "USD", + mandate_data: null, + customer_acceptance: { + acceptance_type: "offline", + accepted_at: "1963-05-03T04:07:52.723Z", + online: { + ip_address: "125.0.0.1", + user_agent: "amet irure esse", + }, + }, + }, + Response: { + status: 200, + body: { + status: "succeeded", + }, + }, + }, + PaymentMethodIdMandateNo3DSManualCapture: { + Request: { + payment_method_data: { + card: successfulNo3DSCardDetails, + }, + currency: "USD", + mandate_data: null, + customer_acceptance: { + acceptance_type: "offline", + accepted_at: "1963-05-03T04:07:52.723Z", + online: { + ip_address: "125.0.0.1", + user_agent: "amet irure esse", + }, + }, + }, + Response: { + status: 200, + body: { + status: "requires_capture", + }, + }, + }, + PaymentMethodIdMandate3DSAutoCapture: { + Request: { + payment_method_data: { + card: successfulThreeDSTestCardDetails, + }, + currency: "USD", + mandate_data: null, + authentication_type: "three_ds", + customer_acceptance: { + acceptance_type: "offline", + accepted_at: "1963-05-03T04:07:52.723Z", + online: { + ip_address: "125.0.0.1", + user_agent: "amet irure esse", + }, + }, + }, + Response: { + status: 200, + body: { + status: "requires_customer_action", + }, + }, + }, + PaymentMethodIdMandate3DSManualCapture: { + Request: { + payment_method_data: { + card: successfulThreeDSTestCardDetails, + }, + mandate_data: null, + authentication_type: "three_ds", + customer_acceptance: { + acceptance_type: "offline", + accepted_at: "1963-05-03T04:07:52.723Z", + online: { + ip_address: "125.0.0.1", + user_agent: "amet irure esse", + }, + }, + }, + Response: { + status: 200, + body: { + status: "requires_customer_action", + }, + }, + }, + }, + bank_redirect_pm: { + PaymentIntent: getCustomExchange({ + Request: { + currency: "EUR", + }, + Response: { + status: 200, + body: { + status: "requires_payment_method", + }, + }, + }), + ideal: { + Request: { + payment_method: "bank_redirect", + payment_method_type: "ideal", + payment_method_data: { + bank_redirect: { + ideal: { + bank_name: "ing", + }, + }, + }, + billing: { + address: { + line1: "1467", + line2: "Harrison Street", + line3: "Harrison Street", + city: "San Fransico", + state: "California", + zip: "94122", + country: "NL", + first_name: "joseph", + last_name: "Doe", + }, + phone: { + number: "9123456789", + country_code: "+91", + }, + }, + }, + Response: { + status: 200, + body: { + status: "requires_customer_action", + }, + }, + }, + giropay: { + Request: { + payment_method: "bank_redirect", + payment_method_type: "giropay", + payment_method_data: { + bank_redirect: { + giropay: {}, + }, + }, + billing: { + address: { + line1: "1467", + line2: "Harrison Street", + line3: "Harrison Street", + city: "San Fransico", + state: "California", + zip: "94122", + country: "DE", + first_name: "joseph", + last_name: "Doe", + }, + phone: { + number: "9123456789", + country_code: "+91", + }, + }, + }, + Response: { + status: 200, + body: { + status: "requires_customer_action", + }, + }, + }, + sofort: { + Request: { + payment_method: "bank_redirect", + payment_method_type: "sofort", + payment_method_data: { + bank_redirect: { + sofort: {}, + }, + }, + billing: { + address: { + line1: "1467", + line2: "Harrison Street", + line3: "Harrison Street", + city: "San Fransico", + state: "California", + zip: "94122", + country: "DE", + first_name: "joseph", + last_name: "Doe", + }, + phone: { + number: "9123456789", + country_code: "+91", + }, + }, + }, + Response: { + status: 200, + body: { + status: "requires_customer_action", + }, + }, + }, + eps: { + Request: { + payment_method: "bank_redirect", + payment_method_type: "eps", + payment_method_data: { + bank_redirect: { + eps: { + bank_name: "bank_austria", + }, + }, + }, + billing: { + address: { + line1: "1467", + line2: "Harrison Street", + line3: "Harrison Street", + city: "San Fransico", + state: "California", + zip: "94122", + country: "AT", + first_name: "joseph", + last_name: "Doe", + }, + phone: { + number: "9123456789", + country_code: "+91", + }, + }, + }, + Response: { + status: 200, + body: { + status: "requires_customer_action", + }, + }, + }, + blik: { + Request: { + payment_method: "bank_redirect", + payment_method_type: "blik", + payment_method_data: { + bank_redirect: { + blik: { + blik_code: "777987", + }, + }, + }, + }, + Response: { + status: 200, + body: { + status: "failed", + error_code: "payment_intent_invalid_parameter", + }, + }, + }, + przelewy24: { + Request: { + payment_method: "bank_redirect", + payment_method_type: "przelewy24", + payment_method_data: { + bank_redirect: { + przelewy24: { + bank_name: "citi", + billing_details: { + email: "guest@juspay.in", + }, + }, + }, + }, + }, + Response: { + status: 200, + body: { + status: "requires_customer_action", + }, + }, + }, + }, +}; diff --git a/cypress-tests/cypress/e2e/PaymentMethodListUtils/utils.js b/cypress-tests/cypress/e2e/PaymentMethodListUtils/utils.js new file mode 100644 index 000000000000..7010ff55beac --- /dev/null +++ b/cypress-tests/cypress/e2e/PaymentMethodListUtils/utils.js @@ -0,0 +1,43 @@ +import { connectorDetails as CommonConnectorDetails } from "./Common.js"; +import { connectorDetails as cybersourceConnectorDetails } from "./Cybersource.js"; +import { connectorDetails as stripeConnectorDetails } from "./Stripe.js"; + +const connectorDetails = { + commons: CommonConnectorDetails, + cybersource: cybersourceConnectorDetails, + stripe: stripeConnectorDetails, +}; + +export default function getConnectorDetails(connectorId) { + let x = mergeDetails(connectorId); + return x; +} + +function mergeDetails(connectorId) { + const connectorData = getValueByKey(connectorDetails, connectorId); + + return connectorData; +} + +function getValueByKey(jsonObject, key) { + const data = + typeof jsonObject === "string" ? JSON.parse(jsonObject) : jsonObject; + + if (data && typeof data === "object" && key in data) { + return data[key]; + } else { + return null; + } +} + +export const should_continue_further = (res_data) => { + if ( + res_data.body.error !== undefined || + res_data.body.error_code !== undefined || + res_data.body.error_message !== undefined + ) { + return false; + } else { + return true; + } +}; diff --git a/cypress-tests/cypress/support/commands.js b/cypress-tests/cypress/support/commands.js index dbad47ab2cbd..2ba821571392 100644 --- a/cypress-tests/cypress/support/commands.js +++ b/cypress-tests/cypress/support/commands.js @@ -86,6 +86,57 @@ Cypress.Commands.add("apiKeyCreateTest", (apiKeyCreateBody, globalState) => { }); }); +Cypress.Commands.add( + "createNamedConnectorCallTest", + ( + createConnectorBody, + payment_methods_enabled, + globalState, + connectorName + ) => { + const merchantId = globalState.get("merchantId"); + createConnectorBody.connector_name = connectorName; + // createConnectorBody.connector_name = globalState.get("connectorId"); + createConnectorBody.payment_methods_enabled = payment_methods_enabled; + // readFile is used to read the contents of the file and it always returns a promise ([Object Object]) due to its asynchronous nature + // it is best to use then() to handle the response within the same block of code + cy.readFile(globalState.get("connectorAuthFilePath")).then( + (jsonContent) => { + const authDetails = getValueByKey( + JSON.stringify(jsonContent), + globalState.get("connectorId") + ); + console.log(`>>>>>>>>>>>>>>>>>>>>>>>>auth "${authDetails}"`); + createConnectorBody.connector_account_details = authDetails; + cy.request({ + method: "POST", + url: `${globalState.get("baseUrl")}/account/${merchantId}/connectors`, + headers: { + "Content-Type": "application/json", + Accept: "application/json", + "api-key": globalState.get("adminApiKey"), + }, + body: createConnectorBody, + failOnStatusCode: false, + }).then((response) => { + logRequestId(response.headers["x-request-id"]); + + if (response.status === 200) { + expect(globalState.get("connectorId")).to.equal( + response.body.connector_name + ); + } else { + cy.task( + "cli_log", + "response status -> " + JSON.stringify(response.status) + ); + } + }); + } + ); + } +); + Cypress.Commands.add( "createConnectorCallTest", (createConnectorBody, payment_methods_enabled, globalState) => { @@ -224,6 +275,89 @@ Cypress.Commands.add( } ); +Cypress.Commands.add( + "paymentMethodListTestLessThanEqualToOneConnector", + (res_data, globalState) => { + cy.request({ + method: "GET", + url: `${globalState.get("baseUrl")}/account/payment_methods?client_secret=${globalState.get("clientSecret")}`, + headers: { + "Content-Type": "application/json", + Accept: "application/json", + "api-key": globalState.get("publishableKey"), + }, + failOnStatusCode: false, + }).then((response) => { + Object.keys(response.body).forEach((key) => { + console.log( + `>>>>>>>>>>>>>>>>>>>>>>>>>key "${key}">>>>>>>>>>>>>body "${response.body[key]}"` + ); + }); + logRequestId(response.headers["x-request-id"]); + expect(response.headers["content-type"]).to.include("application/json"); + if (response.status === 200) { + expect(response.body).to.have.property("currency"); + if (res_data["payment_methods"].length > 0) { + function getPaymentMethodType(obj) { + return obj["payment_methods"][0]["payment_method_types"][0][ + "payment_method_type" + ]; + } + console.log( + `>>>>>>>>>>>>>>>>>>>>>>>>>keyztzzt "${response.body["payment_methods"][0]["payment_method_types"][0]["card_networks"][0]["eligible_connectors"]}"` + ); + expect(getPaymentMethodType(res_data)).to.equal( + getPaymentMethodType(response.body) + ); + } else { + expect(0).to.equal(response.body["payment_methods"].length); + } + } else { + defaultErrorHandler(response, res_data); + } + }); + } +); + +Cypress.Commands.add( + "paymentMethodListTestTwoConnectorsForCredit", + (res_data, globalState) => { + cy.request({ + method: "GET", + url: `${globalState.get("baseUrl")}/account/payment_methods?client_secret=${globalState.get("clientSecret")}`, + headers: { + "Content-Type": "application/json", + Accept: "application/json", + "api-key": globalState.get("publishableKey"), + }, + failOnStatusCode: false, + }).then((response) => { + logRequestId(response.headers["x-request-id"]); + expect(response.headers["content-type"]).to.include("application/json"); + if (response.status === 200) { + expect(response.body).to.have.property("currency"); + if (res_data["payment_methods"].length > 0) { + function getPaymentMethodType(obj) { + return obj["payment_methods"][0]["payment_method_types"][0][ + "payment_method_type" + ]; + } + console.log( + `>>>>>>>>>>>>>>>>>>>>>>>>>keyztzzt "${response.body["payment_methods"][0]["payment_method_types"][0]["card_networks"][0]["eligible_connectors"]}"` + ); + expect(getPaymentMethodType(res_data)).to.equal( + getPaymentMethodType(response.body) + ); + } else { + expect(0).to.equal(response.body["payment_methods"].length); + } + } else { + defaultErrorHandler(response, res_data); + } + }); + } +); + Cypress.Commands.add( "createPaymentIntentTest", ( diff --git a/cypress-tests/package-lock.json b/cypress-tests/package-lock.json index 41c069fea0ee..f73474f6e2fe 100644 --- a/cypress-tests/package-lock.json +++ b/cypress-tests/package-lock.json @@ -12,7 +12,7 @@ "prettier": "^3.3.2" }, "devDependencies": { - "cypress": "^13.10.0", + "cypress": "^13.12.0", "jsqr": "^1.4.0" } }, @@ -584,9 +584,9 @@ } }, "node_modules/cypress": { - "version": "13.10.0", - "resolved": "https://registry.npmjs.org/cypress/-/cypress-13.10.0.tgz", - "integrity": "sha512-tOhwRlurVOQbMduX+KonoMeQILs2cwR3yHGGENoFvvSoLUBHmJ8b9/n21gFSDqjlOJ+SRVcwuh+fG/JDsHsT6Q==", + "version": "13.12.0", + "resolved": "https://registry.npmjs.org/cypress/-/cypress-13.12.0.tgz", + "integrity": "sha512-udzS2JilmI9ApO/UuqurEwOvThclin5ntz7K0BtnHBs+tg2Bl9QShLISXpSEMDv/u8b6mqdoAdyKeZiSqKWL8g==", "dev": true, "hasInstallScript": true, "license": "MIT", diff --git a/cypress-tests/package.json b/cypress-tests/package.json index b2693e9d1ff1..59d188bac8ef 100644 --- a/cypress-tests/package.json +++ b/cypress-tests/package.json @@ -14,7 +14,7 @@ "author": "", "license": "ISC", "devDependencies": { - "cypress": "^13.10.0", + "cypress": "^13.12.0", "jsqr": "^1.4.0" }, "dependencies": { From 2586be171fa7f98214d1a2be3d63c583f1cab0a1 Mon Sep 17 00:00:00 2001 From: "hyperswitch-bot[bot]" <148525504+hyperswitch-bot[bot]@users.noreply.github.com> Date: Wed, 3 Jul 2024 20:34:08 +0000 Subject: [PATCH 07/15] chore: run formatter --- .../router/src/core/payment_methods/cards.rs | 16 ++---- .../router/src/core/payment_methods/utils.rs | 56 ++++++++++--------- 2 files changed, 35 insertions(+), 37 deletions(-) diff --git a/crates/router/src/core/payment_methods/cards.rs b/crates/router/src/core/payment_methods/cards.rs index 83cc7761a977..485572ed6b74 100644 --- a/crates/router/src/core/payment_methods/cards.rs +++ b/crates/router/src/core/payment_methods/cards.rs @@ -1998,16 +1998,13 @@ pub async fn list_payment_methods( // No PM_FILTER_CGRAPH Cache present in MokaCache let mut builder = cgraph::ConstraintGraphBuilder::new(); for mca in &filtered_mcas { - let domain_id = builder - .make_domain( - mca.merchant_connector_id.clone(), - mca.connector_name.as_str(), - ); + let domain_id = builder.make_domain( + mca.merchant_connector_id.clone(), + mca.connector_name.as_str(), + ); let Ok(domain_id) = domain_id else { - logger::error!( - "Failed to construct domain for list payment methods" - ); + logger::error!("Failed to construct domain for list payment methods"); return Err(errors::ApiErrorResponse::InternalServerError.into()); }; @@ -2031,8 +2028,7 @@ pub async fn list_payment_methods( } // Refreshing our CGraph cache - let graph = - refresh_pm_filters_cache(&state, &key, builder.build()).await; + let graph = refresh_pm_filters_cache(&state, &key, builder.build()).await; for mca in &filtered_mcas { let payment_methods = match &mca.payment_methods_enabled { diff --git a/crates/router/src/core/payment_methods/utils.rs b/crates/router/src/core/payment_methods/utils.rs index 4a295c042343..96ed882f248a 100644 --- a/crates/router/src/core/payment_methods/utils.rs +++ b/crates/router/src/core/payment_methods/utils.rs @@ -42,15 +42,9 @@ pub fn make_pm_graph( pub async fn get_merchant_pm_filter_graph<'a>( state: &SessionState, key: &str, -) -> Option< - Arc< - hyperswitch_constraint_graph::ConstraintGraph - >, -> { +) -> Option>> { PM_FILTERS_CGRAPH_CACHE - .get_val::, - >>(CacheKey { + .get_val::>>(CacheKey { key: key.to_string(), prefix: state.tenant.redis_key_prefix.clone(), }) @@ -624,11 +618,12 @@ fn compile_accepted_countries_for_mca( .get(connector.as_str()) .or_else(|| config.0.get("default")) { - if let Some(value) = derived_config - .0 - .get(&settings::PaymentMethodFilterKey::PaymentMethodType( - *payment_method_type, - )) + if let Some(value) = + derived_config + .0 + .get(&settings::PaymentMethodFilterKey::PaymentMethodType( + *payment_method_type, + )) { if let Some(config_countries) = value.country.as_ref() { let config_countries: Vec = Vec::from_iter(config_countries) @@ -650,16 +645,20 @@ fn compile_accepted_countries_for_mca( cgraph::Strength::Weak, )); } - } - else if let Some(default_derived_config) = config.0.get("default") { - if let Some(value) = default_derived_config.0.get( - &settings::PaymentMethodFilterKey::PaymentMethodType(*payment_method_type), - ) { + } else if let Some(default_derived_config) = config.0.get("default") { + if let Some(value) = + default_derived_config + .0 + .get(&settings::PaymentMethodFilterKey::PaymentMethodType( + *payment_method_type, + )) + { if let Some(config_countries) = value.country.as_ref() { - let config_countries: Vec = Vec::from_iter(config_countries) - .into_iter() - .map(|country| common_enums::Country::from_alpha2(*country)) - .collect(); + let config_countries: Vec = + Vec::from_iter(config_countries) + .into_iter() + .map(|country| common_enums::Country::from_alpha2(*country)) + .collect(); let dir_countries: Vec = config_countries .into_iter() .map(dir::DirValue::BillingCountry) @@ -770,11 +769,14 @@ fn compile_accepted_currency_for_mca( cgraph::Strength::Weak, )); } - } - else if let Some(default_derived_config) = config.0.get("default") { - if let Some(value) = default_derived_config.0.get( - &settings::PaymentMethodFilterKey::PaymentMethodType(*payment_method_type), - ) { + } else if let Some(default_derived_config) = config.0.get("default") { + if let Some(value) = + default_derived_config + .0 + .get(&settings::PaymentMethodFilterKey::PaymentMethodType( + *payment_method_type, + )) + { if let Some(config_currencies) = value.currency.as_ref() { let config_currency: Vec = Vec::from_iter(config_currencies) From 01f9f738cb6fe53598a9ebd7131657a150f3b931 Mon Sep 17 00:00:00 2001 From: prajjwalkumar17 Date: Thu, 4 Jul 2024 02:07:04 +0530 Subject: [PATCH 08/15] chore: code beautification --- .../router/src/core/payment_methods/cards.rs | 16 ++---- .../router/src/core/payment_methods/utils.rs | 56 ++++++++++--------- 2 files changed, 35 insertions(+), 37 deletions(-) diff --git a/crates/router/src/core/payment_methods/cards.rs b/crates/router/src/core/payment_methods/cards.rs index 827d1cd07c2c..8852d53df941 100644 --- a/crates/router/src/core/payment_methods/cards.rs +++ b/crates/router/src/core/payment_methods/cards.rs @@ -1981,16 +1981,13 @@ pub async fn list_payment_methods( // No PM_FILTER_CGRAPH Cache present in MokaCache let mut builder = cgraph::ConstraintGraphBuilder::new(); for mca in &filtered_mcas { - let domain_id = builder - .make_domain( - mca.merchant_connector_id.clone(), - mca.connector_name.as_str(), - ); + let domain_id = builder.make_domain( + mca.merchant_connector_id.clone(), + mca.connector_name.as_str(), + ); let Ok(domain_id) = domain_id else { - logger::error!( - "Failed to construct domain for list payment methods" - ); + logger::error!("Failed to construct domain for list payment methods"); return Err(errors::ApiErrorResponse::InternalServerError.into()); }; @@ -2014,8 +2011,7 @@ pub async fn list_payment_methods( } // Refreshing our CGraph cache - let graph = - refresh_pm_filters_cache(&state, &key, builder.build()).await; + let graph = refresh_pm_filters_cache(&state, &key, builder.build()).await; for mca in &filtered_mcas { let payment_methods = match &mca.payment_methods_enabled { diff --git a/crates/router/src/core/payment_methods/utils.rs b/crates/router/src/core/payment_methods/utils.rs index 4a295c042343..96ed882f248a 100644 --- a/crates/router/src/core/payment_methods/utils.rs +++ b/crates/router/src/core/payment_methods/utils.rs @@ -42,15 +42,9 @@ pub fn make_pm_graph( pub async fn get_merchant_pm_filter_graph<'a>( state: &SessionState, key: &str, -) -> Option< - Arc< - hyperswitch_constraint_graph::ConstraintGraph - >, -> { +) -> Option>> { PM_FILTERS_CGRAPH_CACHE - .get_val::, - >>(CacheKey { + .get_val::>>(CacheKey { key: key.to_string(), prefix: state.tenant.redis_key_prefix.clone(), }) @@ -624,11 +618,12 @@ fn compile_accepted_countries_for_mca( .get(connector.as_str()) .or_else(|| config.0.get("default")) { - if let Some(value) = derived_config - .0 - .get(&settings::PaymentMethodFilterKey::PaymentMethodType( - *payment_method_type, - )) + if let Some(value) = + derived_config + .0 + .get(&settings::PaymentMethodFilterKey::PaymentMethodType( + *payment_method_type, + )) { if let Some(config_countries) = value.country.as_ref() { let config_countries: Vec = Vec::from_iter(config_countries) @@ -650,16 +645,20 @@ fn compile_accepted_countries_for_mca( cgraph::Strength::Weak, )); } - } - else if let Some(default_derived_config) = config.0.get("default") { - if let Some(value) = default_derived_config.0.get( - &settings::PaymentMethodFilterKey::PaymentMethodType(*payment_method_type), - ) { + } else if let Some(default_derived_config) = config.0.get("default") { + if let Some(value) = + default_derived_config + .0 + .get(&settings::PaymentMethodFilterKey::PaymentMethodType( + *payment_method_type, + )) + { if let Some(config_countries) = value.country.as_ref() { - let config_countries: Vec = Vec::from_iter(config_countries) - .into_iter() - .map(|country| common_enums::Country::from_alpha2(*country)) - .collect(); + let config_countries: Vec = + Vec::from_iter(config_countries) + .into_iter() + .map(|country| common_enums::Country::from_alpha2(*country)) + .collect(); let dir_countries: Vec = config_countries .into_iter() .map(dir::DirValue::BillingCountry) @@ -770,11 +769,14 @@ fn compile_accepted_currency_for_mca( cgraph::Strength::Weak, )); } - } - else if let Some(default_derived_config) = config.0.get("default") { - if let Some(value) = default_derived_config.0.get( - &settings::PaymentMethodFilterKey::PaymentMethodType(*payment_method_type), - ) { + } else if let Some(default_derived_config) = config.0.get("default") { + if let Some(value) = + default_derived_config + .0 + .get(&settings::PaymentMethodFilterKey::PaymentMethodType( + *payment_method_type, + )) + { if let Some(config_currencies) = value.currency.as_ref() { let config_currency: Vec = Vec::from_iter(config_currencies) From 1b4a434d3832f4c54214b4b63f9c523f18dc1a33 Mon Sep 17 00:00:00 2001 From: prajjwalkumar17 Date: Thu, 4 Jul 2024 02:17:42 +0530 Subject: [PATCH 09/15] chore: code beautification --- .../router/src/core/payment_methods/cards.rs | 161 ------------------ 1 file changed, 161 deletions(-) diff --git a/crates/router/src/core/payment_methods/cards.rs b/crates/router/src/core/payment_methods/cards.rs index 485572ed6b74..2064592edb3b 100644 --- a/crates/router/src/core/payment_methods/cards.rs +++ b/crates/router/src/core/payment_methods/cards.rs @@ -3189,117 +3189,6 @@ fn filter_pm_card_network_based( _ => true, } } -// fn filter_pm_country_based( -// accepted_countries: &Option, -// req_country_list: &Option>, -// ) -> ( -// Option, -// Option>, -// bool, -// ) { -// match (accepted_countries, req_country_list) { -// (None, None) => (None, None, true), -// (None, Some(ref r)) => ( -// Some(admin::AcceptedCountries::EnableOnly(r.to_vec())), -// Some(r.to_vec()), -// true, -// ), -// (Some(l), None) => (Some(l.to_owned()), None, true), -// (Some(l), Some(ref r)) => { -// let updated = match l { -// admin::AcceptedCountries::EnableOnly(acc) => { -// filter_accepted_enum_based(&Some(acc.clone()), &Some(r.to_owned())) -// .map(admin::AcceptedCountries::EnableOnly) -// } -// -// admin::AcceptedCountries::DisableOnly(den) => { -// filter_disabled_enum_based(&Some(den.clone()), &Some(r.to_owned())) -// .map(admin::AcceptedCountries::DisableOnly) -// } -// -// admin::AcceptedCountries::AllAccepted => { -// Some(admin::AcceptedCountries::AllAccepted) -// } -// }; -// -// (updated, Some(r.to_vec()), true) -// } -// } -// } -// -// fn filter_pm_currencies_based( -// accepted_currency: &Option, -// req_currency_list: &Option>, -// ) -> ( -// Option, -// Option>, -// bool, -// ) { -// match (accepted_currency, req_currency_list) { -// (None, None) => (None, None, true), -// (None, Some(ref r)) => ( -// Some(admin::AcceptedCurrencies::EnableOnly(r.to_vec())), -// Some(r.to_vec()), -// true, -// ), -// (Some(l), None) => (Some(l.to_owned()), None, true), -// (Some(l), Some(ref r)) => { -// let updated = match l { -// admin::AcceptedCurrencies::EnableOnly(acc) => { -// filter_accepted_enum_based(&Some(acc.clone()), &Some(r.to_owned())) -// .map(admin::AcceptedCurrencies::EnableOnly) -// } -// -// admin::AcceptedCurrencies::DisableOnly(den) => { -// filter_disabled_enum_based(&Some(den.clone()), &Some(r.to_owned())) -// .map(admin::AcceptedCurrencies::DisableOnly) -// } -// -// admin::AcceptedCurrencies::AllAccepted => { -// Some(admin::AcceptedCurrencies::AllAccepted) -// } -// }; -// -// (updated, Some(r.to_vec()), true) -// } -// } -// } -// -// fn filter_accepted_enum_based( -// left: &Option>, -// right: &Option>, -// ) -> Option> { -// match (left, right) { -// (Some(ref l), Some(ref r)) => { -// let a: HashSet<&T> = HashSet::from_iter(l.iter()); -// let b: HashSet<&T> = HashSet::from_iter(r.iter()); -// -// let y: Vec = a.intersection(&b).map(|&i| i.to_owned()).collect(); -// Some(y) -// } -// (Some(ref l), None) => Some(l.to_vec()), -// (_, _) => None, -// } -// } -// -// fn filter_disabled_enum_based( -// left: &Option>, -// right: &Option>, -// ) -> Option> { -// match (left, right) { -// (Some(ref l), Some(ref r)) => { -// let mut enabled = Vec::new(); -// for element in r { -// if !l.contains(element) { -// enabled.push(element.to_owned()); -// } -// } -// Some(enabled) -// } -// (None, Some(r)) => Some(r.to_vec()), -// (_, _) => None, -// } -// } fn filter_pm_based_on_allowed_types( allowed_types: Option<&Vec>, @@ -3315,56 +3204,6 @@ fn filter_recurring_based( recurring_enabled.map_or(true, |enabled| payment_method.recurring_enabled == enabled) } -// async fn filter_payment_country_based( -// pm: &RequestPaymentMethodTypes, -// address: Option<&domain::Address>, -// ) -> errors::CustomResult { -// Ok(address.map_or(true, |address| { -// address.country.as_ref().map_or(true, |country| { -// pm.accepted_countries.as_ref().map_or(true, |ac| match ac { -// admin::AcceptedCountries::EnableOnly(acc) => acc.contains(country), -// admin::AcceptedCountries::DisableOnly(den) => !den.contains(country), -// admin::AcceptedCountries::AllAccepted => true, -// }) -// }) -// })) -// } -// -// fn filter_payment_currency_based( -// payment_intent: &storage::PaymentIntent, -// pm: &RequestPaymentMethodTypes, -// ) -> bool { -// payment_intent.currency.map_or(true, |currency| { -// pm.accepted_currencies.as_ref().map_or(true, |ac| match ac { -// admin::AcceptedCurrencies::EnableOnly(acc) => acc.contains(¤cy), -// admin::AcceptedCurrencies::DisableOnly(den) => !den.contains(¤cy), -// admin::AcceptedCurrencies::AllAccepted => true, -// }) -// }) -// } -// -// fn filter_payment_amount_based( -// payment_intent: &storage::PaymentIntent, -// pm: &RequestPaymentMethodTypes, -// ) -> bool { -// let amount = payment_intent.amount; -// (pm.maximum_amount.map_or(true, |amt| amount <= amt) -// && pm.minimum_amount.map_or(true, |amt| amount >= amt)) -// || payment_intent.amount == MinorUnit::zero() -// } -// -// async fn filter_payment_mandate_based( -// payment_attempt: Option<&storage::PaymentAttempt>, -// pm: &RequestPaymentMethodTypes, -// ) -> errors::CustomResult { -// let recurring_filter = if !pm.recurring_enabled { -// payment_attempt.map_or(true, |pa| pa.mandate_id.is_none()) -// } else { -// true -// }; -// Ok(recurring_filter) -// } - pub async fn do_list_customer_pm_fetch_customer_if_not_passed( state: routes::SessionState, merchant_account: domain::MerchantAccount, From 4182fe63fd9ae1bf3175ce3db83a5a1d0d719208 Mon Sep 17 00:00:00 2001 From: prajjwalkumar17 Date: Thu, 4 Jul 2024 17:35:05 +0530 Subject: [PATCH 10/15] chore: addition of cypress tests --- ...0000-PaymentMethodListConfigCurrency.cy.js | 7 ++-- ...01-PaymentMethodListMcaWrongCurrency.cy.js | 9 +++-- .../00002-PaymentMethodListMcaCountry.cy.js | 10 +++-- ...-PaymentMethodListConfigWrongCountry.cy.js | 7 ++-- ...entMethodListNoConfigCurrencyCountry.cy.js | 13 ++++--- cypress-tests/cypress/support/commands.js | 39 +++++++------------ 6 files changed, 42 insertions(+), 43 deletions(-) diff --git a/cypress-tests/cypress/e2e/PaymentMethodListTest/00000-PaymentMethodListConfigCurrency.cy.js b/cypress-tests/cypress/e2e/PaymentMethodListTest/00000-PaymentMethodListConfigCurrency.cy.js index 8b98ef2e6916..77d986a7d87f 100644 --- a/cypress-tests/cypress/e2e/PaymentMethodListTest/00000-PaymentMethodListConfigCurrency.cy.js +++ b/cypress-tests/cypress/e2e/PaymentMethodListTest/00000-PaymentMethodListConfigCurrency.cy.js @@ -38,10 +38,11 @@ describe("Account Create flow test", () => { // stripe connector create with ideal enabled it("connector-create-call-test", () => { - cy.createConnectorCallTest( + cy.createNamedConnectorCallTest( createConnectorBody, bank_redirect_ideal_enabled, - globalState + globalState, + "stripe" ); }); @@ -76,6 +77,6 @@ describe("Account Create flow test", () => { let data = getConnectorDetails(globalState.get("connectorId"))["pm_list"][ "PmListResponse" ]["PmListWithStripeForIdeal"]; - cy.paymentMethodListTestLessThanEqualToOneConnector(data, globalState); + cy.paymentMethodListTestLessThanEqualToOnePaymentMethod(data, globalState); }); }); diff --git a/cypress-tests/cypress/e2e/PaymentMethodListTest/00001-PaymentMethodListMcaWrongCurrency.cy.js b/cypress-tests/cypress/e2e/PaymentMethodListTest/00001-PaymentMethodListMcaWrongCurrency.cy.js index 968060ed7502..beb9b0052eb9 100644 --- a/cypress-tests/cypress/e2e/PaymentMethodListTest/00001-PaymentMethodListMcaWrongCurrency.cy.js +++ b/cypress-tests/cypress/e2e/PaymentMethodListTest/00001-PaymentMethodListMcaWrongCurrency.cy.js @@ -15,7 +15,7 @@ import State from "../../utils/State"; // MCA1 -> Stripe configured with ideal = { country = "NL", currency = "EUR" } // MCA2 -> Cybersource configured with credit = { currency = "USD" } // Payment is done with currency as INR and no billing address -// The resultant Payment Method list shouldn't have +// The resultant Payment Method list shouldn't have any payment method let globalState; describe("Account Create flow test", () => { @@ -39,10 +39,11 @@ describe("Account Create flow test", () => { // stripe connector create with ideal enabled it("connector-create-call-test", () => { - cy.createConnectorCallTest( + cy.createNamedConnectorCallTest( createConnectorBody, bank_redirect_ideal_enabled, - globalState + globalState, + "stripe" ); }); @@ -77,6 +78,6 @@ describe("Account Create flow test", () => { let data = getConnectorDetails(globalState.get("connectorId"))["pm_list"][ "PmListResponse" ]["PmListNull"]; - cy.paymentMethodListTestLessThanEqualToOneConnector(data, globalState); + cy.paymentMethodListTestLessThanEqualToOnePaymentMethod(data, globalState); }); }); diff --git a/cypress-tests/cypress/e2e/PaymentMethodListTest/00002-PaymentMethodListMcaCountry.cy.js b/cypress-tests/cypress/e2e/PaymentMethodListTest/00002-PaymentMethodListMcaCountry.cy.js index 860b79a55ddc..eece391296cf 100644 --- a/cypress-tests/cypress/e2e/PaymentMethodListTest/00002-PaymentMethodListMcaCountry.cy.js +++ b/cypress-tests/cypress/e2e/PaymentMethodListTest/00002-PaymentMethodListMcaCountry.cy.js @@ -39,10 +39,11 @@ describe("Account Create flow test", () => { // stripe connector create with credit enabled for US it("connector-create-call-test", () => { - cy.createConnectorCallTest( + cy.createNamedConnectorCallTest( createConnectorBody, card_credit_enabled_in_US, - globalState + globalState, + "stripe" ); }); @@ -77,6 +78,9 @@ describe("Account Create flow test", () => { let data = getConnectorDetails(globalState.get("connectorId"))["pm_list"][ "PmListResponse" ]["PmListWithCreditTwoConnector"]; - cy.paymentMethodListTestLessThanEqualToOneConnector(data, globalState); + cy.paymentMethodListTestTwoConnectorsForOnePaymentMethodCredit( + data, + globalState + ); }); }); diff --git a/cypress-tests/cypress/e2e/PaymentMethodListTest/00003-PaymentMethodListConfigWrongCountry.cy.js b/cypress-tests/cypress/e2e/PaymentMethodListTest/00003-PaymentMethodListConfigWrongCountry.cy.js index c27b44a71b6b..0fcd15dee102 100644 --- a/cypress-tests/cypress/e2e/PaymentMethodListTest/00003-PaymentMethodListConfigWrongCountry.cy.js +++ b/cypress-tests/cypress/e2e/PaymentMethodListTest/00003-PaymentMethodListConfigWrongCountry.cy.js @@ -39,10 +39,11 @@ describe("Account Create flow test", () => { // stripe connector create with ideal enabled it("connector-create-call-test", () => { - cy.createConnectorCallTest( + cy.createNamedConnectorCallTest( createConnectorBody, bank_redirect_ideal_enabled, - globalState + globalState, + "stripe" ); }); @@ -77,6 +78,6 @@ describe("Account Create flow test", () => { let data = getConnectorDetails(globalState.get("connectorId"))["pm_list"][ "PmListResponse" ]["PmListNull"]; - cy.paymentMethodListTestLessThanEqualToOneConnector(data, globalState); + cy.paymentMethodListTestLessThanEqualToOnePaymentMethod(data, globalState); }); }); diff --git a/cypress-tests/cypress/e2e/PaymentMethodListTest/00004-PaymentMethodListNoConfigCurrencyCountry.cy.js b/cypress-tests/cypress/e2e/PaymentMethodListTest/00004-PaymentMethodListNoConfigCurrencyCountry.cy.js index 7fd72328991a..14bc5cff6597 100644 --- a/cypress-tests/cypress/e2e/PaymentMethodListTest/00004-PaymentMethodListNoConfigCurrencyCountry.cy.js +++ b/cypress-tests/cypress/e2e/PaymentMethodListTest/00004-PaymentMethodListNoConfigCurrencyCountry.cy.js @@ -41,10 +41,11 @@ describe("Account Create flow test", () => { // stripe connector create with card credit enabled it("connector-create-call-test", () => { - cy.createConnectorCallTest( + cy.createNamedConnectorCallTest( createConnectorBody, card_credit_enabled, - globalState + globalState, + "stripe" ); }); @@ -52,8 +53,7 @@ describe("Account Create flow test", () => { it("connector-create-call-test", () => { cy.createNamedConnectorCallTest( createConnectorBody, - // card_credit_enabled, - card_credit_enabled, + bank_redirect_ideal_and_credit_enabled, globalState, "cybersource" ); @@ -80,6 +80,9 @@ describe("Account Create flow test", () => { let data = getConnectorDetails(globalState.get("connectorId"))["pm_list"][ "PmListResponse" ]["PmListWithCreditTwoConnector"]; - cy.paymentMethodListTestTwoConnectorsForCredit(data, globalState); + cy.paymentMethodListTestTwoConnectorsForOnePaymentMethodCredit( + data, + globalState + ); }); }); diff --git a/cypress-tests/cypress/support/commands.js b/cypress-tests/cypress/support/commands.js index f9110421da32..b96a3ec1c422 100644 --- a/cypress-tests/cypress/support/commands.js +++ b/cypress-tests/cypress/support/commands.js @@ -96,7 +96,6 @@ Cypress.Commands.add( ) => { const merchantId = globalState.get("merchantId"); createConnectorBody.connector_name = connectorName; - // createConnectorBody.connector_name = globalState.get("connectorId"); createConnectorBody.payment_methods_enabled = payment_methods_enabled; // readFile is used to read the contents of the file and it always returns a promise ([Object Object]) due to its asynchronous nature // it is best to use then() to handle the response within the same block of code @@ -104,9 +103,8 @@ Cypress.Commands.add( (jsonContent) => { const authDetails = getValueByKey( JSON.stringify(jsonContent), - globalState.get("connectorId") + connectorName ); - console.log(`>>>>>>>>>>>>>>>>>>>>>>>>auth "${authDetails}"`); createConnectorBody.connector_account_details = authDetails; cy.request({ method: "POST", @@ -122,9 +120,7 @@ Cypress.Commands.add( logRequestId(response.headers["x-request-id"]); if (response.status === 200) { - expect(globalState.get("connectorId")).to.equal( - response.body.connector_name - ); + expect(connectorName).to.equal(response.body.connector_name); } else { cy.task( "cli_log", @@ -276,7 +272,7 @@ Cypress.Commands.add( ); Cypress.Commands.add( - "paymentMethodListTestLessThanEqualToOneConnector", + "paymentMethodListTestLessThanEqualToOnePaymentMethod", (res_data, globalState) => { cy.request({ method: "GET", @@ -288,24 +284,16 @@ Cypress.Commands.add( }, failOnStatusCode: false, }).then((response) => { - Object.keys(response.body).forEach((key) => { - console.log( - `>>>>>>>>>>>>>>>>>>>>>>>>>key "${key}">>>>>>>>>>>>>body "${response.body[key]}"` - ); - }); logRequestId(response.headers["x-request-id"]); expect(response.headers["content-type"]).to.include("application/json"); if (response.status === 200) { expect(response.body).to.have.property("currency"); - if (res_data["payment_methods"].length > 0) { + if (res_data["payment_methods"].length == 1) { function getPaymentMethodType(obj) { return obj["payment_methods"][0]["payment_method_types"][0][ "payment_method_type" ]; } - console.log( - `>>>>>>>>>>>>>>>>>>>>>>>>>keyztzzt "${response.body["payment_methods"][0]["payment_method_types"][0]["card_networks"][0]["eligible_connectors"]}"` - ); expect(getPaymentMethodType(res_data)).to.equal( getPaymentMethodType(response.body) ); @@ -320,7 +308,7 @@ Cypress.Commands.add( ); Cypress.Commands.add( - "paymentMethodListTestTwoConnectorsForCredit", + "paymentMethodListTestTwoConnectorsForOnePaymentMethodCredit", (res_data, globalState) => { cy.request({ method: "GET", @@ -339,15 +327,16 @@ Cypress.Commands.add( if (res_data["payment_methods"].length > 0) { function getPaymentMethodType(obj) { return obj["payment_methods"][0]["payment_method_types"][0][ - "payment_method_type" - ]; + "card_networks" + ][0]["eligible_connectors"] + .slice() + .sort(); + } + for (let i = 0; i < getPaymentMethodType(response.body).length; i++) { + expect(getPaymentMethodType(res_data)[i]).to.equal( + getPaymentMethodType(response.body)[i] + ); } - console.log( - `>>>>>>>>>>>>>>>>>>>>>>>>>keyztzzt "${response.body["payment_methods"][0]["payment_method_types"][0]["card_networks"][0]["eligible_connectors"]}"` - ); - expect(getPaymentMethodType(res_data)).to.equal( - getPaymentMethodType(response.body) - ); } else { expect(0).to.equal(response.body["payment_methods"].length); } From eafbbb2b2a524e1206f8b28dbcc65453ca8c251e Mon Sep 17 00:00:00 2001 From: prajjwalkumar17 Date: Sun, 7 Jul 2024 03:22:31 +0530 Subject: [PATCH 11/15] chore: addressed comments --- ...0000-PaymentMethodListConfigCurrency.cy.js | 82 -- .../00000-PaymentMethodListTests.cy.js | 428 ++++++++ ...01-PaymentMethodListMcaWrongCurrency.cy.js | 83 -- .../00002-PaymentMethodListMcaCountry.cy.js | 86 -- ...-PaymentMethodListConfigWrongCountry.cy.js | 83 -- ...entMethodListNoConfigCurrencyCountry.cy.js | 88 -- .../e2e/PaymentMethodListUtils/Common.js | 391 -------- .../e2e/PaymentMethodListUtils/Commons.js | 179 ++++ .../e2e/PaymentMethodListUtils/Cybersource.js | 928 +++++++++--------- .../e2e/PaymentMethodListUtils/Stripe.js | 661 ------------- .../e2e/PaymentMethodListUtils/utils.js | 2 +- 11 files changed, 1072 insertions(+), 1939 deletions(-) delete mode 100644 cypress-tests/cypress/e2e/PaymentMethodListTest/00000-PaymentMethodListConfigCurrency.cy.js create mode 100644 cypress-tests/cypress/e2e/PaymentMethodListTest/00000-PaymentMethodListTests.cy.js delete mode 100644 cypress-tests/cypress/e2e/PaymentMethodListTest/00001-PaymentMethodListMcaWrongCurrency.cy.js delete mode 100644 cypress-tests/cypress/e2e/PaymentMethodListTest/00002-PaymentMethodListMcaCountry.cy.js delete mode 100644 cypress-tests/cypress/e2e/PaymentMethodListTest/00003-PaymentMethodListConfigWrongCountry.cy.js delete mode 100644 cypress-tests/cypress/e2e/PaymentMethodListTest/00004-PaymentMethodListNoConfigCurrencyCountry.cy.js delete mode 100644 cypress-tests/cypress/e2e/PaymentMethodListUtils/Common.js create mode 100644 cypress-tests/cypress/e2e/PaymentMethodListUtils/Commons.js diff --git a/cypress-tests/cypress/e2e/PaymentMethodListTest/00000-PaymentMethodListConfigCurrency.cy.js b/cypress-tests/cypress/e2e/PaymentMethodListTest/00000-PaymentMethodListConfigCurrency.cy.js deleted file mode 100644 index 77d986a7d87f..000000000000 --- a/cypress-tests/cypress/e2e/PaymentMethodListTest/00000-PaymentMethodListConfigCurrency.cy.js +++ /dev/null @@ -1,82 +0,0 @@ -import apiKeyCreateBody from "../../fixtures/create-api-key-body.json"; -import createConnectorBody from "../../fixtures/create-connector-body.json"; -import getConnectorDetails from "../PaymentMethodListUtils/utils"; -import merchantCreateBody from "../../fixtures/merchant-create-body.json"; -import * as utils from "../PaymentMethodListUtils/utils"; -import { - card_credit_enabled, - bank_redirect_ideal_enabled, - create_payment_body_in_EUR, -} from "../PaymentMethodListUtils/Common"; -import State from "../../utils/State"; - -// Testing for scenario: -// MCA1 -> Stripe configured with ideal = { country = "NL", currency = "EUR" } -// MCA2 -> Cybersource configured with credit = { currency = "USD" } -// Payment is done with currency as EUR and no billing address -// The resultant Payment Method list should only have ideal with stripe - -let globalState; -describe("Account Create flow test", () => { - before("seed global state", () => { - cy.task("getGlobalState").then((state) => { - globalState = new State(state); - }); - }); - - after("flush global state", () => { - cy.task("setGlobalState", globalState.data); - }); - - it("merchant-create-call-test", () => { - cy.merchantCreateCallTest(merchantCreateBody, globalState); - }); - - it("api-key-create-call-test", () => { - cy.apiKeyCreateTest(apiKeyCreateBody, globalState); - }); - - // stripe connector create with ideal enabled - it("connector-create-call-test", () => { - cy.createNamedConnectorCallTest( - createConnectorBody, - bank_redirect_ideal_enabled, - globalState, - "stripe" - ); - }); - - // cybersource connector create with card credit enabled - it("connector-create-call-test", () => { - cy.createNamedConnectorCallTest( - createConnectorBody, - card_credit_enabled, - globalState, - "cybersource" - ); - }); - - // creating payment with currency as EUR and no billing address - it("create-payment-call-test", () => { - let data = getConnectorDetails("stripe")["pm_list"]["PaymentIntent"]; - let req_data = data["RequestCurrencyEUR"]; - let res_data = data["Response"]; - - cy.createPaymentIntentTest( - create_payment_body_in_EUR, - req_data, - res_data, - "no_three_ds", - "automatic", - globalState - ); - }); - - // payment method list which should only have ideal with stripe - it("payment-method-list-call-test", () => { - let data = getConnectorDetails(globalState.get("connectorId"))["pm_list"][ - "PmListResponse" - ]["PmListWithStripeForIdeal"]; - cy.paymentMethodListTestLessThanEqualToOnePaymentMethod(data, globalState); - }); -}); diff --git a/cypress-tests/cypress/e2e/PaymentMethodListTest/00000-PaymentMethodListTests.cy.js b/cypress-tests/cypress/e2e/PaymentMethodListTest/00000-PaymentMethodListTests.cy.js new file mode 100644 index 000000000000..f4a9ec942ab7 --- /dev/null +++ b/cypress-tests/cypress/e2e/PaymentMethodListTest/00000-PaymentMethodListTests.cy.js @@ -0,0 +1,428 @@ +import apiKeyCreateBody from "../../fixtures/create-api-key-body.json"; +import createConnectorBody from "../../fixtures/create-connector-body.json"; +import getConnectorDetails from "../PaymentMethodListUtils/utils"; +import merchantCreateBody from "../../fixtures/merchant-create-body.json"; +import * as utils from "../PaymentMethodListUtils/utils"; +import { + card_credit_enabled, + card_credit_enabled_in_US, + card_credit_enabled_in_USD, + bank_redirect_ideal_enabled, + bank_redirect_ideal_and_credit_enabled, + create_payment_body_with_currency, + create_payment_body_with_currency_country, +} from "../PaymentMethodListUtils/Commons"; +import State from "../../utils/State"; + +// Testing for scenario: +// MCA1 -> Stripe configured with ideal = { country = "NL", currency = "EUR" } +// MCA2 -> Cybersource configured with credit = { currency = "USD" } +// Payment is done with currency as EUR and no billing address +// The resultant Payment Method list should only have ideal with stripe + +let globalState; +describe("Payment Method list using Constraint Graph flow tests", () => { + // Testing for scenario: + // MCA1 -> Stripe configured with ideal = { country = "NL", currency = "EUR" } + // MCA2 -> Cybersource configured with credit = { currency = "USD" } + // Payment is done with currency as EUR and no billing address + // The resultant Payment Method list should only have ideal with stripe + context( + ` + MCA1 -> Stripe configured with ideal = { country = "NL", currency = "EUR" }\n + MCA2 -> Cybersource configured with credit = { currency = "USD" }\n + Payment is done with currency as EUR and no billing address\n + The resultant Payment Method list should only have ideal with stripe\n + `, + () => { + before("seed global state", () => { + cy.task("getGlobalState").then((state) => { + globalState = new State(state); + }); + }); + + after("flush global state", () => { + cy.task("setGlobalState", globalState.data); + }); + + it("merchant-create-call-test", () => { + cy.merchantCreateCallTest(merchantCreateBody, globalState); + }); + + it("api-key-create-call-test", () => { + cy.apiKeyCreateTest(apiKeyCreateBody, globalState); + }); + + // stripe connector create with ideal enabled + it("connector-create-call-test", () => { + cy.createNamedConnectorCallTest( + createConnectorBody, + bank_redirect_ideal_enabled, + globalState, + "stripe" + ); + }); + + // cybersource connector create with card credit enabled + it("connector-create-call-test", () => { + cy.createNamedConnectorCallTest( + createConnectorBody, + card_credit_enabled, + globalState, + "cybersource" + ); + }); + + // creating payment with currency as EUR and no billing address + it("create-payment-call-test", () => { + let data = getConnectorDetails("stripe")["pm_list"]["PaymentIntent"]; + let req_data = data["RequestCurrencyEUR"]; + let res_data = data["Response"]; + + cy.createPaymentIntentTest( + create_payment_body_with_currency("EUR"), + req_data, + res_data, + "no_three_ds", + "automatic", + globalState + ); + }); + + // payment method list which should only have ideal with stripe + it("payment-method-list-call-test", () => { + let data = getConnectorDetails(globalState.get("connectorId"))[ + "pm_list" + ]["PmListResponse"]["PmListWithStripeForIdeal"]; + cy.paymentMethodListTestLessThanEqualToOnePaymentMethod( + data, + globalState + ); + }); + } + ); + + // Testing for scenario: + // MCA1 -> Stripe configured with ideal = { country = "NL", currency = "EUR" } + // MCA2 -> Cybersource configured with credit = { currency = "USD" } + // Payment is done with currency as INR and no billing address + // The resultant Payment Method list shouldn't have any payment method + context( + ` + MCA1 -> Stripe configured with ideal = { country = "NL", currency = "EUR" }\n + MCA2 -> Cybersource configured with credit = { currency = "USD" }\n + Payment is done with currency as INR and no billing address\n + The resultant Payment Method list shouldn't have any payment method\n + `, + () => { + before("seed global state", () => { + cy.task("getGlobalState").then((state) => { + globalState = new State(state); + }); + }); + + after("flush global state", () => { + cy.task("setGlobalState", globalState.data); + }); + + it("merchant-create-call-test", () => { + cy.merchantCreateCallTest(merchantCreateBody, globalState); + }); + + it("api-key-create-call-test", () => { + cy.apiKeyCreateTest(apiKeyCreateBody, globalState); + }); + + // stripe connector create with ideal enabled + it("connector-create-call-test", () => { + cy.createNamedConnectorCallTest( + createConnectorBody, + bank_redirect_ideal_enabled, + globalState, + "stripe" + ); + }); + + // cybersource connector create with card credit enabled in USD + it("connector-create-call-test", () => { + cy.createNamedConnectorCallTest( + createConnectorBody, + card_credit_enabled_in_USD, + globalState, + "cybersource" + ); + }); + + // creating payment with currency as INR and no billing address + it("create-payment-call-test", () => { + let data = getConnectorDetails("stripe")["pm_list"]["PaymentIntent"]; + let req_data = data["RequestCurrencyINR"]; + let res_data = data["Response"]; + + cy.createPaymentIntentTest( + create_payment_body_with_currency("INR"), + req_data, + res_data, + "no_three_ds", + "automatic", + globalState + ); + }); + + // payment method list which should only have ideal with stripe + it("payment-method-list-call-test", () => { + let data = getConnectorDetails(globalState.get("connectorId"))[ + "pm_list" + ]["PmListResponse"]["PmListNull"]; + cy.paymentMethodListTestLessThanEqualToOnePaymentMethod( + data, + globalState + ); + }); + } + ); + + // Testing for scenario: + // MCA1 -> Stripe configured with credit = { country = "US" } + // MCA2 -> Cybersource configured with credit = { country = "US" } + // Payment is done with country as US and currency as USD + // The resultant Payment Method list should have both Stripe and cybersource + context( + ` + MCA1 -> Stripe configured with credit = { country = "US" }\n + MCA2 -> Cybersource configured with credit = { country = "US" }\n + Payment is done with country as US and currency as USD\n + The resultant Payment Method list should have both Stripe and Cybersource\n + `, + () => { + before("seed global state", () => { + cy.task("getGlobalState").then((state) => { + globalState = new State(state); + }); + }); + + after("flush global state", () => { + cy.task("setGlobalState", globalState.data); + }); + + it("merchant-create-call-test", () => { + cy.merchantCreateCallTest(merchantCreateBody, globalState); + }); + + it("api-key-create-call-test", () => { + cy.apiKeyCreateTest(apiKeyCreateBody, globalState); + }); + + // stripe connector create with credit enabled for US + it("connector-create-call-test", () => { + cy.createNamedConnectorCallTest( + createConnectorBody, + card_credit_enabled_in_US, + globalState, + "stripe" + ); + }); + + // cybersource connector create with card credit enabled in US + it("connector-create-call-test", () => { + cy.createNamedConnectorCallTest( + createConnectorBody, + card_credit_enabled_in_US, + globalState, + "cybersource" + ); + }); + + // creating payment with currency as USD and billing address as US + it("create-payment-call-test", () => { + let data = getConnectorDetails("stripe")["pm_list"]["PaymentIntent"]; + let req_data = data["RequestCurrencyUSD"]; + let res_data = data["Response"]; + + cy.createPaymentIntentTest( + create_payment_body_with_currency("USD"), + req_data, + res_data, + "no_three_ds", + "automatic", + globalState + ); + }); + + // payment method list which should only have credit with Stripe and Cybersource + it("payment-method-list-call-test", () => { + let data = getConnectorDetails(globalState.get("connectorId"))[ + "pm_list" + ]["PmListResponse"]["PmListWithCreditTwoConnector"]; + cy.paymentMethodListTestTwoConnectorsForOnePaymentMethodCredit( + data, + globalState + ); + }); + } + ); + + // Testing for scenario: + // MCA1 -> Stripe configured with ideal = { country = "NL", currency = "EUR" } + // MCA2 -> Cybersource configured with ideal = { country = "NL", currency = "EUR" } + // Payment is done with country as US and currency as EUR + // The resultant Payment Method list shouldn't have anything + context( + ` + MCA1 -> Stripe configured with ideal = { country = "NL", currency = "EUR" }\n + MCA2 -> Cybersource configured with ideal = { country = "NL", currency = "EUR" }\n + Payment is done with country as US and currency as EUR\n + The resultant Payment Method list shouldn't have anything\n + `, + () => { + before("seed global state", () => { + cy.task("getGlobalState").then((state) => { + globalState = new State(state); + }); + }); + + after("flush global state", () => { + cy.task("setGlobalState", globalState.data); + }); + + it("merchant-create-call-test", () => { + cy.merchantCreateCallTest(merchantCreateBody, globalState); + }); + + it("api-key-create-call-test", () => { + cy.apiKeyCreateTest(apiKeyCreateBody, globalState); + }); + + // stripe connector create with ideal enabled + it("connector-create-call-test", () => { + cy.createNamedConnectorCallTest( + createConnectorBody, + bank_redirect_ideal_enabled, + globalState, + "stripe" + ); + }); + + // cybersource connector create with ideal enabled + it("connector-create-call-test", () => { + cy.createNamedConnectorCallTest( + createConnectorBody, + bank_redirect_ideal_enabled, + globalState, + "cybersource" + ); + }); + + // creating payment with currency as EUR and billing address as US + it("create-payment-call-test", () => { + let data = getConnectorDetails("stripe")["pm_list"]["PaymentIntent"]; + let req_data = data["RequestCurrencyEUR"]; + let res_data = data["Response"]; + + cy.createPaymentIntentTest( + create_payment_body_with_currency_country("EUR", "US"), + req_data, + res_data, + "no_three_ds", + "automatic", + globalState + ); + }); + + // payment method list which shouldn't have anything + it("payment-method-list-call-test", () => { + let data = getConnectorDetails(globalState.get("connectorId"))[ + "pm_list" + ]["PmListResponse"]["PmListNull"]; + cy.paymentMethodListTestLessThanEqualToOnePaymentMethod( + data, + globalState + ); + }); + } + ); + + // Testing for scenario: + // MCA1 -> Stripe configured with card credit no configs present + // MCA1 -> Cybersource configured with card credit = { currency = "USD" } + // and ideal (default config present as = { country = "NL", currency = "EUR" } ) + // Payment is done with country as IN and currency as USD + // The resultant Payment Method list should have + // Stripe and cybersource both for credit and none for ideal + context( + ` + MCA1 -> Stripe configured with card credit no configs present\n + MCA2 -> Cybersource configured with card credit = { currency = "USD" }\n + and ideal (default config present as = { country = "NL", currency = "EUR" })\n + Payment is done with country as IN and currency as USD\n + The resultant Payment Method list should have\n + Stripe and Cybersource both for credit and none for ideal\n + `, + () => { + before("seed global state", () => { + cy.task("getGlobalState").then((state) => { + globalState = new State(state); + }); + }); + + after("flush global state", () => { + cy.task("setGlobalState", globalState.data); + }); + + it("merchant-create-call-test", () => { + cy.merchantCreateCallTest(merchantCreateBody, globalState); + }); + + it("api-key-create-call-test", () => { + cy.apiKeyCreateTest(apiKeyCreateBody, globalState); + }); + + // stripe connector create with card credit enabled + it("connector-create-call-test", () => { + cy.createNamedConnectorCallTest( + createConnectorBody, + card_credit_enabled, + globalState, + "stripe" + ); + }); + + // cybersource connector create with card credit and ideal enabled + it("connector-create-call-test", () => { + cy.createNamedConnectorCallTest( + createConnectorBody, + bank_redirect_ideal_and_credit_enabled, + globalState, + "cybersource" + ); + }); + + // creating payment with currency as USD and billing address as IN + it("create-payment-call-test", () => { + let data = getConnectorDetails("stripe")["pm_list"]["PaymentIntent"]; + let req_data = data["RequestCurrencyUSD"]; + let res_data = data["Response"]; + + cy.createPaymentIntentTest( + create_payment_body_with_currency_country("USD", "IN"), + req_data, + res_data, + "no_three_ds", + "automatic", + globalState + ); + }); + + // payment method list which should have credit with stripe and cybersource and no ideal + it("payment-method-list-call-test", () => { + let data = getConnectorDetails(globalState.get("connectorId"))[ + "pm_list" + ]["PmListResponse"]["PmListWithCreditTwoConnector"]; + cy.paymentMethodListTestTwoConnectorsForOnePaymentMethodCredit( + data, + globalState + ); + }); + } + ); +}); diff --git a/cypress-tests/cypress/e2e/PaymentMethodListTest/00001-PaymentMethodListMcaWrongCurrency.cy.js b/cypress-tests/cypress/e2e/PaymentMethodListTest/00001-PaymentMethodListMcaWrongCurrency.cy.js deleted file mode 100644 index beb9b0052eb9..000000000000 --- a/cypress-tests/cypress/e2e/PaymentMethodListTest/00001-PaymentMethodListMcaWrongCurrency.cy.js +++ /dev/null @@ -1,83 +0,0 @@ -import apiKeyCreateBody from "../../fixtures/create-api-key-body.json"; -import createConnectorBody from "../../fixtures/create-connector-body.json"; -import getConnectorDetails from "../PaymentMethodListUtils/utils"; -import merchantCreateBody from "../../fixtures/merchant-create-body.json"; -import * as utils from "../PaymentMethodListUtils/utils"; -import { - card_credit_enabled, - card_credit_enabled_in_USD, - bank_redirect_ideal_enabled, - create_payment_body_in_INR, -} from "../PaymentMethodListUtils/Common"; -import State from "../../utils/State"; - -// Testing for scenario: -// MCA1 -> Stripe configured with ideal = { country = "NL", currency = "EUR" } -// MCA2 -> Cybersource configured with credit = { currency = "USD" } -// Payment is done with currency as INR and no billing address -// The resultant Payment Method list shouldn't have any payment method - -let globalState; -describe("Account Create flow test", () => { - before("seed global state", () => { - cy.task("getGlobalState").then((state) => { - globalState = new State(state); - }); - }); - - after("flush global state", () => { - cy.task("setGlobalState", globalState.data); - }); - - it("merchant-create-call-test", () => { - cy.merchantCreateCallTest(merchantCreateBody, globalState); - }); - - it("api-key-create-call-test", () => { - cy.apiKeyCreateTest(apiKeyCreateBody, globalState); - }); - - // stripe connector create with ideal enabled - it("connector-create-call-test", () => { - cy.createNamedConnectorCallTest( - createConnectorBody, - bank_redirect_ideal_enabled, - globalState, - "stripe" - ); - }); - - // cybersource connector create with card credit enabled in USD - it("connector-create-call-test", () => { - cy.createNamedConnectorCallTest( - createConnectorBody, - card_credit_enabled_in_USD, - globalState, - "cybersource" - ); - }); - - // creating payment with currency as INR and no billing address - it("create-payment-call-test", () => { - let data = getConnectorDetails("stripe")["pm_list"]["PaymentIntent"]; - let req_data = data["RequestCurrencyINR"]; - let res_data = data["Response"]; - - cy.createPaymentIntentTest( - create_payment_body_in_INR, - req_data, - res_data, - "no_three_ds", - "automatic", - globalState - ); - }); - - // payment method list which should only have ideal with stripe - it("payment-method-list-call-test", () => { - let data = getConnectorDetails(globalState.get("connectorId"))["pm_list"][ - "PmListResponse" - ]["PmListNull"]; - cy.paymentMethodListTestLessThanEqualToOnePaymentMethod(data, globalState); - }); -}); diff --git a/cypress-tests/cypress/e2e/PaymentMethodListTest/00002-PaymentMethodListMcaCountry.cy.js b/cypress-tests/cypress/e2e/PaymentMethodListTest/00002-PaymentMethodListMcaCountry.cy.js deleted file mode 100644 index eece391296cf..000000000000 --- a/cypress-tests/cypress/e2e/PaymentMethodListTest/00002-PaymentMethodListMcaCountry.cy.js +++ /dev/null @@ -1,86 +0,0 @@ -import apiKeyCreateBody from "../../fixtures/create-api-key-body.json"; -import createConnectorBody from "../../fixtures/create-connector-body.json"; -import getConnectorDetails from "../PaymentMethodListUtils/utils"; -import merchantCreateBody from "../../fixtures/merchant-create-body.json"; -import * as utils from "../PaymentMethodListUtils/utils"; -import { - card_credit_enabled, - card_credit_enabled_in_US, - bank_redirect_ideal_enabled, - create_payment_body_in_USD, -} from "../PaymentMethodListUtils/Common"; -import State from "../../utils/State"; - -// Testing for scenario: -// MCA1 -> Stripe configured with credit = { country = "US" } -// MCA2 -> Cybersource configured with credit = { country = "US" } -// Payment is done with country as US and currency as USD -// The resultant Payment Method list should have both Stripe and cybersource - -let globalState; -describe("Account Create flow test", () => { - before("seed global state", () => { - cy.task("getGlobalState").then((state) => { - globalState = new State(state); - }); - }); - - after("flush global state", () => { - cy.task("setGlobalState", globalState.data); - }); - - it("merchant-create-call-test", () => { - cy.merchantCreateCallTest(merchantCreateBody, globalState); - }); - - it("api-key-create-call-test", () => { - cy.apiKeyCreateTest(apiKeyCreateBody, globalState); - }); - - // stripe connector create with credit enabled for US - it("connector-create-call-test", () => { - cy.createNamedConnectorCallTest( - createConnectorBody, - card_credit_enabled_in_US, - globalState, - "stripe" - ); - }); - - // cybersource connector create with card credit enabled in US - it("connector-create-call-test", () => { - cy.createNamedConnectorCallTest( - createConnectorBody, - card_credit_enabled_in_US, - globalState, - "cybersource" - ); - }); - - // creating payment with currency as USD and billing address as US - it("create-payment-call-test", () => { - let data = getConnectorDetails("stripe")["pm_list"]["PaymentIntent"]; - let req_data = data["RequestCurrencyUSD"]; - let res_data = data["Response"]; - - cy.createPaymentIntentTest( - create_payment_body_in_USD, - req_data, - res_data, - "no_three_ds", - "automatic", - globalState - ); - }); - - // payment method list which should only have credit with Stripe and Cybersource - it("payment-method-list-call-test", () => { - let data = getConnectorDetails(globalState.get("connectorId"))["pm_list"][ - "PmListResponse" - ]["PmListWithCreditTwoConnector"]; - cy.paymentMethodListTestTwoConnectorsForOnePaymentMethodCredit( - data, - globalState - ); - }); -}); diff --git a/cypress-tests/cypress/e2e/PaymentMethodListTest/00003-PaymentMethodListConfigWrongCountry.cy.js b/cypress-tests/cypress/e2e/PaymentMethodListTest/00003-PaymentMethodListConfigWrongCountry.cy.js deleted file mode 100644 index 0fcd15dee102..000000000000 --- a/cypress-tests/cypress/e2e/PaymentMethodListTest/00003-PaymentMethodListConfigWrongCountry.cy.js +++ /dev/null @@ -1,83 +0,0 @@ -import apiKeyCreateBody from "../../fixtures/create-api-key-body.json"; -import createConnectorBody from "../../fixtures/create-connector-body.json"; -import getConnectorDetails from "../PaymentMethodListUtils/utils"; -import merchantCreateBody from "../../fixtures/merchant-create-body.json"; -import * as utils from "../PaymentMethodListUtils/utils"; -import { - card_credit_enabled, - card_credit_enabled_in_US, - bank_redirect_ideal_enabled, - create_payment_body_in_EUR_US, -} from "../PaymentMethodListUtils/Common"; -import State from "../../utils/State"; - -// Testing for scenario: -// MCA1 -> Stripe configured with ideal = { country = "NL", currency = "EUR" } -// MCA2 -> Cybersource configured with ideal = { country = "NL", currency = "EUR" } -// Payment is done with country as US and currency as EUR -// The resultant Payment Method list shouldn't have anything - -let globalState; -describe("Account Create flow test", () => { - before("seed global state", () => { - cy.task("getGlobalState").then((state) => { - globalState = new State(state); - }); - }); - - after("flush global state", () => { - cy.task("setGlobalState", globalState.data); - }); - - it("merchant-create-call-test", () => { - cy.merchantCreateCallTest(merchantCreateBody, globalState); - }); - - it("api-key-create-call-test", () => { - cy.apiKeyCreateTest(apiKeyCreateBody, globalState); - }); - - // stripe connector create with ideal enabled - it("connector-create-call-test", () => { - cy.createNamedConnectorCallTest( - createConnectorBody, - bank_redirect_ideal_enabled, - globalState, - "stripe" - ); - }); - - // cybersource connector create with ideal enabled - it("connector-create-call-test", () => { - cy.createNamedConnectorCallTest( - createConnectorBody, - bank_redirect_ideal_enabled, - globalState, - "cybersource" - ); - }); - - // creating payment with currency as EUR and billing address as US - it("create-payment-call-test", () => { - let data = getConnectorDetails("stripe")["pm_list"]["PaymentIntent"]; - let req_data = data["RequestCurrencyEUR"]; - let res_data = data["Response"]; - - cy.createPaymentIntentTest( - create_payment_body_in_EUR_US, - req_data, - res_data, - "no_three_ds", - "automatic", - globalState - ); - }); - - // payment method list which shouldn't have anything - it("payment-method-list-call-test", () => { - let data = getConnectorDetails(globalState.get("connectorId"))["pm_list"][ - "PmListResponse" - ]["PmListNull"]; - cy.paymentMethodListTestLessThanEqualToOnePaymentMethod(data, globalState); - }); -}); diff --git a/cypress-tests/cypress/e2e/PaymentMethodListTest/00004-PaymentMethodListNoConfigCurrencyCountry.cy.js b/cypress-tests/cypress/e2e/PaymentMethodListTest/00004-PaymentMethodListNoConfigCurrencyCountry.cy.js deleted file mode 100644 index 14bc5cff6597..000000000000 --- a/cypress-tests/cypress/e2e/PaymentMethodListTest/00004-PaymentMethodListNoConfigCurrencyCountry.cy.js +++ /dev/null @@ -1,88 +0,0 @@ -import apiKeyCreateBody from "../../fixtures/create-api-key-body.json"; -import createConnectorBody from "../../fixtures/create-connector-body.json"; -import getConnectorDetails from "../PaymentMethodListUtils/utils"; -import merchantCreateBody from "../../fixtures/merchant-create-body.json"; -import * as utils from "../PaymentMethodListUtils/utils"; -import { - card_credit_enabled, - card_credit_enabled_in_US, - bank_redirect_ideal_and_credit_enabled, - create_payment_body_in_USD_IN, -} from "../PaymentMethodListUtils/Common"; -import State from "../../utils/State"; - -// Testing for scenario: -// MCA1 -> Stripe configured with card credit no configs present -// MCA1 -> Cybersource configured with card credit = { currency = "USD" } -// and ideal (default config present as = { country = "NL", currency = "EUR" } ) -// Payment is done with country as IN and currency as USD -// The resultant Payment Method list should have -// Stripe and cybersource both for credit and none for ideal - -let globalState; -describe("Account Create flow test", () => { - before("seed global state", () => { - cy.task("getGlobalState").then((state) => { - globalState = new State(state); - }); - }); - - after("flush global state", () => { - cy.task("setGlobalState", globalState.data); - }); - - it("merchant-create-call-test", () => { - cy.merchantCreateCallTest(merchantCreateBody, globalState); - }); - - it("api-key-create-call-test", () => { - cy.apiKeyCreateTest(apiKeyCreateBody, globalState); - }); - - // stripe connector create with card credit enabled - it("connector-create-call-test", () => { - cy.createNamedConnectorCallTest( - createConnectorBody, - card_credit_enabled, - globalState, - "stripe" - ); - }); - - // cybersource connector create with card credit and ideal enabled - it("connector-create-call-test", () => { - cy.createNamedConnectorCallTest( - createConnectorBody, - bank_redirect_ideal_and_credit_enabled, - globalState, - "cybersource" - ); - }); - - // creating payment with currency as USD and billing address as IN - it("create-payment-call-test", () => { - let data = getConnectorDetails("stripe")["pm_list"]["PaymentIntent"]; - let req_data = data["RequestCurrencyUSD"]; - let res_data = data["Response"]; - - cy.createPaymentIntentTest( - create_payment_body_in_USD_IN, - req_data, - res_data, - "no_three_ds", - "automatic", - globalState - ); - }); - - // payment method list which should have credit with stripe and cybersource and no ideal - it("payment-method-list-call-test", () => { - let data = getConnectorDetails(globalState.get("connectorId"))["pm_list"][ - "PmListResponse" - ]["PmListWithCreditTwoConnector"]; - cy.paymentMethodListTestTwoConnectorsForOnePaymentMethodCredit( - data, - globalState - ); - }); -}); diff --git a/cypress-tests/cypress/e2e/PaymentMethodListUtils/Common.js b/cypress-tests/cypress/e2e/PaymentMethodListUtils/Common.js deleted file mode 100644 index 01573179e642..000000000000 --- a/cypress-tests/cypress/e2e/PaymentMethodListUtils/Common.js +++ /dev/null @@ -1,391 +0,0 @@ -import State from "../../utils/State"; - -const globalState = new State({ - connectorId: Cypress.env("CONNECTOR"), - baseUrl: Cypress.env("BASEURL"), - adminApiKey: Cypress.env("ADMINAPIKEY"), - connectorAuthFilePath: Cypress.env("CONNECTOR_AUTH_FILE_PATH"), -}); - -export const card_credit_enabled = [ - { - payment_method: "card", - payment_method_types: [ - { - payment_method_type: "credit", - card_networks: ["Visa"], - minimum_amount: 0, - maximum_amount: 68607706, - recurring_enabled: false, - installment_payment_enabled: true, - }, - ], - }, -]; - -export const card_credit_enabled_in_USD = [ - { - payment_method: "card", - payment_method_types: [ - { - payment_method_type: "credit", - card_networks: ["Visa"], - minimum_amount: 0, - accepted_currencies: { - type: "enable_only", - list: ["USD"], - }, - maximum_amount: 68607706, - recurring_enabled: false, - installment_payment_enabled: true, - }, - ], - }, -]; - -export const card_credit_enabled_in_US = [ - { - payment_method: "card", - payment_method_types: [ - { - payment_method_type: "credit", - card_networks: ["Visa"], - minimum_amount: 0, - accepted_countries: { - type: "enable_only", - list: ["US"], - }, - maximum_amount: 68607706, - recurring_enabled: false, - installment_payment_enabled: true, - }, - ], - }, -]; - -export const bank_redirect_ideal_enabled = [ - { - payment_method: "bank_redirect", - payment_method_types: [ - { - payment_method_type: "ideal", - payment_experience: null, - card_networks: null, - accepted_countries: null, - minimum_amount: 0, - maximum_amount: 68607706, - recurring_enabled: true, - installment_payment_enabled: false, - }, - ], - }, -]; - -export const bank_redirect_ideal_and_credit_enabled = [ - { - payment_method: "card", - payment_method_types: [ - { - payment_method_type: "credit", - card_networks: ["Visa"], - minimum_amount: 0, - maximum_amount: 68607706, - recurring_enabled: false, - installment_payment_enabled: true, - }, - ], - }, - { - payment_method: "bank_redirect", - payment_method_types: [ - { - payment_method_type: "ideal", - payment_experience: null, - card_networks: null, - accepted_countries: null, - minimum_amount: 0, - maximum_amount: 68607706, - recurring_enabled: true, - installment_payment_enabled: false, - }, - ], - }, -]; - -export const create_payment_body_in_EUR = { - currency: "EUR", - amount: 6500, - authentication_type: "three_ds", - description: "Joseph First Crypto", - email: "hyperswitch_sdk_demo_id@gmail.com", - setup_future_usage: "", - metadata: { - udf1: "value1", - new_customer: "true", - login_date: "2019-09-10T10:11:12Z", - }, - business_label: "default", -}; - -export const create_payment_body_in_EUR_US = { - currency: "EUR", - amount: 6500, - authentication_type: "three_ds", - description: "Joseph First Crypto", - email: "hyperswitch_sdk_demo_id@gmail.com", - setup_future_usage: "", - metadata: { - udf1: "value1", - new_customer: "true", - login_date: "2019-09-10T10:11:12Z", - }, - business_label: "default", - billing: { - address: { - line1: "1467", - line2: "Harrison Street", - line3: "Harrison Street", - city: "San Fransico", - state: "California", - zip: "94122", - country: "US", - first_name: "joseph", - last_name: "Doe", - }, - phone: { - number: "8056594427", - country_code: "+91", - }, - email: "example@example.com", - }, -}; - -export const create_payment_body_in_USD_IN = { - currency: "USD", - amount: 6500, - authentication_type: "three_ds", - description: "Ramesh First Crypto", - email: "hyperswitch_sdk_demo_id@gmail.com", - setup_future_usage: "", - metadata: { - udf1: "value1", - new_customer: "true", - login_date: "2019-09-10T10:11:12Z", - }, - business_label: "default", - billing: { - address: { - line1: "1946", - line2: "Gandhi Nagar", - line3: "Ramnagar", - city: "Ranchi", - state: "Jharkhand", - zip: "827013", - country: "IN", - first_name: "Ramesh", - last_name: "Kumar", - }, - phone: { - number: "8056594427", - country_code: "+91", - }, - email: "example@example.com", - }, -}; - -export const create_payment_body_in_INR = { - currency: "INR", - amount: 6500, - authentication_type: "three_ds", - description: "Joseph First Crypto", - email: "hyperswitch_sdk_demo_id@gmail.com", - setup_future_usage: "", - metadata: { - udf1: "value1", - new_customer: "true", - login_date: "2019-09-10T10:11:12Z", - }, - business_label: "default", -}; - -export const create_payment_body_in_USD = { - currency: "USD", - amount: 6500, - authentication_type: "three_ds", - description: "Joseph First Crypto", - email: "hyperswitch_sdk_demo_id@gmail.com", - setup_future_usage: "", - metadata: { - udf1: "value1", - new_customer: "true", - login_date: "2019-09-10T10:11:12Z", - }, - business_label: "default", -}; - -/* -`getDefaultExchange` contains the default Request and Response to be considered if none provided. -`getCustomExchange` takes in 2 optional fields named as Request and Response. -with `getCustomExchange`, if 501 response is expected, there is no need to pass Response as it considers default values. -*/ - -// Const to get default PaymentExchange object -const getDefaultExchange = () => ({ - Request: { - currency: "EUR", - }, - Response: { - status: 501, - body: { - error: { - type: "invalid_request", - message: `Selected payment method is not implemented`, - code: "IR_00", - }, - }, - }, -}); - -// Const to get PaymentExchange with overridden properties -export const getCustomExchange = (overrides) => { - const defaultExchange = getDefaultExchange(); - - return { - ...defaultExchange, - Request: { - ...defaultExchange.Request, - ...(overrides.Request || {}), - }, - Response: { - ...defaultExchange.Response, - ...(overrides.Response || {}), - }, - }; -}; - -export const payment_methods_enabled = [ - { - payment_method: "card", - payment_method_types: [ - { - payment_method_type: "credit", - card_networks: [ - "AmericanExpress", - "Discover", - "Interac", - "JCB", - "Mastercard", - "Visa", - "DinersClub", - "UnionPay", - "RuPay", - ], - minimum_amount: 0, - maximum_amount: 68607706, - recurring_enabled: false, - installment_payment_enabled: true, - }, - { - payment_method_type: "debit", - card_networks: [ - "AmericanExpress", - "Discover", - "Interac", - "JCB", - "Mastercard", - "Visa", - "DinersClub", - "UnionPay", - "RuPay", - ], - minimum_amount: 0, - maximum_amount: 68607706, - recurring_enabled: false, - installment_payment_enabled: true, - }, - ], - }, - { - payment_method: "bank_transfer", - payment_method_types: [ - { - payment_method_type: "pix", - minimum_amount: 0, - maximum_amount: 68607706, - recurring_enabled: false, - installment_payment_enabled: true, - }, - ], - }, - { - payment_method: "bank_redirect", - payment_method_types: [ - { - payment_method_type: "ideal", - payment_experience: null, - card_networks: null, - accepted_currencies: null, - accepted_countries: null, - minimum_amount: 1, - maximum_amount: 68607706, - recurring_enabled: true, - installment_payment_enabled: true, - }, - { - payment_method_type: "giropay", - payment_experience: null, - card_networks: null, - accepted_currencies: null, - accepted_countries: null, - minimum_amount: 1, - maximum_amount: 68607706, - recurring_enabled: true, - installment_payment_enabled: true, - }, - { - payment_method_type: "sofort", - payment_experience: null, - card_networks: null, - accepted_currencies: null, - accepted_countries: null, - minimum_amount: 1, - maximum_amount: 68607706, - recurring_enabled: true, - installment_payment_enabled: true, - }, - { - payment_method_type: "eps", - payment_experience: null, - card_networks: null, - accepted_currencies: null, - accepted_countries: null, - minimum_amount: 1, - maximum_amount: 68607706, - recurring_enabled: true, - installment_payment_enabled: true, - }, - { - payment_method_type: "blik", - payment_experience: null, - card_networks: null, - accepted_currencies: null, - accepted_countries: null, - minimum_amount: 1, - maximum_amount: 68607706, - recurring_enabled: true, - installment_payment_enabled: true, - }, - { - payment_method_type: "przelewy24", - payment_experience: null, - card_networks: null, - accepted_currencies: null, - accepted_countries: null, - minimum_amount: 1, - maximum_amount: 68607706, - recurring_enabled: true, - installment_payment_enabled: true, - }, - ], - }, -]; diff --git a/cypress-tests/cypress/e2e/PaymentMethodListUtils/Commons.js b/cypress-tests/cypress/e2e/PaymentMethodListUtils/Commons.js new file mode 100644 index 000000000000..bc2813deec94 --- /dev/null +++ b/cypress-tests/cypress/e2e/PaymentMethodListUtils/Commons.js @@ -0,0 +1,179 @@ +import State from "../../utils/State"; + +const globalState = new State({ + connectorId: Cypress.env("CONNECTOR"), + baseUrl: Cypress.env("BASEURL"), + adminApiKey: Cypress.env("ADMINAPIKEY"), + connectorAuthFilePath: Cypress.env("CONNECTOR_AUTH_FILE_PATH"), +}); + +export const card_credit_enabled = [ + { + payment_method: "card", + payment_method_types: [ + { + payment_method_type: "credit", + card_networks: ["Visa"], + minimum_amount: 0, + maximum_amount: 68607706, + recurring_enabled: false, + installment_payment_enabled: true, + }, + ], + }, +]; + +export const card_credit_enabled_in_USD = [ + { + payment_method: "card", + payment_method_types: [ + { + payment_method_type: "credit", + card_networks: ["Visa"], + minimum_amount: 0, + accepted_currencies: { + type: "enable_only", + list: ["USD"], + }, + maximum_amount: 68607706, + recurring_enabled: false, + installment_payment_enabled: true, + }, + ], + }, +]; + +export const card_credit_enabled_in_US = [ + { + payment_method: "card", + payment_method_types: [ + { + payment_method_type: "credit", + card_networks: ["Visa"], + minimum_amount: 0, + accepted_countries: { + type: "enable_only", + list: ["US"], + }, + maximum_amount: 68607706, + recurring_enabled: false, + installment_payment_enabled: true, + }, + ], + }, +]; + +export const bank_redirect_ideal_enabled = [ + { + payment_method: "bank_redirect", + payment_method_types: [ + { + payment_method_type: "ideal", + payment_experience: null, + card_networks: null, + accepted_countries: null, + minimum_amount: 0, + maximum_amount: 68607706, + recurring_enabled: true, + installment_payment_enabled: false, + }, + ], + }, +]; + +export const bank_redirect_ideal_and_credit_enabled = [ + { + payment_method: "card", + payment_method_types: [ + { + payment_method_type: "credit", + card_networks: ["Visa"], + minimum_amount: 0, + maximum_amount: 68607706, + recurring_enabled: false, + installment_payment_enabled: true, + }, + ], + }, + { + payment_method: "bank_redirect", + payment_method_types: [ + { + payment_method_type: "ideal", + payment_experience: null, + card_networks: null, + accepted_countries: null, + minimum_amount: 0, + maximum_amount: 68607706, + recurring_enabled: true, + installment_payment_enabled: false, + }, + ], + }, +]; + +export const create_payment_body_with_currency_country = ( + currency, + billingCountry +) => ({ + currency: currency, + amount: 6500, + authentication_type: "three_ds", + description: "Joseph First Crypto", + email: "hyperswitch_sdk_demo_id@gmail.com", + setup_future_usage: "", + metadata: { + udf1: "value1", + new_customer: "true", + login_date: "2019-09-10T10:11:12Z", + }, + business_label: "default", + billing: { + address: { + line1: "1946", + line2: "Gandhi Nagar", + line3: "Ramnagar", + city: "Ranchi", + state: "Jharkhand", + zip: "827013", + country: billingCountry, // Billing country from parameter + first_name: "Joseph", + last_name: "Doe", + }, + phone: { + number: "8056594427", + country_code: "+91", + }, + email: "example@example.com", + }, +}); + +export const create_payment_body_with_currency = (currency) => ({ + currency: currency, + amount: 6500, + authentication_type: "three_ds", + description: "Joseph First Crypto", + email: "hyperswitch_sdk_demo_id@gmail.com", + setup_future_usage: "", + metadata: { + udf1: "value1", + new_customer: "true", + login_date: "2019-09-10T10:11:12Z", + }, + business_label: "default", +}); + +export const create_payment_body_in_USD = { + currency: "USD", + amount: 6500, + authentication_type: "three_ds", + description: "Joseph First Crypto", + email: "hyperswitch_sdk_demo_id@gmail.com", + setup_future_usage: "", + metadata: { + udf1: "value1", + new_customer: "true", + login_date: "2019-09-10T10:11:12Z", + }, + business_label: "default", +}; diff --git a/cypress-tests/cypress/e2e/PaymentMethodListUtils/Cybersource.js b/cypress-tests/cypress/e2e/PaymentMethodListUtils/Cybersource.js index 0ed998e74e4b..caeb168fc80d 100644 --- a/cypress-tests/cypress/e2e/PaymentMethodListUtils/Cybersource.js +++ b/cypress-tests/cypress/e2e/PaymentMethodListUtils/Cybersource.js @@ -1,470 +1,470 @@ -const successfulNo3DSCardDetails = { - card_number: "4242424242424242", - card_exp_month: "01", - card_exp_year: "25", - card_holder_name: "joseph Doe", - card_cvc: "123", -}; +// const successfulNo3DSCardDetails = { +// card_number: "4242424242424242", +// card_exp_month: "01", +// card_exp_year: "25", +// card_holder_name: "joseph Doe", +// card_cvc: "123", +// }; -const successfulThreeDSTestCardDetails = { - card_number: "4000000000001091", - card_exp_month: "01", - card_exp_year: "25", - card_holder_name: "joseph Doe", - card_cvc: "123", -}; +// const successfulThreeDSTestCardDetails = { +// card_number: "4000000000001091", +// card_exp_month: "01", +// card_exp_year: "25", +// card_holder_name: "joseph Doe", +// card_cvc: "123", +// }; -const singleUseMandateData = { - customer_acceptance: { - acceptance_type: "offline", - accepted_at: "1963-05-03T04:07:52.723Z", - online: { - ip_address: "125.0.0.1", - user_agent: "amet irure esse", - }, - }, - mandate_type: { - single_use: { - amount: 8000, - currency: "USD", - }, - }, -}; +// const singleUseMandateData = { +// customer_acceptance: { +// acceptance_type: "offline", +// accepted_at: "1963-05-03T04:07:52.723Z", +// online: { +// ip_address: "125.0.0.1", +// user_agent: "amet irure esse", +// }, +// }, +// mandate_type: { +// single_use: { +// amount: 8000, +// currency: "USD", +// }, +// }, +// }; -const multiUseMandateData = { - customer_acceptance: { - acceptance_type: "offline", - accepted_at: "1963-05-03T04:07:52.723Z", - online: { - ip_address: "125.0.0.1", - user_agent: "amet irure esse", - }, - }, - mandate_type: { - multi_use: { - amount: 8000, - currency: "USD", - }, - }, -}; +// const multiUseMandateData = { +// customer_acceptance: { +// acceptance_type: "offline", +// accepted_at: "1963-05-03T04:07:52.723Z", +// online: { +// ip_address: "125.0.0.1", +// user_agent: "amet irure esse", +// }, +// }, +// mandate_type: { +// multi_use: { +// amount: 8000, +// currency: "USD", +// }, +// }, +// }; export const connectorDetails = { - card_pm: { - PaymentIntent: { - Request: { - card: successfulNo3DSCardDetails, - currency: "USD", - customer_acceptance: null, - setup_future_usage: "on_session", - }, - Response: { - status: 200, - body: { - status: "requires_payment_method", - }, - }, - }, - "3DSManualCapture": { - Request: { - card: successfulThreeDSTestCardDetails, - currency: "USD", - customer_acceptance: null, - setup_future_usage: "on_session", - }, - Response: { - status: 200, - body: { - status: "requires_capture", - }, - }, - }, - "3DSAutoCapture": { - Request: { - card: successfulThreeDSTestCardDetails, - currency: "USD", - customer_acceptance: null, - setup_future_usage: "on_session", - }, - Response: { - status: 200, - body: { - status: "succeeded", - }, - }, - }, - No3DSManualCapture: { - Request: { - card: successfulNo3DSCardDetails, - currency: "USD", - customer_acceptance: null, - setup_future_usage: "on_session", - }, - Response: { - status: 200, - body: { - status: "requires_capture", - }, - }, - }, - No3DSAutoCapture: { - Request: { - card: successfulNo3DSCardDetails, - currency: "USD", - customer_acceptance: null, - setup_future_usage: "on_session", - }, - Response: { - status: 200, - body: { - status: "succeeded", - }, - }, - }, - Capture: { - Request: { - card: successfulNo3DSCardDetails, - currency: "USD", - customer_acceptance: null, - }, - Response: { - status: 200, - body: { - status: "succeeded", - amount: 6500, - amount_capturable: 0, - amount_received: 6500, - }, - }, - }, - PartialCapture: { - Request: {}, - Response: { - status: 200, - body: { - status: "partially_captured", - amount: 6500, - amount_capturable: 0, - amount_received: 100, - }, - }, - }, - Void: { - Request: {}, - Response: { - status: 200, - body: { - status: "cancelled", - }, - }, - }, - Refund: { - Request: { - card: successfulNo3DSCardDetails, - currency: "USD", - customer_acceptance: null, - }, - Response: { - status: 200, - body: { - status: "pending", - }, - }, - }, - PartialRefund: { - Request: { - card: successfulNo3DSCardDetails, - currency: "USD", - customer_acceptance: null, - }, - Response: { - status: 200, - body: { - status: "pending", - }, - }, - }, - SyncRefund: { - Request: { - card: successfulNo3DSCardDetails, - currency: "USD", - customer_acceptance: null, - }, - Response: { - status: 200, - body: { - status: "pending", - }, - }, - }, - MandateSingleUse3DSAutoCapture: { - Request: { - payment_method_data: { - card: successfulThreeDSTestCardDetails, - }, - currency: "USD", - mandate_data: singleUseMandateData, - }, - Response: { - status: 200, - body: { - status: "succeeded", - }, - }, - }, - MandateSingleUse3DSManualCapture: { - Request: { - payment_method_data: { - card: successfulThreeDSTestCardDetails, - }, - currency: "USD", - mandate_data: singleUseMandateData, - }, - Response: { - status: 200, - body: { - status: "requires_customer_action", - }, - }, - }, - MandateSingleUseNo3DSAutoCapture: { - Request: { - payment_method_data: { - card: successfulNo3DSCardDetails, - }, - currency: "USD", - mandate_data: singleUseMandateData, - }, - Response: { - status: 200, - body: { - status: "succeeded", - }, - }, - }, - MandateSingleUseNo3DSManualCapture: { - Request: { - payment_method_data: { - card: successfulNo3DSCardDetails, - }, - currency: "USD", - mandate_data: singleUseMandateData, - }, - Response: { - status: 200, - body: { - status: "requires_capture", - }, - }, - }, - MandateMultiUseNo3DSAutoCapture: { - Request: { - payment_method_data: { - card: successfulNo3DSCardDetails, - }, - currency: "USD", - mandate_data: multiUseMandateData, - }, - Response: { - status: 200, - body: { - status: "succeeded", - }, - }, - }, - MandateMultiUseNo3DSManualCapture: { - Request: { - payment_method_data: { - card: successfulNo3DSCardDetails, - }, - currency: "USD", - mandate_data: multiUseMandateData, - }, - Response: { - status: 200, - body: { - status: "requires_capture", - }, - }, - }, - MandateMultiUse3DSAutoCapture: { - Request: { - payment_method_data: { - card: successfulThreeDSTestCardDetails, - }, - currency: "USD", - mandate_data: multiUseMandateData, - }, - Response: { - status: 200, - body: { - status: "requires_capture", - }, - }, - }, - MandateMultiUse3DSManualCapture: { - Request: { - payment_method_data: { - card: successfulThreeDSTestCardDetails, - }, - currency: "USD", - mandate_data: multiUseMandateData, - }, - Response: { - status: 200, - body: { - status: "requires_capture", - }, - }, - }, - ZeroAuthMandate: { - Request: { - payment_method_data: { - card: successfulNo3DSCardDetails, - }, - currency: "USD", - mandate_data: singleUseMandateData - }, - Response: { - status: 200, - body: { - status: "succeeded", - }, - }, - }, - SaveCardUseNo3DSAutoCapture: { - Request: { - card: successfulNo3DSCardDetails, - currency: "USD", - setup_future_usage: "on_session", - customer_acceptance: { - acceptance_type: "offline", - accepted_at: "1963-05-03T04:07:52.723Z", - online: { - ip_address: "127.0.0.1", - user_agent: "amet irure esse", - }, - }, - }, - Response: { - status: 200, - body: { - status: "succeeded", - }, - }, - }, - SaveCardUseNo3DSManualCapture: { - Request: { - card: successfulNo3DSCardDetails, - currency: "USD", - setup_future_usage: "on_session", - customer_acceptance: { - acceptance_type: "offline", - accepted_at: "1963-05-03T04:07:52.723Z", - online: { - ip_address: "127.0.0.1", - user_agent: "amet irure esse", - }, - }, - }, - Response: { - status: 200, - body: { - status: "requires_capture", - }, - }, - }, - PaymentMethodIdMandateNo3DSAutoCapture: { - Request: { - payment_method_data: { - card: successfulNo3DSCardDetails, - }, - currency: "USD", - mandate_data: null, - customer_acceptance: { - acceptance_type: "offline", - accepted_at: "1963-05-03T04:07:52.723Z", - online: { - ip_address: "125.0.0.1", - user_agent: "amet irure esse", - }, - }, - }, - Response: { - status: 200, - body: { - status: "succeeded", - }, - }, - }, - PaymentMethodIdMandateNo3DSManualCapture: { - Request: { - payment_method_data: { - card: successfulNo3DSCardDetails, - }, - currency: "USD", - mandate_data: null, - customer_acceptance: { - acceptance_type: "offline", - accepted_at: "1963-05-03T04:07:52.723Z", - online: { - ip_address: "125.0.0.1", - user_agent: "amet irure esse", - }, - }, - }, - Response: { - status: 200, - body: { - status: "requires_capture", - }, - }, - }, - PaymentMethodIdMandate3DSAutoCapture: { - Request: { - payment_method_data: { - card: successfulThreeDSTestCardDetails, - }, - currency: "USD", - mandate_data: null, - authentication_type: "three_ds", - customer_acceptance: { - acceptance_type: "offline", - accepted_at: "1963-05-03T04:07:52.723Z", - online: { - ip_address: "125.0.0.1", - user_agent: "amet irure esse", - }, - }, - }, - Response: { - status: 200, - body: { - status: "requires_customer_action", - }, - }, - }, - PaymentMethodIdMandate3DSManualCapture: { - Request: { - payment_method_data: { - card: successfulThreeDSTestCardDetails, - }, - mandate_data: null, - authentication_type: "three_ds", - customer_acceptance: { - acceptance_type: "offline", - accepted_at: "1963-05-03T04:07:52.723Z", - online: { - ip_address: "125.0.0.1", - user_agent: "amet irure esse", - }, - }, - }, - Response: { - status: 200, - body: { - status: "requires_customer_action", - }, - }, - }, - }, + // card_pm: { + // PaymentIntent: { + // Request: { + // card: successfulNo3DSCardDetails, + // currency: "USD", + // customer_acceptance: null, + // setup_future_usage: "on_session", + // }, + // Response: { + // status: 200, + // body: { + // status: "requires_payment_method", + // }, + // }, + // }, + // "3DSManualCapture": { + // Request: { + // card: successfulThreeDSTestCardDetails, + // currency: "USD", + // customer_acceptance: null, + // setup_future_usage: "on_session", + // }, + // Response: { + // status: 200, + // body: { + // status: "requires_capture", + // }, + // }, + // }, + // "3DSAutoCapture": { + // Request: { + // card: successfulThreeDSTestCardDetails, + // currency: "USD", + // customer_acceptance: null, + // setup_future_usage: "on_session", + // }, + // Response: { + // status: 200, + // body: { + // status: "succeeded", + // }, + // }, + // }, + // No3DSManualCapture: { + // Request: { + // card: successfulNo3DSCardDetails, + // currency: "USD", + // customer_acceptance: null, + // setup_future_usage: "on_session", + // }, + // Response: { + // status: 200, + // body: { + // status: "requires_capture", + // }, + // }, + // }, + // No3DSAutoCapture: { + // Request: { + // card: successfulNo3DSCardDetails, + // currency: "USD", + // customer_acceptance: null, + // setup_future_usage: "on_session", + // }, + // Response: { + // status: 200, + // body: { + // status: "succeeded", + // }, + // }, + // }, + // Capture: { + // Request: { + // card: successfulNo3DSCardDetails, + // currency: "USD", + // customer_acceptance: null, + // }, + // Response: { + // status: 200, + // body: { + // status: "succeeded", + // amount: 6500, + // amount_capturable: 0, + // amount_received: 6500, + // }, + // }, + // }, + // PartialCapture: { + // Request: {}, + // Response: { + // status: 200, + // body: { + // status: "partially_captured", + // amount: 6500, + // amount_capturable: 0, + // amount_received: 100, + // }, + // }, + // }, + // Void: { + // Request: {}, + // Response: { + // status: 200, + // body: { + // status: "cancelled", + // }, + // }, + // }, + // Refund: { + // Request: { + // card: successfulNo3DSCardDetails, + // currency: "USD", + // customer_acceptance: null, + // }, + // Response: { + // status: 200, + // body: { + // status: "pending", + // }, + // }, + // }, + // PartialRefund: { + // Request: { + // card: successfulNo3DSCardDetails, + // currency: "USD", + // customer_acceptance: null, + // }, + // Response: { + // status: 200, + // body: { + // status: "pending", + // }, + // }, + // }, + // SyncRefund: { + // Request: { + // card: successfulNo3DSCardDetails, + // currency: "USD", + // customer_acceptance: null, + // }, + // Response: { + // status: 200, + // body: { + // status: "pending", + // }, + // }, + // }, + // MandateSingleUse3DSAutoCapture: { + // Request: { + // payment_method_data: { + // card: successfulThreeDSTestCardDetails, + // }, + // currency: "USD", + // mandate_data: singleUseMandateData, + // }, + // Response: { + // status: 200, + // body: { + // status: "succeeded", + // }, + // }, + // }, + // MandateSingleUse3DSManualCapture: { + // Request: { + // payment_method_data: { + // card: successfulThreeDSTestCardDetails, + // }, + // currency: "USD", + // mandate_data: singleUseMandateData, + // }, + // Response: { + // status: 200, + // body: { + // status: "requires_customer_action", + // }, + // }, + // }, + // MandateSingleUseNo3DSAutoCapture: { + // Request: { + // payment_method_data: { + // card: successfulNo3DSCardDetails, + // }, + // currency: "USD", + // mandate_data: singleUseMandateData, + // }, + // Response: { + // status: 200, + // body: { + // status: "succeeded", + // }, + // }, + // }, + // MandateSingleUseNo3DSManualCapture: { + // Request: { + // payment_method_data: { + // card: successfulNo3DSCardDetails, + // }, + // currency: "USD", + // mandate_data: singleUseMandateData, + // }, + // Response: { + // status: 200, + // body: { + // status: "requires_capture", + // }, + // }, + // }, + // MandateMultiUseNo3DSAutoCapture: { + // Request: { + // payment_method_data: { + // card: successfulNo3DSCardDetails, + // }, + // currency: "USD", + // mandate_data: multiUseMandateData, + // }, + // Response: { + // status: 200, + // body: { + // status: "succeeded", + // }, + // }, + // }, + // MandateMultiUseNo3DSManualCapture: { + // Request: { + // payment_method_data: { + // card: successfulNo3DSCardDetails, + // }, + // currency: "USD", + // mandate_data: multiUseMandateData, + // }, + // Response: { + // status: 200, + // body: { + // status: "requires_capture", + // }, + // }, + // }, + // MandateMultiUse3DSAutoCapture: { + // Request: { + // payment_method_data: { + // card: successfulThreeDSTestCardDetails, + // }, + // currency: "USD", + // mandate_data: multiUseMandateData, + // }, + // Response: { + // status: 200, + // body: { + // status: "requires_capture", + // }, + // }, + // }, + // MandateMultiUse3DSManualCapture: { + // Request: { + // payment_method_data: { + // card: successfulThreeDSTestCardDetails, + // }, + // currency: "USD", + // mandate_data: multiUseMandateData, + // }, + // Response: { + // status: 200, + // body: { + // status: "requires_capture", + // }, + // }, + // }, + // ZeroAuthMandate: { + // Request: { + // payment_method_data: { + // card: successfulNo3DSCardDetails, + // }, + // currency: "USD", + // mandate_data: singleUseMandateData, + // }, + // Response: { + // status: 200, + // body: { + // status: "succeeded", + // }, + // }, + // }, + // SaveCardUseNo3DSAutoCapture: { + // Request: { + // card: successfulNo3DSCardDetails, + // currency: "USD", + // setup_future_usage: "on_session", + // customer_acceptance: { + // acceptance_type: "offline", + // accepted_at: "1963-05-03T04:07:52.723Z", + // online: { + // ip_address: "127.0.0.1", + // user_agent: "amet irure esse", + // }, + // }, + // }, + // Response: { + // status: 200, + // body: { + // status: "succeeded", + // }, + // }, + // }, + // SaveCardUseNo3DSManualCapture: { + // Request: { + // card: successfulNo3DSCardDetails, + // currency: "USD", + // setup_future_usage: "on_session", + // customer_acceptance: { + // acceptance_type: "offline", + // accepted_at: "1963-05-03T04:07:52.723Z", + // online: { + // ip_address: "127.0.0.1", + // user_agent: "amet irure esse", + // }, + // }, + // }, + // Response: { + // status: 200, + // body: { + // status: "requires_capture", + // }, + // }, + // }, + // PaymentMethodIdMandateNo3DSAutoCapture: { + // Request: { + // payment_method_data: { + // card: successfulNo3DSCardDetails, + // }, + // currency: "USD", + // mandate_data: null, + // customer_acceptance: { + // acceptance_type: "offline", + // accepted_at: "1963-05-03T04:07:52.723Z", + // online: { + // ip_address: "125.0.0.1", + // user_agent: "amet irure esse", + // }, + // }, + // }, + // Response: { + // status: 200, + // body: { + // status: "succeeded", + // }, + // }, + // }, + // PaymentMethodIdMandateNo3DSManualCapture: { + // Request: { + // payment_method_data: { + // card: successfulNo3DSCardDetails, + // }, + // currency: "USD", + // mandate_data: null, + // customer_acceptance: { + // acceptance_type: "offline", + // accepted_at: "1963-05-03T04:07:52.723Z", + // online: { + // ip_address: "125.0.0.1", + // user_agent: "amet irure esse", + // }, + // }, + // }, + // Response: { + // status: 200, + // body: { + // status: "requires_capture", + // }, + // }, + // }, + // PaymentMethodIdMandate3DSAutoCapture: { + // Request: { + // payment_method_data: { + // card: successfulThreeDSTestCardDetails, + // }, + // currency: "USD", + // mandate_data: null, + // authentication_type: "three_ds", + // customer_acceptance: { + // acceptance_type: "offline", + // accepted_at: "1963-05-03T04:07:52.723Z", + // online: { + // ip_address: "125.0.0.1", + // user_agent: "amet irure esse", + // }, + // }, + // }, + // Response: { + // status: 200, + // body: { + // status: "requires_customer_action", + // }, + // }, + // }, + // PaymentMethodIdMandate3DSManualCapture: { + // Request: { + // payment_method_data: { + // card: successfulThreeDSTestCardDetails, + // }, + // mandate_data: null, + // authentication_type: "three_ds", + // customer_acceptance: { + // acceptance_type: "offline", + // accepted_at: "1963-05-03T04:07:52.723Z", + // online: { + // ip_address: "125.0.0.1", + // user_agent: "amet irure esse", + // }, + // }, + // }, + // Response: { + // status: 200, + // body: { + // status: "requires_customer_action", + // }, + // }, + // }, + // }, }; diff --git a/cypress-tests/cypress/e2e/PaymentMethodListUtils/Stripe.js b/cypress-tests/cypress/e2e/PaymentMethodListUtils/Stripe.js index bf29f6897821..57fe711300a6 100644 --- a/cypress-tests/cypress/e2e/PaymentMethodListUtils/Stripe.js +++ b/cypress-tests/cypress/e2e/PaymentMethodListUtils/Stripe.js @@ -1,8 +1,3 @@ -import { getCustomExchange } from "./Common"; - -const successfulTestCard = "4242424242424242"; -const successful3DSCard = "4000002500003155"; - const successfulNo3DSCardDetails = { card_number: "4242424242424242", card_exp_month: "10", @@ -11,48 +6,6 @@ const successfulNo3DSCardDetails = { card_cvc: "737", }; -const successfulThreeDSTestCardDetails = { - card_number: "4000002500003155", - card_exp_month: "10", - card_exp_year: "25", - card_holder_name: "morino", - card_cvc: "737", -}; - -const singleUseMandateData = { - customer_acceptance: { - acceptance_type: "offline", - accepted_at: "1963-05-03T04:07:52.723Z", - online: { - ip_address: "125.0.0.1", - user_agent: "amet irure esse", - }, - }, - mandate_type: { - single_use: { - amount: 8000, - currency: "USD", - }, - }, -}; - -const multiUseMandateData = { - customer_acceptance: { - acceptance_type: "offline", - accepted_at: "1963-05-03T04:07:52.723Z", - online: { - ip_address: "125.0.0.1", - user_agent: "amet irure esse", - }, - }, - mandate_type: { - multi_use: { - amount: 8000, - currency: "USD", - }, - }, -}; - export const connectorDetails = { pm_list: { PaymentIntent: { @@ -137,618 +90,4 @@ export const connectorDetails = { }, }, }, - - card_pm: { - PaymentIntent: { - Request: { - card: successfulNo3DSCardDetails, - currency: "USD", - customer_acceptance: null, - setup_future_usage: "on_session", - }, - Response: { - status: 200, - body: { - status: "requires_payment_method", - }, - }, - }, - "3DSManualCapture": { - Request: { - card: successfulThreeDSTestCardDetails, - currency: "USD", - customer_acceptance: null, - setup_future_usage: "on_session", - }, - Response: { - status: 200, - body: { - status: "requires_capture", - }, - }, - }, - "3DSAutoCapture": { - Request: { - card: successfulThreeDSTestCardDetails, - currency: "USD", - customer_acceptance: null, - setup_future_usage: "on_session", - }, - Response: { - status: 200, - body: { - status: "succeeded", - }, - }, - }, - No3DSManualCapture: { - Request: { - card: successfulNo3DSCardDetails, - currency: "USD", - customer_acceptance: null, - setup_future_usage: "on_session", - }, - Response: { - status: 200, - body: { - status: "requires_capture", - }, - }, - }, - No3DSAutoCapture: { - Request: { - card: successfulNo3DSCardDetails, - currency: "USD", - customer_acceptance: null, - setup_future_usage: "on_session", - }, - Response: { - status: 200, - body: { - status: "succeeded", - }, - }, - }, - Capture: { - Request: { - card: successfulNo3DSCardDetails, - currency: "USD", - customer_acceptance: null, - }, - Response: { - status: 200, - body: { - status: "succeeded", - amount: 6500, - amount_capturable: 0, - amount_received: 6500, - }, - }, - }, - PartialCapture: { - Request: {}, - Response: { - status: 200, - body: { - status: "partially_captured", - amount: 6500, - amount_capturable: 0, - amount_received: 100, - }, - }, - }, - Void: { - Request: {}, - Response: { - status: 200, - body: { - status: "cancelled", - }, - }, - }, - Refund: { - Request: { - card: successfulNo3DSCardDetails, - currency: "USD", - customer_acceptance: null, - }, - Response: { - status: 200, - body: { - status: "succeeded", - }, - }, - }, - PartialRefund: { - Request: { - card: successfulNo3DSCardDetails, - currency: "USD", - customer_acceptance: null, - }, - Response: { - status: 200, - body: { - status: "succeeded", - }, - }, - }, - SyncRefund: { - Request: { - card: successfulNo3DSCardDetails, - currency: "USD", - customer_acceptance: null, - }, - Response: { - status: 200, - body: { - status: "succeeded", - }, - }, - }, - MandateSingleUse3DSAutoCapture: { - Request: { - payment_method_data: { - card: successfulThreeDSTestCardDetails, - }, - currency: "USD", - mandate_data: singleUseMandateData, - }, - Response: { - status: 200, - body: { - status: "succeeded", - }, - }, - }, - MandateSingleUse3DSManualCapture: { - Request: { - payment_method_data: { - card: successfulThreeDSTestCardDetails, - }, - currency: "USD", - mandate_data: singleUseMandateData, - }, - Response: { - status: 200, - body: { - status: "requires_customer_action", - }, - }, - }, - MandateSingleUseNo3DSAutoCapture: { - Request: { - payment_method_data: { - card: successfulNo3DSCardDetails, - }, - currency: "USD", - mandate_data: singleUseMandateData, - }, - Response: { - status: 200, - body: { - status: "succeeded", - }, - }, - }, - MandateSingleUseNo3DSManualCapture: { - Request: { - payment_method_data: { - card: successfulNo3DSCardDetails, - }, - currency: "USD", - mandate_data: singleUseMandateData, - }, - Response: { - status: 200, - body: { - status: "requires_capture", - }, - }, - }, - MandateMultiUseNo3DSAutoCapture: { - Request: { - payment_method_data: { - card: successfulNo3DSCardDetails, - }, - currency: "USD", - mandate_data: multiUseMandateData, - }, - Response: { - status: 200, - body: { - status: "succeeded", - }, - }, - }, - MandateMultiUseNo3DSManualCapture: { - Request: { - payment_method_data: { - card: successfulNo3DSCardDetails, - }, - currency: "USD", - mandate_data: multiUseMandateData, - }, - Response: { - status: 200, - body: { - status: "requires_capture", - }, - }, - }, - MandateMultiUse3DSAutoCapture: { - Request: { - payment_method_data: { - card: successfulThreeDSTestCardDetails, - }, - currency: "USD", - mandate_data: multiUseMandateData, - }, - Response: { - status: 200, - body: { - status: "requires_capture", - }, - }, - }, - MandateMultiUse3DSManualCapture: { - Request: { - payment_method_data: { - card: successfulThreeDSTestCardDetails, - }, - currency: "USD", - mandate_data: multiUseMandateData, - }, - Response: { - status: 200, - body: { - status: "requires_capture", - }, - }, - }, - ZeroAuthMandate: { - Request: { - payment_method_data: { - card: successfulNo3DSCardDetails, - }, - currency: "USD", - mandate_data: singleUseMandateData, - }, - Response: { - status: 200, - body: { - status: "succeeded", - }, - }, - }, - SaveCardUseNo3DSAutoCapture: { - Request: { - card: successfulNo3DSCardDetails, - currency: "USD", - setup_future_usage: "on_session", - customer_acceptance: { - acceptance_type: "offline", - accepted_at: "1963-05-03T04:07:52.723Z", - online: { - ip_address: "127.0.0.1", - user_agent: "amet irure esse", - }, - }, - }, - Response: { - status: 200, - body: { - status: "succeeded", - }, - }, - }, - SaveCardUseNo3DSManualCapture: { - Request: { - card: successfulNo3DSCardDetails, - currency: "USD", - setup_future_usage: "on_session", - customer_acceptance: { - acceptance_type: "offline", - accepted_at: "1963-05-03T04:07:52.723Z", - online: { - ip_address: "127.0.0.1", - user_agent: "amet irure esse", - }, - }, - }, - Response: { - status: 200, - body: { - status: "requires_capture", - }, - }, - }, - PaymentMethodIdMandateNo3DSAutoCapture: { - Request: { - payment_method_data: { - card: successfulNo3DSCardDetails, - }, - currency: "USD", - mandate_data: null, - customer_acceptance: { - acceptance_type: "offline", - accepted_at: "1963-05-03T04:07:52.723Z", - online: { - ip_address: "125.0.0.1", - user_agent: "amet irure esse", - }, - }, - }, - Response: { - status: 200, - body: { - status: "succeeded", - }, - }, - }, - PaymentMethodIdMandateNo3DSManualCapture: { - Request: { - payment_method_data: { - card: successfulNo3DSCardDetails, - }, - currency: "USD", - mandate_data: null, - customer_acceptance: { - acceptance_type: "offline", - accepted_at: "1963-05-03T04:07:52.723Z", - online: { - ip_address: "125.0.0.1", - user_agent: "amet irure esse", - }, - }, - }, - Response: { - status: 200, - body: { - status: "requires_capture", - }, - }, - }, - PaymentMethodIdMandate3DSAutoCapture: { - Request: { - payment_method_data: { - card: successfulThreeDSTestCardDetails, - }, - currency: "USD", - mandate_data: null, - authentication_type: "three_ds", - customer_acceptance: { - acceptance_type: "offline", - accepted_at: "1963-05-03T04:07:52.723Z", - online: { - ip_address: "125.0.0.1", - user_agent: "amet irure esse", - }, - }, - }, - Response: { - status: 200, - body: { - status: "requires_customer_action", - }, - }, - }, - PaymentMethodIdMandate3DSManualCapture: { - Request: { - payment_method_data: { - card: successfulThreeDSTestCardDetails, - }, - mandate_data: null, - authentication_type: "three_ds", - customer_acceptance: { - acceptance_type: "offline", - accepted_at: "1963-05-03T04:07:52.723Z", - online: { - ip_address: "125.0.0.1", - user_agent: "amet irure esse", - }, - }, - }, - Response: { - status: 200, - body: { - status: "requires_customer_action", - }, - }, - }, - }, - bank_redirect_pm: { - PaymentIntent: getCustomExchange({ - Request: { - currency: "EUR", - }, - Response: { - status: 200, - body: { - status: "requires_payment_method", - }, - }, - }), - ideal: { - Request: { - payment_method: "bank_redirect", - payment_method_type: "ideal", - payment_method_data: { - bank_redirect: { - ideal: { - bank_name: "ing", - }, - }, - }, - billing: { - address: { - line1: "1467", - line2: "Harrison Street", - line3: "Harrison Street", - city: "San Fransico", - state: "California", - zip: "94122", - country: "NL", - first_name: "joseph", - last_name: "Doe", - }, - phone: { - number: "9123456789", - country_code: "+91", - }, - }, - }, - Response: { - status: 200, - body: { - status: "requires_customer_action", - }, - }, - }, - giropay: { - Request: { - payment_method: "bank_redirect", - payment_method_type: "giropay", - payment_method_data: { - bank_redirect: { - giropay: {}, - }, - }, - billing: { - address: { - line1: "1467", - line2: "Harrison Street", - line3: "Harrison Street", - city: "San Fransico", - state: "California", - zip: "94122", - country: "DE", - first_name: "joseph", - last_name: "Doe", - }, - phone: { - number: "9123456789", - country_code: "+91", - }, - }, - }, - Response: { - status: 200, - body: { - status: "requires_customer_action", - }, - }, - }, - sofort: { - Request: { - payment_method: "bank_redirect", - payment_method_type: "sofort", - payment_method_data: { - bank_redirect: { - sofort: {}, - }, - }, - billing: { - address: { - line1: "1467", - line2: "Harrison Street", - line3: "Harrison Street", - city: "San Fransico", - state: "California", - zip: "94122", - country: "DE", - first_name: "joseph", - last_name: "Doe", - }, - phone: { - number: "9123456789", - country_code: "+91", - }, - }, - }, - Response: { - status: 200, - body: { - status: "requires_customer_action", - }, - }, - }, - eps: { - Request: { - payment_method: "bank_redirect", - payment_method_type: "eps", - payment_method_data: { - bank_redirect: { - eps: { - bank_name: "bank_austria", - }, - }, - }, - billing: { - address: { - line1: "1467", - line2: "Harrison Street", - line3: "Harrison Street", - city: "San Fransico", - state: "California", - zip: "94122", - country: "AT", - first_name: "joseph", - last_name: "Doe", - }, - phone: { - number: "9123456789", - country_code: "+91", - }, - }, - }, - Response: { - status: 200, - body: { - status: "requires_customer_action", - }, - }, - }, - blik: { - Request: { - payment_method: "bank_redirect", - payment_method_type: "blik", - payment_method_data: { - bank_redirect: { - blik: { - blik_code: "777987", - }, - }, - }, - }, - Response: { - status: 200, - body: { - status: "failed", - error_code: "payment_intent_invalid_parameter", - }, - }, - }, - przelewy24: { - Request: { - payment_method: "bank_redirect", - payment_method_type: "przelewy24", - payment_method_data: { - bank_redirect: { - przelewy24: { - bank_name: "citi", - billing_details: { - email: "guest@juspay.in", - }, - }, - }, - }, - }, - Response: { - status: 200, - body: { - status: "requires_customer_action", - }, - }, - }, - }, }; diff --git a/cypress-tests/cypress/e2e/PaymentMethodListUtils/utils.js b/cypress-tests/cypress/e2e/PaymentMethodListUtils/utils.js index 7010ff55beac..78d145b97fcc 100644 --- a/cypress-tests/cypress/e2e/PaymentMethodListUtils/utils.js +++ b/cypress-tests/cypress/e2e/PaymentMethodListUtils/utils.js @@ -1,4 +1,4 @@ -import { connectorDetails as CommonConnectorDetails } from "./Common.js"; +import { connectorDetails as CommonConnectorDetails } from "./Commons.js"; import { connectorDetails as cybersourceConnectorDetails } from "./Cybersource.js"; import { connectorDetails as stripeConnectorDetails } from "./Stripe.js"; From 446a52be69c8c076f0f666a59a1424558f30f4ec Mon Sep 17 00:00:00 2001 From: prajjwalkumar17 Date: Sun, 7 Jul 2024 03:35:10 +0530 Subject: [PATCH 12/15] chore: code beautification --- .../e2e/PaymentMethodListUtils/Cybersource.js | 471 +----------------- .../e2e/PaymentMethodListUtils/Stripe.js | 12 +- 2 files changed, 10 insertions(+), 473 deletions(-) diff --git a/cypress-tests/cypress/e2e/PaymentMethodListUtils/Cybersource.js b/cypress-tests/cypress/e2e/PaymentMethodListUtils/Cybersource.js index caeb168fc80d..0c1b8cef331b 100644 --- a/cypress-tests/cypress/e2e/PaymentMethodListUtils/Cybersource.js +++ b/cypress-tests/cypress/e2e/PaymentMethodListUtils/Cybersource.js @@ -1,470 +1 @@ -// const successfulNo3DSCardDetails = { -// card_number: "4242424242424242", -// card_exp_month: "01", -// card_exp_year: "25", -// card_holder_name: "joseph Doe", -// card_cvc: "123", -// }; - -// const successfulThreeDSTestCardDetails = { -// card_number: "4000000000001091", -// card_exp_month: "01", -// card_exp_year: "25", -// card_holder_name: "joseph Doe", -// card_cvc: "123", -// }; - -// const singleUseMandateData = { -// customer_acceptance: { -// acceptance_type: "offline", -// accepted_at: "1963-05-03T04:07:52.723Z", -// online: { -// ip_address: "125.0.0.1", -// user_agent: "amet irure esse", -// }, -// }, -// mandate_type: { -// single_use: { -// amount: 8000, -// currency: "USD", -// }, -// }, -// }; - -// const multiUseMandateData = { -// customer_acceptance: { -// acceptance_type: "offline", -// accepted_at: "1963-05-03T04:07:52.723Z", -// online: { -// ip_address: "125.0.0.1", -// user_agent: "amet irure esse", -// }, -// }, -// mandate_type: { -// multi_use: { -// amount: 8000, -// currency: "USD", -// }, -// }, -// }; - -export const connectorDetails = { - // card_pm: { - // PaymentIntent: { - // Request: { - // card: successfulNo3DSCardDetails, - // currency: "USD", - // customer_acceptance: null, - // setup_future_usage: "on_session", - // }, - // Response: { - // status: 200, - // body: { - // status: "requires_payment_method", - // }, - // }, - // }, - // "3DSManualCapture": { - // Request: { - // card: successfulThreeDSTestCardDetails, - // currency: "USD", - // customer_acceptance: null, - // setup_future_usage: "on_session", - // }, - // Response: { - // status: 200, - // body: { - // status: "requires_capture", - // }, - // }, - // }, - // "3DSAutoCapture": { - // Request: { - // card: successfulThreeDSTestCardDetails, - // currency: "USD", - // customer_acceptance: null, - // setup_future_usage: "on_session", - // }, - // Response: { - // status: 200, - // body: { - // status: "succeeded", - // }, - // }, - // }, - // No3DSManualCapture: { - // Request: { - // card: successfulNo3DSCardDetails, - // currency: "USD", - // customer_acceptance: null, - // setup_future_usage: "on_session", - // }, - // Response: { - // status: 200, - // body: { - // status: "requires_capture", - // }, - // }, - // }, - // No3DSAutoCapture: { - // Request: { - // card: successfulNo3DSCardDetails, - // currency: "USD", - // customer_acceptance: null, - // setup_future_usage: "on_session", - // }, - // Response: { - // status: 200, - // body: { - // status: "succeeded", - // }, - // }, - // }, - // Capture: { - // Request: { - // card: successfulNo3DSCardDetails, - // currency: "USD", - // customer_acceptance: null, - // }, - // Response: { - // status: 200, - // body: { - // status: "succeeded", - // amount: 6500, - // amount_capturable: 0, - // amount_received: 6500, - // }, - // }, - // }, - // PartialCapture: { - // Request: {}, - // Response: { - // status: 200, - // body: { - // status: "partially_captured", - // amount: 6500, - // amount_capturable: 0, - // amount_received: 100, - // }, - // }, - // }, - // Void: { - // Request: {}, - // Response: { - // status: 200, - // body: { - // status: "cancelled", - // }, - // }, - // }, - // Refund: { - // Request: { - // card: successfulNo3DSCardDetails, - // currency: "USD", - // customer_acceptance: null, - // }, - // Response: { - // status: 200, - // body: { - // status: "pending", - // }, - // }, - // }, - // PartialRefund: { - // Request: { - // card: successfulNo3DSCardDetails, - // currency: "USD", - // customer_acceptance: null, - // }, - // Response: { - // status: 200, - // body: { - // status: "pending", - // }, - // }, - // }, - // SyncRefund: { - // Request: { - // card: successfulNo3DSCardDetails, - // currency: "USD", - // customer_acceptance: null, - // }, - // Response: { - // status: 200, - // body: { - // status: "pending", - // }, - // }, - // }, - // MandateSingleUse3DSAutoCapture: { - // Request: { - // payment_method_data: { - // card: successfulThreeDSTestCardDetails, - // }, - // currency: "USD", - // mandate_data: singleUseMandateData, - // }, - // Response: { - // status: 200, - // body: { - // status: "succeeded", - // }, - // }, - // }, - // MandateSingleUse3DSManualCapture: { - // Request: { - // payment_method_data: { - // card: successfulThreeDSTestCardDetails, - // }, - // currency: "USD", - // mandate_data: singleUseMandateData, - // }, - // Response: { - // status: 200, - // body: { - // status: "requires_customer_action", - // }, - // }, - // }, - // MandateSingleUseNo3DSAutoCapture: { - // Request: { - // payment_method_data: { - // card: successfulNo3DSCardDetails, - // }, - // currency: "USD", - // mandate_data: singleUseMandateData, - // }, - // Response: { - // status: 200, - // body: { - // status: "succeeded", - // }, - // }, - // }, - // MandateSingleUseNo3DSManualCapture: { - // Request: { - // payment_method_data: { - // card: successfulNo3DSCardDetails, - // }, - // currency: "USD", - // mandate_data: singleUseMandateData, - // }, - // Response: { - // status: 200, - // body: { - // status: "requires_capture", - // }, - // }, - // }, - // MandateMultiUseNo3DSAutoCapture: { - // Request: { - // payment_method_data: { - // card: successfulNo3DSCardDetails, - // }, - // currency: "USD", - // mandate_data: multiUseMandateData, - // }, - // Response: { - // status: 200, - // body: { - // status: "succeeded", - // }, - // }, - // }, - // MandateMultiUseNo3DSManualCapture: { - // Request: { - // payment_method_data: { - // card: successfulNo3DSCardDetails, - // }, - // currency: "USD", - // mandate_data: multiUseMandateData, - // }, - // Response: { - // status: 200, - // body: { - // status: "requires_capture", - // }, - // }, - // }, - // MandateMultiUse3DSAutoCapture: { - // Request: { - // payment_method_data: { - // card: successfulThreeDSTestCardDetails, - // }, - // currency: "USD", - // mandate_data: multiUseMandateData, - // }, - // Response: { - // status: 200, - // body: { - // status: "requires_capture", - // }, - // }, - // }, - // MandateMultiUse3DSManualCapture: { - // Request: { - // payment_method_data: { - // card: successfulThreeDSTestCardDetails, - // }, - // currency: "USD", - // mandate_data: multiUseMandateData, - // }, - // Response: { - // status: 200, - // body: { - // status: "requires_capture", - // }, - // }, - // }, - // ZeroAuthMandate: { - // Request: { - // payment_method_data: { - // card: successfulNo3DSCardDetails, - // }, - // currency: "USD", - // mandate_data: singleUseMandateData, - // }, - // Response: { - // status: 200, - // body: { - // status: "succeeded", - // }, - // }, - // }, - // SaveCardUseNo3DSAutoCapture: { - // Request: { - // card: successfulNo3DSCardDetails, - // currency: "USD", - // setup_future_usage: "on_session", - // customer_acceptance: { - // acceptance_type: "offline", - // accepted_at: "1963-05-03T04:07:52.723Z", - // online: { - // ip_address: "127.0.0.1", - // user_agent: "amet irure esse", - // }, - // }, - // }, - // Response: { - // status: 200, - // body: { - // status: "succeeded", - // }, - // }, - // }, - // SaveCardUseNo3DSManualCapture: { - // Request: { - // card: successfulNo3DSCardDetails, - // currency: "USD", - // setup_future_usage: "on_session", - // customer_acceptance: { - // acceptance_type: "offline", - // accepted_at: "1963-05-03T04:07:52.723Z", - // online: { - // ip_address: "127.0.0.1", - // user_agent: "amet irure esse", - // }, - // }, - // }, - // Response: { - // status: 200, - // body: { - // status: "requires_capture", - // }, - // }, - // }, - // PaymentMethodIdMandateNo3DSAutoCapture: { - // Request: { - // payment_method_data: { - // card: successfulNo3DSCardDetails, - // }, - // currency: "USD", - // mandate_data: null, - // customer_acceptance: { - // acceptance_type: "offline", - // accepted_at: "1963-05-03T04:07:52.723Z", - // online: { - // ip_address: "125.0.0.1", - // user_agent: "amet irure esse", - // }, - // }, - // }, - // Response: { - // status: 200, - // body: { - // status: "succeeded", - // }, - // }, - // }, - // PaymentMethodIdMandateNo3DSManualCapture: { - // Request: { - // payment_method_data: { - // card: successfulNo3DSCardDetails, - // }, - // currency: "USD", - // mandate_data: null, - // customer_acceptance: { - // acceptance_type: "offline", - // accepted_at: "1963-05-03T04:07:52.723Z", - // online: { - // ip_address: "125.0.0.1", - // user_agent: "amet irure esse", - // }, - // }, - // }, - // Response: { - // status: 200, - // body: { - // status: "requires_capture", - // }, - // }, - // }, - // PaymentMethodIdMandate3DSAutoCapture: { - // Request: { - // payment_method_data: { - // card: successfulThreeDSTestCardDetails, - // }, - // currency: "USD", - // mandate_data: null, - // authentication_type: "three_ds", - // customer_acceptance: { - // acceptance_type: "offline", - // accepted_at: "1963-05-03T04:07:52.723Z", - // online: { - // ip_address: "125.0.0.1", - // user_agent: "amet irure esse", - // }, - // }, - // }, - // Response: { - // status: 200, - // body: { - // status: "requires_customer_action", - // }, - // }, - // }, - // PaymentMethodIdMandate3DSManualCapture: { - // Request: { - // payment_method_data: { - // card: successfulThreeDSTestCardDetails, - // }, - // mandate_data: null, - // authentication_type: "three_ds", - // customer_acceptance: { - // acceptance_type: "offline", - // accepted_at: "1963-05-03T04:07:52.723Z", - // online: { - // ip_address: "125.0.0.1", - // user_agent: "amet irure esse", - // }, - // }, - // }, - // Response: { - // status: 200, - // body: { - // status: "requires_customer_action", - // }, - // }, - // }, - // }, -}; +export const connectorDetails = {}; diff --git a/cypress-tests/cypress/e2e/PaymentMethodListUtils/Stripe.js b/cypress-tests/cypress/e2e/PaymentMethodListUtils/Stripe.js index 57fe711300a6..758b76687f40 100644 --- a/cypress-tests/cypress/e2e/PaymentMethodListUtils/Stripe.js +++ b/cypress-tests/cypress/e2e/PaymentMethodListUtils/Stripe.js @@ -10,21 +10,27 @@ export const connectorDetails = { pm_list: { PaymentIntent: { RequestCurrencyUSD: { - card: successfulNo3DSCardDetails, + payment_method_data: { + card: successfulNo3DSCardDetails, + }, currency: "USD", customer_acceptance: null, setup_future_usage: "off_session", authentication_type: "no_three_ds", }, RequestCurrencyEUR: { - card: successfulNo3DSCardDetails, + payment_method_data: { + card: successfulNo3DSCardDetails, + }, currency: "EUR", customer_acceptance: null, setup_future_usage: "off_session", authentication_type: "no_three_ds", }, RequestCurrencyINR: { - card: successfulNo3DSCardDetails, + payment_method_data: { + card: successfulNo3DSCardDetails, + }, currency: "INR", customer_acceptance: null, setup_future_usage: "off_session", From bb4d712133813e436afb0f2913a85e5699ac517f Mon Sep 17 00:00:00 2001 From: prajjwalkumar17 Date: Sun, 7 Jul 2024 03:42:17 +0530 Subject: [PATCH 13/15] chore: comments addressal --- cypress-tests/cypress/e2e/PaymentMethodListUtils/Cybersource.js | 1 - cypress-tests/cypress/e2e/PaymentMethodListUtils/utils.js | 2 -- cypress-tests/package.json | 2 +- 3 files changed, 1 insertion(+), 4 deletions(-) delete mode 100644 cypress-tests/cypress/e2e/PaymentMethodListUtils/Cybersource.js diff --git a/cypress-tests/cypress/e2e/PaymentMethodListUtils/Cybersource.js b/cypress-tests/cypress/e2e/PaymentMethodListUtils/Cybersource.js deleted file mode 100644 index 0c1b8cef331b..000000000000 --- a/cypress-tests/cypress/e2e/PaymentMethodListUtils/Cybersource.js +++ /dev/null @@ -1 +0,0 @@ -export const connectorDetails = {}; diff --git a/cypress-tests/cypress/e2e/PaymentMethodListUtils/utils.js b/cypress-tests/cypress/e2e/PaymentMethodListUtils/utils.js index 78d145b97fcc..9a1d35583c42 100644 --- a/cypress-tests/cypress/e2e/PaymentMethodListUtils/utils.js +++ b/cypress-tests/cypress/e2e/PaymentMethodListUtils/utils.js @@ -1,10 +1,8 @@ import { connectorDetails as CommonConnectorDetails } from "./Commons.js"; -import { connectorDetails as cybersourceConnectorDetails } from "./Cybersource.js"; import { connectorDetails as stripeConnectorDetails } from "./Stripe.js"; const connectorDetails = { commons: CommonConnectorDetails, - cybersource: cybersourceConnectorDetails, stripe: stripeConnectorDetails, }; diff --git a/cypress-tests/package.json b/cypress-tests/package.json index 59d188bac8ef..b2693e9d1ff1 100644 --- a/cypress-tests/package.json +++ b/cypress-tests/package.json @@ -14,7 +14,7 @@ "author": "", "license": "ISC", "devDependencies": { - "cypress": "^13.12.0", + "cypress": "^13.10.0", "jsqr": "^1.4.0" }, "dependencies": { From 172520cd767f6e7819175312fd3e5ebc8974d91c Mon Sep 17 00:00:00 2001 From: prajjwalkumar17 Date: Mon, 8 Jul 2024 10:07:42 +0530 Subject: [PATCH 14/15] chore: naming conventions --- .../PaymentMethodListTest/00000-PaymentMethodListTests.cy.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cypress-tests/cypress/e2e/PaymentMethodListTest/00000-PaymentMethodListTests.cy.js b/cypress-tests/cypress/e2e/PaymentMethodListTest/00000-PaymentMethodListTests.cy.js index f4a9ec942ab7..3728377409b5 100644 --- a/cypress-tests/cypress/e2e/PaymentMethodListTest/00000-PaymentMethodListTests.cy.js +++ b/cypress-tests/cypress/e2e/PaymentMethodListTest/00000-PaymentMethodListTests.cy.js @@ -2,7 +2,7 @@ import apiKeyCreateBody from "../../fixtures/create-api-key-body.json"; import createConnectorBody from "../../fixtures/create-connector-body.json"; import getConnectorDetails from "../PaymentMethodListUtils/utils"; import merchantCreateBody from "../../fixtures/merchant-create-body.json"; -import * as utils from "../PaymentMethodListUtils/utils"; +import * as utils from "../PaymentMethodListUtils/Utils"; import { card_credit_enabled, card_credit_enabled_in_US, From 5cf436c2ded9e3378a50dc5742ee5e598630bd96 Mon Sep 17 00:00:00 2001 From: Prajjwal Kumar Date: Mon, 8 Jul 2024 10:09:33 +0530 Subject: [PATCH 15/15] chore: naming conventions --- .../cypress/e2e/PaymentMethodListUtils/{utils.js => Utils.js} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename cypress-tests/cypress/e2e/PaymentMethodListUtils/{utils.js => Utils.js} (100%) diff --git a/cypress-tests/cypress/e2e/PaymentMethodListUtils/utils.js b/cypress-tests/cypress/e2e/PaymentMethodListUtils/Utils.js similarity index 100% rename from cypress-tests/cypress/e2e/PaymentMethodListUtils/utils.js rename to cypress-tests/cypress/e2e/PaymentMethodListUtils/Utils.js