mirror of
				https://github.com/juspay/hyperswitch.git
				synced 2025-10-31 18:17:13 +08:00 
			
		
		
		
	feat(connector): [Fiserv] add Refunds, Cancel and Wallets flow along with Unit Tests (#593)
Co-authored-by: samraat bansal <samraat.bansal@samraat.bansal-MacBookPro> Co-authored-by: Nishant Joshi <nishant.joshi@juspay.in> Co-authored-by: Jagan <jaganelavarasan@gmail.com> Co-authored-by: Arun Raj M <jarnura47@gmail.com>
This commit is contained in:
		| @ -5,11 +5,12 @@ use error_stack::{report, IntoReport, ResultExt}; | ||||
| use masking::Secret; | ||||
| use once_cell::sync::Lazy; | ||||
| use regex::Regex; | ||||
| use serde::Serializer; | ||||
|  | ||||
| use crate::{ | ||||
|     core::errors::{self, CustomResult}, | ||||
|     pii::PeekInterface, | ||||
|     types::{self, api, PaymentsCancelData}, | ||||
|     types::{self, api, PaymentsCancelData, ResponseId}, | ||||
|     utils::OptionExt, | ||||
| }; | ||||
|  | ||||
| @ -142,17 +143,29 @@ impl PaymentsAuthorizeRequestData for types::PaymentsAuthorizeData { | ||||
|  | ||||
| pub trait PaymentsSyncRequestData { | ||||
|     fn is_auto_capture(&self) -> bool; | ||||
|     fn get_connector_transaction_id(&self) -> CustomResult<String, errors::ValidationError>; | ||||
| } | ||||
|  | ||||
| impl PaymentsSyncRequestData for types::PaymentsSyncData { | ||||
|     fn is_auto_capture(&self) -> bool { | ||||
|         self.capture_method == Some(storage_models::enums::CaptureMethod::Automatic) | ||||
|     } | ||||
|     fn get_connector_transaction_id(&self) -> CustomResult<String, errors::ValidationError> { | ||||
|         match self.connector_transaction_id.clone() { | ||||
|             ResponseId::ConnectorTransactionId(txn_id) => Ok(txn_id), | ||||
|             _ => Err(errors::ValidationError::IncorrectValueProvided { | ||||
|                 field_name: "connector_transaction_id", | ||||
|             }) | ||||
|             .into_report() | ||||
|             .attach_printable("Expected connector transaction ID not found"), | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | ||||
| pub trait PaymentsCancelRequestData { | ||||
|     fn get_amount(&self) -> Result<i64, Error>; | ||||
|     fn get_currency(&self) -> Result<storage_models::enums::Currency, Error>; | ||||
|     fn get_cancellation_reason(&self) -> Result<String, Error>; | ||||
| } | ||||
|  | ||||
| impl PaymentsCancelRequestData for PaymentsCancelData { | ||||
| @ -162,6 +175,11 @@ impl PaymentsCancelRequestData for PaymentsCancelData { | ||||
|     fn get_currency(&self) -> Result<storage_models::enums::Currency, Error> { | ||||
|         self.currency.ok_or_else(missing_field_err("currency")) | ||||
|     } | ||||
|     fn get_cancellation_reason(&self) -> Result<String, Error> { | ||||
|         self.cancellation_reason | ||||
|             .clone() | ||||
|             .ok_or_else(missing_field_err("cancellation_reason")) | ||||
|     } | ||||
| } | ||||
|  | ||||
| pub trait RefundsRequestData { | ||||
| @ -355,3 +373,13 @@ pub fn to_currency_base_unit( | ||||
|         _ => Ok((f64::from(amount_u32) / 100.0).to_string()), | ||||
|     } | ||||
| } | ||||
|  | ||||
| pub fn str_to_f32<S>(value: &str, serializer: S) -> Result<S::Ok, S::Error> | ||||
| where | ||||
|     S: Serializer, | ||||
| { | ||||
|     let float_value = value.parse::<f64>().map_err(|_| { | ||||
|         serde::ser::Error::custom("Invalid string, cannot be converted to float value") | ||||
|     })?; | ||||
|     serializer.serialize_f64(float_value) | ||||
| } | ||||
|  | ||||
		Reference in New Issue
	
	Block a user
	 SamraatBansal
					SamraatBansal