mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-29 09:07:09 +08:00
feat(core): Added Reward PaymentMethod & CurrencyAuthKey for Hyperswitch <> UCS Integration (#8767)
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
This commit is contained in:
6
Cargo.lock
generated
6
Cargo.lock
generated
@ -3041,6 +3041,7 @@ dependencies = [
|
||||
"aws-sdk-sts",
|
||||
"aws-smithy-runtime",
|
||||
"base64 0.22.1",
|
||||
"common_enums",
|
||||
"common_utils",
|
||||
"dyn-clone",
|
||||
"error-stack 0.4.1",
|
||||
@ -3061,6 +3062,7 @@ dependencies = [
|
||||
"router_env",
|
||||
"rust-grpc-client",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"thiserror 1.0.69",
|
||||
"time",
|
||||
"tokio 1.45.1",
|
||||
@ -3538,7 +3540,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "grpc-api-types"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/juspay/connector-service?rev=4387a6310dc9c2693b453b455a8032623f3d6a81#4387a6310dc9c2693b453b455a8032623f3d6a81"
|
||||
source = "git+https://github.com/juspay/connector-service?rev=2263c96a70f2606475ab30e6f716b2773e1fd093#2263c96a70f2606475ab30e6f716b2773e1fd093"
|
||||
dependencies = [
|
||||
"axum 0.8.4",
|
||||
"error-stack 0.5.0",
|
||||
@ -6914,7 +6916,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "rust-grpc-client"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/juspay/connector-service?rev=4387a6310dc9c2693b453b455a8032623f3d6a81#4387a6310dc9c2693b453b455a8032623f3d6a81"
|
||||
source = "git+https://github.com/juspay/connector-service?rev=2263c96a70f2606475ab30e6f716b2773e1fd093#2263c96a70f2606475ab30e6f716b2773e1fd093"
|
||||
dependencies = [
|
||||
"grpc-api-types",
|
||||
]
|
||||
|
||||
@ -51,6 +51,7 @@ lettre = "0.11.16"
|
||||
once_cell = "1.21.3"
|
||||
serde = { version = "1.0.219", features = ["derive"] }
|
||||
thiserror = "1.0.69"
|
||||
serde_json = "1.0.140"
|
||||
vaultrs = { version = "0.7.4", optional = true }
|
||||
prost = { version = "0.13", optional = true }
|
||||
prost-types = { version = "0.13", optional = true }
|
||||
@ -65,11 +66,12 @@ reqwest = { version = "0.11.27", features = ["rustls-tls"] }
|
||||
http = "0.2.12"
|
||||
url = { version = "2.5.4", features = ["serde"] }
|
||||
quick-xml = { version = "0.31.0", features = ["serialize"] }
|
||||
unified-connector-service-client = { git = "https://github.com/juspay/connector-service", rev = "4387a6310dc9c2693b453b455a8032623f3d6a81", package = "rust-grpc-client" }
|
||||
unified-connector-service-client = { git = "https://github.com/juspay/connector-service", rev = "2263c96a70f2606475ab30e6f716b2773e1fd093", package = "rust-grpc-client" }
|
||||
|
||||
|
||||
# First party crates
|
||||
common_utils = { version = "0.1.0", path = "../common_utils" }
|
||||
common_enums = { version = "0.1.0", path = "../common_enums" }
|
||||
hyperswitch_interfaces = { version = "0.1.0", path = "../hyperswitch_interfaces", default-features = false }
|
||||
masking = { version = "0.1.0", path = "../masking" }
|
||||
router_env = { version = "0.1.0", path = "../router_env", features = [
|
||||
|
||||
@ -1,3 +1,5 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use common_utils::{consts as common_utils_consts, errors::CustomResult, types::Url};
|
||||
use error_stack::ResultExt;
|
||||
use masking::{PeekInterface, Secret};
|
||||
@ -144,6 +146,10 @@ pub struct ConnectorAuthMetadata {
|
||||
/// Optional API secret used for signature or secure authentication.
|
||||
pub api_secret: Option<Secret<String>>,
|
||||
|
||||
/// Optional auth_key_map used for authentication.
|
||||
pub auth_key_map:
|
||||
Option<HashMap<common_enums::enums::Currency, common_utils::pii::SecretSerdeValue>>,
|
||||
|
||||
/// Id of the merchant.
|
||||
pub merchant_id: Secret<String>,
|
||||
}
|
||||
@ -381,6 +387,16 @@ pub fn build_unified_connector_service_grpc_headers(
|
||||
parse("api_secret", api_secret.peek())?,
|
||||
);
|
||||
}
|
||||
if let Some(auth_key_map) = meta.auth_key_map {
|
||||
let auth_key_map_str = serde_json::to_string(&auth_key_map).map_err(|error| {
|
||||
logger::error!(?error);
|
||||
UnifiedConnectorServiceError::ParsingFailed
|
||||
})?;
|
||||
metadata.append(
|
||||
consts::UCS_HEADER_AUTH_KEY_MAP,
|
||||
parse("auth_key_map", &auth_key_map_str)?,
|
||||
);
|
||||
}
|
||||
|
||||
metadata.append(
|
||||
common_utils_consts::X_MERCHANT_ID,
|
||||
|
||||
@ -85,6 +85,9 @@ pub mod consts {
|
||||
|
||||
/// Header key for sending the API secret in signature-based authentication.
|
||||
pub(crate) const UCS_HEADER_API_SECRET: &str = "x-api-secret";
|
||||
|
||||
/// Header key for sending the AUTH KEY MAP in currency-based authentication.
|
||||
pub(crate) const UCS_HEADER_AUTH_KEY_MAP: &str = "x-auth-key-map";
|
||||
}
|
||||
|
||||
/// Metrics for interactions with external systems.
|
||||
|
||||
@ -89,7 +89,7 @@ reqwest = { version = "0.11.27", features = ["json", "rustls-tls", "gzip", "mult
|
||||
ring = "0.17.14"
|
||||
rust_decimal = { version = "1.37.1", features = ["serde-with-float", "serde-with-str"] }
|
||||
rust-i18n = { git = "https://github.com/kashif-m/rust-i18n", rev = "f2d8096aaaff7a87a847c35a5394c269f75e077a" }
|
||||
unified-connector-service-client = { git = "https://github.com/juspay/connector-service", rev = "4387a6310dc9c2693b453b455a8032623f3d6a81", package = "rust-grpc-client" }
|
||||
unified-connector-service-client = { git = "https://github.com/juspay/connector-service", rev = "2263c96a70f2606475ab30e6f716b2773e1fd093", package = "rust-grpc-client" }
|
||||
rustc-hash = "1.1.0"
|
||||
rustls = "0.22"
|
||||
rustls-pemfile = "2"
|
||||
|
||||
@ -326,3 +326,6 @@ pub const UCS_AUTH_BODY_KEY: &str = "body-key";
|
||||
|
||||
/// Header value indicating that header-key-based authentication is used.
|
||||
pub const UCS_AUTH_HEADER_KEY: &str = "header-key";
|
||||
|
||||
/// Header value indicating that currency-auth-key-based authentication is used.
|
||||
pub const UCS_AUTH_CURRENCY_AUTH_KEY: &str = "currency-auth-key";
|
||||
|
||||
@ -18,7 +18,7 @@ use masking::{ExposeInterface, PeekInterface, Secret};
|
||||
use router_env::logger;
|
||||
use unified_connector_service_client::payments::{
|
||||
self as payments_grpc, payment_method::PaymentMethod, CardDetails, CardPaymentMethodType,
|
||||
PaymentServiceAuthorizeResponse,
|
||||
PaymentServiceAuthorizeResponse, RewardPaymentMethodType,
|
||||
};
|
||||
|
||||
use crate::{
|
||||
@ -325,6 +325,24 @@ pub fn build_unified_connector_service_payment_method(
|
||||
payment_method: Some(upi_type),
|
||||
})
|
||||
}
|
||||
hyperswitch_domain_models::payment_method_data::PaymentMethodData::Reward => {
|
||||
match payment_method_type {
|
||||
PaymentMethodType::ClassicReward => Ok(payments_grpc::PaymentMethod {
|
||||
payment_method: Some(PaymentMethod::Reward(RewardPaymentMethodType {
|
||||
reward_type: 1,
|
||||
})),
|
||||
}),
|
||||
PaymentMethodType::Evoucher => Ok(payments_grpc::PaymentMethod {
|
||||
payment_method: Some(PaymentMethod::Reward(RewardPaymentMethodType {
|
||||
reward_type: 2,
|
||||
})),
|
||||
}),
|
||||
_ => Err(UnifiedConnectorServiceError::NotImplemented(format!(
|
||||
"Unimplemented payment method subtype: {payment_method_type:?}"
|
||||
))
|
||||
.into()),
|
||||
}
|
||||
}
|
||||
_ => Err(UnifiedConnectorServiceError::NotImplemented(format!(
|
||||
"Unimplemented payment method: {payment_method_data:?}"
|
||||
))
|
||||
@ -385,6 +403,7 @@ pub fn build_unified_connector_service_auth_metadata(
|
||||
api_key: Some(api_key.clone()),
|
||||
key1: Some(key1.clone()),
|
||||
api_secret: Some(api_secret.clone()),
|
||||
auth_key_map: None,
|
||||
merchant_id: Secret::new(merchant_id.to_string()),
|
||||
}),
|
||||
ConnectorAuthType::BodyKey { api_key, key1 } => Ok(ConnectorAuthMetadata {
|
||||
@ -393,6 +412,7 @@ pub fn build_unified_connector_service_auth_metadata(
|
||||
api_key: Some(api_key.clone()),
|
||||
key1: Some(key1.clone()),
|
||||
api_secret: None,
|
||||
auth_key_map: None,
|
||||
merchant_id: Secret::new(merchant_id.to_string()),
|
||||
}),
|
||||
ConnectorAuthType::HeaderKey { api_key } => Ok(ConnectorAuthMetadata {
|
||||
@ -401,6 +421,16 @@ pub fn build_unified_connector_service_auth_metadata(
|
||||
api_key: Some(api_key.clone()),
|
||||
key1: None,
|
||||
api_secret: None,
|
||||
auth_key_map: None,
|
||||
merchant_id: Secret::new(merchant_id.to_string()),
|
||||
}),
|
||||
ConnectorAuthType::CurrencyAuthKey { auth_key_map } => Ok(ConnectorAuthMetadata {
|
||||
connector_name,
|
||||
auth_type: consts::UCS_AUTH_CURRENCY_AUTH_KEY.to_string(),
|
||||
api_key: None,
|
||||
key1: None,
|
||||
api_secret: None,
|
||||
auth_key_map: Some(auth_key_map.clone()),
|
||||
merchant_id: Secret::new(merchant_id.to_string()),
|
||||
}),
|
||||
_ => Err(UnifiedConnectorServiceError::FailedToObtainAuthType)
|
||||
|
||||
@ -51,6 +51,16 @@ impl ForeignTryFrom<&RouterData<PSync, PaymentsSyncData, PaymentsResponseData>>
|
||||
})
|
||||
.ok();
|
||||
|
||||
let encoded_data = router_data
|
||||
.request
|
||||
.encoded_data
|
||||
.as_ref()
|
||||
.map(|data| Identifier {
|
||||
id_type: Some(payments_grpc::identifier::IdType::EncodedData(
|
||||
data.to_string(),
|
||||
)),
|
||||
});
|
||||
|
||||
let connector_ref_id = router_data
|
||||
.request
|
||||
.connector_reference_id
|
||||
@ -60,7 +70,7 @@ impl ForeignTryFrom<&RouterData<PSync, PaymentsSyncData, PaymentsResponseData>>
|
||||
});
|
||||
|
||||
Ok(Self {
|
||||
transaction_id: connector_transaction_id,
|
||||
transaction_id: connector_transaction_id.or(encoded_data),
|
||||
request_ref_id: connector_ref_id,
|
||||
})
|
||||
}
|
||||
@ -319,6 +329,19 @@ impl ForeignTryFrom<&RouterData<Authorize, PaymentsAuthorizeData, PaymentsRespon
|
||||
}
|
||||
};
|
||||
|
||||
let capture_method = router_data
|
||||
.request
|
||||
.capture_method
|
||||
.map(payments_grpc::CaptureMethod::foreign_try_from)
|
||||
.transpose()?;
|
||||
|
||||
let browser_info = router_data
|
||||
.request
|
||||
.browser_info
|
||||
.clone()
|
||||
.map(payments_grpc::BrowserInformation::foreign_try_from)
|
||||
.transpose()?;
|
||||
|
||||
Ok(Self {
|
||||
request_ref_id: Some(Identifier {
|
||||
id_type: Some(payments_grpc::identifier::IdType::Id(
|
||||
@ -342,6 +365,13 @@ impl ForeignTryFrom<&RouterData<Authorize, PaymentsAuthorizeData, PaymentsRespon
|
||||
})
|
||||
.unwrap_or_default(),
|
||||
webhook_url: router_data.request.webhook_url.clone(),
|
||||
capture_method: capture_method.map(|capture_method| capture_method.into()),
|
||||
email: router_data
|
||||
.request
|
||||
.email
|
||||
.clone()
|
||||
.map(|e| e.expose().expose()),
|
||||
browser_info,
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -370,13 +400,11 @@ impl ForeignTryFrom<payments_grpc::PaymentServiceAuthorizeResponse>
|
||||
})
|
||||
});
|
||||
|
||||
let transaction_id = response.transaction_id.as_ref().and_then(|id| {
|
||||
id.id_type.clone().and_then(|id_type| match id_type {
|
||||
payments_grpc::identifier::IdType::Id(id) => Some(id),
|
||||
payments_grpc::identifier::IdType::EncodedData(encoded_data) => Some(encoded_data),
|
||||
payments_grpc::identifier::IdType::NoResponseIdMarker(_) => None,
|
||||
})
|
||||
});
|
||||
let resource_id: hyperswitch_domain_models::router_request_types::ResponseId = match response.transaction_id.as_ref().and_then(|id| id.id_type.clone()) {
|
||||
Some(payments_grpc::identifier::IdType::Id(id)) => hyperswitch_domain_models::router_request_types::ResponseId::ConnectorTransactionId(id),
|
||||
Some(payments_grpc::identifier::IdType::EncodedData(encoded_data)) => hyperswitch_domain_models::router_request_types::ResponseId::EncodedData(encoded_data),
|
||||
Some(payments_grpc::identifier::IdType::NoResponseIdMarker(_)) | None => hyperswitch_domain_models::router_request_types::ResponseId::NoResponseId,
|
||||
};
|
||||
|
||||
let (connector_metadata, redirection_data) = match response.redirection_data.clone() {
|
||||
Some(redirection_data) => match redirection_data.form_type {
|
||||
@ -423,13 +451,8 @@ impl ForeignTryFrom<payments_grpc::PaymentServiceAuthorizeResponse>
|
||||
})
|
||||
} else {
|
||||
Ok(PaymentsResponseData::TransactionResponse {
|
||||
resource_id: match transaction_id.as_ref() {
|
||||
Some(transaction_id) => hyperswitch_domain_models::router_request_types::ResponseId::ConnectorTransactionId(transaction_id.clone()),
|
||||
None => hyperswitch_domain_models::router_request_types::ResponseId::NoResponseId,
|
||||
},
|
||||
redirection_data: Box::new(
|
||||
redirection_data
|
||||
),
|
||||
resource_id,
|
||||
redirection_data: Box::new(redirection_data),
|
||||
mandate_reference: Box::new(None),
|
||||
connector_metadata,
|
||||
network_txn_id: response.network_txn_id.clone(),
|
||||
@ -469,6 +492,12 @@ impl ForeignTryFrom<payments_grpc::PaymentServiceGetResponse>
|
||||
|
||||
let status_code = convert_connector_service_status_code(response.status_code)?;
|
||||
|
||||
let resource_id: hyperswitch_domain_models::router_request_types::ResponseId = match response.transaction_id.as_ref().and_then(|id| id.id_type.clone()) {
|
||||
Some(payments_grpc::identifier::IdType::Id(id)) => hyperswitch_domain_models::router_request_types::ResponseId::ConnectorTransactionId(id),
|
||||
Some(payments_grpc::identifier::IdType::EncodedData(encoded_data)) => hyperswitch_domain_models::router_request_types::ResponseId::EncodedData(encoded_data),
|
||||
Some(payments_grpc::identifier::IdType::NoResponseIdMarker(_)) | None => hyperswitch_domain_models::router_request_types::ResponseId::NoResponseId,
|
||||
};
|
||||
|
||||
let response = if response.error_code.is_some() {
|
||||
Err(ErrorResponse {
|
||||
code: response.error_code().to_owned(),
|
||||
@ -483,21 +512,22 @@ impl ForeignTryFrom<payments_grpc::PaymentServiceGetResponse>
|
||||
})
|
||||
} else {
|
||||
Ok(PaymentsResponseData::TransactionResponse {
|
||||
resource_id: match connector_response_reference_id.as_ref() {
|
||||
Some(connector_response_reference_id) => hyperswitch_domain_models::router_request_types::ResponseId::ConnectorTransactionId(connector_response_reference_id.clone()),
|
||||
None => hyperswitch_domain_models::router_request_types::ResponseId::NoResponseId,
|
||||
},
|
||||
redirection_data: Box::new(
|
||||
None
|
||||
),
|
||||
mandate_reference: Box::new(None),
|
||||
resource_id,
|
||||
redirection_data: Box::new(None),
|
||||
mandate_reference: Box::new(response.mandate_reference.map(|grpc_mandate| {
|
||||
hyperswitch_domain_models::router_response_types::MandateReference {
|
||||
connector_mandate_id: grpc_mandate.mandate_id,
|
||||
payment_method_id: None,
|
||||
mandate_metadata: None,
|
||||
connector_mandate_request_reference_id: None,
|
||||
}
|
||||
})),
|
||||
connector_metadata: None,
|
||||
network_txn_id: response.network_txn_id.clone(),
|
||||
connector_response_reference_id,
|
||||
incremental_authorization_allowed: None,
|
||||
charges: None,
|
||||
}
|
||||
)
|
||||
})
|
||||
};
|
||||
|
||||
Ok(response)
|
||||
|
||||
Reference in New Issue
Block a user