Skip to content

Commit

Permalink
Merge branch 'main' into signup
Browse files Browse the repository at this point in the history
  • Loading branch information
ThisIsMani authored Nov 10, 2023
2 parents a2514aa + b5ea8db commit 8fb9a75
Show file tree
Hide file tree
Showing 8 changed files with 769 additions and 726 deletions.
5 changes: 2 additions & 3 deletions crates/api_models/src/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -463,9 +463,8 @@ pub struct PaymentLinkConfig {
#[serde(deny_unknown_fields)]

pub struct PaymentLinkColorSchema {
pub primary_color: Option<String>,
pub primary_accent_color: Option<String>,
pub secondary_color: Option<String>,
pub background_primary_color: Option<String>,
pub sdk_theme: Option<String>,
}

#[derive(Clone, Debug, Deserialize, ToSchema, Serialize)]
Expand Down
3 changes: 2 additions & 1 deletion crates/api_models/src/payments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3150,6 +3150,7 @@ pub struct PaymentLinkDetails {
pub merchant_logo: String,
pub return_url: String,
pub merchant_name: String,
pub order_details: Vec<pii::SecretSerdeValue>,
pub order_details: Option<Vec<OrderDetailsWithAmount>>,
pub max_items_visible_after_collapse: i8,
pub sdk_theme: Option<String>,
}
4 changes: 2 additions & 2 deletions crates/common_enums/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ dummy_connector = []

[dependencies]
diesel = { version = "2.1.0", features = ["postgres"] }
serde = { version = "1.0.160", features = [ "derive" ] }
serde = { version = "1.0.160", features = ["derive"] }
serde_json = "1.0.96"
strum = { version = "0.25", features = [ "derive" ] }
strum = { version = "0.25", features = ["derive"] }
time = { version = "0.3.21", features = ["serde", "serde-well-known", "std"] }
utoipa = { version = "3.3.0", features = ["preserve_order"] }

Expand Down
12 changes: 12 additions & 0 deletions crates/common_utils/src/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,15 @@ pub const SURCHARGE_PERCENTAGE_PRECISION_LENGTH: u8 = 2;

/// Header Key for application overhead of a request
pub const X_HS_LATENCY: &str = "x-hs-latency";

/// SDK Default Theme const
pub const DEFAULT_SDK_THEME: &str = "#7EA8F6";

/// Default Payment Link Background color
pub const DEFAULT_BACKGROUND_COLOR: &str = "#E5E5E5";

/// Default product Img Link
pub const DEFAULT_PRODUCT_IMG: &str = "https://i.imgur.com/On3VtKF.png";

/// Default Merchant Logo Link
pub const DEFAULT_MERCHANT_LOGO: &str = "https://i.imgur.com/RfxPFQo.png";
91 changes: 32 additions & 59 deletions crates/router/src/connector/zen/transformers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,10 +290,9 @@ impl
| api_models::payments::VoucherData::FamilyMart { .. }
| api_models::payments::VoucherData::Seicomart { .. }
| api_models::payments::VoucherData::PayEasy { .. } => {
Err(errors::ConnectorError::NotSupported {
message: utils::SELECTED_PAYMENT_METHOD.to_string(),
connector: "Zen",
})?
Err(errors::ConnectorError::NotImplemented(
utils::get_unimplemented_payment_method_error_message("Zen"),
))?
}
};
Ok(Self::ApiRequest(Box::new(ApiRequest {
Expand Down Expand Up @@ -342,12 +341,8 @@ impl
api_models::payments::BankTransferData::Pse { .. } => {
ZenPaymentChannels::PclBoacompraPse
}
api_models::payments::BankTransferData::SepaBankTransfer { .. } => {
Err(errors::ConnectorError::NotImplemented(
utils::get_unimplemented_payment_method_error_message("Zen"),
))?
}
api_models::payments::BankTransferData::AchBankTransfer { .. }
api_models::payments::BankTransferData::SepaBankTransfer { .. }
| api_models::payments::BankTransferData::AchBankTransfer { .. }
| api_models::payments::BankTransferData::BacsBankTransfer { .. }
| api_models::payments::BankTransferData::PermataBankTransfer { .. }
| api_models::payments::BankTransferData::BcaBankTransfer { .. }
Expand All @@ -356,10 +351,9 @@ impl
| api_models::payments::BankTransferData::CimbVaBankTransfer { .. }
| api_models::payments::BankTransferData::DanamonVaBankTransfer { .. }
| api_models::payments::BankTransferData::MandiriVaBankTransfer { .. } => {
Err(errors::ConnectorError::NotSupported {
message: utils::SELECTED_PAYMENT_METHOD.to_string(),
connector: "Zen",
})?
Err(errors::ConnectorError::NotImplemented(
utils::get_unimplemented_payment_method_error_message("Zen"),
))?
}
};
Ok(Self::ApiRequest(Box::new(ApiRequest {
Expand Down Expand Up @@ -489,12 +483,8 @@ impl
api_models::payments::WalletData::WeChatPayRedirect(_)
| api_models::payments::WalletData::PaypalRedirect(_)
| api_models::payments::WalletData::ApplePay(_)
| api_models::payments::WalletData::GooglePay(_) => {
Err(errors::ConnectorError::NotImplemented(
utils::get_unimplemented_payment_method_error_message("Zen"),
))?
}
api_models::payments::WalletData::AliPayQr(_)
| api_models::payments::WalletData::GooglePay(_)
| api_models::payments::WalletData::AliPayQr(_)
| api_models::payments::WalletData::AliPayRedirect(_)
| api_models::payments::WalletData::AliPayHkRedirect(_)
| api_models::payments::WalletData::MomoRedirect(_)
Expand All @@ -514,10 +504,9 @@ impl
| api_models::payments::WalletData::CashappQr(_)
| api_models::payments::WalletData::SwishQr(_)
| api_models::payments::WalletData::WeChatPayQr(_) => {
Err(errors::ConnectorError::NotSupported {
message: utils::SELECTED_PAYMENT_METHOD.to_string(),
connector: "Zen",
})?
Err(errors::ConnectorError::NotImplemented(
utils::get_unimplemented_payment_method_error_message("Zen"),
))?
}
};
let terminal_uuid = session_data
Expand Down Expand Up @@ -719,10 +708,9 @@ impl TryFrom<&ZenRouterData<&types::PaymentsAuthorizeRouterData>> for ZenPayment
| api_models::payments::PaymentMethodData::MandatePayment
| api_models::payments::PaymentMethodData::Reward
| api_models::payments::PaymentMethodData::Upi(_) => {
Err(errors::ConnectorError::NotSupported {
message: utils::SELECTED_PAYMENT_METHOD.to_string(),
connector: "Zen",
})?
Err(errors::ConnectorError::NotImplemented(
utils::get_unimplemented_payment_method_error_message("Zen"),
))?
}
}
}
Expand All @@ -736,13 +724,8 @@ impl TryFrom<&api_models::payments::BankRedirectData> for ZenPaymentsRequest {
| api_models::payments::BankRedirectData::Sofort { .. }
| api_models::payments::BankRedirectData::BancontactCard { .. }
| api_models::payments::BankRedirectData::Blik { .. }
| api_models::payments::BankRedirectData::Trustly { .. } => {
Err(errors::ConnectorError::NotImplemented(
utils::get_unimplemented_payment_method_error_message("Zen"),
)
.into())
}
api_models::payments::BankRedirectData::Eps { .. }
| api_models::payments::BankRedirectData::Trustly { .. }
| api_models::payments::BankRedirectData::Eps { .. }
| api_models::payments::BankRedirectData::Giropay { .. }
| api_models::payments::BankRedirectData::Przelewy24 { .. }
| api_models::payments::BankRedirectData::Bizum {}
Expand All @@ -754,10 +737,9 @@ impl TryFrom<&api_models::payments::BankRedirectData> for ZenPaymentsRequest {
| api_models::payments::BankRedirectData::OpenBankingUk { .. }
| api_models::payments::BankRedirectData::OnlineBankingFpx { .. }
| api_models::payments::BankRedirectData::OnlineBankingThailand { .. } => {
Err(errors::ConnectorError::NotSupported {
message: utils::SELECTED_PAYMENT_METHOD.to_string(),
connector: "Zen",
}
Err(errors::ConnectorError::NotImplemented(
utils::get_unimplemented_payment_method_error_message("Zen"),
)
.into())
}
}
Expand All @@ -776,10 +758,9 @@ impl TryFrom<&api_models::payments::PayLaterData> for ZenPaymentsRequest {
| api_models::payments::PayLaterData::WalleyRedirect {}
| api_models::payments::PayLaterData::AlmaRedirect {}
| api_models::payments::PayLaterData::AtomeRedirect {} => {
Err(errors::ConnectorError::NotSupported {
message: utils::SELECTED_PAYMENT_METHOD.to_string(),
connector: "Zen",
}
Err(errors::ConnectorError::NotImplemented(
utils::get_unimplemented_payment_method_error_message("Zen"),
)
.into())
}
}
Expand All @@ -794,10 +775,9 @@ impl TryFrom<&api_models::payments::BankDebitData> for ZenPaymentsRequest {
| api_models::payments::BankDebitData::SepaBankDebit { .. }
| api_models::payments::BankDebitData::BecsBankDebit { .. }
| api_models::payments::BankDebitData::BacsBankDebit { .. } => {
Err(errors::ConnectorError::NotSupported {
message: utils::SELECTED_PAYMENT_METHOD.to_string(),
connector: "Zen",
}
Err(errors::ConnectorError::NotImplemented(
utils::get_unimplemented_payment_method_error_message("Zen"),
)
.into())
}
}
Expand All @@ -811,10 +791,9 @@ impl TryFrom<&api_models::payments::CardRedirectData> for ZenPaymentsRequest {
api_models::payments::CardRedirectData::Knet {}
| api_models::payments::CardRedirectData::Benefit {}
| api_models::payments::CardRedirectData::MomoAtm {} => {
Err(errors::ConnectorError::NotSupported {
message: utils::SELECTED_PAYMENT_METHOD.to_string(),
connector: "Zen",
}
Err(errors::ConnectorError::NotImplemented(
utils::get_unimplemented_payment_method_error_message("Zen"),
)
.into())
}
}
Expand All @@ -825,19 +804,13 @@ impl TryFrom<&api_models::payments::GiftCardData> for ZenPaymentsRequest {
type Error = error_stack::Report<errors::ConnectorError>;
fn try_from(value: &api_models::payments::GiftCardData) -> Result<Self, Self::Error> {
match value {
api_models::payments::GiftCardData::PaySafeCard {} => {
api_models::payments::GiftCardData::PaySafeCard {}
| api_models::payments::GiftCardData::Givex(_) => {
Err(errors::ConnectorError::NotImplemented(
utils::get_unimplemented_payment_method_error_message("Zen"),
)
.into())
}
api_models::payments::GiftCardData::Givex(_) => {
Err(errors::ConnectorError::NotSupported {
message: utils::SELECTED_PAYMENT_METHOD.to_string(),
connector: "Zen",
}
.into())
}
}
}
}
Expand Down
98 changes: 65 additions & 33 deletions crates/router/src/core/payment_link.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
use api_models::admin as admin_types;
use common_utils::{
consts::{
DEFAULT_BACKGROUND_COLOR, DEFAULT_MERCHANT_LOGO, DEFAULT_PRODUCT_IMG, DEFAULT_SDK_THEME,
},
ext_traits::ValueExt,
};
use error_stack::{IntoReport, ResultExt};
use masking::PeekInterface;
use masking::{PeekInterface, Secret};

use super::errors::{self, RouterResult, StorageErrorExt};
use crate::{
Expand Down Expand Up @@ -76,12 +82,7 @@ pub async fn intiate_payment_link_flow(
})
.transpose()?;

let order_details = payment_intent
.order_details
.get_required_value("order_details")
.change_context(errors::ApiErrorResponse::MissingRequiredField {
field_name: "order_details",
})?;
let order_details = validate_order_details(payment_intent.order_details)?;

let return_url = if let Some(payment_create_return_url) = payment_intent.return_url {
payment_create_return_url
Expand All @@ -99,6 +100,9 @@ pub async fn intiate_payment_link_flow(
payment_intent.client_secret,
)?;

let (default_sdk_theme, default_background_color) =
(DEFAULT_SDK_THEME, DEFAULT_BACKGROUND_COLOR);

let payment_details = api_models::payments::PaymentLinkDetails {
amount: payment_intent.amount,
currency,
Expand All @@ -116,13 +120,25 @@ pub async fn intiate_payment_link_flow(
client_secret,
merchant_logo: payment_link_config
.clone()
.map(|pl_metadata| pl_metadata.merchant_logo.unwrap_or_default())
.map(|pl_config| {
pl_config
.merchant_logo
.unwrap_or(DEFAULT_MERCHANT_LOGO.to_string())
})
.unwrap_or_default(),
max_items_visible_after_collapse: 3,
sdk_theme: payment_link_config.clone().and_then(|pl_config| {
pl_config
.color_scheme
.map(|color| color.sdk_theme.unwrap_or(default_sdk_theme.to_string()))
}),
};

let js_script = get_js_script(payment_details)?;
let css_script = get_color_scheme_css(payment_link_config.clone());
let css_script = get_color_scheme_css(
payment_link_config.clone(),
default_background_color.to_string(),
);
let payment_link_data = services::PaymentLinkFormData {
js_script,
sdk_url: state.conf.payment_link.sdk_url.clone(),
Expand All @@ -149,38 +165,21 @@ fn get_js_script(

fn get_color_scheme_css(
payment_link_config: Option<api_models::admin::PaymentLinkConfig>,
default_primary_color: String,
) -> String {
let (default_primary_color, default_accent_color, default_secondary_color) = (
"#C6C7C8".to_string(),
"#6A8EF5".to_string(),
"#0C48F6".to_string(),
);

let (primary_color, primary_accent_color, secondary_color) = payment_link_config
let background_primary_color = payment_link_config
.and_then(|pl_config| {
pl_config.color_scheme.map(|color| {
(
color.primary_color.unwrap_or(default_primary_color.clone()),
color
.primary_accent_color
.unwrap_or(default_accent_color.clone()),
color
.secondary_color
.unwrap_or(default_secondary_color.clone()),
)
color
.background_primary_color
.unwrap_or(default_primary_color.clone())
})
})
.unwrap_or((
default_primary_color,
default_accent_color,
default_secondary_color,
));
.unwrap_or(default_primary_color);

format!(
":root {{
--primary-color: {primary_color};
--primary-accent-color: {primary_accent_color};
--secondary-color: {secondary_color};
--primary-color: {background_primary_color};
}}"
)
}
Expand All @@ -203,3 +202,36 @@ fn validate_sdk_requirements(
})?;
Ok((pub_key, currency, client_secret))
}

fn validate_order_details(
order_details: Option<Vec<Secret<serde_json::Value>>>,
) -> Result<
Option<Vec<api_models::payments::OrderDetailsWithAmount>>,
error_stack::Report<errors::ApiErrorResponse>,
> {
let order_details = order_details
.map(|order_details| {
order_details
.iter()
.map(|data| {
data.to_owned()
.parse_value("OrderDetailsWithAmount")
.change_context(errors::ApiErrorResponse::InvalidDataValue {
field_name: "OrderDetailsWithAmount",
})
.attach_printable("Unable to parse OrderDetailsWithAmount")
})
.collect::<Result<Vec<api_models::payments::OrderDetailsWithAmount>, _>>()
})
.transpose()?;

let updated_order_details = order_details.map(|mut order_details| {
for order in order_details.iter_mut() {
if order.product_img_link.is_none() {
order.product_img_link = Some(DEFAULT_PRODUCT_IMG.to_string());
}
}
order_details
});
Ok(updated_order_details)
}
Loading

0 comments on commit 8fb9a75

Please sign in to comment.