mirror of
				https://github.com/juspay/hyperswitch.git
				synced 2025-11-01 02:57:02 +08:00 
			
		
		
		
	feat(connector): [Nuvei] add support for card mandates (#818)
Co-authored-by: Arun Raj M <jarnura47@gmail.com>
This commit is contained in:
		| @ -1,7 +1,9 @@ | ||||
| use std::collections::HashMap; | ||||
|  | ||||
| use api_models::payments; | ||||
| use base64::Engine; | ||||
| use common_utils::{ | ||||
|     date_time, | ||||
|     errors::ReportSwitchExt, | ||||
|     pii::{self, Email}, | ||||
| }; | ||||
| @ -145,6 +147,7 @@ pub trait PaymentsAuthorizeRequestData { | ||||
|     fn get_browser_info(&self) -> Result<types::BrowserInformation, Error>; | ||||
|     fn get_card(&self) -> Result<api::Card, Error>; | ||||
|     fn get_return_url(&self) -> Result<String, Error>; | ||||
|     fn connector_mandate_id(&self) -> Option<String>; | ||||
|     fn is_mandate_payment(&self) -> bool; | ||||
|     fn get_webhook_url(&self) -> Result<String, Error>; | ||||
| } | ||||
| @ -172,6 +175,11 @@ impl PaymentsAuthorizeRequestData for types::PaymentsAuthorizeData { | ||||
|             .clone() | ||||
|             .ok_or_else(missing_field_err("return_url")) | ||||
|     } | ||||
|     fn connector_mandate_id(&self) -> Option<String> { | ||||
|         self.mandate_id | ||||
|             .as_ref() | ||||
|             .and_then(|mandate_ids| mandate_ids.connector_mandate_id.clone()) | ||||
|     } | ||||
|     fn is_mandate_payment(&self) -> bool { | ||||
|         self.setup_mandate_details.is_some() | ||||
|             || self | ||||
| @ -435,6 +443,27 @@ impl AddressDetailsData for api::AddressDetails { | ||||
|     } | ||||
| } | ||||
|  | ||||
| pub trait MandateData { | ||||
|     fn get_end_date(&self, format: date_time::DateFormat) -> Result<String, Error>; | ||||
|     fn get_metadata(&self) -> Result<pii::SecretSerdeValue, Error>; | ||||
| } | ||||
|  | ||||
| impl MandateData for payments::MandateAmountData { | ||||
|     fn get_end_date(&self, format: date_time::DateFormat) -> Result<String, Error> { | ||||
|         let date = self.end_date.ok_or_else(missing_field_err( | ||||
|             "mandate_data.mandate_type.{multi_use|single_use}.end_date", | ||||
|         ))?; | ||||
|         date_time::format_date(date, format) | ||||
|             .into_report() | ||||
|             .change_context(errors::ConnectorError::DateFormattingFailed) | ||||
|     } | ||||
|     fn get_metadata(&self) -> Result<pii::SecretSerdeValue, Error> { | ||||
|         self.metadata.clone().ok_or_else(missing_field_err( | ||||
|             "mandate_data.mandate_type.{multi_use|single_use}.metadata", | ||||
|         )) | ||||
|     } | ||||
| } | ||||
|  | ||||
| pub fn get_header_key_value<'a>( | ||||
|     key: &str, | ||||
|     headers: &'a actix_web::http::header::HeaderMap, | ||||
|  | ||||
		Reference in New Issue
	
	Block a user
	 Jagan
					Jagan