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(revenue_recovery): [chargebee] populate card info from payment_method_details for wallet payment methods (#14323)
CHALLA NISHANTH BABUbfb7e37e35ff
diff --git a/crates/hyperswitch_connectors/src/connectors/chargebee/transformers.rs b/crates/hyperswitch_connectors/src/connectors/chargebee/transformers.rsindex 9074027e65..79eaedc433 100644--- a/crates/hyperswitch_connectors/src/connectors/chargebee/transformers.rs+++ b/crates/hyperswitch_connectors/src/connectors/chargebee/transformers.rs@@ -431,6 +431,7 @@ pub struct ChargebeeWebhookContent {pub invoice: ChargebeeInvoiceData,pub customer: Option<ChargebeeCustomer>,pub subscription: Option<ChargebeeSubscriptionData>,+ pub card: Option<ChargebeeCardDetails>,}#[derive(Serialize, Deserialize, Debug)]@@ -587,26 +588,6 @@ impl ChargebeeTransactionPaymentMethod {Self::Other => None,}}-- fn parse_payment_method_details(- self,- raw_details: &str,- ) -> Result<ChargebeePaymentMethodDetails, error_stack::Report<errors::ConnectorError>> {- match self {- Self::Card | Self::UnionPay | Self::SouthKoreanCards => {- let details: ChargebeeCardPaymentMethodDetails = serde_json::from_str(raw_details)- .change_context(errors::ConnectorError::WebhookBodyDecodingFailed)?;- Ok(ChargebeePaymentMethodDetails::Card(details.card))- }- _ => Ok(ChargebeePaymentMethodDetails::NonCard),- }- }-}--#[derive(Debug)]-pub enum ChargebeePaymentMethodDetails {- Card(ChargebeeCardDetails),- NonCard,}#[cfg(all(feature = "revenue_recovery", feature = "v2"))]@@ -615,11 +596,25 @@ struct ChargebeeCardPaymentMethodDetails {card: ChargebeeCardDetails,}+#[cfg(all(feature = "revenue_recovery", feature = "v2"))]+impl ChargebeeCardPaymentMethodDetails {+ fn parse_card_details(raw_details: &str) -> Option<ChargebeeCardDetails> {+ serde_json::from_str::<Self>(raw_details)+ .ok()+ .map(|details| details.card)+ }+}+#[derive(Serialize, Deserialize, Debug)]pub struct ChargebeeCardDetails {- funding_type: ChargebeeFundingType,- brand: ChargebeeCardBrand,- iin: String,+ funding_type: Option<ChargebeeFundingType>,+ // `payment_method_details` names the network `brand`, the `card` resource names it `card_type`.+ #[serde(alias = "card_type")]+ brand: Option<ChargebeeCardBrand>,+ iin: Option<String>,+ last4: Option<String>,+ expiry_month: Option<u8>,+ expiry_year: Option<u16>,}// Chargebee sends card brand values in lowercase snake_case (e.g. `visa`, `mastercard`,@@ -673,7 +668,7 @@ impl From<ChargebeeCardBrand> for Option<common_enums::CardNetwork> {}}-#[derive(Serialize, Deserialize, Debug)]+#[derive(Serialize, Deserialize, Debug, Clone, Copy)]#[serde(rename_all = "snake_case")]pub enum ChargebeeFundingType {Credit,@@ -860,33 +855,37 @@ impl TryFrom<ChargebeeWebhookBody> for revenue_recovery::RevenueRecoveryAttemptDlet transaction_created_at = item.content.transaction.date;let status = enums::AttemptStatus::from(item.content.transaction.status);let chargebee_payment_method = item.content.transaction.payment_method;- let payment_method_type = enums::PaymentMethod::try_from(chargebee_payment_method)?;- let payment_method_details = item+ let payment_method_type = enums::PaymentMethod::try_from(chargebee_payment_method)+ .unwrap_or(enums::PaymentMethod::Card);+ let card_details = item.content.transaction.payment_method_details.as_deref()- .map(|raw_details| chargebee_payment_method.parse_payment_method_details(raw_details))- .transpose()?;- let (payment_method_sub_type, card_info) = match payment_method_details {- Some(ChargebeePaymentMethodDetails::Card(card)) => (- enums::PaymentMethodType::from(card.funding_type),- api_models::payments::AdditionalCardInfo {- card_network: card.brand.into(),- card_isin: Some(card.iin),- ..Default::default()- },- ),- Some(ChargebeePaymentMethodDetails::NonCard) | None => (- chargebee_payment_method.payment_method_sub_type().ok_or(- errors::ConnectorError::NotSupported {- message: "payment method in revenue recovery webhook".to_string(),- connector: "chargebee",- },- )?,- api_models::payments::AdditionalCardInfo::default(),- ),- };+ .and_then(ChargebeeCardPaymentMethodDetails::parse_card_details)+ .or(item.content.card);+ let payment_method_sub_type = chargebee_payment_method+ .payment_method_sub_type()+ .or_else(|| {+ card_details+ .as_ref()+ .and_then(|card| card.funding_type)+ .map(enums::PaymentMethodType::from)+ })+ .unwrap_or(enums::PaymentMethodType::Card);+ let card_info = card_details+ .map(|card| api_models::payments::AdditionalCardInfo {+ card_network: card.brand.and_then(Into::into),+ funding_source: card.funding_type.and_then(Into::into),+ card_exp_month: card+ .expiry_month+ .map(|month| Secret::new(format!("{month:02}"))),+ card_exp_year: card.expiry_year.map(|year| Secret::new(year.to_string())),+ last4: card.last4,+ card_isin: card.iin,+ ..Default::default()+ })+ .unwrap_or_default();// Chargebee retry count will always be less than u16 always. Chargebee can have maximum 12 retry attempts#[allow(clippy::as_conversions)]let retry_count = item@@ -1000,6 +999,19 @@ impl TryFrom<ChargebeeTransactionPaymentMethod> for enums::PaymentMethod {}}+impl From<ChargebeeFundingType> for Option<common_enums::FundingSource> {+ fn from(funding_type: ChargebeeFundingType) -> Self {+ match funding_type {+ ChargebeeFundingType::Credit => Some(common_enums::FundingSource::Credit),+ ChargebeeFundingType::Debit => Some(common_enums::FundingSource::Debit),+ ChargebeeFundingType::Prepaid => Some(common_enums::FundingSource::Prepaid),+ ChargebeeFundingType::NotKnown+ | ChargebeeFundingType::NotApplicable+ | ChargebeeFundingType::Other => None,+ }+ }+}+impl From<ChargebeeFundingType> for enums::PaymentMethodType {fn from(funding_type: ChargebeeFundingType) -> Self {match funding_type {