mirror of
				https://github.com/juspay/hyperswitch.git
				synced 2025-11-01 02:57:02 +08:00 
			
		
		
		
	fix(connector): [Airwallex] Change Session Token to Init Payment (#798)
This commit is contained in:
		| @ -172,14 +172,14 @@ impl ConnectorIntegration<api::AccessTokenAuth, types::AccessTokenRequestData, t | |||||||
|  |  | ||||||
| impl | impl | ||||||
|     ConnectorIntegration< |     ConnectorIntegration< | ||||||
|         api::AuthorizeSessionToken, |         api::InitPayment, | ||||||
|         types::AuthorizeSessionTokenData, |         types::PaymentsAuthorizeData, | ||||||
|         types::PaymentsResponseData, |         types::PaymentsResponseData, | ||||||
|     > for Airwallex |     > for Airwallex | ||||||
| { | { | ||||||
|     fn get_headers( |     fn get_headers( | ||||||
|         &self, |         &self, | ||||||
|         req: &types::PaymentsAuthorizeSessionTokenRouterData, |         req: &types::PaymentsInitRouterData, | ||||||
|         connectors: &settings::Connectors, |         connectors: &settings::Connectors, | ||||||
|     ) -> CustomResult<Vec<(String, String)>, errors::ConnectorError> { |     ) -> CustomResult<Vec<(String, String)>, errors::ConnectorError> { | ||||||
|         self.build_headers(req, connectors) |         self.build_headers(req, connectors) | ||||||
| @ -191,7 +191,7 @@ impl | |||||||
|  |  | ||||||
|     fn get_url( |     fn get_url( | ||||||
|         &self, |         &self, | ||||||
|         _req: &types::PaymentsAuthorizeSessionTokenRouterData, |         _req: &types::PaymentsInitRouterData, | ||||||
|         connectors: &settings::Connectors, |         connectors: &settings::Connectors, | ||||||
|     ) -> CustomResult<String, errors::ConnectorError> { |     ) -> CustomResult<String, errors::ConnectorError> { | ||||||
|         Ok(format!( |         Ok(format!( | ||||||
| @ -203,7 +203,7 @@ impl | |||||||
|  |  | ||||||
|     fn get_request_body( |     fn get_request_body( | ||||||
|         &self, |         &self, | ||||||
|         req: &types::PaymentsAuthorizeSessionTokenRouterData, |         req: &types::PaymentsInitRouterData, | ||||||
|     ) -> CustomResult<Option<String>, errors::ConnectorError> { |     ) -> CustomResult<Option<String>, errors::ConnectorError> { | ||||||
|         let req_obj = airwallex::AirwallexIntentRequest::try_from(req)?; |         let req_obj = airwallex::AirwallexIntentRequest::try_from(req)?; | ||||||
|         let req = |         let req = | ||||||
| @ -214,46 +214,24 @@ impl | |||||||
|  |  | ||||||
|     fn build_request( |     fn build_request( | ||||||
|         &self, |         &self, | ||||||
|         req: &types::PaymentsAuthorizeSessionTokenRouterData, |         req: &types::PaymentsInitRouterData, | ||||||
|         connectors: &settings::Connectors, |         connectors: &settings::Connectors, | ||||||
|     ) -> CustomResult<Option<services::Request>, errors::ConnectorError> { |     ) -> CustomResult<Option<services::Request>, errors::ConnectorError> { | ||||||
|         Ok(Some( |         Ok(Some( | ||||||
|             services::RequestBuilder::new() |             services::RequestBuilder::new() | ||||||
|                 .method(services::Method::Post) |                 .method(services::Method::Post) | ||||||
|                 .url(&types::PaymentsPreAuthorizeType::get_url( |                 .url(&types::PaymentsInitType::get_url(self, req, connectors)?) | ||||||
|                     self, req, connectors, |                 .headers(types::PaymentsInitType::get_headers(self, req, connectors)?) | ||||||
|                 )?) |                 .body(types::PaymentsInitType::get_request_body(self, req)?) | ||||||
|                 .headers(types::PaymentsPreAuthorizeType::get_headers( |  | ||||||
|                     self, req, connectors, |  | ||||||
|                 )?) |  | ||||||
|                 .body(types::PaymentsPreAuthorizeType::get_request_body( |  | ||||||
|                     self, req, |  | ||||||
|                 )?) |  | ||||||
|                 .build(), |                 .build(), | ||||||
|         )) |         )) | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     fn handle_response( |     fn handle_response( | ||||||
|         &self, |         &self, | ||||||
|         data: &RouterData< |         data: &types::PaymentsInitRouterData, | ||||||
|             api::AuthorizeSessionToken, |  | ||||||
|             types::AuthorizeSessionTokenData, |  | ||||||
|             types::PaymentsResponseData, |  | ||||||
|         >, |  | ||||||
|         res: Response, |         res: Response, | ||||||
|     ) -> CustomResult< |     ) -> CustomResult<types::PaymentsInitRouterData, errors::ConnectorError> { | ||||||
|         RouterData< |  | ||||||
|             api::AuthorizeSessionToken, |  | ||||||
|             types::AuthorizeSessionTokenData, |  | ||||||
|             types::PaymentsResponseData, |  | ||||||
|         >, |  | ||||||
|         errors::ConnectorError, |  | ||||||
|     > |  | ||||||
|     where |  | ||||||
|         api::AuthorizeSessionToken: Clone, |  | ||||||
|         types::AuthorizeSessionTokenData: Clone, |  | ||||||
|         types::PaymentsResponseData: Clone, |  | ||||||
|     { |  | ||||||
|         let response: airwallex::AirwallexPaymentsResponse = res |         let response: airwallex::AirwallexPaymentsResponse = res | ||||||
|             .response |             .response | ||||||
|             .parse_struct("airwallex AirwallexPaymentsResponse") |             .parse_struct("airwallex AirwallexPaymentsResponse") | ||||||
| @ -289,17 +267,15 @@ impl ConnectorIntegration<api::Authorize, types::PaymentsAuthorizeData, types::P | |||||||
|     ) -> CustomResult<(), errors::ConnectorError> { |     ) -> CustomResult<(), errors::ConnectorError> { | ||||||
|         let integ: Box< |         let integ: Box< | ||||||
|             &(dyn ConnectorIntegration< |             &(dyn ConnectorIntegration< | ||||||
|                 api::AuthorizeSessionToken, |                 api::InitPayment, | ||||||
|                 types::AuthorizeSessionTokenData, |                 types::PaymentsAuthorizeData, | ||||||
|                 types::PaymentsResponseData, |                 types::PaymentsResponseData, | ||||||
|             > + Send |             > + Send | ||||||
|                   + Sync |                   + Sync | ||||||
|                   + 'static), |                   + 'static), | ||||||
|         > = Box::new(&Self); |         > = Box::new(&Self); | ||||||
|         let authorize_data = &types::PaymentsAuthorizeSessionTokenRouterData::from(( |         let authorize_data = | ||||||
|             &router_data, |             &types::PaymentsInitRouterData::from((&router_data, router_data.request.clone())); | ||||||
|             types::AuthorizeSessionTokenData::from(&router_data), |  | ||||||
|         )); |  | ||||||
|         let resp = services::execute_connector_processing_step( |         let resp = services::execute_connector_processing_step( | ||||||
|             app_state, |             app_state, | ||||||
|             integ, |             integ, | ||||||
|  | |||||||
| @ -20,11 +20,9 @@ pub struct AirwallexIntentRequest { | |||||||
|     //ID created in merchant's order system that corresponds to this PaymentIntent. |     //ID created in merchant's order system that corresponds to this PaymentIntent. | ||||||
|     merchant_order_id: String, |     merchant_order_id: String, | ||||||
| } | } | ||||||
| impl TryFrom<&types::PaymentsAuthorizeSessionTokenRouterData> for AirwallexIntentRequest { | impl TryFrom<&types::PaymentsInitRouterData> for AirwallexIntentRequest { | ||||||
|     type Error = error_stack::Report<errors::ConnectorError>; |     type Error = error_stack::Report<errors::ConnectorError>; | ||||||
|     fn try_from( |     fn try_from(item: &types::PaymentsInitRouterData) -> Result<Self, Self::Error> { | ||||||
|         item: &types::PaymentsAuthorizeSessionTokenRouterData, |  | ||||||
|     ) -> Result<Self, Self::Error> { |  | ||||||
|         Ok(Self { |         Ok(Self { | ||||||
|             request_id: Uuid::new_v4().to_string(), |             request_id: Uuid::new_v4().to_string(), | ||||||
|             amount: utils::to_currency_base_unit(item.request.amount, item.request.currency)?, |             amount: utils::to_currency_base_unit(item.request.amount, item.request.currency)?, | ||||||
| @ -390,6 +388,5 @@ pub struct AirwallexWebhookObjectResource { | |||||||
| pub struct AirwallexErrorResponse { | pub struct AirwallexErrorResponse { | ||||||
|     pub code: String, |     pub code: String, | ||||||
|     pub message: String, |     pub message: String, | ||||||
|     pub details: Option<Vec<String>>, |  | ||||||
|     pub source: Option<String>, |     pub source: Option<String>, | ||||||
| } | } | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user
	 SamraatBansal
					SamraatBansal