mirror of
				https://github.com/juspay/hyperswitch.git
				synced 2025-10-31 10:06:32 +08:00 
			
		
		
		
	feat(connector): [Noon] Add script generated template code (#1164)
This commit is contained in:
		| @ -384,6 +384,7 @@ pub struct Connectors { | ||||
|     pub multisafepay: ConnectorParams, | ||||
|     pub nexinets: ConnectorParams, | ||||
|     pub nmi: ConnectorParams, | ||||
|     pub noon: ConnectorParams, | ||||
|     pub nuvei: ConnectorParams, | ||||
|     pub opennode: ConnectorParams, | ||||
|     pub payeezy: ConnectorParams, | ||||
|  | ||||
| @ -21,6 +21,7 @@ pub mod mollie; | ||||
| pub mod multisafepay; | ||||
| pub mod nexinets; | ||||
| pub mod nmi; | ||||
| pub mod noon; | ||||
| pub mod nuvei; | ||||
| pub mod opennode; | ||||
| pub mod payeezy; | ||||
| @ -42,7 +43,7 @@ pub use self::{ | ||||
|     bambora::Bambora, bitpay::Bitpay, bluesnap::Bluesnap, braintree::Braintree, checkout::Checkout, | ||||
|     coinbase::Coinbase, cybersource::Cybersource, dlocal::Dlocal, fiserv::Fiserv, forte::Forte, | ||||
|     globalpay::Globalpay, iatapay::Iatapay, klarna::Klarna, mollie::Mollie, | ||||
|     multisafepay::Multisafepay, nexinets::Nexinets, nmi::Nmi, nuvei::Nuvei, opennode::Opennode, | ||||
|     payeezy::Payeezy, paypal::Paypal, payu::Payu, rapyd::Rapyd, shift4::Shift4, stripe::Stripe, | ||||
|     trustpay::Trustpay, worldline::Worldline, worldpay::Worldpay, zen::Zen, | ||||
|     multisafepay::Multisafepay, nexinets::Nexinets, nmi::Nmi, noon::Noon, nuvei::Nuvei, | ||||
|     opennode::Opennode, payeezy::Payeezy, paypal::Paypal, payu::Payu, rapyd::Rapyd, shift4::Shift4, | ||||
|     stripe::Stripe, trustpay::Trustpay, worldline::Worldline, worldpay::Worldpay, zen::Zen, | ||||
| }; | ||||
|  | ||||
							
								
								
									
										499
									
								
								crates/router/src/connector/noon.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										499
									
								
								crates/router/src/connector/noon.rs
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,499 @@ | ||||
| mod transformers; | ||||
|  | ||||
| use std::fmt::Debug; | ||||
|  | ||||
| use error_stack::{IntoReport, ResultExt}; | ||||
| use transformers as noon; | ||||
|  | ||||
| use crate::{ | ||||
|     configs::settings, | ||||
|     core::errors::{self, CustomResult}, | ||||
|     headers, | ||||
|     services::{self, ConnectorIntegration}, | ||||
|     types::{ | ||||
|         self, | ||||
|         api::{self, ConnectorCommon, ConnectorCommonExt}, | ||||
|         ErrorResponse, Response, | ||||
|     }, | ||||
|     utils::{self, BytesExt}, | ||||
| }; | ||||
|  | ||||
| #[derive(Debug, Clone)] | ||||
| pub struct Noon; | ||||
|  | ||||
| impl api::Payment for Noon {} | ||||
| impl api::PaymentSession for Noon {} | ||||
| impl api::ConnectorAccessToken for Noon {} | ||||
| impl api::PreVerify for Noon {} | ||||
| impl api::PaymentAuthorize for Noon {} | ||||
| impl api::PaymentSync for Noon {} | ||||
| impl api::PaymentCapture for Noon {} | ||||
| impl api::PaymentVoid for Noon {} | ||||
| impl api::Refund for Noon {} | ||||
| impl api::RefundExecute for Noon {} | ||||
| impl api::RefundSync for Noon {} | ||||
| impl api::PaymentToken for Noon {} | ||||
|  | ||||
| impl | ||||
|     ConnectorIntegration< | ||||
|         api::PaymentMethodToken, | ||||
|         types::PaymentMethodTokenizationData, | ||||
|         types::PaymentsResponseData, | ||||
|     > for Noon | ||||
| { | ||||
|     // Not Implemented (R) | ||||
| } | ||||
|  | ||||
| impl<Flow, Request, Response> ConnectorCommonExt<Flow, Request, Response> for Noon | ||||
| where | ||||
|     Self: ConnectorIntegration<Flow, Request, Response>, | ||||
| { | ||||
|     fn build_headers( | ||||
|         &self, | ||||
|         req: &types::RouterData<Flow, Request, Response>, | ||||
|         _connectors: &settings::Connectors, | ||||
|     ) -> CustomResult<Vec<(String, String)>, errors::ConnectorError> { | ||||
|         let mut header = vec![( | ||||
|             headers::CONTENT_TYPE.to_string(), | ||||
|             types::PaymentsAuthorizeType::get_content_type(self).to_string(), | ||||
|         )]; | ||||
|         let mut api_key = self.get_auth_header(&req.connector_auth_type)?; | ||||
|         header.append(&mut api_key); | ||||
|         Ok(header) | ||||
|     } | ||||
| } | ||||
|  | ||||
| impl ConnectorCommon for Noon { | ||||
|     fn id(&self) -> &'static str { | ||||
|         "noon" | ||||
|     } | ||||
|  | ||||
|     fn common_get_content_type(&self) -> &'static str { | ||||
|         "application/json" | ||||
|     } | ||||
|  | ||||
|     fn base_url<'a>(&self, connectors: &'a settings::Connectors) -> &'a str { | ||||
|         connectors.noon.base_url.as_ref() | ||||
|     } | ||||
|  | ||||
|     fn get_auth_header( | ||||
|         &self, | ||||
|         auth_type: &types::ConnectorAuthType, | ||||
|     ) -> CustomResult<Vec<(String, String)>, errors::ConnectorError> { | ||||
|         let auth = noon::NoonAuthType::try_from(auth_type) | ||||
|             .change_context(errors::ConnectorError::FailedToObtainAuthType)?; | ||||
|         Ok(vec![(headers::AUTHORIZATION.to_string(), auth.api_key)]) | ||||
|     } | ||||
|  | ||||
|     fn build_error_response( | ||||
|         &self, | ||||
|         res: Response, | ||||
|     ) -> CustomResult<ErrorResponse, errors::ConnectorError> { | ||||
|         let response: noon::NoonErrorResponse = res | ||||
|             .response | ||||
|             .parse_struct("NoonErrorResponse") | ||||
|             .change_context(errors::ConnectorError::ResponseDeserializationFailed)?; | ||||
|  | ||||
|         Ok(ErrorResponse { | ||||
|             status_code: res.status_code, | ||||
|             code: response.code, | ||||
|             message: response.message, | ||||
|             reason: response.reason, | ||||
|         }) | ||||
|     } | ||||
| } | ||||
|  | ||||
| impl ConnectorIntegration<api::Session, types::PaymentsSessionData, types::PaymentsResponseData> | ||||
|     for Noon | ||||
| { | ||||
|     //TODO: implement sessions flow | ||||
| } | ||||
|  | ||||
| impl ConnectorIntegration<api::AccessTokenAuth, types::AccessTokenRequestData, types::AccessToken> | ||||
|     for Noon | ||||
| { | ||||
| } | ||||
|  | ||||
| impl ConnectorIntegration<api::Verify, types::VerifyRequestData, types::PaymentsResponseData> | ||||
|     for Noon | ||||
| { | ||||
| } | ||||
|  | ||||
| impl ConnectorIntegration<api::Authorize, types::PaymentsAuthorizeData, types::PaymentsResponseData> | ||||
|     for Noon | ||||
| { | ||||
|     fn get_headers( | ||||
|         &self, | ||||
|         req: &types::PaymentsAuthorizeRouterData, | ||||
|         connectors: &settings::Connectors, | ||||
|     ) -> CustomResult<Vec<(String, String)>, errors::ConnectorError> { | ||||
|         self.build_headers(req, connectors) | ||||
|     } | ||||
|  | ||||
|     fn get_content_type(&self) -> &'static str { | ||||
|         self.common_get_content_type() | ||||
|     } | ||||
|  | ||||
|     fn get_url( | ||||
|         &self, | ||||
|         _req: &types::PaymentsAuthorizeRouterData, | ||||
|         _connectors: &settings::Connectors, | ||||
|     ) -> CustomResult<String, errors::ConnectorError> { | ||||
|         Err(errors::ConnectorError::NotImplemented("get_url method".to_string()).into()) | ||||
|     } | ||||
|  | ||||
|     fn get_request_body( | ||||
|         &self, | ||||
|         req: &types::PaymentsAuthorizeRouterData, | ||||
|     ) -> CustomResult<Option<String>, errors::ConnectorError> { | ||||
|         let req_obj = noon::NoonPaymentsRequest::try_from(req)?; | ||||
|         let noon_req = | ||||
|             utils::Encode::<noon::NoonPaymentsRequest>::encode_to_string_of_json(&req_obj) | ||||
|                 .change_context(errors::ConnectorError::RequestEncodingFailed)?; | ||||
|         Ok(Some(noon_req)) | ||||
|     } | ||||
|  | ||||
|     fn build_request( | ||||
|         &self, | ||||
|         req: &types::PaymentsAuthorizeRouterData, | ||||
|         connectors: &settings::Connectors, | ||||
|     ) -> CustomResult<Option<services::Request>, errors::ConnectorError> { | ||||
|         Ok(Some( | ||||
|             services::RequestBuilder::new() | ||||
|                 .method(services::Method::Post) | ||||
|                 .url(&types::PaymentsAuthorizeType::get_url( | ||||
|                     self, req, connectors, | ||||
|                 )?) | ||||
|                 .attach_default_headers() | ||||
|                 .headers(types::PaymentsAuthorizeType::get_headers( | ||||
|                     self, req, connectors, | ||||
|                 )?) | ||||
|                 .body(types::PaymentsAuthorizeType::get_request_body(self, req)?) | ||||
|                 .build(), | ||||
|         )) | ||||
|     } | ||||
|  | ||||
|     fn handle_response( | ||||
|         &self, | ||||
|         data: &types::PaymentsAuthorizeRouterData, | ||||
|         res: Response, | ||||
|     ) -> CustomResult<types::PaymentsAuthorizeRouterData, errors::ConnectorError> { | ||||
|         let response: noon::NoonPaymentsResponse = res | ||||
|             .response | ||||
|             .parse_struct("Noon PaymentsAuthorizeResponse") | ||||
|             .change_context(errors::ConnectorError::ResponseDeserializationFailed)?; | ||||
|         types::RouterData::try_from(types::ResponseRouterData { | ||||
|             response, | ||||
|             data: data.clone(), | ||||
|             http_code: res.status_code, | ||||
|         }) | ||||
|         .change_context(errors::ConnectorError::ResponseHandlingFailed) | ||||
|     } | ||||
|  | ||||
|     fn get_error_response( | ||||
|         &self, | ||||
|         res: Response, | ||||
|     ) -> CustomResult<ErrorResponse, errors::ConnectorError> { | ||||
|         self.build_error_response(res) | ||||
|     } | ||||
| } | ||||
|  | ||||
| impl ConnectorIntegration<api::PSync, types::PaymentsSyncData, types::PaymentsResponseData> | ||||
|     for Noon | ||||
| { | ||||
|     fn get_headers( | ||||
|         &self, | ||||
|         req: &types::PaymentsSyncRouterData, | ||||
|         connectors: &settings::Connectors, | ||||
|     ) -> CustomResult<Vec<(String, String)>, errors::ConnectorError> { | ||||
|         self.build_headers(req, connectors) | ||||
|     } | ||||
|  | ||||
|     fn get_content_type(&self) -> &'static str { | ||||
|         self.common_get_content_type() | ||||
|     } | ||||
|  | ||||
|     fn get_url( | ||||
|         &self, | ||||
|         _req: &types::PaymentsSyncRouterData, | ||||
|         _connectors: &settings::Connectors, | ||||
|     ) -> CustomResult<String, errors::ConnectorError> { | ||||
|         Err(errors::ConnectorError::NotImplemented("get_url method".to_string()).into()) | ||||
|     } | ||||
|  | ||||
|     fn build_request( | ||||
|         &self, | ||||
|         req: &types::PaymentsSyncRouterData, | ||||
|         connectors: &settings::Connectors, | ||||
|     ) -> CustomResult<Option<services::Request>, errors::ConnectorError> { | ||||
|         Ok(Some( | ||||
|             services::RequestBuilder::new() | ||||
|                 .method(services::Method::Get) | ||||
|                 .url(&types::PaymentsSyncType::get_url(self, req, connectors)?) | ||||
|                 .attach_default_headers() | ||||
|                 .headers(types::PaymentsSyncType::get_headers(self, req, connectors)?) | ||||
|                 .build(), | ||||
|         )) | ||||
|     } | ||||
|  | ||||
|     fn handle_response( | ||||
|         &self, | ||||
|         data: &types::PaymentsSyncRouterData, | ||||
|         res: Response, | ||||
|     ) -> CustomResult<types::PaymentsSyncRouterData, errors::ConnectorError> { | ||||
|         let response: noon::NoonPaymentsResponse = res | ||||
|             .response | ||||
|             .parse_struct("noon PaymentsSyncResponse") | ||||
|             .change_context(errors::ConnectorError::ResponseDeserializationFailed)?; | ||||
|         types::RouterData::try_from(types::ResponseRouterData { | ||||
|             response, | ||||
|             data: data.clone(), | ||||
|             http_code: res.status_code, | ||||
|         }) | ||||
|         .change_context(errors::ConnectorError::ResponseHandlingFailed) | ||||
|     } | ||||
|  | ||||
|     fn get_error_response( | ||||
|         &self, | ||||
|         res: Response, | ||||
|     ) -> CustomResult<ErrorResponse, errors::ConnectorError> { | ||||
|         self.build_error_response(res) | ||||
|     } | ||||
| } | ||||
|  | ||||
| impl ConnectorIntegration<api::Capture, types::PaymentsCaptureData, types::PaymentsResponseData> | ||||
|     for Noon | ||||
| { | ||||
|     fn get_headers( | ||||
|         &self, | ||||
|         req: &types::PaymentsCaptureRouterData, | ||||
|         connectors: &settings::Connectors, | ||||
|     ) -> CustomResult<Vec<(String, String)>, errors::ConnectorError> { | ||||
|         self.build_headers(req, connectors) | ||||
|     } | ||||
|  | ||||
|     fn get_content_type(&self) -> &'static str { | ||||
|         self.common_get_content_type() | ||||
|     } | ||||
|  | ||||
|     fn get_url( | ||||
|         &self, | ||||
|         _req: &types::PaymentsCaptureRouterData, | ||||
|         _connectors: &settings::Connectors, | ||||
|     ) -> CustomResult<String, errors::ConnectorError> { | ||||
|         Err(errors::ConnectorError::NotImplemented("get_url method".to_string()).into()) | ||||
|     } | ||||
|  | ||||
|     fn get_request_body( | ||||
|         &self, | ||||
|         _req: &types::PaymentsCaptureRouterData, | ||||
|     ) -> CustomResult<Option<String>, errors::ConnectorError> { | ||||
|         Err(errors::ConnectorError::NotImplemented("get_request_body method".to_string()).into()) | ||||
|     } | ||||
|  | ||||
|     fn build_request( | ||||
|         &self, | ||||
|         req: &types::PaymentsCaptureRouterData, | ||||
|         connectors: &settings::Connectors, | ||||
|     ) -> CustomResult<Option<services::Request>, errors::ConnectorError> { | ||||
|         Ok(Some( | ||||
|             services::RequestBuilder::new() | ||||
|                 .method(services::Method::Post) | ||||
|                 .url(&types::PaymentsCaptureType::get_url(self, req, connectors)?) | ||||
|                 .attach_default_headers() | ||||
|                 .headers(types::PaymentsCaptureType::get_headers( | ||||
|                     self, req, connectors, | ||||
|                 )?) | ||||
|                 .body(types::PaymentsCaptureType::get_request_body(self, req)?) | ||||
|                 .build(), | ||||
|         )) | ||||
|     } | ||||
|  | ||||
|     fn handle_response( | ||||
|         &self, | ||||
|         data: &types::PaymentsCaptureRouterData, | ||||
|         res: Response, | ||||
|     ) -> CustomResult<types::PaymentsCaptureRouterData, errors::ConnectorError> { | ||||
|         let response: noon::NoonPaymentsResponse = res | ||||
|             .response | ||||
|             .parse_struct("Noon PaymentsCaptureResponse") | ||||
|             .change_context(errors::ConnectorError::ResponseDeserializationFailed)?; | ||||
|         types::RouterData::try_from(types::ResponseRouterData { | ||||
|             response, | ||||
|             data: data.clone(), | ||||
|             http_code: res.status_code, | ||||
|         }) | ||||
|         .change_context(errors::ConnectorError::ResponseHandlingFailed) | ||||
|     } | ||||
|  | ||||
|     fn get_error_response( | ||||
|         &self, | ||||
|         res: Response, | ||||
|     ) -> CustomResult<ErrorResponse, errors::ConnectorError> { | ||||
|         self.build_error_response(res) | ||||
|     } | ||||
| } | ||||
|  | ||||
| impl ConnectorIntegration<api::Void, types::PaymentsCancelData, types::PaymentsResponseData> | ||||
|     for Noon | ||||
| { | ||||
| } | ||||
|  | ||||
| impl ConnectorIntegration<api::Execute, types::RefundsData, types::RefundsResponseData> for Noon { | ||||
|     fn get_headers( | ||||
|         &self, | ||||
|         req: &types::RefundsRouterData<api::Execute>, | ||||
|         connectors: &settings::Connectors, | ||||
|     ) -> CustomResult<Vec<(String, String)>, errors::ConnectorError> { | ||||
|         self.build_headers(req, connectors) | ||||
|     } | ||||
|  | ||||
|     fn get_content_type(&self) -> &'static str { | ||||
|         self.common_get_content_type() | ||||
|     } | ||||
|  | ||||
|     fn get_url( | ||||
|         &self, | ||||
|         _req: &types::RefundsRouterData<api::Execute>, | ||||
|         _connectors: &settings::Connectors, | ||||
|     ) -> CustomResult<String, errors::ConnectorError> { | ||||
|         Err(errors::ConnectorError::NotImplemented("get_url method".to_string()).into()) | ||||
|     } | ||||
|  | ||||
|     fn get_request_body( | ||||
|         &self, | ||||
|         req: &types::RefundsRouterData<api::Execute>, | ||||
|     ) -> CustomResult<Option<String>, errors::ConnectorError> { | ||||
|         let req_obj = noon::NoonRefundRequest::try_from(req)?; | ||||
|         let noon_req = utils::Encode::<noon::NoonRefundRequest>::encode_to_string_of_json(&req_obj) | ||||
|             .change_context(errors::ConnectorError::RequestEncodingFailed)?; | ||||
|         Ok(Some(noon_req)) | ||||
|     } | ||||
|  | ||||
|     fn build_request( | ||||
|         &self, | ||||
|         req: &types::RefundsRouterData<api::Execute>, | ||||
|         connectors: &settings::Connectors, | ||||
|     ) -> CustomResult<Option<services::Request>, errors::ConnectorError> { | ||||
|         let request = services::RequestBuilder::new() | ||||
|             .method(services::Method::Post) | ||||
|             .url(&types::RefundExecuteType::get_url(self, req, connectors)?) | ||||
|             .attach_default_headers() | ||||
|             .headers(types::RefundExecuteType::get_headers( | ||||
|                 self, req, connectors, | ||||
|             )?) | ||||
|             .body(types::RefundExecuteType::get_request_body(self, req)?) | ||||
|             .build(); | ||||
|         Ok(Some(request)) | ||||
|     } | ||||
|  | ||||
|     fn handle_response( | ||||
|         &self, | ||||
|         data: &types::RefundsRouterData<api::Execute>, | ||||
|         res: Response, | ||||
|     ) -> CustomResult<types::RefundsRouterData<api::Execute>, errors::ConnectorError> { | ||||
|         let response: noon::RefundResponse = res | ||||
|             .response | ||||
|             .parse_struct("noon RefundResponse") | ||||
|             .change_context(errors::ConnectorError::ResponseDeserializationFailed)?; | ||||
|         types::RouterData::try_from(types::ResponseRouterData { | ||||
|             response, | ||||
|             data: data.clone(), | ||||
|             http_code: res.status_code, | ||||
|         }) | ||||
|         .change_context(errors::ConnectorError::ResponseHandlingFailed) | ||||
|     } | ||||
|  | ||||
|     fn get_error_response( | ||||
|         &self, | ||||
|         res: Response, | ||||
|     ) -> CustomResult<ErrorResponse, errors::ConnectorError> { | ||||
|         self.build_error_response(res) | ||||
|     } | ||||
| } | ||||
|  | ||||
| impl ConnectorIntegration<api::RSync, types::RefundsData, types::RefundsResponseData> for Noon { | ||||
|     fn get_headers( | ||||
|         &self, | ||||
|         req: &types::RefundSyncRouterData, | ||||
|         connectors: &settings::Connectors, | ||||
|     ) -> CustomResult<Vec<(String, String)>, errors::ConnectorError> { | ||||
|         self.build_headers(req, connectors) | ||||
|     } | ||||
|  | ||||
|     fn get_content_type(&self) -> &'static str { | ||||
|         self.common_get_content_type() | ||||
|     } | ||||
|  | ||||
|     fn get_url( | ||||
|         &self, | ||||
|         _req: &types::RefundSyncRouterData, | ||||
|         _connectors: &settings::Connectors, | ||||
|     ) -> CustomResult<String, errors::ConnectorError> { | ||||
|         Err(errors::ConnectorError::NotImplemented("get_url method".to_string()).into()) | ||||
|     } | ||||
|  | ||||
|     fn build_request( | ||||
|         &self, | ||||
|         req: &types::RefundSyncRouterData, | ||||
|         connectors: &settings::Connectors, | ||||
|     ) -> CustomResult<Option<services::Request>, errors::ConnectorError> { | ||||
|         Ok(Some( | ||||
|             services::RequestBuilder::new() | ||||
|                 .method(services::Method::Get) | ||||
|                 .url(&types::RefundSyncType::get_url(self, req, connectors)?) | ||||
|                 .attach_default_headers() | ||||
|                 .headers(types::RefundSyncType::get_headers(self, req, connectors)?) | ||||
|                 .body(types::RefundSyncType::get_request_body(self, req)?) | ||||
|                 .build(), | ||||
|         )) | ||||
|     } | ||||
|  | ||||
|     fn handle_response( | ||||
|         &self, | ||||
|         data: &types::RefundSyncRouterData, | ||||
|         res: Response, | ||||
|     ) -> CustomResult<types::RefundSyncRouterData, errors::ConnectorError> { | ||||
|         let response: noon::RefundResponse = | ||||
|             res.response | ||||
|                 .parse_struct("noon RefundSyncResponse") | ||||
|                 .change_context(errors::ConnectorError::ResponseDeserializationFailed)?; | ||||
|         types::RouterData::try_from(types::ResponseRouterData { | ||||
|             response, | ||||
|             data: data.clone(), | ||||
|             http_code: res.status_code, | ||||
|         }) | ||||
|         .change_context(errors::ConnectorError::ResponseHandlingFailed) | ||||
|     } | ||||
|  | ||||
|     fn get_error_response( | ||||
|         &self, | ||||
|         res: Response, | ||||
|     ) -> CustomResult<ErrorResponse, errors::ConnectorError> { | ||||
|         self.build_error_response(res) | ||||
|     } | ||||
| } | ||||
|  | ||||
| #[async_trait::async_trait] | ||||
| impl api::IncomingWebhook for Noon { | ||||
|     fn get_webhook_object_reference_id( | ||||
|         &self, | ||||
|         _request: &api::IncomingWebhookRequestDetails<'_>, | ||||
|     ) -> CustomResult<api::webhooks::ObjectReferenceId, errors::ConnectorError> { | ||||
|         Err(errors::ConnectorError::WebhooksNotImplemented).into_report() | ||||
|     } | ||||
|  | ||||
|     fn get_webhook_event_type( | ||||
|         &self, | ||||
|         _request: &api::IncomingWebhookRequestDetails<'_>, | ||||
|     ) -> CustomResult<api::IncomingWebhookEvent, errors::ConnectorError> { | ||||
|         Err(errors::ConnectorError::WebhooksNotImplemented).into_report() | ||||
|     } | ||||
|  | ||||
|     fn get_webhook_resource_object( | ||||
|         &self, | ||||
|         _request: &api::IncomingWebhookRequestDetails<'_>, | ||||
|     ) -> CustomResult<serde_json::Value, errors::ConnectorError> { | ||||
|         Err(errors::ConnectorError::WebhooksNotImplemented).into_report() | ||||
|     } | ||||
| } | ||||
							
								
								
									
										204
									
								
								crates/router/src/connector/noon/transformers.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										204
									
								
								crates/router/src/connector/noon/transformers.rs
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,204 @@ | ||||
| use masking::Secret; | ||||
| use serde::{Deserialize, Serialize}; | ||||
|  | ||||
| use crate::{ | ||||
|     connector::utils::PaymentsAuthorizeRequestData, | ||||
|     core::errors, | ||||
|     types::{self, api, storage::enums}, | ||||
| }; | ||||
|  | ||||
| //TODO: Fill the struct with respective fields | ||||
| #[derive(Default, Debug, Serialize, Eq, PartialEq)] | ||||
| pub struct NoonPaymentsRequest { | ||||
|     amount: i64, | ||||
|     card: NoonCard, | ||||
| } | ||||
|  | ||||
| #[derive(Default, Debug, Serialize, Eq, PartialEq)] | ||||
| pub struct NoonCard { | ||||
|     name: Secret<String>, | ||||
|     number: cards::CardNumber, | ||||
|     expiry_month: Secret<String>, | ||||
|     expiry_year: Secret<String>, | ||||
|     cvc: Secret<String>, | ||||
|     complete: bool, | ||||
| } | ||||
|  | ||||
| impl TryFrom<&types::PaymentsAuthorizeRouterData> for NoonPaymentsRequest { | ||||
|     type Error = error_stack::Report<errors::ConnectorError>; | ||||
|     fn try_from(item: &types::PaymentsAuthorizeRouterData) -> Result<Self, Self::Error> { | ||||
|         match item.request.payment_method_data.clone() { | ||||
|             api::PaymentMethodData::Card(req_card) => { | ||||
|                 let card = NoonCard { | ||||
|                     name: req_card.card_holder_name, | ||||
|                     number: req_card.card_number, | ||||
|                     expiry_month: req_card.card_exp_month, | ||||
|                     expiry_year: req_card.card_exp_year, | ||||
|                     cvc: req_card.card_cvc, | ||||
|                     complete: item.request.is_auto_capture()?, | ||||
|                 }; | ||||
|                 Ok(Self { | ||||
|                     amount: item.request.amount, | ||||
|                     card, | ||||
|                 }) | ||||
|             } | ||||
|             _ => Err(errors::ConnectorError::NotImplemented("Payment methods".to_string()).into()), | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | ||||
| //TODO: Fill the struct with respective fields | ||||
| // Auth Struct | ||||
| pub struct NoonAuthType { | ||||
|     pub(super) api_key: String, | ||||
| } | ||||
|  | ||||
| impl TryFrom<&types::ConnectorAuthType> for NoonAuthType { | ||||
|     type Error = error_stack::Report<errors::ConnectorError>; | ||||
|     fn try_from(auth_type: &types::ConnectorAuthType) -> Result<Self, Self::Error> { | ||||
|         match auth_type { | ||||
|             types::ConnectorAuthType::HeaderKey { api_key } => Ok(Self { | ||||
|                 api_key: api_key.to_string(), | ||||
|             }), | ||||
|             _ => Err(errors::ConnectorError::FailedToObtainAuthType.into()), | ||||
|         } | ||||
|     } | ||||
| } | ||||
| // PaymentsResponse | ||||
| //TODO: Append the remaining status flags | ||||
| #[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq)] | ||||
| #[serde(rename_all = "lowercase")] | ||||
| pub enum NoonPaymentStatus { | ||||
|     Succeeded, | ||||
|     Failed, | ||||
|     #[default] | ||||
|     Processing, | ||||
| } | ||||
|  | ||||
| impl From<NoonPaymentStatus> for enums::AttemptStatus { | ||||
|     fn from(item: NoonPaymentStatus) -> Self { | ||||
|         match item { | ||||
|             NoonPaymentStatus::Succeeded => Self::Charged, | ||||
|             NoonPaymentStatus::Failed => Self::Failure, | ||||
|             NoonPaymentStatus::Processing => Self::Authorizing, | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | ||||
| //TODO: Fill the struct with respective fields | ||||
| #[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq)] | ||||
| pub struct NoonPaymentsResponse { | ||||
|     status: NoonPaymentStatus, | ||||
|     id: String, | ||||
| } | ||||
|  | ||||
| impl<F, T> | ||||
|     TryFrom<types::ResponseRouterData<F, NoonPaymentsResponse, T, types::PaymentsResponseData>> | ||||
|     for types::RouterData<F, T, types::PaymentsResponseData> | ||||
| { | ||||
|     type Error = error_stack::Report<errors::ConnectorError>; | ||||
|     fn try_from( | ||||
|         item: types::ResponseRouterData<F, NoonPaymentsResponse, T, types::PaymentsResponseData>, | ||||
|     ) -> Result<Self, Self::Error> { | ||||
|         Ok(Self { | ||||
|             status: enums::AttemptStatus::from(item.response.status), | ||||
|             response: Ok(types::PaymentsResponseData::TransactionResponse { | ||||
|                 resource_id: types::ResponseId::ConnectorTransactionId(item.response.id), | ||||
|                 redirection_data: None, | ||||
|                 mandate_reference: None, | ||||
|                 connector_metadata: None, | ||||
|                 network_txn_id: None, | ||||
|             }), | ||||
|             ..item.data | ||||
|         }) | ||||
|     } | ||||
| } | ||||
|  | ||||
| //TODO: Fill the struct with respective fields | ||||
| // REFUND : | ||||
| // Type definition for RefundRequest | ||||
| #[derive(Default, Debug, Serialize)] | ||||
| pub struct NoonRefundRequest { | ||||
|     pub amount: i64, | ||||
| } | ||||
|  | ||||
| impl<F> TryFrom<&types::RefundsRouterData<F>> for NoonRefundRequest { | ||||
|     type Error = error_stack::Report<errors::ConnectorError>; | ||||
|     fn try_from(item: &types::RefundsRouterData<F>) -> Result<Self, Self::Error> { | ||||
|         Ok(Self { | ||||
|             amount: item.request.amount, | ||||
|         }) | ||||
|     } | ||||
| } | ||||
|  | ||||
| // Type definition for Refund Response | ||||
|  | ||||
| #[allow(dead_code)] | ||||
| #[derive(Debug, Serialize, Default, Deserialize, Clone)] | ||||
| pub enum RefundStatus { | ||||
|     Succeeded, | ||||
|     Failed, | ||||
|     #[default] | ||||
|     Processing, | ||||
| } | ||||
|  | ||||
| impl From<RefundStatus> for enums::RefundStatus { | ||||
|     fn from(item: RefundStatus) -> Self { | ||||
|         match item { | ||||
|             RefundStatus::Succeeded => Self::Success, | ||||
|             RefundStatus::Failed => Self::Failure, | ||||
|             RefundStatus::Processing => Self::Pending, | ||||
|             //TODO: Review mapping | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | ||||
| //TODO: Fill the struct with respective fields | ||||
| #[derive(Default, Debug, Clone, Serialize, Deserialize)] | ||||
| pub struct RefundResponse { | ||||
|     id: String, | ||||
|     status: RefundStatus, | ||||
| } | ||||
|  | ||||
| impl TryFrom<types::RefundsResponseRouterData<api::Execute, RefundResponse>> | ||||
|     for types::RefundsRouterData<api::Execute> | ||||
| { | ||||
|     type Error = error_stack::Report<errors::ConnectorError>; | ||||
|     fn try_from( | ||||
|         item: types::RefundsResponseRouterData<api::Execute, RefundResponse>, | ||||
|     ) -> Result<Self, Self::Error> { | ||||
|         Ok(Self { | ||||
|             response: Ok(types::RefundsResponseData { | ||||
|                 connector_refund_id: item.response.id.to_string(), | ||||
|                 refund_status: enums::RefundStatus::from(item.response.status), | ||||
|             }), | ||||
|             ..item.data | ||||
|         }) | ||||
|     } | ||||
| } | ||||
|  | ||||
| impl TryFrom<types::RefundsResponseRouterData<api::RSync, RefundResponse>> | ||||
|     for types::RefundsRouterData<api::RSync> | ||||
| { | ||||
|     type Error = error_stack::Report<errors::ConnectorError>; | ||||
|     fn try_from( | ||||
|         item: types::RefundsResponseRouterData<api::RSync, RefundResponse>, | ||||
|     ) -> Result<Self, Self::Error> { | ||||
|         Ok(Self { | ||||
|             response: Ok(types::RefundsResponseData { | ||||
|                 connector_refund_id: item.response.id.to_string(), | ||||
|                 refund_status: enums::RefundStatus::from(item.response.status), | ||||
|             }), | ||||
|             ..item.data | ||||
|         }) | ||||
|     } | ||||
| } | ||||
|  | ||||
| //TODO: Fill the struct with respective fields | ||||
| #[derive(Default, Debug, Serialize, Deserialize, PartialEq)] | ||||
| pub struct NoonErrorResponse { | ||||
|     pub status_code: u16, | ||||
|     pub code: String, | ||||
|     pub message: String, | ||||
|     pub reason: Option<String>, | ||||
| } | ||||
| @ -129,6 +129,7 @@ default_imp_for_complete_authorize!( | ||||
|     connector::Multisafepay, | ||||
|     connector::Nexinets, | ||||
|     connector::Nmi, | ||||
|     connector::Noon, | ||||
|     connector::Opennode, | ||||
|     connector::Payeezy, | ||||
|     connector::Payu, | ||||
| @ -188,6 +189,7 @@ default_imp_for_create_customer!( | ||||
|     connector::Multisafepay, | ||||
|     connector::Nexinets, | ||||
|     connector::Nmi, | ||||
|     connector::Noon, | ||||
|     connector::Nuvei, | ||||
|     connector::Opennode, | ||||
|     connector::Payeezy, | ||||
| @ -246,6 +248,7 @@ default_imp_for_connector_redirect_response!( | ||||
|     connector::Multisafepay, | ||||
|     connector::Nexinets, | ||||
|     connector::Nmi, | ||||
|     connector::Noon, | ||||
|     connector::Opennode, | ||||
|     connector::Payeezy, | ||||
|     connector::Payu, | ||||
| @ -287,6 +290,7 @@ default_imp_for_connector_request_id!( | ||||
|     connector::Mollie, | ||||
|     connector::Multisafepay, | ||||
|     connector::Nmi, | ||||
|     connector::Noon, | ||||
|     connector::Nuvei, | ||||
|     connector::Opennode, | ||||
|     connector::Payeezy, | ||||
| @ -351,6 +355,7 @@ default_imp_for_accept_dispute!( | ||||
|     connector::Multisafepay, | ||||
|     connector::Nexinets, | ||||
|     connector::Nmi, | ||||
|     connector::Noon, | ||||
|     connector::Nuvei, | ||||
|     connector::Payeezy, | ||||
|     connector::Paypal, | ||||
| @ -435,6 +440,7 @@ default_imp_for_file_upload!( | ||||
|     connector::Multisafepay, | ||||
|     connector::Nexinets, | ||||
|     connector::Nmi, | ||||
|     connector::Noon, | ||||
|     connector::Nuvei, | ||||
|     connector::Payeezy, | ||||
|     connector::Paypal, | ||||
| @ -496,6 +502,7 @@ default_imp_for_submit_evidence!( | ||||
|     connector::Multisafepay, | ||||
|     connector::Nexinets, | ||||
|     connector::Nmi, | ||||
|     connector::Noon, | ||||
|     connector::Nuvei, | ||||
|     connector::Payeezy, | ||||
|     connector::Paypal, | ||||
| @ -557,6 +564,7 @@ default_imp_for_defend_dispute!( | ||||
|     connector::Multisafepay, | ||||
|     connector::Nexinets, | ||||
|     connector::Nmi, | ||||
|     connector::Noon, | ||||
|     connector::Nuvei, | ||||
|     connector::Payeezy, | ||||
|     connector::Paypal, | ||||
|  | ||||
| @ -224,6 +224,7 @@ impl ConnectorData { | ||||
|             "klarna" => Ok(Box::new(&connector::Klarna)), | ||||
|             "mollie" => Ok(Box::new(&connector::Mollie)), | ||||
|             "nmi" => Ok(Box::new(&connector::Nmi)), | ||||
|             // "noon" => Ok(Box::new(&connector::Noon)), added as template code for future usage | ||||
|             "nuvei" => Ok(Box::new(&connector::Nuvei)), | ||||
|             "opennode" => Ok(Box::new(&connector::Opennode)), | ||||
|             // "payeezy" => Ok(Box::new(&connector::Payeezy)), As psync and rsync are not supported by this connector, it is added as template code for future usage | ||||
|  | ||||
		Reference in New Issue
	
	Block a user
	 SamraatBansal
					SamraatBansal