mirror of
				https://github.com/juspay/hyperswitch.git
				synced 2025-10-31 18:17:13 +08:00 
			
		
		
		
	fix(connector): convert cents to dollar before sending to connector (#699)
Co-authored-by: Jagan Elavarasan <jaganelavarasan@gmail.com> Co-authored-by: Arjun Karthik <m.arjunkarthik@gmail.com> Co-authored-by: Arun Raj M <jarnura47@gmail.com>
This commit is contained in:
		| @ -323,3 +323,35 @@ pub fn get_header_key_value<'a>( | ||||
|             errors::ConnectorError::WebhookSourceVerificationFailed | ||||
|         ))? | ||||
| } | ||||
|  | ||||
| pub fn to_currency_base_unit_from_optional_amount( | ||||
|     amount: Option<i64>, | ||||
|     currency: storage_models::enums::Currency, | ||||
| ) -> Result<String, error_stack::Report<errors::ConnectorError>> { | ||||
|     match amount { | ||||
|         Some(a) => to_currency_base_unit(a, currency), | ||||
|         _ => Err(errors::ConnectorError::MissingRequiredField { | ||||
|             field_name: "amount", | ||||
|         } | ||||
|         .into()), | ||||
|     } | ||||
| } | ||||
|  | ||||
| pub fn to_currency_base_unit( | ||||
|     amount: i64, | ||||
|     currency: storage_models::enums::Currency, | ||||
| ) -> Result<String, error_stack::Report<errors::ConnectorError>> { | ||||
|     let amount_u32 = u32::try_from(amount) | ||||
|         .into_report() | ||||
|         .change_context(errors::ConnectorError::RequestEncodingFailed)?; | ||||
|     match currency { | ||||
|         storage_models::enums::Currency::JPY | storage_models::enums::Currency::KRW => { | ||||
|             Ok(amount.to_string()) | ||||
|         } | ||||
|         storage_models::enums::Currency::BHD | ||||
|         | storage_models::enums::Currency::JOD | ||||
|         | storage_models::enums::Currency::KWD | ||||
|         | storage_models::enums::Currency::OMR => Ok((f64::from(amount_u32) / 1000.0).to_string()), | ||||
|         _ => Ok((f64::from(amount_u32) / 100.0).to_string()), | ||||
|     } | ||||
| } | ||||
|  | ||||
		Reference in New Issue
	
	Block a user
	 SamraatBansal
					SamraatBansal