diff --git a/crates/integrations/connector-integration/src/connectors/braintree/transformers.rs b/crates/integrations/connector-integration/src/connectors/braintree/transformers.rs index 9725d6c726..44a32049a3 100644 --- a/crates/integrations/connector-integration/src/connectors/braintree/transformers.rs +++ b/crates/integrations/connector-integration/src/connectors/braintree/transformers.rs @@ -15,7 +15,7 @@ use domain_types::{ connector_types::{ self, AmountInfo, ApplePayPaymentRequest, ApplePaySessionResponse, ApplepayClientAuthenticationResponse, ClientAuthenticationTokenData, - ClientAuthenticationTokenRequestData, GooglePaySessionResponse, + ClientAuthenticationTokenRequestData, ConnectorEnum, GooglePaySessionResponse, GpayAllowedMethodsParameters, GpayAllowedPaymentMethods, GpayClientAuthenticationResponse, GpayMerchantInfo, GpayShippingAddressParameters, GpayTokenParameters, GpayTokenizationSpecification, GpayTransactionInfo, MandateReference, NextActionCall, @@ -2111,7 +2111,7 @@ impl TryFrom> required_shipping_contact_fields: None, recurring_payment_request: None, }), - connector: BRAINTREE_CONNECTOR_NAME.to_string(), + connector: ConnectorEnum::Braintree, delayed_session_token: false, sdk_next_action: SdkNextAction { next_action: NextActionCall::Confirm, diff --git a/crates/integrations/connector-integration/src/connectors/trustpay/transformers.rs b/crates/integrations/connector-integration/src/connectors/trustpay/transformers.rs index 91cb2aaffb..f53d1b4e4f 100644 --- a/crates/integrations/connector-integration/src/connectors/trustpay/transformers.rs +++ b/crates/integrations/connector-integration/src/connectors/trustpay/transformers.rs @@ -19,7 +19,7 @@ use domain_types::{ }, connector_types::{ AmountInfo, ApplePayPaymentRequest, ApplePaySessionResponse, - ApplepayClientAuthenticationResponse, ClientAuthenticationTokenData, + ApplepayClientAuthenticationResponse, ClientAuthenticationTokenData, ConnectorEnum, GooglePaySessionResponse, GpayAllowedPaymentMethods, GpayClientAuthenticationResponse, GpayMerchantInfo, GpayShippingAddressParameters, MandateReference, MandateReferenceId, NextActionCall, PaymentCreateOrderData, PaymentCreateOrderResponse, PaymentFlowData, @@ -2485,7 +2485,7 @@ pub(crate) fn get_apple_pay_session( required_shipping_contact_fields: None, recurring_payment_request: None, }), - connector: "trustpay".to_string(), + connector: ConnectorEnum::Trustpay, delayed_session_token: true, sdk_next_action: { SdkNextAction { diff --git a/crates/types-traits/domain_types/src/connector_types.rs b/crates/types-traits/domain_types/src/connector_types.rs index ea042f94f9..dfaea12971 100644 --- a/crates/types-traits/domain_types/src/connector_types.rs +++ b/crates/types-traits/domain_types/src/connector_types.rs @@ -5362,7 +5362,7 @@ pub struct ApplepayClientAuthenticationResponse { /// Payment request object for Apple Pay pub payment_request_data: Option, /// The session token is w.r.t this connector - pub connector: String, + pub connector: ConnectorEnum, /// Identifier for the delayed session response pub delayed_session_token: bool, /// The next action for the sdk (ex: calling confirm or sync call) diff --git a/crates/types-traits/domain_types/src/types.rs b/crates/types-traits/domain_types/src/types.rs index 914ecfbb47..abebabd3c5 100644 --- a/crates/types-traits/domain_types/src/types.rs +++ b/crates/types-traits/domain_types/src/types.rs @@ -15389,7 +15389,7 @@ pub fn generate_payment_sdk_session_token_response( let apple_pay_response = grpc_api_types::payments::ApplepayClientAuthenticationResponse { session_response: apple_pay_token.session_response.map(grpc_api_types::payments::ApplePaySessionResponse::foreign_try_from).transpose()?, payment_request_data: apple_pay_token.payment_request_data.map(grpc_api_types::payments::ApplePayPaymentRequest::foreign_try_from).transpose()?, - connector: apple_pay_token.connector, + connector: grpc_api_types::payments::Connector::foreign_try_from(apple_pay_token.connector)?.into(), delayed_session_token: apple_pay_token.delayed_session_token, sdk_next_action: grpc_api_types::payments::SdkNextAction::from(apple_pay_token.sdk_next_action.next_action).into(), connector_reference_id: apple_pay_token.connector_reference_id, @@ -15587,6 +15587,27 @@ impl From for grpc_api_types::payments::GpayBillingAdd } } +impl ForeignTryFrom for grpc_api_types::payments::Connector { + type Error = ConnectorError; + + fn foreign_try_from( + connector: ConnectorEnum, + ) -> Result> { + // `ConnectorEnum` spells its variants in snake_case and the proto spells the same + // names in SCREAMING_SNAKE_CASE, which is what `from_str_name` matches on. + let grpc_connector = Self::from_str_name(&connector.to_string().to_ascii_uppercase()) + .ok_or_else(|| ConnectorError::UnexpectedResponseError { + context: ResponseTransformationErrorContext { + http_status_code: None, + additional_context: Some(format!( + "Connector {connector} has no matching variant in the proto Connector enum" + )), + }, + })?; + Ok(grpc_connector) + } +} + impl ForeignTryFrom for grpc_api_types::payments::ApplePaySessionResponse { type Error = ConnectorError; @@ -15714,7 +15735,10 @@ impl ForeignTryFrom .payment_request_data .map(grpc_api_types::payments::ApplePayPaymentRequest::foreign_try_from) .transpose()?, - connector: apple_pay_token.connector, + connector: grpc_api_types::payments::Connector::foreign_try_from( + apple_pay_token.connector, + )? + .into(), delayed_session_token: apple_pay_token.delayed_session_token, sdk_next_action: grpc_api_types::payments::SdkNextAction::from( apple_pay_token.sdk_next_action.next_action, @@ -18501,3 +18525,32 @@ impl From for grpc_api_types::payment } } } + +#[cfg(test)] +mod tests { + use super::*; + + /// `ApplepayClientAuthenticationResponse.connector` is a proto `Connector` rather than a + /// free-form string, so the two connectors that build an Apple Pay session token have to + /// land on the right proto variant. The mapping goes through the SCREAMING_SNAKE_CASE + /// name, which is easy to break by renaming either side. + #[test] + fn apple_pay_session_connectors_map_to_their_proto_variants() { + for (connector, expected) in [ + ( + ConnectorEnum::Braintree, + grpc_api_types::payments::Connector::Braintree, + ), + ( + ConnectorEnum::Trustpay, + grpc_api_types::payments::Connector::Trustpay, + ), + ] { + assert_eq!( + grpc_api_types::payments::Connector::foreign_try_from(connector).ok(), + Some(expected), + "{connector} does not map onto its proto Connector variant" + ); + } + } +} diff --git a/crates/types-traits/grpc-api-types/proto/payment.proto b/crates/types-traits/grpc-api-types/proto/payment.proto index 82b810553e..cc746d9729 100644 --- a/crates/types-traits/grpc-api-types/proto/payment.proto +++ b/crates/types-traits/grpc-api-types/proto/payment.proto @@ -2367,7 +2367,7 @@ message GpayTransactionInfo { message ApplepayClientAuthenticationResponse { optional ApplePaySessionResponse session_response = 1; ApplePayPaymentRequest payment_request_data = 2; - string connector = 3; + Connector connector = 3; bool delayed_session_token = 4; SdkNextAction sdk_next_action = 5; optional string connector_reference_id = 6;