mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-11-02 12:06:56 +08:00
refactor(core): Refactor customer payment method list for v2 (#4856)
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
This commit is contained in:
@ -229,6 +229,11 @@ pub async fn list_payment_method_api(
|
||||
))
|
||||
.await
|
||||
}
|
||||
|
||||
#[cfg(all(
|
||||
any(feature = "v2", feature = "v1"),
|
||||
not(feature = "payment_methods_v2")
|
||||
))]
|
||||
/// List payment methods for a Customer
|
||||
///
|
||||
/// To filter and list the applicable payment methods for a particular Customer ID
|
||||
@ -287,6 +292,134 @@ pub async fn list_customer_payment_method_api(
|
||||
))
|
||||
.await
|
||||
}
|
||||
|
||||
#[cfg(all(feature = "v2", feature = "payment_methods_v2"))]
|
||||
/// List payment methods for a Customer v2
|
||||
///
|
||||
/// To filter and list the applicable payment methods for a particular Customer ID, is to be associated with a payment
|
||||
#[utoipa::path(
|
||||
get,
|
||||
path = "v2/payments/{payment_id}/saved_payment_methods",
|
||||
params (
|
||||
("client-secret" = String, Path, description = "A secret known only to your application and the authorization server"),
|
||||
("accepted_country" = Vec<String>, Query, description = "The two-letter ISO currency code"),
|
||||
("accepted_currency" = Vec<Currency>, Path, description = "The three-letter ISO currency code"),
|
||||
("minimum_amount" = i64, Query, description = "The minimum amount accepted for processing by the particular payment method."),
|
||||
("maximum_amount" = i64, Query, description = "The maximum amount amount accepted for processing by the particular payment method."),
|
||||
("recurring_payment_enabled" = bool, Query, description = "Indicates whether the payment method is eligible for recurring payments"),
|
||||
("installment_payment_enabled" = bool, Query, description = "Indicates whether the payment method is eligible for installment payments"),
|
||||
),
|
||||
responses(
|
||||
(status = 200, description = "Payment Methods retrieved for customer tied to its respective client-secret passed in the param", body = CustomerPaymentMethodsListResponse),
|
||||
(status = 400, description = "Invalid Data"),
|
||||
(status = 404, description = "Payment Methods does not exist in records")
|
||||
),
|
||||
tag = "Payment Methods",
|
||||
operation_id = "List all Payment Methods for a Customer",
|
||||
security(("publishable_key" = []))
|
||||
)]
|
||||
#[instrument(skip_all, fields(flow = ?Flow::CustomerPaymentMethodsList))]
|
||||
pub async fn list_customer_payment_method_for_payment(
|
||||
state: web::Data<AppState>,
|
||||
payment_id: web::Path<(String,)>,
|
||||
req: HttpRequest,
|
||||
query_payload: web::Query<payment_methods::PaymentMethodListRequest>,
|
||||
) -> HttpResponse {
|
||||
let flow = Flow::CustomerPaymentMethodsList;
|
||||
let payload = query_payload.into_inner();
|
||||
let _payment_id = payment_id.into_inner().0.clone();
|
||||
|
||||
let (auth, _) = match auth::check_client_secret_and_get_auth(req.headers(), &payload) {
|
||||
Ok((auth, _auth_flow)) => (auth, _auth_flow),
|
||||
Err(e) => return api::log_and_return_error_response(e),
|
||||
};
|
||||
|
||||
Box::pin(api::server_wrap(
|
||||
flow,
|
||||
state,
|
||||
&req,
|
||||
payload,
|
||||
|state, auth, req, _| {
|
||||
cards::list_customer_payment_method_util(
|
||||
state,
|
||||
auth.merchant_account,
|
||||
auth.key_store,
|
||||
Some(req),
|
||||
None,
|
||||
true,
|
||||
)
|
||||
},
|
||||
&*auth,
|
||||
api_locking::LockAction::NotApplicable,
|
||||
))
|
||||
.await
|
||||
}
|
||||
|
||||
#[cfg(all(feature = "v2", feature = "payment_methods_v2"))]
|
||||
/// List payment methods for a Customer v2
|
||||
///
|
||||
/// To filter and list the applicable payment methods for a particular Customer ID, to be used in a non-payments context
|
||||
#[utoipa::path(
|
||||
get,
|
||||
path = "v2/customers/{customer_id}/saved_payment_methods",
|
||||
params (
|
||||
("accepted_country" = Vec<String>, Query, description = "The two-letter ISO currency code"),
|
||||
("accepted_currency" = Vec<Currency>, Path, description = "The three-letter ISO currency code"),
|
||||
("minimum_amount" = i64, Query, description = "The minimum amount accepted for processing by the particular payment method."),
|
||||
("maximum_amount" = i64, Query, description = "The maximum amount amount accepted for processing by the particular payment method."),
|
||||
("recurring_payment_enabled" = bool, Query, description = "Indicates whether the payment method is eligible for recurring payments"),
|
||||
("installment_payment_enabled" = bool, Query, description = "Indicates whether the payment method is eligible for installment payments"),
|
||||
),
|
||||
responses(
|
||||
(status = 200, description = "Payment Methods retrieved", body = CustomerPaymentMethodsListResponse),
|
||||
(status = 400, description = "Invalid Data"),
|
||||
(status = 404, description = "Payment Methods does not exist in records")
|
||||
),
|
||||
tag = "Payment Methods",
|
||||
operation_id = "List all Payment Methods for a Customer",
|
||||
security(("api_key" = []))
|
||||
)]
|
||||
#[instrument(skip_all, fields(flow = ?Flow::CustomerPaymentMethodsList))]
|
||||
pub async fn list_customer_payment_method_api(
|
||||
state: web::Data<AppState>,
|
||||
customer_id: web::Path<(id_type::CustomerId,)>,
|
||||
req: HttpRequest,
|
||||
query_payload: web::Query<payment_methods::PaymentMethodListRequest>,
|
||||
) -> HttpResponse {
|
||||
let flow = Flow::CustomerPaymentMethodsList;
|
||||
let payload = query_payload.into_inner();
|
||||
let customer_id = customer_id.into_inner().0.clone();
|
||||
|
||||
let ephemeral_or_api_auth = match auth::is_ephemeral_auth(req.headers()) {
|
||||
Ok(auth) => auth,
|
||||
Err(err) => return api::log_and_return_error_response(err),
|
||||
};
|
||||
|
||||
Box::pin(api::server_wrap(
|
||||
flow,
|
||||
state,
|
||||
&req,
|
||||
payload,
|
||||
|state, auth, req, _| {
|
||||
cards::list_customer_payment_method_util(
|
||||
state,
|
||||
auth.merchant_account,
|
||||
auth.key_store,
|
||||
Some(req),
|
||||
Some(customer_id.clone()),
|
||||
false,
|
||||
)
|
||||
},
|
||||
&*ephemeral_or_api_auth,
|
||||
api_locking::LockAction::NotApplicable,
|
||||
))
|
||||
.await
|
||||
}
|
||||
|
||||
#[cfg(all(
|
||||
any(feature = "v2", feature = "v1"),
|
||||
not(feature = "payment_methods_v2")
|
||||
))]
|
||||
/// List payment methods for a Customer
|
||||
///
|
||||
/// To filter and list the applicable payment methods for a particular Customer ID
|
||||
|
||||
Reference in New Issue
Block a user