mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-27 19:46:48 +08:00
fix(list): remove enabled payment methods from list customer payment … (#689)
This commit is contained in:
@ -1,5 +1,3 @@
|
||||
use std::collections::HashSet;
|
||||
|
||||
use common_utils::pii;
|
||||
use serde::de;
|
||||
use utoipa::ToSchema;
|
||||
@ -443,21 +441,6 @@ impl serde::Serialize for ListPaymentMethod {
|
||||
|
||||
#[derive(Debug, serde::Serialize, ToSchema)]
|
||||
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
|
||||
pub customer_payment_methods: Vec<CustomerPaymentMethod>,
|
||||
}
|
||||
|
||||
@ -1039,31 +1039,6 @@ pub async fn list_customer_payment_method(
|
||||
customer_id: &str,
|
||||
) -> errors::RouterResponse<api::ListCustomerPaymentMethodsResponse> {
|
||||
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
|
||||
.find_payment_method_by_customer_id_merchant_id_list(
|
||||
@ -1080,7 +1055,7 @@ pub async fn list_customer_payment_method(
|
||||
errors::ApiErrorResponse::PaymentMethodNotFound
|
||||
));
|
||||
}
|
||||
let mut vec = Vec::new();
|
||||
let mut customer_pms = Vec::new();
|
||||
for pm in resp.into_iter() {
|
||||
let payment_token = generate_id(consts::ID_LENGTH, "token");
|
||||
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]),
|
||||
created: Some(pm.created_at),
|
||||
};
|
||||
vec.push(pma);
|
||||
customer_pms.push(pma);
|
||||
}
|
||||
|
||||
let response = api::ListCustomerPaymentMethodsResponse {
|
||||
enabled_payment_methods: enabled_methods,
|
||||
customer_payment_methods: vec,
|
||||
customer_payment_methods: customer_pms,
|
||||
};
|
||||
|
||||
Ok(services::ApplicationResponse::Json(response))
|
||||
|
||||
Reference in New Issue
Block a user