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): [dummy_connector] add upi collect (#8014)

AkshayaFoiger32df40124a9d
diff --git a/crates/router/src/connector/dummyconnector.rs b/crates/router/src/connector/dummyconnector.rs
index fabdb5ba8e..ea63a27102 100644
--- a/crates/router/src/connector/dummyconnector.rs
+++ b/crates/router/src/connector/dummyconnector.rs
@@ -209,9 +209,12 @@ impl<const T: u8>
connectors: &settings::Connectors,
) -> CustomResult<String, errors::ConnectorError> {
match req.payment_method {
- enums::PaymentMethod::Card => Ok(format!("{}/payment", self.base_url(connectors))),
- enums::PaymentMethod::Wallet => Ok(format!("{}/payment", self.base_url(connectors))),
- enums::PaymentMethod::PayLater => Ok(format!("{}/payment", self.base_url(connectors))),
+ enums::PaymentMethod::Card
+ | enums::PaymentMethod::Upi
+ | enums::PaymentMethod::Wallet
+ | enums::PaymentMethod::PayLater => {
+ Ok(format!("{}/payment", self.base_url(connectors)))
+ }
_ => Err(error_stack::report!(errors::ConnectorError::NotSupported {
message: format!("The payment method {} is not supported", req.payment_method),
connector: Into::<transformers::DummyConnectors>::into(T).get_dummy_connector_id(),
diff --git a/crates/router/src/connector/dummyconnector/transformers.rs b/crates/router/src/connector/dummyconnector/transformers.rs
index 9d745ca197..392a2249d9 100644
--- a/crates/router/src/connector/dummyconnector/transformers.rs
+++ b/crates/router/src/connector/dummyconnector/transformers.rs
@@ -1,3 +1,4 @@
+use common_utils::pii;
use diesel_models::enums::Currency;
use masking::Secret;
use serde::{Deserialize, Serialize};
@@ -73,6 +74,31 @@ pub enum PaymentMethodData {
Card(DummyConnectorCard),
Wallet(DummyConnectorWallet),
PayLater(DummyConnectorPayLater),
+ Upi(DummyConnectorUpi),
+}
+
+#[derive(Clone, Debug, serde::Serialize, Eq, PartialEq, serde::Deserialize)]
+#[serde(rename_all = "snake_case")]
+pub enum DummyConnectorUpi {
+ UpiCollect(DummyConnectorUpiCollect),
+}
+
+#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq)]
+pub struct DummyConnectorUpiCollect {
+ vpa_id: Secret<String, pii::UpiVpaMaskingStrategy>,
+}
+
+impl TryFrom<domain::UpiCollectData> for DummyConnectorUpi {
+ type Error = error_stack::Report<errors::ConnectorError>;
+ fn try_from(value: domain::UpiCollectData) -> Result<Self, Self::Error> {
+ Ok(Self::UpiCollect(DummyConnectorUpiCollect {
+ vpa_id: value
+ .vpa_id
+ .ok_or(errors::ConnectorError::MissingRequiredField {
+ field_name: "vpa_id",
+ })?,
+ }))
+ }
}
#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq)]
@@ -161,6 +187,14 @@ impl<const T: u8> TryFrom<&types::PaymentsAuthorizeRouterData>
card_holder_name,
))?))
}
+ domain::PaymentMethodData::Upi(ref req_upi_data) => match req_upi_data {
+ domain::UpiData::UpiCollect(data) => Ok(PaymentMethodData::Upi(
+ DummyConnectorUpi::try_from(data.clone())?,
+ )),
+ domain::UpiData::UpiIntent(_) => {
+ Err(errors::ConnectorError::NotImplemented("UPI Intent".to_string()).into())
+ }
+ },
domain::PaymentMethodData::Wallet(ref wallet_data) => {
Ok(PaymentMethodData::Wallet(wallet_data.clone().try_into()?))
}
@@ -231,10 +265,16 @@ pub struct PaymentsResponse {
#[serde(rename_all = "lowercase")]
pub enum PaymentMethodType {
Card,
+ Upi(DummyConnectorUpiType),
Wallet(DummyConnectorWallet),
PayLater(DummyConnectorPayLater),
}
+#[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq)]
+pub enum DummyConnectorUpiType {
+ UpiCollect,
+}
+
impl<F, T> TryFrom<types::ResponseRouterData<F, PaymentsResponse, T, types::PaymentsResponseData>>
for types::RouterData<F, T, types::PaymentsResponseData>
{
diff --git a/crates/router/src/routes/dummy_connector/consts.rs b/crates/router/src/routes/dummy_connector/consts.rs
index ffd89fc9e9..d5474cfdda 100644
--- a/crates/router/src/routes/dummy_connector/consts.rs
+++ b/crates/router/src/routes/dummy_connector/consts.rs
@@ -1,3 +1,5 @@
pub const ATTEMPT_ID_PREFIX: &str = "dummy_attempt";
pub const REFUND_ID_PREFIX: &str = "dummy_ref";
pub const THREE_DS_CSS: &str = include_str!("threeds_page.css");
+pub const DUMMY_CONNECTOR_UPI_FAILURE_VPA_ID: &str = "failure@upi";
+pub const DUMMY_CONNECTOR_UPI_SUCCESS_VPA_ID: &str = "success@upi";
diff --git a/crates/router/src/routes/dummy_connector/types.rs b/crates/router/src/routes/dummy_connector/types.rs
index fa84ab1f55..e58342c258 100644
--- a/crates/router/src/routes/dummy_connector/types.rs
+++ b/crates/router/src/routes/dummy_connector/types.rs
@@ -1,5 +1,5 @@
use api_models::enums::Currency;
-use common_utils::{errors::CustomResult, generate_id_with_default_len};
+use common_utils::{errors::CustomResult, generate_id_with_default_len, pii};
use error_stack::report;
use masking::Secret;
use router_env::types::FlowMetric;
@@ -129,6 +129,7 @@ pub trait GetPaymentMethodDetails {
#[serde(rename_all = "lowercase")]
pub enum DummyConnectorPaymentMethodData {
Card(DummyConnectorCard),
+ Upi(DummyConnectorUpi),
Wallet(DummyConnectorWallet),
PayLater(DummyConnectorPayLater),
}
@@ -140,6 +141,7 @@ pub enum DummyConnectorPaymentMethodData {
pub enum DummyConnectorPaymentMethodType {
#[default]
Card,
+ Upi(DummyConnectorUpiType),
Wallet(DummyConnectorWallet),
PayLater(DummyConnectorPayLater),
}
@@ -148,6 +150,9 @@ impl From<DummyConnectorPaymentMethodData> for DummyConnectorPaymentMethodType {
fn from(value: DummyConnectorPaymentMethodData) -> Self {
match value {
DummyConnectorPaymentMethodData::Card(_) => Self::Card,
+ DummyConnectorPaymentMethodData::Upi(upi_data) => match upi_data {
+ DummyConnectorUpi::UpiCollect(_) => Self::Upi(DummyConnectorUpiType::UpiCollect),
+ },
DummyConnectorPaymentMethodData::Wallet(wallet) => Self::Wallet(wallet),
DummyConnectorPaymentMethodData::PayLater(pay_later) => Self::PayLater(pay_later),
}
@@ -158,6 +163,7 @@ impl GetPaymentMethodDetails for DummyConnectorPaymentMethodType {
fn get_name(&self) -> &'static str {
match self {
Self::Card => "3D Secure",
+ Self::Upi(upi_type) => upi_type.get_name(),
Self::Wallet(wallet) => wallet.get_name(),
Self::PayLater(pay_later) => pay_later.get_name(),
}
@@ -166,6 +172,7 @@ impl GetPaymentMethodDetails for DummyConnectorPaymentMethodType {
fn get_image_link(&self, base_url: &str) -> String {
match self {
Self::Card => format!("{}{}", base_url, "CARD.svg"),
+ Self::Upi(upi_type) => upi_type.get_image_link(base_url),
Self::Wallet(wallet) => wallet.get_image_link(base_url),
Self::PayLater(pay_later) => pay_later.get_image_link(base_url),
}
@@ -181,6 +188,17 @@ pub struct DummyConnectorCard {
pub cvc: Secret<String>,
}
+#[derive(Clone, Debug, Eq, PartialEq, serde::Serialize, serde::Deserialize)]
+pub struct DummyConnectorUpiCollect {
+ pub vpa_id: Secret<String, pii::UpiVpaMaskingStrategy>,
+}
+
+#[derive(Clone, Debug, serde::Serialize, Eq, PartialEq, serde::Deserialize)]
+#[serde(rename_all = "snake_case")]
+pub enum DummyConnectorUpi {
+ UpiCollect(DummyConnectorUpiCollect),
+}
+
pub enum DummyConnectorCardFlow {
NoThreeDS(DummyConnectorStatus, Option<DummyConnectorErrors>),
ThreeDS(DummyConnectorStatus, Option<DummyConnectorErrors>),
@@ -196,6 +214,25 @@ pub enum DummyConnectorWallet {
AliPayHK,
}
+#[derive(Clone, Debug, serde::Serialize, Eq, PartialEq, serde::Deserialize)]
+pub enum DummyConnectorUpiType {
+ UpiCollect,
+}
+
+impl GetPaymentMethodDetails for DummyConnectorUpiType {
+ fn get_name(&self) -> &'static str {
+ match self {
+ Self::UpiCollect => "UPI Collect",
+ }
+ }
+ fn get_image_link(&self, base_url: &str) -> String {
+ let image_name = match self {
+ Self::UpiCollect => "UPI_COLLECT.svg",
+ };
+ format!("{}{}", base_url, image_name)
+ }
+}
+
impl GetPaymentMethodDetails for DummyConnectorWallet {
fn get_name(&self) -> &'static str {
match self {
@@ -376,3 +413,9 @@ pub type DummyConnectorResponse<T> =
CustomResult<services::ApplicationResponse<T>, DummyConnectorErrors>;
pub type DummyConnectorResult<T> = CustomResult<T, DummyConnectorErrors>;
+
+pub struct DummyConnectorUpiFlow {
+ pub status: DummyConnectorStatus,
+ pub error: Option<DummyConnectorErrors>,
+ pub is_next_action_required: bool,
+}
diff --git a/crates/router/src/routes/dummy_connector/utils.rs b/crates/router/src/routes/dummy_connector/utils.rs
index edbe6d9ddd..367c3bc63d 100644
--- a/crates/router/src/routes/dummy_connector/utils.rs
+++ b/crates/router/src/routes/dummy_connector/utils.rs
@@ -237,6 +237,57 @@ impl ProcessPaymentAttempt for types::DummyConnectorCard {
}
}
+impl ProcessPaymentAttempt for types::DummyConnectorUpiCollect {
+ fn build_payment_data_from_payment_attempt(
+ self,
+ payment_attempt: types::DummyConnectorPaymentAttempt,
+ redirect_url: String,
+ ) -> types::DummyConnectorResult<types::DummyConnectorPaymentData> {
+ let upi_collect_response = self.get_flow_from_upi_collect()?;
+ if let Some(error) = upi_collect_response.error {
+ Err(error)?;
+ }
+ let next_action = upi_collect_response
+ .is_next_action_required
+ .then_some(types::DummyConnectorNextAction::RedirectToUrl(redirect_url));
+ let return_url = payment_attempt.payment_request.return_url.clone();
+ Ok(
+ payment_attempt.build_payment_data(
+ upi_collect_response.status,
+ next_action,
+ return_url,
+ ),
+ )
+ }
+}
+
+impl types::DummyConnectorUpiCollect {
+ pub fn get_flow_from_upi_collect(
+ self,
+ ) -> types::DummyConnectorResult<types::DummyConnectorUpiFlow> {
+ let vpa_id = self.vpa_id.peek();
+ match vpa_id.as_str() {
+ consts::DUMMY_CONNECTOR_UPI_FAILURE_VPA_ID => Ok(types::DummyConnectorUpiFlow {
+ status: types::DummyConnectorStatus::Failed,
+ error: errors::DummyConnectorErrors::PaymentNotSuccessful.into(),
+ is_next_action_required: false,
+ }),
+ consts::DUMMY_CONNECTOR_UPI_SUCCESS_VPA_ID => Ok(types::DummyConnectorUpiFlow {
+ status: types::DummyConnectorStatus::Processing,
+ error: None,
+ is_next_action_required: true,
+ }),
+ _ => Ok(types::DummyConnectorUpiFlow {
+ status: types::DummyConnectorStatus::Failed,
+ error: Some(errors::DummyConnectorErrors::PaymentDeclined {
+ message: "Invalid Upi id",
+ }),
+ is_next_action_required: false,
+ }),
+ }
+ }
+}
+
impl types::DummyConnectorCard {
pub fn get_flow_from_card_number(
self,
@@ -324,6 +375,10 @@ impl ProcessPaymentAttempt for types::DummyConnectorPaymentMethodData {
Self::Card(card) => {
card.build_payment_data_from_payment_attempt(payment_attempt, redirect_url)
}
+ Self::Upi(upi_data) => match upi_data {
+ types::DummyConnectorUpi::UpiCollect(upi_collect) => upi_collect
+ .build_payment_data_from_payment_attempt(payment_attempt, redirect_url),
+ },
Self::Wallet(wallet) => {
wallet.build_payment_data_from_payment_attempt(payment_attempt, redirect_url)
}