Skip to content

Commit

Permalink
chore: merge main
Browse files Browse the repository at this point in the history
  • Loading branch information
prajjwalkumar17 committed Jan 18, 2024
2 parents f0438d6 + 63cdc18 commit cfe2803
Show file tree
Hide file tree
Showing 32 changed files with 839 additions and 35 deletions.
3 changes: 2 additions & 1 deletion crates/api_models/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ readme = "README.md"
license.workspace = true

[features]
default = ["payouts", "frm"]
default = ["payouts", "frm", "recon"]
business_profile_routing = []
connector_choice_bcompat = []
errors = ["dep:actix-web", "dep:reqwest"]
Expand All @@ -18,6 +18,7 @@ dummy_connector = ["euclid/dummy_connector", "common_enums/dummy_connector"]
detailed_errors = []
payouts = []
frm = []
recon = []

[dependencies]
actix-web = { version = "4.3.1", optional = true }
Expand Down
6 changes: 6 additions & 0 deletions crates/api_models/src/connector_onboarding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,9 @@ pub struct PayPalOnboardingDone {
pub struct PayPalIntegrationDone {
pub connector_id: String,
}

#[derive(serde::Deserialize, serde::Serialize, Debug, Clone)]
pub struct ResetTrackingIdRequest {
pub connector_id: String,
pub connector: enums::Connector,
}
2 changes: 2 additions & 0 deletions crates/api_models/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ mod locker_migration;
pub mod payment;
#[cfg(feature = "payouts")]
pub mod payouts;
#[cfg(feature = "recon")]
pub mod recon;
pub mod refund;
pub mod routing;
pub mod user;
Expand Down
4 changes: 3 additions & 1 deletion crates/api_models/src/events/connector_onboarding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ use common_utils::events::{ApiEventMetric, ApiEventsType};

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

common_utils::impl_misc_api_event_type!(
ActionUrlRequest,
ActionUrlResponse,
OnboardingSyncRequest,
OnboardingStatus
OnboardingStatus,
ResetTrackingIdRequest
);
21 changes: 21 additions & 0 deletions crates/api_models/src/events/recon.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
use common_utils::events::{ApiEventMetric, ApiEventsType};

use crate::recon::{ReconStatusResponse, ReconTokenResponse, ReconUpdateMerchantRequest};

impl ApiEventMetric for ReconUpdateMerchantRequest {
fn get_api_event_type(&self) -> Option<ApiEventsType> {
Some(ApiEventsType::Recon)
}
}

impl ApiEventMetric for ReconTokenResponse {
fn get_api_event_type(&self) -> Option<ApiEventsType> {
Some(ApiEventsType::Recon)
}
}

impl ApiEventMetric for ReconStatusResponse {
fn get_api_event_type(&self) -> Option<ApiEventsType> {
Some(ApiEventsType::Recon)
}
}
14 changes: 14 additions & 0 deletions crates/api_models/src/events/user.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
use common_utils::events::{ApiEventMetric, ApiEventsType};
#[cfg(feature = "recon")]
use masking::PeekInterface;

#[cfg(feature = "dummy_connector")]
use crate::user::sample_data::SampleDataRequest;
#[cfg(feature = "recon")]
use crate::user::VerifyTokenResponse;
use crate::user::{
dashboard_metadata::{
GetMetaDataRequest, GetMetaDataResponse, GetMultipleMetaDataPayload, SetMetaDataRequest,
Expand All @@ -21,6 +25,16 @@ impl ApiEventMetric for DashboardEntryResponse {
}
}

#[cfg(feature = "recon")]
impl ApiEventMetric for VerifyTokenResponse {
fn get_api_event_type(&self) -> Option<ApiEventsType> {
Some(ApiEventsType::User {
merchant_id: self.merchant_id.clone(),
user_id: self.user_email.peek().to_string(),
})
}
}

common_utils::impl_misc_api_event_type!(
SignUpRequest,
SignUpWithMerchantIdRequest,
Expand Down
2 changes: 2 additions & 0 deletions crates/api_models/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ pub mod payments;
#[cfg(feature = "payouts")]
pub mod payouts;
pub mod pm_auth;
#[cfg(feature = "recon")]
pub mod recon;
pub mod refunds;
pub mod routing;
pub mod surcharge_decision_configs;
Expand Down
5 changes: 5 additions & 0 deletions crates/api_models/src/payments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2277,6 +2277,11 @@ pub struct PaymentsResponse {
/// List of incremental authorizations happened to the payment
pub incremental_authorizations: Option<Vec<IncrementalAuthorizationResponse>>,

/// Date Time expiry of the payment
#[schema(example = "2022-09-10T10:11:12Z")]
#[serde(default, with = "common_utils::custom_serde::iso8601::option")]
pub expires_on: Option<PrimitiveDateTime>,

/// Payment Fingerprint
pub fingerprint: Option<String>,
}
Expand Down
21 changes: 21 additions & 0 deletions crates/api_models/src/recon.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
use common_utils::pii;
use masking::Secret;

use crate::enums;

#[derive(serde::Deserialize, Debug, serde::Serialize)]
pub struct ReconUpdateMerchantRequest {
pub merchant_id: String,
pub recon_status: enums::ReconStatus,
pub user_email: pii::Email,
}

#[derive(Debug, serde::Serialize)]
pub struct ReconTokenResponse {
pub token: Secret<String>,
}

#[derive(Debug, serde::Serialize)]
pub struct ReconStatusResponse {
pub recon_status: enums::ReconStatus,
}
7 changes: 7 additions & 0 deletions crates/api_models/src/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,10 @@ pub struct UserMerchantAccount {
pub merchant_id: String,
pub merchant_name: OptionalEncryptableName,
}

#[cfg(feature = "recon")]
#[derive(serde::Serialize, Debug)]
pub struct VerifyTokenResponse {
pub merchant_id: String,
pub user_email: pii::Email,
}
1 change: 1 addition & 0 deletions crates/common_utils/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ pub enum ApiEventsType {
Miscellaneous,
RustLocker,
FraudCheck,
Recon,
}

impl ApiEventMetric for serde_json::Value {}
Expand Down
3 changes: 2 additions & 1 deletion crates/router/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ readme = "README.md"
license.workspace = true

[features]
default = ["kv_store", "stripe", "oltp", "olap", "backwards_compatibility", "accounts_cache", "dummy_connector", "payouts", "business_profile_routing", "connector_choice_mca_id", "profile_specific_fallback_routing", "retry", "frm"]
default = ["kv_store", "stripe", "oltp", "olap", "backwards_compatibility", "accounts_cache", "dummy_connector", "payouts", "business_profile_routing", "connector_choice_mca_id", "profile_specific_fallback_routing", "retry", "frm", "recon"]
s3 = ["dep:aws-sdk-s3", "dep:aws-config"]
kms = ["external_services/kms", "dep:aws-config"]
email = ["external_services/email", "dep:aws-config", "olap"]
Expand All @@ -30,6 +30,7 @@ connector_choice_mca_id = ["api_models/connector_choice_mca_id", "euclid/connect
external_access_dc = ["dummy_connector"]
detailed_errors = ["api_models/detailed_errors", "error-stack/serde"]
payouts = []
recon = ["email"]
retry = []

[dependencies]
Expand Down
3 changes: 3 additions & 0 deletions crates/router/src/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ pub const VERIFY_CONNECTOR_ID_PREFIX: &str = "conn_verify";
#[cfg(feature = "olap")]
pub const VERIFY_CONNECTOR_MERCHANT_ID: &str = "test_merchant";

#[cfg(feature = "olap")]
pub const CONNECTOR_ONBOARDING_CONFIG_PREFIX: &str = "onboarding";

/// Max payment session expiry
pub const MAX_SESSION_EXPIRY: u32 = 7890000;

Expand Down
44 changes: 32 additions & 12 deletions crates/router/src/core/connector_onboarding.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use api_models::{connector_onboarding as api, enums};
use error_stack::ResultExt;
use masking::Secret;

use crate::{
Expand All @@ -19,16 +18,23 @@ pub trait AccessToken {

pub async fn get_action_url(
state: AppState,
user_from_token: auth::UserFromToken,
request: api::ActionUrlRequest,
) -> RouterResponse<api::ActionUrlResponse> {
utils::check_if_connector_exists(&state, &request.connector_id, &user_from_token.merchant_id)
.await?;

let connector_onboarding_conf = state.conf.connector_onboarding.clone();
let is_enabled = utils::is_enabled(request.connector, &connector_onboarding_conf);
let tracking_id =
utils::get_tracking_id_from_configs(&state, &request.connector_id, request.connector)
.await?;

match (is_enabled, request.connector) {
(Some(true), enums::Connector::Paypal) => {
let action_url = Box::pin(paypal::get_action_url_from_paypal(
state,
request.connector_id,
tracking_id,
request.return_url,
))
.await?;
Expand All @@ -49,40 +55,42 @@ pub async fn sync_onboarding_status(
user_from_token: auth::UserFromToken,
request: api::OnboardingSyncRequest,
) -> RouterResponse<api::OnboardingStatus> {
let merchant_account = user_from_token
.get_merchant_account(state.clone())
.await
.change_context(ApiErrorResponse::MerchantAccountNotFound)?;
utils::check_if_connector_exists(&state, &request.connector_id, &user_from_token.merchant_id)
.await?;

let connector_onboarding_conf = state.conf.connector_onboarding.clone();
let is_enabled = utils::is_enabled(request.connector, &connector_onboarding_conf);
let tracking_id =
utils::get_tracking_id_from_configs(&state, &request.connector_id, request.connector)
.await?;

match (is_enabled, request.connector) {
(Some(true), enums::Connector::Paypal) => {
let status = Box::pin(paypal::sync_merchant_onboarding_status(
state.clone(),
request.connector_id.clone(),
tracking_id,
))
.await?;
if let api::OnboardingStatus::PayPal(api::PayPalOnboardingStatus::Success(
ref inner_data,
ref paypal_onboarding_data,
)) = status
{
let connector_onboarding_conf = state.conf.connector_onboarding.clone();
let auth_details = oss_types::ConnectorAuthType::SignatureKey {
api_key: connector_onboarding_conf.paypal.client_secret,
key1: connector_onboarding_conf.paypal.client_id,
api_secret: Secret::new(inner_data.payer_id.clone()),
api_secret: Secret::new(paypal_onboarding_data.payer_id.clone()),
};
let some_data = paypal::update_mca(
let update_mca_data = paypal::update_mca(
&state,
&merchant_account,
user_from_token.merchant_id,
request.connector_id.to_owned(),
auth_details,
)
.await?;

return Ok(ApplicationResponse::Json(api::OnboardingStatus::PayPal(
api::PayPalOnboardingStatus::ConnectorIntegrated(some_data),
api::PayPalOnboardingStatus::ConnectorIntegrated(update_mca_data),
)));
}
Ok(ApplicationResponse::Json(status))
Expand All @@ -94,3 +102,15 @@ pub async fn sync_onboarding_status(
.into()),
}
}

pub async fn reset_tracking_id(
state: AppState,
user_from_token: auth::UserFromToken,
request: api::ResetTrackingIdRequest,
) -> RouterResponse<()> {
utils::check_if_connector_exists(&state, &request.connector_id, &user_from_token.merchant_id)
.await?;
utils::set_tracking_id_in_configs(&state, &request.connector_id, request.connector).await?;

Ok(ApplicationResponse::StatusOk)
}
20 changes: 8 additions & 12 deletions crates/router/src/core/connector_onboarding/paypal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ fn build_referral_url(state: AppState) -> String {

async fn build_referral_request(
state: AppState,
connector_id: String,
tracking_id: String,
return_url: String,
) -> RouterResult<Request> {
let access_token = utils::paypal::generate_access_token(state.clone()).await?;
let request_body = types::paypal::PartnerReferralRequest::new(connector_id, return_url);
let request_body = types::paypal::PartnerReferralRequest::new(tracking_id, return_url);

utils::paypal::build_paypal_post_request(
build_referral_url(state),
Expand All @@ -38,12 +38,12 @@ async fn build_referral_request(

pub async fn get_action_url_from_paypal(
state: AppState,
connector_id: String,
tracking_id: String,
return_url: String,
) -> RouterResult<String> {
let referral_request = Box::pin(build_referral_request(
state.clone(),
connector_id,
tracking_id,
return_url,
))
.await?;
Expand Down Expand Up @@ -137,7 +137,7 @@ async fn find_paypal_merchant_by_tracking_id(

pub async fn update_mca(
state: &AppState,
merchant_account: &oss_types::domain::MerchantAccount,
merchant_id: String,
connector_id: String,
auth_details: oss_types::ConnectorAuthType,
) -> RouterResult<oss_api_types::MerchantConnectorResponse> {
Expand All @@ -159,13 +159,9 @@ pub async fn update_mca(
connector_webhook_details: None,
pm_auth_config: None,
};
let mca_response = admin::update_payment_connector(
state.clone(),
&merchant_account.merchant_id,
&connector_id,
request,
)
.await?;
let mca_response =
admin::update_payment_connector(state.clone(), &merchant_id, &connector_id, request)
.await?;

match mca_response {
ApplicationResponse::Json(mca_data) => Ok(mca_data),
Expand Down
2 changes: 2 additions & 0 deletions crates/router/src/core/payments/transformers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,7 @@ where
.set_fingerprint(payment_intent.fingerprint_id)
.set_authorization_count(payment_intent.authorization_count)
.set_incremental_authorizations(incremental_authorizations_response)
.set_expires_on(payment_intent.session_expiry)
.to_owned(),
headers,
))
Expand Down Expand Up @@ -775,6 +776,7 @@ where
incremental_authorization_allowed: payment_intent.incremental_authorization_allowed,
authorization_count: payment_intent.authorization_count,
incremental_authorizations: incremental_authorizations_response,
expires_on: payment_intent.session_expiry,
..Default::default()
},
headers,
Expand Down
29 changes: 29 additions & 0 deletions crates/router/src/core/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -757,3 +757,32 @@ pub async fn send_verification_mail(

Ok(ApplicationResponse::StatusOk)
}

#[cfg(feature = "recon")]
pub async fn verify_token(
state: AppState,
req: auth::ReconUser,
) -> UserResponse<user_api::VerifyTokenResponse> {
let user = state
.store
.find_user_by_id(&req.user_id)
.await
.map_err(|e| {
if e.current_context().is_db_not_found() {
e.change_context(UserErrors::UserNotFound)
} else {
e.change_context(UserErrors::InternalServerError)
}
})?;
let merchant_id = state
.store
.find_user_role_by_user_id(&req.user_id)
.await
.change_context(UserErrors::InternalServerError)?
.merchant_id;

Ok(ApplicationResponse::Json(user_api::VerifyTokenResponse {
merchant_id: merchant_id.to_string(),
user_email: user.email,
}))
}
Loading

0 comments on commit cfe2803

Please sign in to comment.