feat(router): add mandates list api (#1143)

This commit is contained in:
Sai Harsha Vardhan
2023-05-17 21:31:13 +05:30
committed by GitHub
parent bd8868efd0
commit 75ba3ff09f
8 changed files with 198 additions and 1 deletions

View File

@ -1,5 +1,6 @@
use common_utils::{ext_traits::Encode, pii};
use error_stack::{report, ResultExt};
use futures::future;
use router_env::{instrument, logger, tracing};
use storage_models::enums as storage_enums;
@ -259,6 +260,25 @@ where
Ok(resp)
}
#[instrument(skip(state))]
pub async fn retrieve_mandates_list(
state: &AppState,
merchant_account: storage::MerchantAccount,
constraints: api_models::mandates::MandateListConstraints,
) -> RouterResponse<Vec<api_models::mandates::MandateResponse>> {
let mandates = state
.store
.find_mandates_by_merchant_id(&merchant_account.merchant_id, constraints)
.await
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("Unable to retrieve mandates")?;
let mandates_list = future::try_join_all(mandates.into_iter().map(|mandate| {
mandates::MandateResponse::from_db_mandate(state, mandate, &merchant_account)
}))
.await?;
Ok(services::ApplicationResponse::Json(mandates_list))
}
impl ForeignTryFrom<Result<types::PaymentsResponseData, types::ErrorResponse>>
for Option<pii::SecretSerdeValue>
{