Skip to content

Commit

Permalink
added route to enable platform account
Browse files Browse the repository at this point in the history
  • Loading branch information
racnan committed Dec 17, 2024
1 parent 01deb60 commit 00a063f
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 1 deletion.
32 changes: 32 additions & 0 deletions crates/router/src/core/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4766,3 +4766,35 @@ async fn locker_recipient_create_call(

Ok(store_resp.card_reference)
}

pub async fn enable_platform_account(
state: SessionState,
merchant_id: id_type::MerchantId,
) -> RouterResponse<()> {
let db = state.store.as_ref();
let key_manager_state = &(&state).into();
let key_store = db
.get_merchant_key_store_by_merchant_id(
key_manager_state,
&merchant_id,
&db.get_master_key().to_vec().into(),
)
.await
.to_not_found_response(errors::ApiErrorResponse::MerchantAccountNotFound)?;

let merchant_account = db
.find_merchant_account_by_merchant_id(key_manager_state, &merchant_id, &key_store)
.await
.to_not_found_response(errors::ApiErrorResponse::MerchantAccountNotFound)?;

db.update_merchant(
key_manager_state,
merchant_account,
storage::MerchantAccountUpdate::ToPlatformAccount,
&key_store,
)
.await
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("Error while enabling platform merchant account")
.map(|_| services::ApplicationResponse::StatusOk)
}
23 changes: 23 additions & 0 deletions crates/router/src/routes/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -910,3 +910,26 @@ pub async fn merchant_account_transfer_keys(
))
.await
}

/// Merchant Account - Platform Account
///
/// Enable platform account
#[instrument(skip_all)]
pub async fn merchant_account_enable_platform_account(
state: web::Data<AppState>,
req: HttpRequest,
path: web::Path<common_utils::id_type::MerchantId>,
) -> HttpResponse {
let flow = Flow::EnablePlatformAccount;
let merchant_id = path.into_inner();
Box::pin(api::server_wrap(
flow,
state,
&req,
merchant_id,
|state, _, req, _| enable_platform_account(state, req),
&auth::AdminApiAuth,
api_locking::LockAction::NotApplicable,
))
.await
}
1 change: 1 addition & 0 deletions crates/router/src/routes/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1324,6 +1324,7 @@ impl MerchantAccount {
.route(web::post().to(admin::merchant_account_toggle_kv))
.route(web::get().to(admin::merchant_account_kv_status)),
)
.service(web::resource("/{id}/platform").route(web::post().to(admin::merchant_account_enable_platform_account)))
.service(
web::resource("/transfer")
.route(web::post().to(admin::merchant_account_transfer_keys)),
Expand Down
3 changes: 2 additions & 1 deletion crates/router/src/routes/lock_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ impl From<Flow> for ApiIdentifier {
| Flow::MerchantsAccountUpdate
| Flow::MerchantsAccountDelete
| Flow::MerchantTransferKey
| Flow::MerchantAccountList => Self::MerchantAccount,
| Flow::MerchantAccountList
| Flow::EnablePlatformAccount=> Self::MerchantAccount,

Flow::OrganizationCreate | Flow::OrganizationRetrieve | Flow::OrganizationUpdate => {
Self::Organization
Expand Down
2 changes: 2 additions & 0 deletions crates/router_env/src/logger/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ pub enum Flow {
ConfigKeyCreate,
/// ConfigKey fetch flow.
ConfigKeyFetch,
/// Enable platform account flow.
EnablePlatformAccount,
/// ConfigKey Update flow.
ConfigKeyUpdate,
/// ConfigKey Delete flow.
Expand Down

0 comments on commit 00a063f

Please sign in to comment.