Skip to content

Commit

Permalink
fix(cards): Return a 200 response indicating that a customer is none (#…
Browse files Browse the repository at this point in the history
…3773)

Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
  • Loading branch information
1 parent 54fa309 commit 2c95dcd
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 10 deletions.
2 changes: 2 additions & 0 deletions crates/api_models/src/payment_methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,8 @@ impl serde::Serialize for PaymentMethodList {
pub struct CustomerPaymentMethodsListResponse {
/// List of payment methods for customer
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)]
Expand Down
31 changes: 21 additions & 10 deletions crates/router/src/core/payment_methods/cards.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2569,18 +2569,28 @@ pub async fn do_list_customer_pm_fetch_customer_if_not_passed(
)
.await?;

let customer_id = payment_intent
match payment_intent
.as_ref()
.and_then(|intent| intent.customer_id.to_owned())
.ok_or(errors::ApiErrorResponse::CustomerNotFound)?;
Box::pin(list_customer_payment_method(
&state,
merchant_account,
key_store,
payment_intent,
&customer_id,
))
.await
{
Some(customer_id) => {
Box::pin(list_customer_payment_method(
&state,
merchant_account,
key_store,
payment_intent,
&customer_id,
))
.await
}
None => {
let response = api::CustomerPaymentMethodsListResponse {
customer_payment_methods: Vec::new(),
is_guest_customer: Some(true),
};
Ok(services::ApplicationResponse::Json(response))
}
}
}
}

Expand Down Expand Up @@ -2776,6 +2786,7 @@ pub async fn list_customer_payment_method(

let mut response = api::CustomerPaymentMethodsListResponse {
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
.as_ref()
Expand Down
5 changes: 5 additions & 0 deletions openapi/openapi_spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -7510,6 +7510,11 @@
"$ref": "#/components/schemas/CustomerPaymentMethod"
},
"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
}
}
},
Expand Down

0 comments on commit 2c95dcd

Please sign in to comment.