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:
Saptak Dutta
2025-08-13 16:34:06 +05:30
committed by GitHub
parent 97b45f7027
commit 0821d1b0cd
8 changed files with 116 additions and 30 deletions

View File

@ -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";

View File

@ -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)

View File

@ -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)