mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-11-03 13:30:39 +08:00
feat(payment_methods_v2): add total-payment-method-count api (#7479)
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
This commit is contained in:
@ -1308,6 +1308,20 @@ pub async fn list_saved_payment_methods_for_customer(
|
||||
))
|
||||
}
|
||||
|
||||
#[cfg(all(feature = "v2", feature = "olap"))]
|
||||
#[instrument(skip_all)]
|
||||
pub async fn get_total_saved_payment_methods_for_merchant(
|
||||
state: SessionState,
|
||||
merchant_account: domain::MerchantAccount,
|
||||
) -> RouterResponse<api::TotalPaymentMethodCountResponse> {
|
||||
let total_payment_method_count =
|
||||
get_total_payment_method_count_core(&state, &merchant_account).await?;
|
||||
|
||||
Ok(hyperswitch_domain_models::api::ApplicationResponse::Json(
|
||||
total_payment_method_count,
|
||||
))
|
||||
}
|
||||
|
||||
#[cfg(feature = "v2")]
|
||||
/// Container for the inputs required for the required fields
|
||||
struct RequiredFieldsInput {
|
||||
@ -1778,6 +1792,27 @@ pub async fn list_customer_payment_method_core(
|
||||
Ok(response)
|
||||
}
|
||||
|
||||
#[cfg(all(feature = "v2", feature = "olap"))]
|
||||
pub async fn get_total_payment_method_count_core(
|
||||
state: &SessionState,
|
||||
merchant_account: &domain::MerchantAccount,
|
||||
) -> RouterResult<api::TotalPaymentMethodCountResponse> {
|
||||
let db = &*state.store;
|
||||
|
||||
let total_count = db
|
||||
.get_payment_method_count_by_merchant_id_status(
|
||||
merchant_account.get_id(),
|
||||
common_enums::PaymentMethodStatus::Active,
|
||||
)
|
||||
.await
|
||||
.change_context(errors::ApiErrorResponse::InternalServerError)
|
||||
.attach_printable("Unable to get total payment method count")?;
|
||||
|
||||
let response = api::TotalPaymentMethodCountResponse { total_count };
|
||||
|
||||
Ok(response)
|
||||
}
|
||||
|
||||
#[cfg(all(feature = "v2", feature = "payment_methods_v2"))]
|
||||
#[instrument(skip_all)]
|
||||
pub async fn retrieve_payment_method(
|
||||
|
||||
@ -2176,6 +2176,16 @@ impl PaymentMethodInterface for KafkaStore {
|
||||
.await
|
||||
}
|
||||
|
||||
async fn get_payment_method_count_by_merchant_id_status(
|
||||
&self,
|
||||
merchant_id: &id_type::MerchantId,
|
||||
status: common_enums::PaymentMethodStatus,
|
||||
) -> CustomResult<i64, errors::DataStorageError> {
|
||||
self.diesel_store
|
||||
.get_payment_method_count_by_merchant_id_status(merchant_id, status)
|
||||
.await
|
||||
}
|
||||
|
||||
#[cfg(all(
|
||||
any(feature = "v1", feature = "v2"),
|
||||
not(feature = "payment_methods_v2")
|
||||
|
||||
@ -1039,6 +1039,10 @@ impl Customers {
|
||||
{
|
||||
route = route
|
||||
.service(web::resource("/list").route(web::get().to(customers::customers_list)))
|
||||
.service(
|
||||
web::resource("/total-payment-methods")
|
||||
.route(web::get().to(payment_methods::get_total_payment_method_count)),
|
||||
)
|
||||
}
|
||||
#[cfg(all(feature = "oltp", feature = "v2", feature = "customer_v2"))]
|
||||
{
|
||||
|
||||
@ -118,7 +118,8 @@ impl From<Flow> for ApiIdentifier {
|
||||
| Flow::ValidatePaymentMethod
|
||||
| Flow::ListCountriesCurrencies
|
||||
| Flow::DefaultPaymentMethodsSet
|
||||
| Flow::PaymentMethodSave => Self::PaymentMethods,
|
||||
| Flow::PaymentMethodSave
|
||||
| Flow::TotalPaymentMethodCount => Self::PaymentMethods,
|
||||
|
||||
Flow::PmAuthLinkTokenCreate | Flow::PmAuthExchangeToken => Self::PaymentMethodAuth,
|
||||
|
||||
|
||||
@ -624,6 +624,37 @@ pub async fn list_customer_payment_method_api(
|
||||
.await
|
||||
}
|
||||
|
||||
#[cfg(all(feature = "v2", feature = "olap"))]
|
||||
#[instrument(skip_all, fields(flow = ?Flow::TotalPaymentMethodCount))]
|
||||
pub async fn get_total_payment_method_count(
|
||||
state: web::Data<AppState>,
|
||||
req: HttpRequest,
|
||||
) -> HttpResponse {
|
||||
let flow = Flow::TotalPaymentMethodCount;
|
||||
|
||||
Box::pin(api::server_wrap(
|
||||
flow,
|
||||
state,
|
||||
&req,
|
||||
(),
|
||||
|state, auth: auth::AuthenticationData, _, _| {
|
||||
payment_methods_routes::get_total_saved_payment_methods_for_merchant(
|
||||
state,
|
||||
auth.merchant_account,
|
||||
)
|
||||
},
|
||||
auth::auth_type(
|
||||
&auth::V2ApiKeyAuth,
|
||||
&auth::JWTAuth {
|
||||
permission: Permission::MerchantCustomerRead,
|
||||
},
|
||||
req.headers(),
|
||||
),
|
||||
api_locking::LockAction::NotApplicable,
|
||||
))
|
||||
.await
|
||||
}
|
||||
|
||||
#[cfg(all(any(feature = "v1", feature = "v2"), not(feature = "customer_v2")))]
|
||||
/// Generate a form link for collecting payment methods for a customer
|
||||
#[instrument(skip_all, fields(flow = ?Flow::PaymentMethodCollectLink))]
|
||||
|
||||
@ -11,7 +11,7 @@ pub use api_models::payment_methods::{
|
||||
PaymentMethodMigrateResponse, PaymentMethodResponse, PaymentMethodResponseData,
|
||||
PaymentMethodUpdate, PaymentMethodUpdateData, PaymentMethodsData, TokenizePayloadEncrypted,
|
||||
TokenizePayloadRequest, TokenizedCardValue1, TokenizedCardValue2, TokenizedWalletValue1,
|
||||
TokenizedWalletValue2,
|
||||
TokenizedWalletValue2, TotalPaymentMethodCountResponse,
|
||||
};
|
||||
#[cfg(all(
|
||||
any(feature = "v2", feature = "v1"),
|
||||
|
||||
Reference in New Issue
Block a user