Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: use hashmap deserializer for generic_link options #5157

Merged
merged 12 commits into from
Jul 2, 2024
Merged
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion api-reference/openapi_spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -9127,7 +9127,8 @@
"items": {
"$ref": "#/components/schemas/PaymentMethodType"
},
"description": "An array of associated payment method types"
"description": "An array of associated payment method types",
"uniqueItems": true
}
}
},
Expand Down
12 changes: 6 additions & 6 deletions config/config.example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -551,9 +551,9 @@ theme = "#1A1A1A"
logo = "https://app.hyperswitch.io/HyperswitchFavicon.png"
merchant_name = "HyperSwitch"
[generic_link.payment_method_collect.enabled_payment_methods]
card = ["credit", "debit"]
bank_transfer = ["ach", "bacs", "sepa"]
wallet = ["paypal", "pix", "venmo"]
card = "credit,debit"
bank_transfer = "ach,bacs,sepa"
wallet = "paypal,pix,venmo"

[generic_link.payout_link]
sdk_url = "http://localhost:9090/0.16.7/v0/HyperLoader.js"
Expand All @@ -563,9 +563,9 @@ theme = "#1A1A1A"
logo = "https://app.hyperswitch.io/HyperswitchFavicon.png"
merchant_name = "HyperSwitch"
[generic_link.payout_link.enabled_payment_methods]
card = ["credit", "debit"]
bank_transfer = ["ach", "bacs", "sepa"]
wallet = ["paypal", "pix", "venmo"]
card = "credit,debit"
bank_transfer = "ach,bacs,sepa"
wallet = "paypal,pix,venmo"

[payment_link]
sdk_url = "http://localhost:9090/0.16.7/v0/HyperLoader.js"
Expand Down
12 changes: 6 additions & 6 deletions config/deployments/env_specific.toml
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,9 @@ theme = "#4285F4"
logo = "https://app.hyperswitch.io/HyperswitchFavicon.png"
merchant_name = "HyperSwitch"
[generic_link.payment_method_collect.enabled_payment_methods]
card = ["credit", "debit"]
bank_transfer = ["ach", "bacs", "sepa"]
wallet = ["paypal", "pix", "venmo"]
card = "credit,debit"
bank_transfer = "ach,bacs,sepa"
wallet = "paypal,pix,venmo"

[generic_link.payout_link]
sdk_url = "http://localhost:9090/0.16.7/v0/HyperLoader.js"
Expand All @@ -177,9 +177,9 @@ theme = "#4285F4"
logo = "https://app.hyperswitch.io/HyperswitchFavicon.png"
merchant_name = "HyperSwitch"
[generic_link.payout_link.enabled_payment_methods]
card = ["credit", "debit"]
bank_transfer = ["ach", "bacs", "sepa"]
wallet = ["paypal", "pix", "venmo"]
card = "credit,debit"
bank_transfer = "ach,bacs,sepa"
wallet = "paypal,pix,venmo"

[payment_link]
sdk_url = "http://localhost:9090/0.16.7/v0/HyperLoader.js"
Expand Down
12 changes: 6 additions & 6 deletions config/development.toml
Original file line number Diff line number Diff line change
Expand Up @@ -574,9 +574,9 @@ theme = "#4285F4"
logo = "https://app.hyperswitch.io/HyperswitchFavicon.png"
merchant_name = "HyperSwitch"
[generic_link.payment_method_collect.enabled_payment_methods]
card = ["credit", "debit"]
bank_transfer = ["ach", "bacs", "sepa"]
wallet = ["paypal", "pix", "venmo"]
card = "credit,debit"
bank_transfer = "ach,bacs,sepa"
wallet = "paypal,pix,venmo"

[generic_link.payout_link]
sdk_url = "http://localhost:9050/HyperLoader.js"
Expand All @@ -586,9 +586,9 @@ theme = "#4285F4"
logo = "https://app.hyperswitch.io/HyperswitchFavicon.png"
merchant_name = "HyperSwitch"
[generic_link.payout_link.enabled_payment_methods]
card = ["credit", "debit"]
bank_transfer = ["ach", "bacs", "sepa"]
wallet = ["paypal", "pix", "venmo"]
card = "credit,debit"
bank_transfer = "ach,bacs,sepa"
wallet = "paypal,pix,venmo"

