Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -2111,7 +2111,7 @@ impl<F> TryFrom<ResponseRouterData<BraintreeSessionResponse, Self>>
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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion crates/types-traits/domain_types/src/connector_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5362,7 +5362,7 @@ pub struct ApplepayClientAuthenticationResponse {
/// Payment request object for Apple Pay
pub payment_request_data: Option<ApplePayPaymentRequest>,
/// The session token is w.r.t this connector
pub connector: String,
pub connector: ConnectorEnum,
/// Identifier for the delayed session response
Comment on lines 5363 to 5366
pub delayed_session_token: bool,
/// The next action for the sdk (ex: calling confirm or sync call)
Expand Down
57 changes: 55 additions & 2 deletions crates/types-traits/domain_types/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -15587,6 +15587,27 @@ impl From<GpayBillingAddressFormat> for grpc_api_types::payments::GpayBillingAdd
}
}

impl ForeignTryFrom<ConnectorEnum> for grpc_api_types::payments::Connector {
type Error = ConnectorError;

fn foreign_try_from(
connector: ConnectorEnum,
) -> Result<Self, error_stack::Report<Self::Error>> {
// `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<ApplePaySessionResponse> for grpc_api_types::payments::ApplePaySessionResponse {
type Error = ConnectorError;

Expand Down Expand Up @@ -15714,7 +15735,10 @@ impl ForeignTryFrom<ClientAuthenticationTokenData>
.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,
Expand Down Expand Up @@ -18501,3 +18525,32 @@ impl From<connector_types::WebhookResourceReference> 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"
);
}
}
}
2 changes: 1 addition & 1 deletion crates/types-traits/grpc-api-types/proto/payment.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading