Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(merchant_account): add merchant account retrieve v2 route #5092

Open
wants to merge 2 commits into
base: merchant_account_create_v2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion crates/openapi/src/openapi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,11 @@ struct SecurityAddon;
#[cfg(feature = "v2")]
#[derive(utoipa::OpenApi)]
#[openapi(
paths(routes::merchant_account::merchant_account_create_v2),
paths(
// Routes for MerchantAccount
routes::merchant_account::merchant_account_create_v2,
routes::merchant_account::retrieve_merchant_account_v2
),
components(schemas(
api_models::admin::MerchantAccountCreateV2,
api_models::admin::MerchantAccountResponseV2,
Expand Down
18 changes: 18 additions & 0 deletions crates/openapi/src/routes/merchant_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,24 @@ pub async fn merchant_account_create_v2() {}
)]
pub async fn retrieve_merchant_account() {}

#[cfg(feature = "v2")]
/// Merchant Account - Retrieve
///
/// Retrieve a *merchant* account details.
#[utoipa::path(
get,
path = "/v2/accounts/{id}",
params (("id" = String, Path, description = "The unique identifier for the merchant account")),
responses(
(status = 200, description = "Merchant Account Retrieved", body = MerchantAccountResponseV2),
(status = 404, description = "Merchant account not found")
),
tag = "Merchant Account",
operation_id = "Retrieve a Merchant Account",
security(("admin_api_key" = []))
)]
pub async fn retrieve_merchant_account_v2() {}

/// Merchant Account - Update
///
/// Updates details of an existing merchant account. Helpful in updating merchant details such as email, contact details, or other configuration details like webhook, routing algorithm etc
Expand Down
14 changes: 10 additions & 4 deletions crates/router/src/core/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ pub async fn insert_merchant_configs(
Ok(())
}

#[cfg(feature = "v2")]
type MerchantAccountResponse = api::MerchantAccountResponseV2;

#[cfg(not(feature = "v2"))]
type MerchantAccountResponse = api::MerchantAccountResponse;

