-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of github.com:juspay/hyperswitch into migrate-plaid
- Loading branch information
Showing
25 changed files
with
875 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
use super::{admin, enums}; | ||
|
||
#[derive(serde::Deserialize, serde::Serialize, Debug, Clone)] | ||
pub struct ActionUrlRequest { | ||
pub connector: enums::Connector, | ||
pub connector_id: String, | ||
pub return_url: String, | ||
} | ||
|
||
#[derive(serde::Serialize, Debug, Clone)] | ||
#[serde(rename_all = "lowercase")] | ||
pub enum ActionUrlResponse { | ||
PayPal(PayPalActionUrlResponse), | ||
} | ||
|
||
#[derive(serde::Deserialize, serde::Serialize, Debug, Clone)] | ||
pub struct OnboardingSyncRequest { | ||
pub profile_id: String, | ||
pub connector_id: String, | ||
pub connector: enums::Connector, | ||
} | ||
|
||
#[derive(serde::Serialize, Debug, Clone)] | ||
pub struct PayPalActionUrlResponse { | ||
pub action_url: String, | ||
} | ||
|
||
#[derive(serde::Serialize, Debug, Clone)] | ||
#[serde(rename_all = "lowercase")] | ||
pub enum OnboardingStatus { | ||
PayPal(PayPalOnboardingStatus), | ||
} | ||
|
||
#[derive(serde::Serialize, Debug, Clone)] | ||
#[serde(rename_all = "snake_case")] | ||
pub enum PayPalOnboardingStatus { | ||
AccountNotFound, | ||
PaymentsNotReceivable, | ||
PpcpCustomDenied, | ||
MorePermissionsNeeded, | ||
EmailNotVerified, | ||
Success(PayPalOnboardingDone), | ||
ConnectorIntegrated(admin::MerchantConnectorResponse), | ||
} | ||
|
||
#[derive(serde::Serialize, Debug, Clone)] | ||
pub struct PayPalOnboardingDone { | ||
pub payer_id: String, | ||
} | ||
|
||
#[derive(serde::Serialize, Debug, Clone)] | ||
pub struct PayPalIntegrationDone { | ||
pub connector_id: String, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
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, | ||
}; | ||
|
||
pub mod paypal; | ||
|
||
#[async_trait::async_trait] | ||
pub trait AccessToken { | ||
async fn access_token(state: &AppState) -> RouterResult<oss_types::AccessToken>; | ||
} | ||
|
||
pub async fn get_action_url( | ||
state: AppState, | ||
request: api::ActionUrlRequest, | ||
) -> RouterResponse<api::ActionUrlResponse> { | ||
let connector_onboarding_conf = state.conf.connector_onboarding.clone(); | ||
let is_enabled = utils::is_enabled(request.connector, &connector_onboarding_conf); | ||
|
||
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, | ||
request.return_url, | ||
)) | ||
.await?; | ||
Ok(ApplicationResponse::Json(api::ActionUrlResponse::PayPal( | ||
api::PayPalActionUrlResponse { action_url }, | ||
))) | ||
} | ||
_ => Err(ApiErrorResponse::FlowNotSupported { | ||
flow: "Connector onboarding".to_string(), | ||
connector: request.connector.to_string(), | ||
} | ||
.into()), | ||
} | ||
} | ||
|
||
pub async fn sync_onboarding_status( | ||
state: AppState, | ||
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)?; | ||
let connector_onboarding_conf = state.conf.connector_onboarding.clone(); | ||
let is_enabled = utils::is_enabled(request.connector, &connector_onboarding_conf); | ||
|
||
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(), | ||
)) | ||
.await?; | ||
if let api::OnboardingStatus::PayPal(api::PayPalOnboardingStatus::Success( | ||
ref inner_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()), | ||
}; | ||
let some_data = paypal::update_mca( | ||
&state, | ||
&merchant_account, | ||
request.connector_id.to_owned(), | ||
auth_details, | ||
) | ||
.await?; | ||
|
||
return Ok(ApplicationResponse::Json(api::OnboardingStatus::PayPal( | ||
api::PayPalOnboardingStatus::ConnectorIntegrated(some_data), | ||
))); | ||
} | ||
Ok(ApplicationResponse::Json(status)) | ||
} | ||
_ => Err(ApiErrorResponse::FlowNotSupported { | ||
flow: "Connector onboarding".to_string(), | ||
connector: request.connector.to_string(), | ||
} | ||
.into()), | ||
} | ||
} |
Oops, something went wrong.