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): Add invoice number and email in AuthorizeDotNet connector (#7726)
Anuragc2f9658c9d8a
diff --git a/crates/hyperswitch_connectors/src/connectors/authorizedotnet/transformers.rs b/crates/hyperswitch_connectors/src/connectors/authorizedotnet/transformers.rsindex bb93d9279d..9bd809c124 100644--- a/crates/hyperswitch_connectors/src/connectors/authorizedotnet/transformers.rs+++ b/crates/hyperswitch_connectors/src/connectors/authorizedotnet/transformers.rs@@ -5,6 +5,7 @@ use common_enums::enums;use common_utils::{errors::CustomResult,ext_traits::{Encode, OptionExt, ValueExt},+ pii::Email,request::Method,};use error_stack::ResultExt;@@ -36,6 +37,12 @@ use crate::{},};+const MAX_ID_LENGTH: usize = 20;++fn get_random_string() -> String {+ Alphanumeric.sample_string(&mut rand::thread_rng(), MAX_ID_LENGTH)+}+#[derive(Debug, Serialize)]pub enum TransactionType {#[serde(rename = "authCaptureTransaction")]@@ -207,6 +214,7 @@ struct PaymentProfileDetails {#[serde(rename_all = "camelCase")]pub struct CustomerDetails {id: String,+ email: Option<Email>,}#[derive(Debug, Serialize)]@@ -230,6 +238,7 @@ pub struct BillTo {#[derive(Debug, Serialize)]#[serde(rename_all = "camelCase")]pub struct Order {+ invoice_number: String,description: String,}@@ -611,7 +620,7 @@ impl TryFrom<&AuthorizedotnetRouterData<&PaymentsAuthorizeRouterData>>let merchant_authentication =AuthorizedotnetAuthType::try_from(&item.router_data.connector_auth_type)?;- let ref_id = if item.router_data.connector_request_reference_id.len() <= 20 {+ let ref_id = if item.router_data.connector_request_reference_id.len() <= MAX_ID_LENGTH {Some(item.router_data.connector_request_reference_id.clone())} else {None@@ -727,9 +736,17 @@ impl}),profile: None,order: Order {+ invoice_number: get_random_string(),description: item.router_data.connector_request_reference_id.clone(),},- customer: None,+ customer: Some(CustomerDetails {+ id: if item.router_data.payment_id.len() <= MAX_ID_LENGTH {+ item.router_data.payment_id.clone()+ } else {+ get_random_string()+ },+ email: item.router_data.request.get_optional_email(),+ }),bill_to: item.router_data.get_optional_billing()@@ -798,9 +815,17 @@ impl})}),order: Order {+ invoice_number: get_random_string(),description: item.router_data.connector_request_reference_id.clone(),},- customer: None,+ customer: Some(CustomerDetails {+ id: if item.router_data.payment_id.len() <= MAX_ID_LENGTH {+ item.router_data.payment_id.clone()+ } else {+ get_random_string()+ },+ email: item.router_data.request.get_optional_email(),+ }),bill_to: None,user_fields: match item.router_data.request.metadata.clone() {Some(metadata) => Some(UserFields {@@ -835,24 +860,21 @@ impl&Card,),) -> Result<Self, Self::Error> {- let (profile, customer) = if item.router_data.request.is_mandate_payment() {- (- Some(ProfileDetails::CreateProfileDetails(CreateProfileDetails {- create_profile: true,- })),- Some(CustomerDetails {- //The payment ID is included in the customer details because the connector requires unique customer information with a length of fewer than 20 characters when creating a mandate.- //If the length exceeds 20 characters, a random alphanumeric string is used instead.- id: if item.router_data.payment_id.len() <= 20 {- item.router_data.payment_id.clone()- } else {- Alphanumeric.sample_string(&mut rand::thread_rng(), 20)- },- }),- )- } else {- (None, None)- };+ let (profile, customer) = (+ Some(ProfileDetails::CreateProfileDetails(CreateProfileDetails {+ create_profile: true,+ })),+ Some(CustomerDetails {+ //The payment ID is included in the customer details because the connector requires unique customer information with a length of fewer than 20 characters when creating a mandate.+ //If the length exceeds 20 characters, a random alphanumeric string is used instead.+ id: if item.router_data.payment_id.len() <= MAX_ID_LENGTH {+ item.router_data.payment_id.clone()+ } else {+ get_random_string()+ },+ email: item.router_data.request.get_optional_email(),+ }),+ );Ok(Self {transaction_type: TransactionType::try_from(item.router_data.request.capture_method)?,amount: item.amount,@@ -864,6 +886,7 @@ impl})),profile,order: Order {+ invoice_number: get_random_string(),description: item.router_data.connector_request_reference_id.clone(),},customer,@@ -911,23 +934,19 @@ impl&WalletData,),) -> Result<Self, Self::Error> {- let (profile, customer) = if item.router_data.request.is_mandate_payment() {- (- Some(ProfileDetails::CreateProfileDetails(CreateProfileDetails {- create_profile: true,- })),- Some(CustomerDetails {- id: if item.router_data.payment_id.len() <= 20 {- item.router_data.payment_id.clone()- } else {- Alphanumeric.sample_string(&mut rand::thread_rng(), 20)- },- }),- )- } else {- (None, None)- };-+ let (profile, customer) = (+ Some(ProfileDetails::CreateProfileDetails(CreateProfileDetails {+ create_profile: true,+ })),+ Some(CustomerDetails {+ id: if item.router_data.payment_id.len() <= MAX_ID_LENGTH {+ item.router_data.payment_id.clone()+ } else {+ get_random_string()+ },+ email: item.router_data.request.get_optional_email(),+ }),+ );Ok(Self {transaction_type: TransactionType::try_from(item.router_data.request.capture_method)?,amount: item.amount,@@ -938,6 +957,7 @@ impl)?),profile,order: Order {+ invoice_number: get_random_string(),description: item.router_data.connector_request_reference_id.clone(),},customer,