mirror of
				https://github.com/juspay/hyperswitch.git
				synced 2025-11-01 02:57:02 +08:00 
			
		
		
		
	feat(router): [cybersource] add disable_avs and disable_cvn flag in connector metadata (#5667)
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
This commit is contained in:
		| @ -54,6 +54,23 @@ impl<T> TryFrom<(&api::CurrencyUnit, enums::Currency, i64, T)> for CybersourceRo | ||||
|     } | ||||
| } | ||||
|  | ||||
| #[derive(Debug, Default, Serialize, Deserialize)] | ||||
| pub struct CybersourceConnectorMetadataObject { | ||||
|     pub disable_avs: Option<bool>, | ||||
|     pub disable_cvn: Option<bool>, | ||||
| } | ||||
|  | ||||
| impl TryFrom<&Option<pii::SecretSerdeValue>> for CybersourceConnectorMetadataObject { | ||||
|     type Error = error_stack::Report<errors::ConnectorError>; | ||||
|     fn try_from(meta_data: &Option<pii::SecretSerdeValue>) -> Result<Self, Self::Error> { | ||||
|         let metadata = utils::to_connector_meta_from_secret::<Self>(meta_data.clone()) | ||||
|             .change_context(errors::ConnectorError::InvalidConnectorConfig { | ||||
|                 config: "metadata", | ||||
|             })?; | ||||
|         Ok(metadata) | ||||
|     } | ||||
| } | ||||
|  | ||||
| #[derive(Debug, Serialize)] | ||||
| #[serde(rename_all = "camelCase")] | ||||
| pub struct CybersourceZeroMandateRequest { | ||||
| @ -76,6 +93,9 @@ impl TryFrom<&types::SetupMandateRouterData> for CybersourceZeroMandateRequest { | ||||
|             }, | ||||
|             bill_to: Some(bill_to), | ||||
|         }; | ||||
|         let connector_merchant_config = | ||||
|             CybersourceConnectorMetadataObject::try_from(&item.connector_meta_data)?; | ||||
|  | ||||
|         let (action_list, action_token_types, authorization_options) = ( | ||||
|             Some(vec![CybersourceActionsList::TokenCreate]), | ||||
|             Some(vec![ | ||||
| @ -89,6 +109,8 @@ impl TryFrom<&types::SetupMandateRouterData> for CybersourceZeroMandateRequest { | ||||
|                     stored_credential_used: None, | ||||
|                 }), | ||||
|                 merchant_intitiated_transaction: None, | ||||
|                 ignore_avs_result: connector_merchant_config.disable_avs, | ||||
|                 ignore_cv_result: connector_merchant_config.disable_cvn, | ||||
|             }), | ||||
|         ); | ||||
|  | ||||
| @ -310,6 +332,8 @@ pub enum CybersourceActionsTokenType { | ||||
| pub struct CybersourceAuthorizationOptions { | ||||
|     initiator: Option<CybersourcePaymentInitiator>, | ||||
|     merchant_intitiated_transaction: Option<MerchantInitiatedTransaction>, | ||||
|     ignore_avs_result: Option<bool>, | ||||
|     ignore_cv_result: Option<bool>, | ||||
| } | ||||
|  | ||||
| #[derive(Debug, Serialize)] | ||||
| @ -548,6 +572,9 @@ impl | ||||
|             .unwrap_or("internet") | ||||
|             .to_string(); | ||||
|  | ||||
|         let connector_merchant_config = | ||||
|             CybersourceConnectorMetadataObject::try_from(&item.router_data.connector_meta_data)?; | ||||
|  | ||||
|         let (action_list, action_token_types, authorization_options) = if item | ||||
|             .router_data | ||||
|             .request | ||||
| @ -576,6 +603,8 @@ impl | ||||
|                         credential_stored_on_file: Some(true), | ||||
|                         stored_credential_used: None, | ||||
|                     }), | ||||
|                     ignore_avs_result: connector_merchant_config.disable_avs, | ||||
|                     ignore_cv_result: connector_merchant_config.disable_cvn, | ||||
|                     merchant_intitiated_transaction: None, | ||||
|                 }), | ||||
|             ) | ||||
| @ -624,6 +653,8 @@ impl | ||||
|                                 original_authorized_amount, | ||||
|                                 previous_transaction_id: None, | ||||
|                             }), | ||||
|                             ignore_avs_result: connector_merchant_config.disable_avs, | ||||
|                             ignore_cv_result: connector_merchant_config.disable_cvn, | ||||
|                         }), | ||||
|                     ) | ||||
|                 } | ||||
| @ -690,13 +721,24 @@ impl | ||||
|                                 original_authorized_amount, | ||||
|                                 previous_transaction_id: Some(Secret::new(network_transaction_id)), | ||||
|                             }), | ||||
|                             ignore_avs_result: connector_merchant_config.disable_avs, | ||||
|                             ignore_cv_result: connector_merchant_config.disable_cvn, | ||||
|                         }), | ||||
|                     ) | ||||
|                 } | ||||
|                 None => (None, None, None), | ||||
|             } | ||||
|         } else { | ||||
|             (None, None, None) | ||||
|             ( | ||||
|                 None, | ||||
|                 None, | ||||
|                 Some(CybersourceAuthorizationOptions { | ||||
|                     initiator: None, | ||||
|                     merchant_intitiated_transaction: None, | ||||
|                     ignore_avs_result: connector_merchant_config.disable_avs, | ||||
|                     ignore_cv_result: connector_merchant_config.disable_cvn, | ||||
|                 }), | ||||
|             ) | ||||
|         }; | ||||
|         // this logic is for external authenticated card | ||||
|         let commerce_indicator_for_external_authentication = item | ||||
| @ -778,19 +820,23 @@ fn get_commerce_indicator_for_external_authentication( | ||||
| } | ||||
|  | ||||
| impl | ||||
|     From<( | ||||
|     TryFrom<( | ||||
|         &CybersourceRouterData<&types::PaymentsCompleteAuthorizeRouterData>, | ||||
|         Option<PaymentSolution>, | ||||
|         &CybersourceConsumerAuthValidateResponse, | ||||
|     )> for ProcessingInformation | ||||
| { | ||||
|     fn from( | ||||
|     type Error = error_stack::Report<errors::ConnectorError>; | ||||
|     fn try_from( | ||||
|         (item, solution, three_ds_data): ( | ||||
|             &CybersourceRouterData<&types::PaymentsCompleteAuthorizeRouterData>, | ||||
|             Option<PaymentSolution>, | ||||
|             &CybersourceConsumerAuthValidateResponse, | ||||
|         ), | ||||
|     ) -> Self { | ||||
|     ) -> Result<Self, Self::Error> { | ||||
|         let connector_merchant_config = | ||||
|             CybersourceConnectorMetadataObject::try_from(&item.router_data.connector_meta_data)?; | ||||
|  | ||||
|         let (action_list, action_token_types, authorization_options) = if item | ||||
|             .router_data | ||||
|             .request | ||||
| @ -813,12 +859,14 @@ impl | ||||
|                         stored_credential_used: None, | ||||
|                     }), | ||||
|                     merchant_intitiated_transaction: None, | ||||
|                     ignore_avs_result: connector_merchant_config.disable_avs, | ||||
|                     ignore_cv_result: connector_merchant_config.disable_cvn, | ||||
|                 }), | ||||
|             ) | ||||
|         } else { | ||||
|             (None, None, None) | ||||
|         }; | ||||
|         Self { | ||||
|         Ok(Self { | ||||
|             capture: Some(matches!( | ||||
|                 item.router_data.request.capture_method, | ||||
|                 Some(enums::CaptureMethod::Automatic) | None | ||||
| @ -832,7 +880,7 @@ impl | ||||
|                 .indicator | ||||
|                 .to_owned() | ||||
|                 .unwrap_or(String::from("internet")), | ||||
|         } | ||||
|         }) | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -1100,7 +1148,7 @@ impl | ||||
|             })?; | ||||
|  | ||||
|         let processing_information = | ||||
|             ProcessingInformation::from((item, None, &three_ds_info.three_ds_data)); | ||||
|             ProcessingInformation::try_from((item, None, &three_ds_info.three_ds_data))?; | ||||
|  | ||||
|         let consumer_authentication_information = Some(CybersourceConsumerAuthInformation { | ||||
|             ucaf_collection_indicator: three_ds_info.three_ds_data.ucaf_collection_indicator, | ||||
| @ -1585,6 +1633,9 @@ impl TryFrom<&CybersourceRouterData<&types::PaymentsIncrementalAuthorizationRout | ||||
|     fn try_from( | ||||
|         item: &CybersourceRouterData<&types::PaymentsIncrementalAuthorizationRouterData>, | ||||
|     ) -> Result<Self, Self::Error> { | ||||
|         let connector_merchant_config = | ||||
|             CybersourceConnectorMetadataObject::try_from(&item.router_data.connector_meta_data)?; | ||||
|  | ||||
|         Ok(Self { | ||||
|             processing_information: ProcessingInformation { | ||||
|                 action_list: None, | ||||
| @ -1600,6 +1651,8 @@ impl TryFrom<&CybersourceRouterData<&types::PaymentsIncrementalAuthorizationRout | ||||
|                         previous_transaction_id: None, | ||||
|                         original_authorized_amount: None, | ||||
|                     }), | ||||
|                     ignore_avs_result: connector_merchant_config.disable_avs, | ||||
|                     ignore_cv_result: connector_merchant_config.disable_cvn, | ||||
|                 }), | ||||
|                 commerce_indicator: String::from("internet"), | ||||
|                 capture: None, | ||||
|  | ||||
| @ -1329,6 +1329,9 @@ impl<'a> ConnectorAuthTypeAndMetadataValidation<'a> { | ||||
|             } | ||||
|             api_enums::Connector::Cybersource => { | ||||
|                 cybersource::transformers::CybersourceAuthType::try_from(self.auth_type)?; | ||||
|                 cybersource::transformers::CybersourceConnectorMetadataObject::try_from( | ||||
|                     self.connector_meta_data, | ||||
|                 )?; | ||||
|                 Ok(()) | ||||
|             } | ||||
|             api_enums::Connector::Datatrans => { | ||||
|  | ||||
		Reference in New Issue
	
	Block a user
	 AkshayaFoiger
					AkshayaFoiger