Open source, composable payments platform | PCI compliant | SaaS and Self-host options | Enables connectivity to multiple payment, payout, fraud, vault and tokenization providers | Uplifts authorization with intelligent routing and revenue recovery | Reduce payment processing costs with cost observability | Reduces payment ops with reconciliation
Rust adyenbeginner-friendlyfeaturedfinancefintechhacktoberfesthigh-performanceopen-sourceorchestrationpaymentpayment-gatewaypayment-integrationpayment-processingpaymentspayments-platformrestful-apirustsdkstripeworks-with-react
feat(connector): [airwallex] add extended authorization (#12825)
Akshaya Shankar9e41693371ff
diff --git a/crates/hyperswitch_connectors/src/connectors/airwallex/transformers.rs b/crates/hyperswitch_connectors/src/connectors/airwallex/transformers.rsindex eb1023d325..e3a59b4225 100644--- a/crates/hyperswitch_connectors/src/connectors/airwallex/transformers.rs+++ b/crates/hyperswitch_connectors/src/connectors/airwallex/transformers.rs@@ -1,4 +1,5 @@use common_enums::enums;+use common_types::primitive_wrappers;use common_utils::{errors::ParsingError,ext_traits::ValueExt,@@ -12,7 +13,10 @@ use hyperswitch_domain_models::{payment_method_data::{BankRedirectData, BankTransferData, PayLaterData, PaymentMethodData, WalletData,},- router_data::{AccessToken, ConnectorAuthType, RouterData},+ router_data::{+ AccessToken, ConnectorAuthType, ConnectorResponseData, ExtendedAuthorizationResponseData,+ RouterData,+ },router_flow_types::{refunds::{Execute, RSync},PSync,@@ -34,8 +38,8 @@ use uuid::Uuid;use crate::{types::{CreateOrderResponseRouterData, RefundsResponseRouterData, ResponseRouterData},utils::{- self, BrowserInformationData, CardData as _, ForeignTryFrom, PaymentsAuthorizeRequestData,- PhoneDetailsData, RouterData as _,+ self, BrowserInformationData, CardData as _, ExtendedAuthorizationData, ForeignTryFrom,+ PaymentsAuthorizeRequestData, PhoneDetailsData, RouterData as _,},};@@ -492,6 +496,14 @@ pub enum AirwallexPaymentOptions {#[derive(Debug, Serialize)]pub struct AirwallexCardPaymentOptions {auto_capture: bool,+ authorization_type: Option<AirwallexCardAuthorizationType>,+}++#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]+#[serde(rename_all = "snake_case")]+pub enum AirwallexCardAuthorizationType {+ PreAuth,+ FinalAuth,}#[derive(Debug, Serialize)]@@ -518,6 +530,15 @@ impl TryFrom<&AirwallexRouterData<&types::PaymentsAuthorizeRouterData>>| Some(enums::CaptureMethod::SequentialAutomatic)| None),+ authorization_type: item+ .router_data+ .request+ .request_extended_authorization+ .and_then(|extended_authorization| {+ extended_authorization+ .is_true()+ .then_some(AirwallexCardAuthorizationType::PreAuth)+ }),}));Ok(AirwallexPaymentMethod::Card(AirwallexCard {card: AirwallexCardDetails {@@ -1249,6 +1270,8 @@ fn get_redirection_form(response_url_data: AirwallexPaymentsNextAction) -> Optioimpl<F, T>ForeignTryFrom<ResponseRouterData<F, AirwallexAuthorizeResponse, T, PaymentsResponseData>>for RouterData<F, T, PaymentsResponseData>+where+ T: ExtendedAuthorizationData,{type Error = error_stack::Report<errors::ConnectorError>;fn foreign_try_from(@@ -1291,6 +1314,8 @@ impl<F, T>impl<F, T> TryFrom<ResponseRouterData<F, AirwallexPaymentsResponse, T, PaymentsResponseData>>for RouterData<F, T, PaymentsResponseData>+where+ T: ExtendedAuthorizationData,{type Error = error_stack::Report<errors::ConnectorError>;fn try_from(@@ -1365,11 +1390,23 @@ impl<F, T> TryFrom<ResponseRouterData<F, AirwallexPaymentsResponse, T, PaymentsRmandate_metadata: item.response.latest_payment_attempt+ .clone().and_then(|attempt| attempt.payment_method).map(|pm| Secret::new(serde_json::json!(AirwallexMandateMetadata { id: pm.id }))),connector_mandate_request_reference_id: None,}));+ let connector_response = item+ .data+ .request+ .extended_authorization_requested()+ .and_then(|request_extended_authorization| {+ build_airwallex_connector_response_data(+ request_extended_authorization,+ item.data.payment_method,+ )+ });+Ok(Self {status,reference_id: Some(item.response.id.clone()),@@ -1385,6 +1422,7 @@ impl<F, T> TryFrom<ResponseRouterData<F, AirwallexPaymentsResponse, T, PaymentsRauthentication_data: None,charges: None,}),+ connector_response,..item.data})}@@ -1978,3 +2016,33 @@ impl<F, T> TryFrom<ResponseRouterData<F, AirwallexCustomerResponse, T, PaymentsR})}}++fn build_airwallex_connector_response_data(+ extended_authorization_requested: primitive_wrappers::RequestExtendedAuthorizationBool,+ payment_method: enums::PaymentMethod,+) -> Option<ConnectorResponseData> {+ let extended_authentication_applicable = matches!(payment_method, enums::PaymentMethod::Card);+ let extended_authentication_applied =+ if extended_authorization_requested.is_true() && extended_authentication_applicable {+ Some(primitive_wrappers::ExtendedAuthorizationAppliedBool::from(+ true,+ ))+ } else if extended_authorization_requested.is_true() {+ Some(primitive_wrappers::ExtendedAuthorizationAppliedBool::from(+ false,+ ))+ } else {+ None+ };++ Some(ConnectorResponseData::new(+ None,+ None,+ Some(ExtendedAuthorizationResponseData {+ extended_authentication_applied,+ capture_before: None,+ extended_authorization_last_applied_at: None,+ }),+ None,+ ))+}diff --git a/crates/hyperswitch_connectors/src/utils.rs b/crates/hyperswitch_connectors/src/utils.rsindex e80b4aa1ee..db51a92137 100644--- a/crates/hyperswitch_connectors/src/utils.rs+++ b/crates/hyperswitch_connectors/src/utils.rs@@ -32,6 +32,7 @@ use common_enums::{UsStatesAbbreviation,},};+use common_types::primitive_wrappers;use common_utils::{consts::{BASE64_ENGINE, BASE64_ENGINE_STD_NO_PAD, BASE64_ENGINE_URL_SAFE,@@ -8215,3 +8216,49 @@ macro_rules! convert_connector_response_to_domain_response {}};}++pub trait ExtendedAuthorizationData {+ fn extended_authorization_requested(+ &self,+ ) -> Option<primitive_wrappers::RequestExtendedAuthorizationBool>;+}++impl ExtendedAuthorizationData for PaymentsAuthorizeData {+ fn extended_authorization_requested(+ &self,+ ) -> Option<primitive_wrappers::RequestExtendedAuthorizationBool> {+ self.request_extended_authorization+ }+}++impl ExtendedAuthorizationData for PaymentsSyncData {+ fn extended_authorization_requested(+ &self,+ ) -> Option<primitive_wrappers::RequestExtendedAuthorizationBool> {+ None+ }+}++impl ExtendedAuthorizationData for PaymentsCaptureData {+ fn extended_authorization_requested(+ &self,+ ) -> Option<primitive_wrappers::RequestExtendedAuthorizationBool> {+ None+ }+}++impl ExtendedAuthorizationData for CompleteAuthorizeData {+ fn extended_authorization_requested(+ &self,+ ) -> Option<primitive_wrappers::RequestExtendedAuthorizationBool> {+ None+ }+}++impl ExtendedAuthorizationData for PaymentsCancelData {+ fn extended_authorization_requested(+ &self,+ ) -> Option<primitive_wrappers::RequestExtendedAuthorizationBool> {+ None+ }+}