Skip to content

Open source, composable payments platform | PCI compliant | SaaS and Self-host options | Enables connectivity to multiple payment, payout, fraud, vault and tokenization providers | Uplifts authorization with intelligent routing and revenue recovery | Reduce payment processing costs with cost observability | Reduces payment ops with reconciliation

feat(router): add payment, refund routes for dummy connector (#1071)

ThisIsMani822fc695a385
diff --git a/config/config.example.toml b/config/config.example.toml
index 3138ae9dcf..c00649aba4 100644
--- a/config/config.example.toml
+++ b/config/config.example.toml
@@ -240,3 +240,15 @@ paypal = { currency = "USD,INR", country = "US" }
[kms]
key_id = "" # The AWS key ID used by the KMS SDK for decrypting data.
region = "" # The AWS region used by the KMS SDK for decrypting data.
+
+[dummy_connector]
+payment_ttl = 172800 # Time to live for dummy connector payment in redis
+payment_duration = 1000 # Fake delay duration for dummy connector payment
+payment_tolerance = 100 # Fake delay tolerance for dummy connector payment
+payment_retrieve_duration = 500 # Fake delay duration for dummy connector payment sync
+payment_retrieve_tolerance = 100 # Fake delay tolerance for dummy connector payment sync
+refund_ttl = 172800 # Time to live for dummy connector refund in redis
+refund_duration = 1000 # Fake delay duration for dummy connector refund
+refund_tolerance = 100 # Fake delay tolerance for dummy connector refund
+refund_retrieve_duration = 500 # Fake delay duration for dummy connector refund sync
+refund_retrieve_tolerance = 100 # Fake delay tolerance for dummy connector refund sync
diff --git a/config/development.toml b/config/development.toml
index 6929bdc045..f5bdd4d6b5 100644
--- a/config/development.toml
+++ b/config/development.toml
@@ -241,3 +241,10 @@ connector_list = "bluesnap,stripe"
payment_ttl = 172800
payment_duration = 1000
payment_tolerance = 100
+payment_retrieve_duration = 500
+payment_retrieve_tolerance = 100
+refund_ttl = 172800
+refund_duration = 1000
+refund_tolerance = 100
+refund_retrieve_duration = 500
+refund_retrieve_tolerance = 100
diff --git a/config/docker_compose.toml b/config/docker_compose.toml
index b7e8a5261a..fbd131a2fc 100644
--- a/config/docker_compose.toml
+++ b/config/docker_compose.toml
@@ -151,3 +151,15 @@ stream = "SCHEDULER_STREAM"
[scheduler.consumer]
disabled = false
consumer_group = "SCHEDULER_GROUP"
+
+[dummy_connector]
+payment_ttl = 172800
+payment_duration = 1000
+payment_tolerance = 100
+payment_retrieve_duration = 500
+payment_retrieve_tolerance = 100
+refund_ttl = 172800
+refund_duration = 1000
+refund_tolerance = 100
+refund_retrieve_duration = 500
+refund_retrieve_tolerance = 100
diff --git a/crates/router/src/configs/settings.rs b/crates/router/src/configs/settings.rs
index 9f2bc3deba..606d086ce2 100644
--- a/crates/router/src/configs/settings.rs
+++ b/crates/router/src/configs/settings.rs
@@ -101,6 +101,13 @@ pub struct DummyConnector {
pub payment_ttl: i64,
pub payment_duration: u64,
pub payment_tolerance: u64,
+ pub payment_retrieve_duration: u64,
+ pub payment_retrieve_tolerance: u64,
+ pub refund_ttl: i64,
+ pub refund_duration: u64,
+ pub refund_tolerance: u64,
+ pub refund_retrieve_duration: u64,
+ pub refund_retrieve_tolerance: u64,
}
#[derive(Debug, Deserialize, Clone, Default)]
diff --git a/crates/router/src/routes/app.rs b/crates/router/src/routes/app.rs
index 98ce3f4467..e32bd5481a 100644
--- a/crates/router/src/routes/app.rs
+++ b/crates/router/src/routes/app.rs
@@ -89,8 +89,19 @@ impl DummyConnector {
{
route = route.guard(actix_web::guard::Host("localhost"));
}
- route =
- route.service(web::resource("/payment").route(web::post().to(dummy_connector_payment)));
+ route = route
+ .service(web::resource("/payment").route(web::post().to(dummy_connector_payment)))
+ .service(
+ web::resource("/payments/{payment_id}")
+ .route(web::get().to(dummy_connector_payment_data)),
+ )
+ .service(
+ web::resource("/{payment_id}/refund").route(web::post().to(dummy_connector_refund)),
+ )
+ .service(
+ web::resource("/refunds/{refund_id}")
+ .route(web::get().to(dummy_connector_refund_data)),
+ );
route
}
}
diff --git a/crates/router/src/routes/dummy_connector.rs b/crates/router/src/routes/dummy_connector.rs
index 133fbb2d3e..457501968a 100644
--- a/crates/router/src/routes/dummy_connector.rs
+++ b/crates/router/src/routes/dummy_connector.rs
@@ -1,7 +1,6 @@
use actix_web::web;
use router_env::{instrument, tracing};
-use self::types::DummyConnectorPaymentRequest;
use super::app;
use crate::services::{api, authentication as auth};
@@ -13,7 +12,7 @@ mod utils;
pub async fn dummy_connector_payment(
state: web::Data<app::AppState>,
req: actix_web::HttpRequest,
- json_payload: web::Json<DummyConnectorPaymentRequest>,
+ json_payload: web::Json<types::DummyConnectorPaymentRequest>,
) -> impl actix_web::Responder {
let flow = types::Flow::DummyPaymentCreate;
let payload = json_payload.into_inner();
@@ -27,3 +26,64 @@ pub async fn dummy_connector_payment(
)
.await
}
+
+#[instrument(skip_all, fields(flow = ?types::Flow::DummyPaymentRetrieve))]
+pub async fn dummy_connector_payment_data(
+ state: web::Data<app::AppState>,
+ req: actix_web::HttpRequest,
+ path: web::Path<String>,
+) -> impl actix_web::Responder {
+ let flow = types::Flow::DummyPaymentRetrieve;
+ let payment_id = path.into_inner();
+ let payload = types::DummyConnectorPaymentRetrieveRequest { payment_id };
+ api::server_wrap(
+ flow,
+ state.get_ref(),
+ &req,
+ payload,
+ |state, _, req| utils::payment_data(state, req),
+ &auth::NoAuth,
+ )
+ .await
+}
+
+#[instrument(skip_all, fields(flow = ?types::Flow::DummyRefundCreate))]
+pub async fn dummy_connector_refund(
+ state: web::Data<app::AppState>,
+ req: actix_web::HttpRequest,
+ json_payload: web::Json<types::DummyConnectorRefundRequest>,
+ path: web::Path<String>,
+) -> impl actix_web::Responder {
+ let flow = types::Flow::DummyRefundCreate;
+ let mut payload = json_payload.into_inner();
+ payload.payment_id = Some(path.to_string());
+ api::server_wrap(
+ flow,
+ state.get_ref(),
+ &req,
+ payload,
+ |state, _, req| utils::refund_payment(state, req),
+ &auth::NoAuth,
+ )
+ .await
+}
+
+#[instrument(skip_all, fields(flow = ?types::Flow::DummyRefundRetrieve))]
+pub async fn dummy_connector_refund_data(
+ state: web::Data<app::AppState>,
+ req: actix_web::HttpRequest,
+ path: web::Path<String>,
+) -> impl actix_web::Responder {
+ let flow = types::Flow::DummyRefundRetrieve;
+ let refund_id = path.into_inner();
+ let payload = types::DummyConnectorRefundRetrieveRequest { refund_id };
+ api::server_wrap(
+ flow,
+ state.get_ref(),
+ &req,
+ payload,
+ |state, _, req| utils::refund_data(state, req),
+ &auth::NoAuth,
+ )
+ .await
+}
diff --git a/crates/router/src/routes/dummy_connector/errors.rs b/crates/router/src/routes/dummy_connector/errors.rs
index 4b75bb4057..9387d67ce8 100644
--- a/crates/router/src/routes/dummy_connector/errors.rs
+++ b/crates/router/src/routes/dummy_connector/errors.rs
@@ -2,13 +2,33 @@
#[serde(rename_all = "snake_case")]
pub enum ErrorType {
ServerNotAvailable,
+ ObjectNotFound,
+ InvalidRequestError,
}
#[derive(Debug, Clone, router_derive::ApiError)]
#[error(error_type_enum = ErrorType)]
pub enum DummyConnectorErrors {
- #[error(error_type = ErrorType::ServerNotAvailable, code = "DC_00", message = "")]
+ #[error(error_type = ErrorType::ServerNotAvailable, code = "DC_00", message = "Error occurred while storing the payment")]
PaymentStoringError,
+
+ #[error(error_type = ErrorType::ObjectNotFound, code = "DC_01", message = "Payment does not exist in our records")]
+ PaymentNotFound,
+
+ #[error(error_type = ErrorType::InvalidRequestError, code = "DC_02", message = "Missing required param: {field_name}")]
+ MissingRequiredField { field_name: &'static str },
+
+ #[error(error_type = ErrorType::InvalidRequestError, code = "DC_03", message = "Refund amount exceeds the payment amount")]
+ RefundAmountExceedsPaymentAmount,
+
+ #[error(error_type = ErrorType::InvalidRequestError, code = "DC_04", message = "Card not supported. Please use test cards")]
+ CardNotSupported,
+
+ #[error(error_type = ErrorType::ObjectNotFound, code = "DC_05", message = "Refund does not exist in our records")]
+ RefundNotFound,
+
+ #[error(error_type = ErrorType::InvalidRequestError, code = "DC_06", message = "Payment is not successful")]
+ PaymentNotSuccessful,
}
impl core::fmt::Display for DummyConnectorErrors {
@@ -28,7 +48,27 @@ impl common_utils::errors::ErrorSwitch<api_models::errors::types::ApiErrorRespon
fn switch(&self) -> api_models::errors::types::ApiErrorResponse {
use api_models::errors::types::{ApiError, ApiErrorResponse as AER};
match self {
- Self::PaymentStoringError => AER::InternalServerError(ApiError::new("DC", 0, "", None)),
+ Self::PaymentStoringError => {
+ AER::InternalServerError(ApiError::new("DC", 0, self.error_message(), None))
+ }
+ Self::PaymentNotFound => {
+ AER::NotFound(ApiError::new("DC", 1, self.error_message(), None))
+ }
+ Self::MissingRequiredField { field_name: _ } => {
+ AER::BadRequest(ApiError::new("DC", 2, self.error_message(), None))
+ }
+ Self::RefundAmountExceedsPaymentAmount => {
+ AER::InternalServerError(ApiError::new("DC", 3, self.error_message(), None))
+ }
+ Self::CardNotSupported => {
+ AER::BadRequest(ApiError::new("DC", 4, self.error_message(), None))
+ }
+ Self::RefundNotFound => {
+ AER::NotFound(ApiError::new("DC", 5, self.error_message(), None))
+ }
+ Self::PaymentNotSuccessful => {
+ AER::BadRequest(ApiError::new("DC", 6, self.error_message(), None))
+ }
}
}
}
diff --git a/crates/router/src/routes/dummy_connector/types.rs b/crates/router/src/routes/dummy_connector/types.rs
index c66fa13d1a..9ebf229c7b 100644
--- a/crates/router/src/routes/dummy_connector/types.rs
+++ b/crates/router/src/routes/dummy_connector/types.rs
@@ -1,21 +1,40 @@
+use api_models::enums::Currency;
use common_utils::errors::CustomResult;
use masking::Secret;
use router_env::types::FlowMetric;
use strum::Display;
+use time::PrimitiveDateTime;
use super::errors::DummyConnectorErrors;
use crate::services;
#[derive(Debug, Display, Clone, PartialEq, Eq)]
+#[allow(clippy::enum_variant_names)]
pub enum Flow {
DummyPaymentCreate,
+ DummyPaymentRetrieve,
+ DummyRefundCreate,
+ DummyRefundRetrieve,
}
impl FlowMetric for Flow {}
+#[allow(dead_code)]
+#[derive(
+ Default, serde::Serialize, serde::Deserialize, strum::Display, Clone, PartialEq, Debug, Eq,
+)]
+#[serde(rename_all = "lowercase")]
+pub enum DummyConnectorStatus {
+ Succeeded,
+ #[default]
+ Processing,
+ Failed,
+}
+
#[derive(Debug, serde::Serialize, Eq, PartialEq, serde::Deserialize)]
pub struct DummyConnectorPaymentRequest {
pub amount: i64,
+ pub currency: Currency,
pub payment_method_data: DummyConnectorPaymentMethodData,
}
@@ -34,65 +53,123 @@ pub struct DummyConnectorCard {
pub complete: bool,
}
-#[derive(Default, Debug, Clone, serde::Serialize, serde::Deserialize, PartialEq)]
+#[derive(
+ Default, serde::Serialize, serde::Deserialize, strum::Display, PartialEq, Debug, Clone,
+)]
+#[serde(rename_all = "lowercase")]
+pub enum PaymentMethodType {
+ #[default]
+ Card,
+}
+
+#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, PartialEq)]
pub struct DummyConnectorPaymentData {
- pub status: String,
+ pub status: DummyConnectorStatus,
pub amount: i64,
pub eligible_amount: i64,
- pub payemnt_method_type: String,
+ pub currency: Currency,
+ #[serde(with = "common_utils::custom_serde::iso8601")]
+ pub created: PrimitiveDateTime,
+ pub payment_method_type: PaymentMethodType,
}
impl DummyConnectorPaymentData {
pub fn new(
- status: String,
+ status: DummyConnectorStatus,
amount: i64,
eligible_amount: i64,
- payemnt_method_type: String,
+ currency: Currency,
+ created: PrimitiveDateTime,
+ payment_method_type: PaymentMethodType,
) -> Self {
Self {
status,
amount,
eligible_amount,
- payemnt_method_type,
+ currency,
+ created,
+ payment_method_type,
}
}
}
-#[allow(dead_code)]
-pub enum DummyConnectorTransactionStatus {
- Success,
- InProcess,
- Fail,
+#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
+pub struct DummyConnectorPaymentResponse {
+ pub status: DummyConnectorStatus,
+ pub id: String,
+ pub amount: i64,
+ pub currency: Currency,
+ #[serde(with = "common_utils::custom_serde::iso8601")]
+ pub created: PrimitiveDateTime,
+ pub payment_method_type: PaymentMethodType,
}
-impl std::fmt::Display for DummyConnectorTransactionStatus {
- fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
- match self {
- Self::Success => write!(f, "succeeded"),
- Self::InProcess => write!(f, "processing"),
- Self::Fail => write!(f, "failed"),
+#[derive(Default, Debug, Clone, serde::Serialize, serde::Deserialize)]
+pub struct DummyConnectorPaymentRetrieveRequest {
+ pub payment_id: String,
+}
+
+impl DummyConnectorPaymentResponse {
+ pub fn new(
+ status: DummyConnectorStatus,
+ id: String,
+ amount: i64,
+ currency: Currency,
+ created: PrimitiveDateTime,
+ payment_method_type: PaymentMethodType,
+ ) -> Self {
+ Self {
+ status,
+ id,
+ amount,
+ currency,
+ created,
+ payment_method_type,
}
}
}
-#[derive(Default, Debug, Clone, serde::Serialize, serde::Deserialize)]
-pub struct DummyConnectorPaymentResponse {
- pub status: String,
- pub id: String,
+#[derive(Default, Debug, serde::Serialize, Eq, PartialEq, serde::Deserialize)]
+pub struct DummyConnectorRefundRequest {
pub amount: i64,
- pub payment_method_type: String,
+ pub payment_id: Option<String>,
}
-impl DummyConnectorPaymentResponse {
- pub fn new(status: String, id: String, amount: i64, payment_method_type: String) -> Self {
+#[derive(Clone, Debug, serde::Serialize, Eq, PartialEq, serde::Deserialize)]
+pub struct DummyConnectorRefundResponse {
+ pub status: DummyConnectorStatus,
+ pub id: String,
+ pub currency: Currency,
+ #[serde(with = "common_utils::custom_serde::iso8601")]
+ pub created: PrimitiveDateTime,
+ pub payment_amount: i64,
+ pub refund_amount: i64,
+}
+
+impl DummyConnectorRefundResponse {
+ pub fn new(
+ status: DummyConnectorStatus,
+ id: String,
+ currency: Currency,
+ created: PrimitiveDateTime,
+ payment_amount: i64,
+ refund_amount: i64,
+ ) -> Self {
Self {
status,
id,
- amount,
- payment_method_type,
+ currency,
+ created,
+ payment_amount,
+ refund_amount,
}
}
}
+#[derive(Default, Debug, Clone, serde::Serialize, serde::Deserialize)]
+pub struct DummyConnectorRefundRetrieveRequest {
+ pub refund_id: String,
+}
+
pub type DummyConnectorResponse<T> =
CustomResult<services::ApplicationResponse<T>, DummyConnectorErrors>;
diff --git a/crates/router/src/routes/dummy_connector/utils.rs b/crates/router/src/routes/dummy_connector/utils.rs
index f218833192..840e1590d4 100644
--- a/crates/router/src/routes/dummy_connector/utils.rs
+++ b/crates/router/src/routes/dummy_connector/utils.rs
@@ -1,12 +1,15 @@
+use std::{fmt::Debug, sync::Arc};
+
use app::AppState;
-use error_stack::{IntoReport, ResultExt};
+use common_utils::generate_id;
+use error_stack::{report, ResultExt};
use masking::PeekInterface;
use rand::Rng;
use redis_interface::RedisConnectionPool;
use tokio::time as tokio;
use super::{errors, types};
-use crate::{connection, core::errors as api_errors, logger, routes::app, services::api};
+use crate::{routes::app, services::api, utils::OptionExt};
pub async fn tokio_mock_sleep(delay: u64, tolerance: u64) {
let mut rng = rand::thread_rng();
@@ -18,69 +21,184 @@ pub async fn payment(
state: &AppState,
req: types::DummyConnectorPaymentRequest,
) -> types::DummyConnectorResponse<types::DummyConnectorPaymentResponse> {
- let payment_id = format!("dummy_{}", uuid::Uuid::new_v4());
+ tokio_mock_sleep(
+ state.conf.dummy_connector.payment_duration,
+ state.conf.dummy_connector.payment_tolerance,
+ )
+ .await;
+
+ let payment_id = generate_id(20, "dummy_pay_");
match req.payment_method_data {
types::DummyConnectorPaymentMethodData::Card(card) => {
let card_number = card.number.peek();
- tokio_mock_sleep(
- state.conf.dummy_connector.payment_duration,
- state.conf.dummy_connector.payment_tolerance,
- )
- .await;
-
- if card_number == "4111111111111111" || card_number == "4242424242424242" {
- let key_for_dummy_payment = format!("p_{}", payment_id);
-
- let redis_conn = connection::redis_connection(&state.conf).await;
- store_payment_data(
- &redis_conn,
- key_for_dummy_payment,
- types::DummyConnectorPaymentData::new(
- types::DummyConnectorTransactionStatus::Success.to_string(),
- req.amount,
- req.amount,
- "card".to_string(),
- ),
- state.conf.dummy_connector.payment_ttl,
- )
- .await?;
-
- Ok(api::ApplicationResponse::Json(
- types::DummyConnectorPaymentResponse::new(
- types::DummyConnectorTransactionStatus::Success.to_string(),
- payment_id,
+
+ match card_number.as_str() {
+ "4111111111111111" | "4242424242424242" => {
+ let timestamp = common_utils::date_time::now();
+ let payment_data = types::DummyConnectorPaymentData::new(
+ types::DummyConnectorStatus::Succeeded,
req.amount,
- "card".to_string(),
- ),
- ))
- } else {
- Ok(api::ApplicationResponse::Json(
- types::DummyConnectorPaymentResponse::new(
- types::DummyConnectorTransactionStatus::Fail.to_string(),
- payment_id,
req.amount,
- "card".to_string(),
- ),
- ))
+ req.currency,
+ timestamp.to_owned(),
+ types::PaymentMethodType::Card,
+ );
+ let redis_conn = state.store.get_redis_conn();
+ store_data_in_redis(
+ redis_conn,
+ payment_id.to_owned(),
+ payment_data,
+ state.conf.dummy_connector.payment_ttl,
+ )
+ .await?;
+ Ok(api::ApplicationResponse::Json(
+ types::DummyConnectorPaymentResponse::new(
+ types::DummyConnectorStatus::Succeeded,
+ payment_id,
+ req.amount,
+ req.currency,
+ timestamp,
+ types::PaymentMethodType::Card,
+ ),
+ ))
+ }
+ _ => Err(report!(errors::DummyConnectorErrors::CardNotSupported)
+ .attach_printable("The card is not supported")),
}
}
}
}
-async fn store_payment_data(
- redis_conn: &RedisConnectionPool,
+pub async fn payment_data(
+ state: &AppState,
+ req: types::DummyConnectorPaymentRetrieveRequest,
+) -> types::DummyConnectorResponse<types::DummyConnectorPaymentResponse> {
+ let payment_id = req.payment_id;
+ tokio_mock_sleep(
+ state.conf.dummy_connector.payment_retrieve_duration,
+ state.conf.dummy_connector.payment_retrieve_tolerance,
+ )
+ .await;
+
+ let redis_conn = state.store.get_redis_conn();
+ let payment_data = redis_conn
+ .get_and_deserialize_key::<types::DummyConnectorPaymentData>(
+ payment_id.as_str(),
+ "DummyConnectorPaymentData",
+ )
+ .await
+ .change_context(errors::DummyConnectorErrors::PaymentNotFound)?;
+
+ Ok(api::ApplicationResponse::Json(
+ types::DummyConnectorPaymentResponse::new(
+ payment_data.status,
+ payment_id,
+ payment_data.amount,
+ payment_data.currency,
+ payment_data.created,
+ payment_data.payment_method_type,
+ ),
+ ))
+}
+
+pub async fn refund_payment(
+ state: &AppState,
+ req: types::DummyConnectorRefundRequest,
+) -> types::DummyConnectorResponse<types::DummyConnectorRefundResponse> {
+ tokio_mock_sleep(
+ state.conf.dummy_connector.refund_duration,
+ state.conf.dummy_connector.refund_tolerance,
+ )
+ .await;
+
+ let payment_id = req
+ .payment_id
+ .get_required_value("payment_id")
+ .change_context(errors::DummyConnectorErrors::MissingRequiredField {
+ field_name: "payment_id",
+ })?;
+
+ let redis_conn = state.store.get_redis_conn();
+ let mut payment_data = redis_conn
+ .get_and_deserialize_key::<types::DummyConnectorPaymentData>(
+ payment_id.as_str(),
+ "DummyConnectorPaymentData",
+ )
+ .await
+ .change_context(errors::DummyConnectorErrors::PaymentNotFound)?;
+
+ if payment_data.eligible_amount < req.amount {
+ return Err(
+ report!(errors::DummyConnectorErrors::RefundAmountExceedsPaymentAmount)
+ .attach_printable("Eligible amount is lesser than refund amount"),
+ );
+ }
+
+ if payment_data.status != types::DummyConnectorStatus::Succeeded {
+ return Err(report!(errors::DummyConnectorErrors::PaymentNotSuccessful)
+ .attach_printable("Payment is not successful to process the refund"));
+ }
+
+ let refund_id = generate_id(20, "dummy_ref_");
+ payment_data.eligible_amount -= req.amount;
+ store_data_in_redis(
+ redis_conn.to_owned(),
+ payment_id,
+ payment_data.to_owned(),
+ state.conf.dummy_connector.payment_ttl,
+ )
+ .await?;
+
+ let refund_data = types::DummyConnectorRefundResponse::new(
+ types::DummyConnectorStatus::Succeeded,
+ refund_id.to_owned(),
+ payment_data.currency,
+ common_utils::date_time::now(),
+ payment_data.amount,
+ req.amount,
+ );
+
+ store_data_in_redis(
+ redis_conn,
+ refund_id,
+ refund_data.to_owned(),
+ state.conf.dummy_connector.refund_ttl,
+ )
+ .await?;
+ Ok(api::ApplicationResponse::Json(refund_data))
+}
+
+pub async fn refund_data(
+ state: &AppState,
+ req: types::DummyConnectorRefundRetrieveRequest,
+) -> types::DummyConnectorResponse<types::DummyConnectorRefundResponse> {
+ let refund_id = req.refund_id;
+ tokio_mock_sleep(
+ state.conf.dummy_connector.refund_retrieve_duration,
+ state.conf.dummy_connector.refund_retrieve_tolerance,
+ )
+ .await;
+
+ let redis_conn = state.store.get_redis_conn();
+ let refund_data = redis_conn
+ .get_and_deserialize_key::<types::DummyConnectorRefundResponse>(
+ refund_id.as_str(),
+ "DummyConnectorRefundResponse",
+ )
+ .await
+ .change_context(errors::DummyConnectorErrors::RefundNotFound)?;
+ Ok(api::ApplicationResponse::Json(refund_data))
+}
+
+async fn store_data_in_redis(
+ redis_conn: Arc<RedisConnectionPool>,
key: String,
- payment_data: types::DummyConnectorPaymentData,
+ data: impl serde::Serialize + Debug,
ttl: i64,
) -> Result<(), error_stack::Report<errors::DummyConnectorErrors>> {
redis_conn
- .serialize_and_set_key_with_expiry(&key, payment_data, ttl)
+ .serialize_and_set_key_with_expiry(&key, data, ttl)
.await
- .map_err(|error| {
- logger::error!(dummy_connector_payment_storage_error=?error);
- api_errors::StorageError::KVError
- })
- .into_report()
.change_context(errors::DummyConnectorErrors::PaymentStoringError)
.attach_printable("Failed to add data in redis")?;
Ok(())
diff --git a/loadtest/config/development.toml b/loadtest/config/development.toml
index 70b88c322d..7127a2b8d4 100644
--- a/loadtest/config/development.toml
+++ b/loadtest/config/development.toml
@@ -131,3 +131,15 @@ cards = [
"worldpay",
"zen",
]
+
+[dummy_connector]
+payment_ttl = 172800
+payment_duration = 1000
+payment_tolerance = 100
+payment_retrieve_duration = 500
+payment_retrieve_tolerance = 100
+refund_ttl = 172800
+refund_duration = 1000
+refund_tolerance = 100
+refund_retrieve_duration = 500
+refund_retrieve_tolerance = 100