mirror of
				https://github.com/juspay/hyperswitch.git
				synced 2025-11-01 02:57:02 +08:00 
			
		
		
		
	feat(connector): add payment, refund urls for dummy connector (#1084)
This commit is contained in:
		| @ -2,9 +2,11 @@ mod transformers; | |||||||
|  |  | ||||||
| use std::fmt::Debug; | use std::fmt::Debug; | ||||||
|  |  | ||||||
|  | use api_models::payments::PaymentMethodData; | ||||||
| use error_stack::{IntoReport, ResultExt}; | use error_stack::{IntoReport, ResultExt}; | ||||||
| use transformers as dummyconnector; | use transformers as dummyconnector; | ||||||
|  |  | ||||||
|  | use super::utils::{PaymentsAuthorizeRequestData, RefundsRequestData}; | ||||||
| use crate::{ | use crate::{ | ||||||
|     configs::settings, |     configs::settings, | ||||||
|     core::errors::{self, CustomResult}, |     core::errors::{self, CustomResult}, | ||||||
| @ -96,9 +98,9 @@ impl ConnectorCommon for DummyConnector { | |||||||
|  |  | ||||||
|         Ok(ErrorResponse { |         Ok(ErrorResponse { | ||||||
|             status_code: res.status_code, |             status_code: res.status_code, | ||||||
|             code: response.code, |             code: response.error.code, | ||||||
|             message: response.message, |             message: response.error.message, | ||||||
|             reason: response.reason, |             reason: response.error.reason, | ||||||
|         }) |         }) | ||||||
|     } |     } | ||||||
| } | } | ||||||
| @ -136,10 +138,22 @@ impl ConnectorIntegration<api::Authorize, types::PaymentsAuthorizeData, types::P | |||||||
|  |  | ||||||
|     fn get_url( |     fn get_url( | ||||||
|         &self, |         &self, | ||||||
|         _req: &types::PaymentsAuthorizeRouterData, |         req: &types::PaymentsAuthorizeRouterData, | ||||||
|         _connectors: &settings::Connectors, |         connectors: &settings::Connectors, | ||||||
|     ) -> CustomResult<String, errors::ConnectorError> { |     ) -> CustomResult<String, errors::ConnectorError> { | ||||||
|         Err(errors::ConnectorError::NotImplemented("get_url method".to_string()).into()) |         let payment_method_data = req.request.payment_method_data.to_owned(); | ||||||
|  |         let payment_method_type = req.request.get_payment_method_type()?; | ||||||
|  |         match payment_method_data { | ||||||
|  |             PaymentMethodData::Card(_) => Ok(format!("{}/payment", self.base_url(connectors))), | ||||||
|  |             _ => Err(error_stack::report!(errors::ConnectorError::NotSupported { | ||||||
|  |                 message: format!( | ||||||
|  |                     "The payment method {} is not supported", | ||||||
|  |                     payment_method_type | ||||||
|  |                 ), | ||||||
|  |                 connector: "dummyconnector", | ||||||
|  |                 payment_experience: api::enums::PaymentExperience::RedirectToUrl.to_string(), | ||||||
|  |             })), | ||||||
|  |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     fn get_request_body( |     fn get_request_body( | ||||||
| @ -180,7 +194,7 @@ impl ConnectorIntegration<api::Authorize, types::PaymentsAuthorizeData, types::P | |||||||
|         data: &types::PaymentsAuthorizeRouterData, |         data: &types::PaymentsAuthorizeRouterData, | ||||||
|         res: Response, |         res: Response, | ||||||
|     ) -> CustomResult<types::PaymentsAuthorizeRouterData, errors::ConnectorError> { |     ) -> CustomResult<types::PaymentsAuthorizeRouterData, errors::ConnectorError> { | ||||||
|         let response: dummyconnector::DummyConnectorPaymentsResponse = res |         let response: dummyconnector::PaymentsResponse = res | ||||||
|             .response |             .response | ||||||
|             .parse_struct("DummyConnector PaymentsAuthorizeResponse") |             .parse_struct("DummyConnector PaymentsAuthorizeResponse") | ||||||
|             .change_context(errors::ConnectorError::ResponseDeserializationFailed)?; |             .change_context(errors::ConnectorError::ResponseDeserializationFailed)?; | ||||||
| @ -217,10 +231,23 @@ impl ConnectorIntegration<api::PSync, types::PaymentsSyncData, types::PaymentsRe | |||||||
|  |  | ||||||
|     fn get_url( |     fn get_url( | ||||||
|         &self, |         &self, | ||||||
|         _req: &types::PaymentsSyncRouterData, |         req: &types::PaymentsSyncRouterData, | ||||||
|         _connectors: &settings::Connectors, |         connectors: &settings::Connectors, | ||||||
|     ) -> CustomResult<String, errors::ConnectorError> { |     ) -> CustomResult<String, errors::ConnectorError> { | ||||||
|         Err(errors::ConnectorError::NotImplemented("get_url method".to_string()).into()) |         match req | ||||||
|  |             .request | ||||||
|  |             .connector_transaction_id | ||||||
|  |             .get_connector_transaction_id() | ||||||
|  |         { | ||||||
|  |             Ok(transaction_id) => Ok(format!( | ||||||
|  |                 "{}/payments/{}", | ||||||
|  |                 self.base_url(connectors), | ||||||
|  |                 transaction_id | ||||||
|  |             )), | ||||||
|  |             Err(_) => Err(error_stack::report!( | ||||||
|  |                 errors::ConnectorError::MissingConnectorTransactionID | ||||||
|  |             )), | ||||||
|  |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     fn build_request( |     fn build_request( | ||||||
| @ -243,7 +270,7 @@ impl ConnectorIntegration<api::PSync, types::PaymentsSyncData, types::PaymentsRe | |||||||
|         data: &types::PaymentsSyncRouterData, |         data: &types::PaymentsSyncRouterData, | ||||||
|         res: Response, |         res: Response, | ||||||
|     ) -> CustomResult<types::PaymentsSyncRouterData, errors::ConnectorError> { |     ) -> CustomResult<types::PaymentsSyncRouterData, errors::ConnectorError> { | ||||||
|         let response: dummyconnector::DummyConnectorPaymentsResponse = res |         let response: dummyconnector::PaymentsResponse = res | ||||||
|             .response |             .response | ||||||
|             .parse_struct("dummyconnector PaymentsSyncResponse") |             .parse_struct("dummyconnector PaymentsSyncResponse") | ||||||
|             .change_context(errors::ConnectorError::ResponseDeserializationFailed)?; |             .change_context(errors::ConnectorError::ResponseDeserializationFailed)?; | ||||||
| @ -315,7 +342,7 @@ impl ConnectorIntegration<api::Capture, types::PaymentsCaptureData, types::Payme | |||||||
|         data: &types::PaymentsCaptureRouterData, |         data: &types::PaymentsCaptureRouterData, | ||||||
|         res: Response, |         res: Response, | ||||||
|     ) -> CustomResult<types::PaymentsCaptureRouterData, errors::ConnectorError> { |     ) -> CustomResult<types::PaymentsCaptureRouterData, errors::ConnectorError> { | ||||||
|         let response: dummyconnector::DummyConnectorPaymentsResponse = res |         let response: dummyconnector::PaymentsResponse = res | ||||||
|             .response |             .response | ||||||
|             .parse_struct("DummyConnector PaymentsCaptureResponse") |             .parse_struct("DummyConnector PaymentsCaptureResponse") | ||||||
|             .change_context(errors::ConnectorError::ResponseDeserializationFailed)?; |             .change_context(errors::ConnectorError::ResponseDeserializationFailed)?; | ||||||
| @ -357,10 +384,14 @@ impl ConnectorIntegration<api::Execute, types::RefundsData, types::RefundsRespon | |||||||
|  |  | ||||||
|     fn get_url( |     fn get_url( | ||||||
|         &self, |         &self, | ||||||
|         _req: &types::RefundsRouterData<api::Execute>, |         req: &types::RefundsRouterData<api::Execute>, | ||||||
|         _connectors: &settings::Connectors, |         connectors: &settings::Connectors, | ||||||
|     ) -> CustomResult<String, errors::ConnectorError> { |     ) -> CustomResult<String, errors::ConnectorError> { | ||||||
|         Err(errors::ConnectorError::NotImplemented("get_url method".to_string()).into()) |         Ok(format!( | ||||||
|  |             "{}/{}/refund", | ||||||
|  |             self.base_url(connectors), | ||||||
|  |             req.request.connector_transaction_id | ||||||
|  |         )) | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     fn get_request_body( |     fn get_request_body( | ||||||
| @ -435,10 +466,15 @@ impl ConnectorIntegration<api::RSync, types::RefundsData, types::RefundsResponse | |||||||
|  |  | ||||||
|     fn get_url( |     fn get_url( | ||||||
|         &self, |         &self, | ||||||
|         _req: &types::RefundSyncRouterData, |         req: &types::RefundSyncRouterData, | ||||||
|         _connectors: &settings::Connectors, |         connectors: &settings::Connectors, | ||||||
|     ) -> CustomResult<String, errors::ConnectorError> { |     ) -> CustomResult<String, errors::ConnectorError> { | ||||||
|         Err(errors::ConnectorError::NotImplemented("get_url method".to_string()).into()) |         let refund_id = req.request.get_connector_refund_id()?; | ||||||
|  |         Ok(format!( | ||||||
|  |             "{}/refunds/{}", | ||||||
|  |             self.base_url(connectors), | ||||||
|  |             refund_id | ||||||
|  |         )) | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     fn build_request( |     fn build_request( | ||||||
|  | |||||||
| @ -1,5 +1,6 @@ | |||||||
| use masking::Secret; | use masking::Secret; | ||||||
| use serde::{Deserialize, Serialize}; | use serde::{Deserialize, Serialize}; | ||||||
|  | use storage_models::enums::Currency; | ||||||
|  |  | ||||||
| use crate::{ | use crate::{ | ||||||
|     connector::utils::PaymentsAuthorizeRequestData, |     connector::utils::PaymentsAuthorizeRequestData, | ||||||
| @ -7,14 +8,19 @@ use crate::{ | |||||||
|     types::{self, api, storage::enums}, |     types::{self, api, storage::enums}, | ||||||
| }; | }; | ||||||
|  |  | ||||||
| //TODO: Fill the struct with respective fields | #[derive(Debug, Serialize, Eq, PartialEq)] | ||||||
| #[derive(Default, Debug, Serialize, Eq, PartialEq)] |  | ||||||
| pub struct DummyConnectorPaymentsRequest { | pub struct DummyConnectorPaymentsRequest { | ||||||
|     amount: i64, |     amount: i64, | ||||||
|     card: DummyConnectorCard, |     currency: Currency, | ||||||
|  |     payment_method_data: PaymentMethodData, | ||||||
| } | } | ||||||
|  |  | ||||||
| #[derive(Default, Debug, Serialize, Eq, PartialEq)] | #[derive(Debug, serde::Serialize, Eq, PartialEq)] | ||||||
|  | pub enum PaymentMethodData { | ||||||
|  |     Card(DummyConnectorCard), | ||||||
|  | } | ||||||
|  |  | ||||||
|  | #[derive(Debug, Serialize, Eq, PartialEq)] | ||||||
| pub struct DummyConnectorCard { | pub struct DummyConnectorCard { | ||||||
|     name: Secret<String>, |     name: Secret<String>, | ||||||
|     number: cards::CardNumber, |     number: cards::CardNumber, | ||||||
| @ -39,7 +45,8 @@ impl TryFrom<&types::PaymentsAuthorizeRouterData> for DummyConnectorPaymentsRequ | |||||||
|                 }; |                 }; | ||||||
|                 Ok(Self { |                 Ok(Self { | ||||||
|                     amount: item.request.amount, |                     amount: item.request.amount, | ||||||
|                     card, |                     currency: item.request.currency, | ||||||
|  |                     payment_method_data: PaymentMethodData::Card(card), | ||||||
|                 }) |                 }) | ||||||
|             } |             } | ||||||
|             _ => Err(errors::ConnectorError::NotImplemented("Payment methods".to_string()).into()), |             _ => Err(errors::ConnectorError::NotImplemented("Payment methods".to_string()).into()), | ||||||
| @ -47,7 +54,6 @@ impl TryFrom<&types::PaymentsAuthorizeRouterData> for DummyConnectorPaymentsRequ | |||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
| //TODO: Fill the struct with respective fields |  | ||||||
| // Auth Struct | // Auth Struct | ||||||
| pub struct DummyConnectorAuthType { | pub struct DummyConnectorAuthType { | ||||||
|     pub(super) api_key: String, |     pub(super) api_key: String, | ||||||
| @ -85,31 +91,22 @@ impl From<DummyConnectorPaymentStatus> for enums::AttemptStatus { | |||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
| //TODO: Fill the struct with respective fields |  | ||||||
| #[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq)] | #[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq)] | ||||||
| pub struct DummyConnectorPaymentsResponse { | pub struct PaymentsResponse { | ||||||
|     status: DummyConnectorPaymentStatus, |     status: DummyConnectorPaymentStatus, | ||||||
|     id: String, |     id: String, | ||||||
|  |     amount: i64, | ||||||
|  |     currency: Currency, | ||||||
|  |     created: String, | ||||||
|  |     payment_method_type: String, | ||||||
| } | } | ||||||
|  |  | ||||||
| impl<F, T> | impl<F, T> TryFrom<types::ResponseRouterData<F, PaymentsResponse, T, types::PaymentsResponseData>> | ||||||
|     TryFrom< |     for types::RouterData<F, T, types::PaymentsResponseData> | ||||||
|         types::ResponseRouterData< |  | ||||||
|             F, |  | ||||||
|             DummyConnectorPaymentsResponse, |  | ||||||
|             T, |  | ||||||
|             types::PaymentsResponseData, |  | ||||||
|         >, |  | ||||||
|     > for types::RouterData<F, T, types::PaymentsResponseData> |  | ||||||
| { | { | ||||||
|     type Error = error_stack::Report<errors::ConnectorError>; |     type Error = error_stack::Report<errors::ConnectorError>; | ||||||
|     fn try_from( |     fn try_from( | ||||||
|         item: types::ResponseRouterData< |         item: types::ResponseRouterData<F, PaymentsResponse, T, types::PaymentsResponseData>, | ||||||
|             F, |  | ||||||
|             DummyConnectorPaymentsResponse, |  | ||||||
|             T, |  | ||||||
|             types::PaymentsResponseData, |  | ||||||
|         >, |  | ||||||
|     ) -> Result<Self, Self::Error> { |     ) -> Result<Self, Self::Error> { | ||||||
|         Ok(Self { |         Ok(Self { | ||||||
|             status: enums::AttemptStatus::from(item.response.status), |             status: enums::AttemptStatus::from(item.response.status), | ||||||
| @ -125,7 +122,6 @@ impl<F, T> | |||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
| //TODO: Fill the struct with respective fields |  | ||||||
| // REFUND : | // REFUND : | ||||||
| // Type definition for RefundRequest | // Type definition for RefundRequest | ||||||
| #[derive(Default, Debug, Serialize)] | #[derive(Default, Debug, Serialize)] | ||||||
| @ -137,7 +133,7 @@ impl<F> TryFrom<&types::RefundsRouterData<F>> for DummyConnectorRefundRequest { | |||||||
|     type Error = error_stack::Report<errors::ConnectorError>; |     type Error = error_stack::Report<errors::ConnectorError>; | ||||||
|     fn try_from(item: &types::RefundsRouterData<F>) -> Result<Self, Self::Error> { |     fn try_from(item: &types::RefundsRouterData<F>) -> Result<Self, Self::Error> { | ||||||
|         Ok(Self { |         Ok(Self { | ||||||
|             amount: item.request.amount, |             amount: item.request.refund_amount, | ||||||
|         }) |         }) | ||||||
|     } |     } | ||||||
| } | } | ||||||
| @ -146,6 +142,7 @@ impl<F> TryFrom<&types::RefundsRouterData<F>> for DummyConnectorRefundRequest { | |||||||
|  |  | ||||||
| #[allow(dead_code)] | #[allow(dead_code)] | ||||||
| #[derive(Debug, Serialize, Default, Deserialize, Clone)] | #[derive(Debug, Serialize, Default, Deserialize, Clone)] | ||||||
|  | #[serde(rename_all = "lowercase")] | ||||||
| pub enum RefundStatus { | pub enum RefundStatus { | ||||||
|     Succeeded, |     Succeeded, | ||||||
|     Failed, |     Failed, | ||||||
| @ -164,11 +161,14 @@ impl From<RefundStatus> for enums::RefundStatus { | |||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
| //TODO: Fill the struct with respective fields |  | ||||||
| #[derive(Default, Debug, Clone, Serialize, Deserialize)] | #[derive(Default, Debug, Clone, Serialize, Deserialize)] | ||||||
| pub struct RefundResponse { | pub struct RefundResponse { | ||||||
|     id: String, |     id: String, | ||||||
|     status: RefundStatus, |     status: RefundStatus, | ||||||
|  |     currency: Currency, | ||||||
|  |     created: String, | ||||||
|  |     payment_amount: i64, | ||||||
|  |     refund_amount: i64, | ||||||
| } | } | ||||||
|  |  | ||||||
| impl TryFrom<types::RefundsResponseRouterData<api::Execute, RefundResponse>> | impl TryFrom<types::RefundsResponseRouterData<api::Execute, RefundResponse>> | ||||||
| @ -205,10 +205,13 @@ impl TryFrom<types::RefundsResponseRouterData<api::RSync, RefundResponse>> | |||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
| //TODO: Fill the struct with respective fields |  | ||||||
| #[derive(Default, Debug, Serialize, Deserialize, PartialEq)] | #[derive(Default, Debug, Serialize, Deserialize, PartialEq)] | ||||||
| pub struct DummyConnectorErrorResponse { | pub struct DummyConnectorErrorResponse { | ||||||
|     pub status_code: u16, |     pub error: ErrorData, | ||||||
|  | } | ||||||
|  |  | ||||||
|  | #[derive(Default, Debug, Serialize, Deserialize, PartialEq)] | ||||||
|  | pub struct ErrorData { | ||||||
|     pub code: String, |     pub code: String, | ||||||
|     pub message: String, |     pub message: String, | ||||||
|     pub reason: Option<String>, |     pub reason: Option<String>, | ||||||
|  | |||||||
| @ -170,6 +170,7 @@ pub trait PaymentsAuthorizeRequestData { | |||||||
|     fn is_mandate_payment(&self) -> bool; |     fn is_mandate_payment(&self) -> bool; | ||||||
|     fn get_webhook_url(&self) -> Result<String, Error>; |     fn get_webhook_url(&self) -> Result<String, Error>; | ||||||
|     fn get_router_return_url(&self) -> Result<String, Error>; |     fn get_router_return_url(&self) -> Result<String, Error>; | ||||||
|  |     fn get_payment_method_type(&self) -> Result<storage_models::enums::PaymentMethodType, Error>; | ||||||
| } | } | ||||||
|  |  | ||||||
| impl PaymentsAuthorizeRequestData for types::PaymentsAuthorizeData { | impl PaymentsAuthorizeRequestData for types::PaymentsAuthorizeData { | ||||||
| @ -233,6 +234,11 @@ impl PaymentsAuthorizeRequestData for types::PaymentsAuthorizeData { | |||||||
|             .clone() |             .clone() | ||||||
|             .ok_or_else(missing_field_err("webhook_url")) |             .ok_or_else(missing_field_err("webhook_url")) | ||||||
|     } |     } | ||||||
|  |     fn get_payment_method_type(&self) -> Result<storage_models::enums::PaymentMethodType, Error> { | ||||||
|  |         self.payment_method_type | ||||||
|  |             .to_owned() | ||||||
|  |             .ok_or_else(missing_field_err("payment_method_type")) | ||||||
|  |     } | ||||||
| } | } | ||||||
|  |  | ||||||
| pub trait BrowserInformationData { | pub trait BrowserInformationData { | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user
	 ThisIsMani
					ThisIsMani