Skip to content

Commit

Permalink
feat: add apis in routes
Browse files Browse the repository at this point in the history
  • Loading branch information
ThisIsMani committed Dec 4, 2023
1 parent 2b4672b commit 9fb490b
Show file tree
Hide file tree
Showing 17 changed files with 118 additions and 34 deletions.
1 change: 1 addition & 0 deletions crates/api_models/src/events.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub mod connector_onboarding;
pub mod customer;
pub mod gsm;
mod locker_migration;
Expand Down
12 changes: 12 additions & 0 deletions crates/api_models/src/events/connector_onboarding.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
use common_utils::events::{ApiEventMetric, ApiEventsType};

use crate::connector_onboarding::{
ActionUrlRequest, ActionUrlResponse, OnboardingStatus, OnboardingSyncRequest,
};

common_utils::impl_misc_api_event_type!(
ActionUrlRequest,
ActionUrlResponse,
OnboardingSyncRequest,
OnboardingStatus
);
2 changes: 1 addition & 1 deletion crates/api_models/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ pub mod api_keys;
pub mod bank_accounts;
pub mod cards_info;
pub mod conditional_configs;
pub mod connector_onboarding;
pub mod currency;
pub mod customers;
pub mod disputes;
Expand All @@ -30,4 +31,3 @@ pub mod user_role;
pub mod verifications;
pub mod verify_connector;
pub mod webhooks;
pub mod connector_onboarding;
4 changes: 2 additions & 2 deletions crates/router/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ pub mod cache;
pub mod cards_info;
pub mod conditional_config;
pub mod configs;
#[cfg(feature = "olap")]
pub mod connector_onboarding;
#[cfg(any(feature = "olap", feature = "oltp"))]
pub mod currency;
pub mod customers;
Expand Down Expand Up @@ -33,5 +35,3 @@ pub mod verification;
#[cfg(feature = "olap")]
pub mod verify_connector;
pub mod webhooks;
#[cfg(feature = "olap")]
pub mod connector_onboarding;
10 changes: 6 additions & 4 deletions crates/router/src/core/connector_onboarding.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
use api_models::{connector_onboarding as api, enums};
use error_stack::ResultExt;
use masking::Secret;

use crate::{
core::errors::{ApiErrorResponse, RouterResponse, RouterResult},
services::{authentication as auth, ApplicationResponse},
types::{self as oss_types},
utils::connector_onboarding as utils,
AppState,
};
use crate::{utils::connector_onboarding as utils, AppState};
use api_models::{connector_onboarding as api, enums};
use error_stack::ResultExt;
use masking::Secret;

pub mod paypal;

Expand Down
13 changes: 7 additions & 6 deletions crates/router/src/core/connector_onboarding/paypal.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
use crate::{
core::errors::{ApiErrorResponse, RouterResult},
services::{send_request, ApplicationResponse, Request},
types::{self as oss_types, api as oss_api_types},
};
use api_models::{admin::MerchantConnectorUpdate, connector_onboarding as api};
use common_utils::ext_traits::Encode;
use error_stack::{IntoReport, ResultExt};
use masking::{ExposeInterface, PeekInterface, Secret};

use crate::{
core::admin, types::api::connector_onboarding as types, utils::connector_onboarding as utils,
core::{
admin,
errors::{ApiErrorResponse, RouterResult},
},
services::{send_request, ApplicationResponse, Request},
types::{self as oss_types, api as oss_api_types, api::connector_onboarding as types},
utils::connector_onboarding as utils,
AppState,
};

Expand Down
1 change: 1 addition & 0 deletions crates/router/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ pub fn mk_app(
.service(routes::Gsm::server(state.clone()))
.service(routes::PaymentLink::server(state.clone()))
.service(routes::User::server(state.clone()))
.service(routes::ConnectorOnboarding::server(state.clone()))
}