[payment_link]
sdk_url = "http://localhost:9050/HyperLoader.js"
Expand Down
12 changes: 6 additions & 6 deletions config/docker_compose.toml
Original file line number Diff line number Diff line change
Expand Up @@ -523,9 +523,9 @@ theme = "#4285F4"
logo = "https://app.hyperswitch.io/HyperswitchFavicon.png"
merchant_name = "HyperSwitch"
[generic_link.payment_method_collect.enabled_payment_methods]
card = ["credit", "debit"]
bank_transfer = ["ach", "bacs", "sepa"]
wallet = ["paypal", "pix", "venmo"]
card = "credit,debit"
bank_transfer = "ach,bacs,sepa"
wallet = "paypal,pix,venmo"

[generic_link.payout_link]
sdk_url = "http://localhost:9090/0.16.7/v0/HyperLoader.js"
Expand All @@ -535,6 +535,6 @@ theme = "#4285F4"
logo = "https://app.hyperswitch.io/HyperswitchFavicon.png"
merchant_name = "HyperSwitch"
[generic_link.payout_link.enabled_payment_methods]
card = ["credit", "debit"]
bank_transfer = ["ach", "bacs", "sepa"]
wallet = ["paypal", "pix", "venmo"]
card = "credit,debit"
bank_transfer = "ach,bacs,sepa"
wallet = "paypal,pix,venmo"
8 changes: 4 additions & 4 deletions crates/api_models/src/payment_methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -989,7 +989,7 @@ pub struct PaymentMethodCollectLinkResponse {

/// URL to the form's link generated for collecting payment method details.
#[schema(value_type = String, example = "https://sandbox.hyperswitch.io/payment_method/collect/pm_collect_link_2bdacf398vwzq5n422S1")]
pub link: masking::Secret<String>,
pub link: masking::Secret<url::Url>,

/// Redirect to this URL post completion
#[schema(value_type = Option<String>, example = "https://sandbox.hyperswitch.io/payment_method/collect/pm_collect_link_2bdacf398vwzq5n422S1/status")]
Expand Down Expand Up @@ -1026,7 +1026,7 @@ pub struct PaymentMethodCollectLinkDetails {
pub session_expiry: time::PrimitiveDateTime,
pub return_url: Option<String>,
#[serde(flatten)]
pub ui_config: link_utils::GenericLinkUIConfigFormData,
pub ui_config: link_utils::GenericLinkUiConfigFormData,
pub enabled_payment_methods: Option<Vec<link_utils::EnabledPaymentMethod>>,
}

Expand All @@ -1036,10 +1036,10 @@ pub struct PaymentMethodCollectLinkStatusDetails {
pub customer_id: id_type::CustomerId,
#[serde(with = "common_utils::custom_serde::iso8601")]
pub session_expiry: time::PrimitiveDateTime,
pub return_url: Option<String>,
pub return_url: Option<url::Url>,
pub status: link_utils::PaymentMethodCollectStatus,
#[serde(flatten)]
pub ui_config: link_utils::GenericLinkUIConfigFormData,
pub ui_config: link_utils::GenericLinkUiConfigFormData,
}

#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, ToSchema)]
Expand Down
10 changes: 5 additions & 5 deletions crates/api_models/src/payouts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,7 @@ pub struct PayoutListFilters {
pub struct PayoutLinkResponse {
pub payout_link_id: String,
#[schema(value_type = String)]
pub link: Secret<String>,
pub link: Secret<url::Url>,
}

#[derive(Clone, Debug, serde::Deserialize, ToSchema, serde::Serialize)]
Expand All @@ -720,9 +720,9 @@ pub struct PayoutLinkDetails {
pub customer_id: id_type::CustomerId,
#[serde(with = "common_utils::custom_serde::iso8601")]
pub session_expiry: PrimitiveDateTime,
pub return_url: Option<String>,
pub return_url: Option<url::Url>,
#[serde(flatten)]
pub ui_config: link_utils::GenericLinkUIConfigFormData,
pub ui_config: link_utils::GenericLinkUiConfigFormData,
pub enabled_payment_methods: Vec<link_utils::EnabledPaymentMethod>,
pub amount: common_utils::types::StringMajorUnit,
pub currency: common_enums::Currency,
Expand All @@ -735,10 +735,10 @@ pub struct PayoutLinkStatusDetails {
pub customer_id: id_type::CustomerId,
#[serde(with = "common_utils::custom_serde::iso8601")]
pub session_expiry: PrimitiveDateTime,
pub return_url: Option<String>,
pub return_url: Option<url::Url>,
pub status: api_enums::PayoutStatus,
pub error_code: Option<String>,
pub error_message: Option<String>,
#[serde(flatten)]
pub ui_config: link_utils::GenericLinkUIConfigFormData,
pub ui_config: link_utils::GenericLinkUiConfigFormData,
}
1 change: 1 addition & 0 deletions crates/common_utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ strum = { version = "0.26.2", features = ["derive"] }
thiserror = "1.0.58"
time = { version = "0.3.35", features = ["serde", "serde-well-known", "std"] }
tokio = { version = "1.37.0", features = ["macros", "rt-multi-thread"], optional = true }
url = { version = "2.5.0", features = ["serde"] }
utoipa = { version = "4.2.0", features = ["preserve_order", "preserve_path_order"] }
uuid = { version = "1.8.0", features = ["v7"] }

Expand Down
20 changes: 10 additions & 10 deletions crates/common_utils/src/link_utils.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Common

use std::primitive::i64;
use std::{collections::HashSet, primitive::i64};

use common_enums::enums;
use diesel::{
Expand Down Expand Up @@ -148,7 +148,7 @@ pub struct PayoutLinkData {
/// Identifier for the payouts resource
pub payout_id: String,
/// Link to render the payout link
pub link: Secret<String>,
pub link: url::Url,
/// Client secret generated for authenticating frontend APIs
pub client_secret: Secret<String>,
/// Expiry in seconds from the time it was created
Expand All @@ -167,11 +167,11 @@ pub struct PayoutLinkData {
crate::impl_to_sql_from_sql_json!(PayoutLinkData);

/// Object for GenericLinkUiConfig
#[derive(Clone, Debug, Default, serde::Deserialize, Serialize, ToSchema)]
#[derive(Clone, Debug, serde::Deserialize, Serialize, ToSchema)]
pub struct GenericLinkUiConfig {
/// Merchant's display logo
#[schema(value_type = Option<String>, max_length = 255, example = "https://hyperswitch.io/favicon.ico")]
pub logo: Option<String>,
pub logo: Option<url::Url>,

/// Custom merchant name for the link
#[schema(value_type = Option<String>, max_length = 255, example = "Hyperswitch")]
Expand All @@ -182,12 +182,12 @@ pub struct GenericLinkUiConfig {
pub theme: Option<String>,
}

/// Object for GenericLinkUIConfigFormData
#[derive(Clone, Debug, Default, serde::Deserialize, Serialize, ToSchema)]
pub struct GenericLinkUIConfigFormData {
/// Object for GenericLinkUiConfigFormData
#[derive(Clone, Debug, serde::Deserialize, Serialize, ToSchema)]
pub struct GenericLinkUiConfigFormData {
/// Merchant's display logo
#[schema(value_type = String, max_length = 255, example = "https://hyperswitch.io/favicon.ico")]
pub logo: String,
pub logo: url::Url,

/// Custom merchant name for the link
#[schema(value_type = String, max_length = 255, example = "Hyperswitch")]
Expand All @@ -206,6 +206,6 @@ pub struct EnabledPaymentMethod {
pub payment_method: enums::PaymentMethod,

/// An array of associated payment method types
#[schema(value_type = Vec<PaymentMethodType>)]
pub payment_method_types: Vec<enums::PaymentMethodType>,
#[schema(value_type = HashSet<PaymentMethodType>)]
pub payment_method_types: HashSet<enums::PaymentMethodType>,
}
1 change: 1 addition & 0 deletions crates/masking/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ serde = { version = "1", features = ["derive"], optional = true }
serde_json = { version = "1.0.115", optional = true }
subtle = "2.5.0"
time = {version = "0.3.35", optional = true, features = ["serde-human-readable"] }
url = { version = "2.5.0", features = ["serde"] }
zeroize = { version = "1.7", default-features = false }

[dev-dependencies]
Expand Down
1 change: 1 addition & 0 deletions crates/masking/src/serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ impl SerializableSecret for u8 {}
impl SerializableSecret for u16 {}
impl SerializableSecret for i8 {}
impl SerializableSecret for i32 {}
impl SerializableSecret for url::Url {}

#[cfg(feature = "time")]
impl SerializableSecret for time::Date {}
Expand Down
Loading
Loading