-
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' into pm-auth-fix
- Loading branch information
Showing
18 changed files
with
552 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
use common_utils::events::{ApiEventMetric, ApiEventsType}; | ||
|
||
use crate::{admin, enums}; | ||
|
||
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)] | ||
pub struct VerifyConnectorRequest { | ||
pub connector_name: enums::Connector, | ||
pub connector_account_details: admin::ConnectorAuthType, | ||
} | ||
|
||
common_utils::impl_misc_api_event_type!(VerifyConnectorRequest); |
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,63 @@ | ||
use api_models::{enums::Connector, verify_connector::VerifyConnectorRequest}; | ||
use error_stack::{IntoReport, ResultExt}; | ||
|
||
use crate::{ | ||
connector, | ||
core::errors, | ||
services, | ||
types::{ | ||
api, | ||
api::verify_connector::{self as types, VerifyConnector}, | ||
}, | ||
utils::verify_connector as utils, | ||
AppState, | ||
}; | ||
|
||
pub async fn verify_connector_credentials( | ||
state: AppState, | ||
req: VerifyConnectorRequest, | ||
) -> errors::RouterResponse<()> { | ||
let boxed_connector = api::ConnectorData::get_connector_by_name( | ||
&state.conf.connectors, | ||
&req.connector_name.to_string(), | ||
api::GetToken::Connector, | ||
None, | ||
) | ||
.change_context(errors::ApiErrorResponse::IncorrectConnectorNameGiven)?; | ||
|
||
let card_details = utils::get_test_card_details(req.connector_name)? | ||
.ok_or(errors::ApiErrorResponse::FlowNotSupported { | ||
flow: "Verify credentials".to_string(), | ||
connector: req.connector_name.to_string(), | ||
}) | ||
.into_report()?; | ||
|
||
match req.connector_name { | ||
Connector::Stripe => { | ||
connector::Stripe::verify( | ||
&state, | ||
types::VerifyConnectorData { | ||
connector: *boxed_connector.connector, | ||
connector_auth: req.connector_account_details.into(), | ||
card_details, | ||
}, | ||
) | ||
.await | ||
} | ||
Connector::Paypal => connector::Paypal::get_access_token( | ||
&state, | ||
types::VerifyConnectorData { | ||
connector: *boxed_connector.connector, | ||
connector_auth: req.connector_account_details.into(), | ||
card_details, | ||
}, | ||
) | ||
.await | ||
.map(|_| services::ApplicationResponse::StatusOk), | ||
_ => Err(errors::ApiErrorResponse::FlowNotSupported { | ||
flow: "Verify credentials".to_string(), | ||
connector: req.connector_name.to_string(), | ||
}) | ||
.into_report(), | ||
} | ||
} |
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,28 @@ | ||
use actix_web::{web, HttpRequest, HttpResponse}; | ||
use api_models::verify_connector::VerifyConnectorRequest; | ||
use router_env::{instrument, tracing, Flow}; | ||
|
||
use super::AppState; | ||
use crate::{ | ||
core::{api_locking, verify_connector}, | ||
services::{self, authentication as auth, authorization::permissions::Permission}, | ||
}; | ||
|
||
#[instrument(skip_all, fields(flow = ?Flow::VerifyPaymentConnector))] | ||
pub async fn payment_connector_verify( | ||
state: web::Data<AppState>, | ||
req: HttpRequest, | ||
json_payload: web::Json<VerifyConnectorRequest>, | ||
) -> HttpResponse { | ||
let flow = Flow::VerifyPaymentConnector; | ||
Box::pin(services::server_wrap( | ||
flow, | ||
state, | ||
&req, | ||
json_payload.into_inner(), | ||
|state, _: (), req| verify_connector::verify_connector_credentials(state, req), | ||
&auth::JWTAuth(Permission::MerchantConnectorAccountWrite), | ||
api_locking::LockAction::NotApplicable, | ||
)) | ||
.await | ||
} |
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
Oops, something went wrong.