#[cfg(all(feature = "olap", feature = "kms"))]
Expand Down
8 changes: 5 additions & 3 deletions crates/router/src/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ pub mod app;
pub mod cache;
pub mod cards_info;
pub mod configs;
#[cfg(feature = "olap")]
pub mod connector_onboarding;
#[cfg(any(feature = "olap", feature = "oltp"))]
pub mod currency;
pub mod customers;
Expand Down Expand Up @@ -47,9 +49,9 @@ pub use self::app::Routing;
#[cfg(all(feature = "olap", feature = "kms"))]
pub use self::app::Verify;
pub use self::app::{
ApiKeys, AppState, BusinessProfile, Cache, Cards, Configs, Customers, Disputes, EphemeralKey,
Files, Gsm, Health, LockerMigrate, Mandates, MerchantAccount, MerchantConnectorAccount,
PaymentLink, PaymentMethods, Payments, Refunds, User, Webhooks,
ApiKeys, AppState, BusinessProfile, Cache, Cards, Configs, ConnectorOnboarding, Customers,
Disputes, EphemeralKey, Files, Gsm, Health, LockerMigrate, Mandates, MerchantAccount,
MerchantConnectorAccount, PaymentLink, PaymentMethods, Payments, Refunds, User, Webhooks,
};
#[cfg(feature = "stripe")]
pub use super::compatibility::stripe::StripeApis;
Expand Down
16 changes: 14 additions & 2 deletions crates/router/src/routes/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ use super::routing as cloud_routing;
use super::verification::{apple_pay_merchant_registration, retrieve_apple_pay_verified_domains};
#[cfg(feature = "olap")]
use super::{
admin::*, api_keys::*, disputes::*, files::*, gsm::*, locker_migration, payment_link::*,
user::*, user_role::*,
admin::*, api_keys::*, connector_onboarding::*, disputes::*, files::*, gsm::*,
locker_migration, payment_link::*, user::*, user_role::*,
};
use super::{cache::*, health::*};
#[cfg(any(feature = "olap", feature = "oltp"))]
Expand Down Expand Up @@ -881,3 +881,15 @@ impl LockerMigrate {
)
}
}

pub struct ConnectorOnboarding;

#[cfg(feature = "olap")]
impl ConnectorOnboarding {
pub fn server(state: AppState) -> Scope {
web::scope("/connector_onboarding")
.app_data(web::Data::new(state))
.service(web::resource("/action_url").route(web::post().to(get_action_url)))
.service(web::resource("/sync").route(web::post().to(sync_onboarding_status)))
}
}
47 changes: 47 additions & 0 deletions crates/router/src/routes/connector_onboarding.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
use actix_web::{web, HttpRequest, HttpResponse};
use api_models::connector_onboarding as api_types;
use router_env::Flow;

use super::AppState;
use crate::{
core::{api_locking, connector_onboarding as core},
services::{api, authentication as auth, authorization::permissions::Permission},
};

pub async fn get_action_url(
state: web::Data<AppState>,
http_req: HttpRequest,
json_payload: web::Json<api_types::ActionUrlRequest>,
) -> HttpResponse {
let flow = Flow::GetActionUrl;
let req_payload = json_payload.into_inner();
Box::pin(api::server_wrap(
flow.clone(),
state,
&http_req,
req_payload.clone(),
|state, _: auth::UserFromToken, req| core::get_action_url(state, req),
&auth::JWTAuth(Permission::MerchantAccountWrite),
api_locking::LockAction::NotApplicable,
))
.await
}

pub async fn sync_onboarding_status(
state: web::Data<AppState>,
http_req: HttpRequest,
json_payload: web::Json<api_types::OnboardingSyncRequest>,
) -> HttpResponse {
let flow = Flow::SyncOnboardingStatus;
let req_payload = json_payload.into_inner();
Box::pin(api::server_wrap(
flow.clone(),
state,
&http_req,
req_payload.clone(),
core::sync_onboarding_status,
&auth::JWTAuth(Permission::MerchantAccountWrite),
api_locking::LockAction::NotApplicable,
))
.await
}
3 changes: 3 additions & 0 deletions crates/router/src/routes/lock_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ pub enum ApiIdentifier {
Gsm,
User,
UserRole,
ConnectorOnboarding,
}