pub async fn create_merchant_account(
state: SessionState,
req: api::MerchantAccountCreate,
Expand Down Expand Up @@ -294,7 +300,7 @@ pub async fn create_merchant_account(
pub async fn create_merchant_account_v2(
state: SessionState,
req: api::MerchantAccountCreateV2,
) -> RouterResponse<api::MerchantAccountResponseV2> {
) -> RouterResponse<MerchantAccountResponse> {
let publishable_key = create_merchant_publishable_key();

let merchant_details: OptionalSecretValue = req
Expand Down Expand Up @@ -406,7 +412,7 @@ pub async fn create_merchant_account_v2(
insert_merchant_configs(db, &merchant_account.merchant_id).await?;

Ok(service_api::ApplicationResponse::Json(
api::MerchantAccountResponseV2::foreign_try_from(merchant_account)
MerchantAccountResponse::foreign_try_from(merchant_account)
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("Failed while generating response")?,
))
Expand Down Expand Up @@ -440,7 +446,7 @@ pub async fn list_merchant_account(
pub async fn get_merchant_account(
state: SessionState,
req: api::MerchantId,
) -> RouterResponse<api::MerchantAccountResponse> {
) -> RouterResponse<MerchantAccountResponse> {
let db = state.store.as_ref();
let key_store = db
.get_merchant_key_store_by_merchant_id(
Expand All @@ -456,7 +462,7 @@ pub async fn get_merchant_account(
.to_not_found_response(errors::ApiErrorResponse::MerchantAccountNotFound)?;

Ok(service_api::ApplicationResponse::Json(
api::MerchantAccountResponse::foreign_try_from(merchant_account)
MerchantAccountResponse::foreign_try_from(merchant_account)
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("Failed to construct response")?,
))
Expand Down
78 changes: 33 additions & 45 deletions crates/router/src/routes/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,6 @@ use crate::{
types::api::admin,
};

/// Merchant Account - Create
///
/// Create a new account for a merchant and the merchant could be a seller or retailer or client who likes to receive and send payments.
#[utoipa::path(
post,
path = "/accounts",
request_body= MerchantAccountCreate,
responses(
(status = 200, description = "Merchant Account Created", body = MerchantAccountResponse),
(status = 400, description = "Invalid data")
),
tag = "Merchant Account",
operation_id = "Create a Merchant Account",
security(("admin_api_key" = []))
)]
#[instrument(skip_all, fields(flow = ?Flow::MerchantsAccountCreate))]
pub async fn merchant_account_create(
state: web::Data<AppState>,
Expand All @@ -43,21 +28,6 @@ pub async fn merchant_account_create(
}

#[cfg(feature = "v2")]
/// Merchant Account - Create
///
/// Create a new account for a merchant and the merchant could be a seller or retailer or client who likes to receive and send payments.
#[utoipa::path(
post,
path = "/v2/accounts",
request_body= MerchantAccountCreateV2,
responses(
(status = 200, description = "Merchant Account Created", body = MerchantAccountResponseV2),
(status = 400, description = "Invalid data")
),
tag = "Merchant Account",
operation_id = "Create a Merchant Account",
security(("admin_api_key" = []))
)]
#[instrument(skip_all, fields(flow = ?Flow::MerchantAccountCreateV2))]
pub async fn merchant_account_create_v2(
state: web::Data<AppState>,
Expand All @@ -77,21 +47,6 @@ pub async fn merchant_account_create_v2(
.await
}

/// Merchant Account - Retrieve
///
/// Retrieve a merchant account details.
#[utoipa::path(
get,
path = "/accounts/{account_id}",
params (("account_id" = String, Path, description = "The unique identifier for the merchant account")),
responses(
(status = 200, description = "Merchant Account Retrieved", body = MerchantAccountResponse),
(status = 404, description = "Merchant account not found")
),
tag = "Merchant Account",
operation_id = "Retrieve a Merchant Account",
security(("admin_api_key" = []))
)]
#[instrument(skip_all, fields(flow = ?Flow::MerchantsAccountRetrieve))]
pub async fn retrieve_merchant_account(
state: web::Data<AppState>,
Expand Down Expand Up @@ -124,6 +79,39 @@ pub async fn retrieve_merchant_account(
.await
}

#[cfg(feature = "v2")]
#[instrument(skip_all, fields(flow = ?Flow::MerchantAccountRetrieveV2))]
pub async fn retrieve_merchant_account_v2(
state: web::Data<AppState>,
req: HttpRequest,
mid: web::Path<String>,
) -> HttpResponse {
let flow = Flow::MerchantAccountRetrieveV2;
let merchant_id = mid.into_inner();
let payload = web::Json(admin::MerchantId {
merchant_id: merchant_id.to_owned(),
})
.into_inner();

api::server_wrap(
flow,
state,
&req,
payload,
|state, _, req, _| get_merchant_account(state, req),
auth::auth_type(
&auth::AdminApiAuth,
&auth::JWTAuthMerchantFromRoute {
merchant_id,
required_permission: Permission::MerchantAccountRead,
},
req.headers(),
),
api_locking::LockAction::NotApplicable,
)
.await
}

#[cfg(feature = "olap")]
#[instrument(skip_all, fields(flow = ?Flow::MerchantAccountList))]
pub async fn merchant_account_list(
Expand Down
1 change: 1 addition & 0 deletions crates/router/src/routes/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -988,6 +988,7 @@ impl MerchantAccountV2 {
web::scope("/v2/accounts")
.app_data(web::Data::new(state))
.service(web::resource("").route(web::post().to(merchant_account_create_v2)))
.service(web::resource("/{id}").route(web::get().to(retrieve_merchant_account_v2)))
}
}

Expand Down
4 changes: 3 additions & 1 deletion crates/router/src/routes/lock_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ impl From<Flow> for ApiIdentifier {
| Flow::MerchantAccountList => Self::MerchantAccount,

#[cfg(feature = "v2")]
Flow::MerchantAccountCreateV2 => Self::MerchantAccount,
Flow::MerchantAccountCreateV2 | Flow::MerchantAccountRetrieveV2 => {
Self::MerchantAccount
}

Flow::RoutingCreateConfig
| Flow::RoutingLinkConfig
Expand Down
3 changes: 3 additions & 0 deletions crates/router_env/src/logger/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ pub enum Flow {
MerchantAccountCreateV2,
/// Merchants account retrieve flow.
MerchantsAccountRetrieve,
/// Merchant account retrieve flow for v2
#[cfg(feature = "v2")]
MerchantAccountRetrieveV2,
/// Merchants account update flow.
MerchantsAccountUpdate,
/// Merchants account delete flow.
Expand Down
Loading