fix(cards): Return a 200 response indicating that a customer is none (#3773)

Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
This commit is contained in:
Vrishab Srivatsa
2024-02-23 14:57:32 +05:30
committed by GitHub
parent 54fa309b7d
commit 2c95dcd197
3 changed files with 28 additions and 10 deletions

View File

@ -717,6 +717,8 @@ impl serde::Serialize for PaymentMethodList {
pub struct CustomerPaymentMethodsListResponse { pub struct CustomerPaymentMethodsListResponse {
/// List of payment methods for customer /// List of payment methods for customer
pub customer_payment_methods: Vec<CustomerPaymentMethod>, pub customer_payment_methods: Vec<CustomerPaymentMethod>,
/// Returns whether a customer id is not tied to a payment intent (only when the request is made against a client secret)
pub is_guest_customer: Option<bool>,
} }
#[derive(Debug, serde::Serialize, ToSchema)] #[derive(Debug, serde::Serialize, ToSchema)]

View File

@ -2569,18 +2569,28 @@ pub async fn do_list_customer_pm_fetch_customer_if_not_passed(
) )
.await?; .await?;
let customer_id = payment_intent match payment_intent
.as_ref() .as_ref()
.and_then(|intent| intent.customer_id.to_owned()) .and_then(|intent| intent.customer_id.to_owned())
.ok_or(errors::ApiErrorResponse::CustomerNotFound)?; {
Box::pin(list_customer_payment_method( Some(customer_id) => {
&state, Box::pin(list_customer_payment_method(
merchant_account, &state,
key_store, merchant_account,
payment_intent, key_store,
&customer_id, payment_intent,
)) &customer_id,
.await ))
.await
}
None => {
let response = api::CustomerPaymentMethodsListResponse {
customer_payment_methods: Vec::new(),
is_guest_customer: Some(true),
};
Ok(services::ApplicationResponse::Json(response))
}
}
} }
} }
@ -2776,6 +2786,7 @@ pub async fn list_customer_payment_method(
let mut response = api::CustomerPaymentMethodsListResponse { let mut response = api::CustomerPaymentMethodsListResponse {
customer_payment_methods: customer_pms, customer_payment_methods: customer_pms,
is_guest_customer: payment_intent.as_ref().map(|_| false), //to return this key only when the request is tied to a payment intent
}; };
let payment_attempt = payment_intent let payment_attempt = payment_intent
.as_ref() .as_ref()

View File

@ -7510,6 +7510,11 @@
"$ref": "#/components/schemas/CustomerPaymentMethod" "$ref": "#/components/schemas/CustomerPaymentMethod"
}, },
"description": "List of payment methods for customer" "description": "List of payment methods for customer"
},
"is_guest_customer": {
"type": "boolean",
"description": "Returns whether a customer id is not tied to a payment intent (only when the request is made against a client secret)",
"nullable": true
} }
} }
}, },