impl From<Flow> for ApiIdentifier {
Expand Down Expand Up @@ -164,6 +165,8 @@ impl From<Flow> for ApiIdentifier {
Flow::ListRoles | Flow::GetRole | Flow::UpdateUserRole | Flow::GetAuthorizationInfo => {
Self::UserRole
}

Flow::GetActionUrl | Flow::SyncOnboardingStatus => Self::ConnectorOnboarding,
}
}
}
4 changes: 2 additions & 2 deletions crates/router/src/types/api.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
pub mod admin;
pub mod api_keys;
pub mod configs;
#[cfg(feature = "olap")]
pub mod connector_onboarding;
pub mod customers;
pub mod disputes;
pub mod enums;
Expand All @@ -16,8 +18,6 @@ pub mod routing;
#[cfg(feature = "olap")]
pub mod verify_connector;
pub mod webhooks;
#[cfg(feature = "olap")]
pub mod connector_onboarding;

use std::{fmt::Debug, str::FromStr};

Expand Down
1 change: 1 addition & 0 deletions crates/router/src/types/api/connector_onboarding/paypal.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use api_models::connector_onboarding as api;
use error_stack::{IntoReport, ResultExt};

use crate::core::errors::{ApiErrorResponse, RouterResult};

#[derive(serde::Deserialize, Debug)]
Expand Down
4 changes: 2 additions & 2 deletions crates/router/src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#[cfg(feature = "olap")]
pub mod connector_onboarding;
pub mod currency;
pub mod custom_serde;
pub mod db_utils;
Expand All @@ -10,8 +12,6 @@ pub mod user;
pub mod user_role;
#[cfg(feature = "olap")]
pub mod verify_connector;
#[cfg(feature = "olap")]
pub mod connector_onboarding;

use std::fmt::Debug;

Expand Down
2 changes: 1 addition & 1 deletion crates/router/src/utils/connector_onboarding.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::routes::app::settings;
use crate::{
core::errors::{api_error_response::NotImplementedMessage, ApiErrorResponse, RouterResult},
routes::app::settings,
types::{self, api::enums},
};

Expand Down
20 changes: 9 additions & 11 deletions crates/router/src/utils/connector_onboarding/paypal.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
use common_utils::{
ext_traits::Encode,
request::{Method, Request, RequestBuilder},
};
use error_stack::{IntoReport, ResultExt};
use http::header;
use serde_json::json;

use crate::{
connector,
core::errors::{ApiErrorResponse, RouterResult},
Expand All @@ -9,24 +17,14 @@ use crate::{
},
utils::verify_connector as verify_connector_utils,
};
use common_utils::{
ext_traits::Encode,
request::{Method, Request, RequestBuilder},
};
use error_stack::{IntoReport, ResultExt};
use http::header;
use serde_json::json;

pub async fn generate_access_token(state: AppState) -> RouterResult<types::AccessToken> {
let connector = enums::Connector::Paypal;
let boxed_connector = types::api::ConnectorData::convert_connector(
&state.conf.connectors,
connector.to_string().as_str(),
)?;
let connector_auth = super::get_connector_auth(
connector,
&state.conf.connector_onboarding,
)?;
let connector_auth = super::get_connector_auth(connector, &state.conf.connector_onboarding)?;

connector::Paypal::get_access_token(
&state,
Expand Down
4 changes: 4 additions & 0 deletions crates/router_env/src/logger/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,10 @@ pub enum Flow {
UserMerchantAccountList,
/// Get users for merchant account
GetUserDetails,
/// Get action URL for connector onboarding
GetActionUrl,
/// Sync connector onboarding status
SyncOnboardingStatus,
}

///
Expand Down

0 comments on commit 9fb490b

Please sign in to comment.