mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-27 19:46:48 +08:00
feat(router): Add support for Proxy api (#7901)
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
This commit is contained in:
@ -32,6 +32,8 @@ pub mod payouts;
|
||||
pub mod pm_auth;
|
||||
pub mod poll;
|
||||
pub mod process_tracker;
|
||||
#[cfg(all(feature = "v2", feature = "payment_methods_v2"))]
|
||||
pub mod proxy;
|
||||
#[cfg(feature = "recon")]
|
||||
pub mod recon;
|
||||
pub mod refunds;
|
||||
|
||||
69
crates/api_models/src/proxy.rs
Normal file
69
crates/api_models/src/proxy.rs
Normal file
@ -0,0 +1,69 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use common_utils::request::Method;
|
||||
use reqwest::header::HeaderMap;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::Value;
|
||||
use utoipa::ToSchema;
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
pub struct Headers(pub HashMap<String, String>);
|
||||
|
||||
impl Headers {
|
||||
pub fn as_map(&self) -> &HashMap<String, String> {
|
||||
&self.0
|
||||
}
|
||||
|
||||
pub fn from_header_map(headers: Option<&HeaderMap>) -> Self {
|
||||
headers
|
||||
.map(|h| {
|
||||
let map = h
|
||||
.iter()
|
||||
.map(|(k, v)| (k.to_string(), v.to_str().unwrap_or("").to_string()))
|
||||
.collect();
|
||||
Self(map)
|
||||
})
|
||||
.unwrap_or_else(|| Self(HashMap::new()))
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, ToSchema, Clone, Deserialize, Serialize)]
|
||||
pub struct ProxyRequest {
|
||||
/// The request body that needs to be forwarded
|
||||
pub request_body: Value,
|
||||
/// The destination URL where the request needs to be forwarded
|
||||
#[schema(value_type = String, example = "https://api.example.com/endpoint")]
|
||||
pub destination_url: url::Url,
|
||||
/// The headers that need to be forwarded
|
||||
#[schema(value_type = Object, example = r#"{ "key1": "value-1", "key2": "value-2" }"#)]
|
||||
pub headers: Headers,
|
||||
/// The method that needs to be used for the request
|
||||
#[schema(value_type = Method, example = "Post")]
|
||||
pub method: Method,
|
||||
/// The vault token that is used to fetch sensitive data from the vault
|
||||
pub token: String,
|
||||
/// The type of token that is used to fetch sensitive data from the vault
|
||||
#[schema(value_type = TokenType, example = "payment_method_id")]
|
||||
pub token_type: TokenType,
|
||||
}
|
||||
|
||||
#[derive(Debug, ToSchema, Clone, Deserialize, Serialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum TokenType {
|
||||
TokenizationId,
|
||||
PaymentMethodId,
|
||||
}
|
||||
|
||||
#[derive(Debug, ToSchema, Clone, Deserialize, Serialize)]
|
||||
pub struct ProxyResponse {
|
||||
/// The response received from the destination
|
||||
pub response: Value,
|
||||
/// The status code of the response
|
||||
pub status_code: u16,
|
||||
/// The headers of the response
|
||||
#[schema(value_type = Object, example = r#"{ "key1": "value-1", "key2": "value-2" }"#)]
|
||||
pub response_headers: Headers,
|
||||
}
|
||||
|
||||
impl common_utils::events::ApiEventMetric for ProxyRequest {}
|
||||
impl common_utils::events::ApiEventMetric for ProxyResponse {}
|
||||
@ -382,6 +382,7 @@ pub struct RefundListRequest {
|
||||
#[schema(value_type = Option<String>)]
|
||||
pub payment_id: Option<common_utils::id_type::GlobalPaymentId>,
|
||||
/// The identifier for the refund
|
||||
#[schema(value_type = String)]
|
||||
pub refund_id: Option<common_utils::id_type::GlobalRefundId>,
|
||||
/// Limit on the number of objects to return
|
||||
pub limit: Option<i64>,
|
||||
|
||||
Reference in New Issue
Block a user