fix(list): remove enabled payment methods from list customer payment … (#689)

This commit is contained in:
Nishant Joshi
2023-02-28 18:29:08 +05:30
committed by GitHub
parent d0c9dded8b
commit 5c29f37ab2
2 changed files with 3 additions and 46 deletions

View File

@ -1,5 +1,3 @@
use std::collections::HashSet;
use common_utils::pii; use common_utils::pii;
use serde::de; use serde::de;
use utoipa::ToSchema; use utoipa::ToSchema;
@ -443,21 +441,6 @@ impl serde::Serialize for ListPaymentMethod {
#[derive(Debug, serde::Serialize, ToSchema)] #[derive(Debug, serde::Serialize, ToSchema)]
pub struct ListCustomerPaymentMethodsResponse { pub struct ListCustomerPaymentMethodsResponse {
/// List of enabled payment methods for a customer
#[schema(value_type = Vec<ListPaymentMethod>,example = json!(
[
{
"payment_method": "wallet",
"payment_experience": null,
"payment_method_issuers": [
"labore magna ipsum",
"aute"
]
}
]
))]
pub enabled_payment_methods: HashSet<ListPaymentMethod>,
/// List of payment methods for customer /// List of payment methods for customer
pub customer_payment_methods: Vec<CustomerPaymentMethod>, pub customer_payment_methods: Vec<CustomerPaymentMethod>,
} }

View File

@ -1039,31 +1039,6 @@ pub async fn list_customer_payment_method(
customer_id: &str, customer_id: &str,
) -> errors::RouterResponse<api::ListCustomerPaymentMethodsResponse> { ) -> errors::RouterResponse<api::ListCustomerPaymentMethodsResponse> {
let db = &*state.store; let db = &*state.store;
let all_mcas = db
.find_merchant_connector_account_by_merchant_id_and_disabled_list(
&merchant_account.merchant_id,
false,
)
.await
.map_err(|error| {
error.to_not_found_response(errors::ApiErrorResponse::MerchantAccountNotFound)
})?;
let mut enabled_methods: HashSet<api::ListPaymentMethod> = HashSet::new();
for mca in all_mcas {
let payment_methods = match mca.payment_methods_enabled {
Some(pm) => pm,
None => continue,
};
for payment_method in payment_methods.into_iter() {
if let Ok(payment_method_object) =
serde_json::from_value::<api::ListPaymentMethod>(payment_method)
{
enabled_methods.insert(payment_method_object);
}
}
}
let resp = db let resp = db
.find_payment_method_by_customer_id_merchant_id_list( .find_payment_method_by_customer_id_merchant_id_list(
@ -1080,7 +1055,7 @@ pub async fn list_customer_payment_method(
errors::ApiErrorResponse::PaymentMethodNotFound errors::ApiErrorResponse::PaymentMethodNotFound
)); ));
} }
let mut vec = Vec::new(); let mut customer_pms = Vec::new();
for pm in resp.into_iter() { for pm in resp.into_iter() {
let payment_token = generate_id(consts::ID_LENGTH, "token"); let payment_token = generate_id(consts::ID_LENGTH, "token");
let card = if pm.payment_method == enums::PaymentMethod::Card { let card = if pm.payment_method == enums::PaymentMethod::Card {
@ -1109,12 +1084,11 @@ pub async fn list_customer_payment_method(
payment_experience: Some(vec![api_models::enums::PaymentExperience::RedirectToUrl]), payment_experience: Some(vec![api_models::enums::PaymentExperience::RedirectToUrl]),
created: Some(pm.created_at), created: Some(pm.created_at),
}; };
vec.push(pma); customer_pms.push(pma);
} }
let response = api::ListCustomerPaymentMethodsResponse { let response = api::ListCustomerPaymentMethodsResponse {
enabled_payment_methods: enabled_methods, customer_payment_methods: customer_pms,
customer_payment_methods: vec,
}; };
Ok(services::ApplicationResponse::Json(response)) Ok(services::ApplicationResponse::Json(response))