mirror of
				https://github.com/juspay/hyperswitch.git
				synced 2025-10-31 10:06:32 +08:00 
			
		
		
		
	refactor(connector): [Mifinity] fix redirection after payment completion and handle 5xx error (#5250)
This commit is contained in:
		| @ -2,16 +2,17 @@ pub mod transformers; | |||||||
|  |  | ||||||
| use std::fmt::Debug; | use std::fmt::Debug; | ||||||
|  |  | ||||||
| use error_stack::{report, ResultExt}; | use error_stack::{report, Report, ResultExt}; | ||||||
| use masking::ExposeInterface; | use masking::ExposeInterface; | ||||||
| use transformers as mifinity; | use transformers as mifinity; | ||||||
|  |  | ||||||
| use self::transformers::auth_headers; | use self::transformers::auth_headers; | ||||||
| use crate::{ | use crate::{ | ||||||
|     configs::settings, |     configs::settings, | ||||||
|  |     consts, | ||||||
|     core::errors::{self, CustomResult}, |     core::errors::{self, CustomResult}, | ||||||
|     events::connector_api_logs::ConnectorEvent, |     events::connector_api_logs::ConnectorEvent, | ||||||
|     headers, |     headers, logger, | ||||||
|     services::{ |     services::{ | ||||||
|         self, |         self, | ||||||
|         request::{self, Mask}, |         request::{self, Mask}, | ||||||
| @ -112,14 +113,25 @@ impl ConnectorCommon for Mifinity { | |||||||
|         res: Response, |         res: Response, | ||||||
|         event_builder: Option<&mut ConnectorEvent>, |         event_builder: Option<&mut ConnectorEvent>, | ||||||
|     ) -> CustomResult<ErrorResponse, errors::ConnectorError> { |     ) -> CustomResult<ErrorResponse, errors::ConnectorError> { | ||||||
|         let response: mifinity::MifinityErrorResponse = res |         if res.response.is_empty() { | ||||||
|             .response |             Ok(ErrorResponse { | ||||||
|             .parse_struct("MifinityErrorResponse") |                 status_code: res.status_code, | ||||||
|             .change_context(errors::ConnectorError::ResponseDeserializationFailed)?; |                 code: consts::NO_ERROR_CODE.to_string(), | ||||||
|  |                 message: consts::NO_ERROR_MESSAGE.to_string(), | ||||||
|  |                 reason: Some(consts::CONNECTOR_UNAUTHORIZED_ERROR.to_string()), | ||||||
|  |                 attempt_status: None, | ||||||
|  |                 connector_transaction_id: None, | ||||||
|  |             }) | ||||||
|  |         } else { | ||||||
|  |             let response: Result< | ||||||
|  |                 mifinity::MifinityErrorResponse, | ||||||
|  |                 Report<common_utils::errors::ParsingError>, | ||||||
|  |             > = res.response.parse_struct("MifinityErrorResponse"); | ||||||
|  |  | ||||||
|  |             match response { | ||||||
|  |                 Ok(response) => { | ||||||
|                     event_builder.map(|i| i.set_response_body(&response)); |                     event_builder.map(|i| i.set_response_body(&response)); | ||||||
|                     router_env::logger::info!(connector_response=?response); |                     router_env::logger::info!(connector_response=?response); | ||||||
|  |  | ||||||
|                     Ok(ErrorResponse { |                     Ok(ErrorResponse { | ||||||
|                         status_code: res.status_code, |                         status_code: res.status_code, | ||||||
|                         code: response |                         code: response | ||||||
| @ -146,6 +158,15 @@ impl ConnectorCommon for Mifinity { | |||||||
|                         connector_transaction_id: None, |                         connector_transaction_id: None, | ||||||
|                     }) |                     }) | ||||||
|                 } |                 } | ||||||
|  |  | ||||||
|  |                 Err(error_msg) => { | ||||||
|  |                     event_builder.map(|event| event.set_error(serde_json::json!({"error": res.response.escape_ascii().to_string(), "status_code": res.status_code}))); | ||||||
|  |                     logger::error!(deserialization_error =? error_msg); | ||||||
|  |                     crate::utils::handle_json_response_deserialization_failure(res, "mifinity") | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |     } | ||||||
| } | } | ||||||
|  |  | ||||||
| impl ConnectorValidation for Mifinity { | impl ConnectorValidation for Mifinity { | ||||||
|  | |||||||
| @ -1877,10 +1877,11 @@ pub fn build_redirection_form( | |||||||
|         RedirectForm::Mifinity { |         RedirectForm::Mifinity { | ||||||
|             initialization_token, |             initialization_token, | ||||||
|         } => { |         } => { | ||||||
|  |             let mifinity_base_url = config.connectors.mifinity.base_url; | ||||||
|             maud::html! { |             maud::html! { | ||||||
|                         (maud::DOCTYPE) |                         (maud::DOCTYPE) | ||||||
|                         head { |                         head { | ||||||
|                             (PreEscaped(r#"<script src='https://demo.mifinity.com/widgets/sgpg.js?58190a411dc3'></script>"#)) |                             (PreEscaped(format!(r#"<script src='{mifinity_base_url}widgets/sgpg.js?58190a411dc3'></script>"#))) | ||||||
|                         } |                         } | ||||||
|  |  | ||||||
|                         (PreEscaped(format!("<div id='widget-container'></div> |                         (PreEscaped(format!("<div id='widget-container'></div> | ||||||
| @ -1888,9 +1889,11 @@ pub fn build_redirection_form( | |||||||
| 		  var widget = showPaymentIframe('widget-container', {{ | 		  var widget = showPaymentIframe('widget-container', {{ | ||||||
| 			  token: '{initialization_token}', | 			  token: '{initialization_token}', | ||||||
| 			  complete: function() {{ | 			  complete: function() {{ | ||||||
| 				  setTimeout(function() {{ |                 var f = document.createElement('form'); | ||||||
| 					widget.close(); |                 f.action=window.location.pathname.replace(/payments\\/redirect\\/(\\w+)\\/(\\w+)\\/\\w+/, \"payments/$1/$2/redirect/response/mifinity\"); | ||||||
| 				  }}, 5000); |                 f.method='GET'; | ||||||
|  |                 document.body.appendChild(f); | ||||||
|  |                 f.submit(); | ||||||
| 			  }} | 			  }} | ||||||
| 		   }}); | 		   }}); | ||||||
| 	   </script>"))) | 	   </script>"))) | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user
	 Swangi Kumari
					Swangi Kumari