Skip to content

Commit

Permalink
refactor(payment_methods): refactor customer payment methods list v2 …
Browse files Browse the repository at this point in the history
…code to follow better code practices (#6433)
  • Loading branch information
SanchithHegde authored and Sayak Bhattacharya committed Nov 26, 2024
1 parent 24bb2b5 commit 299dbb5
Show file tree
Hide file tree
Showing 32 changed files with 499 additions and 409 deletions.
11 changes: 8 additions & 3 deletions api-reference-v2/openapi_spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -16624,7 +16624,7 @@
},
"is_network_tokenization_enabled": {
"type": "boolean",
"description": "Indicates if is_network_tokenization_enabled is enabled or not.\nIf set to `true` is_network_tokenization_enabled will be checked."
"description": "Indicates if network tokenization is enabled or not."
}
},
"additionalProperties": false
Expand Down Expand Up @@ -16656,7 +16656,8 @@
"enable_payment_response_hash",
"redirect_to_merchant_with_http_post",
"is_tax_connector_enabled",
"is_network_tokenization_enabled"
"is_network_tokenization_enabled",
"should_collect_cvv_during_payment"
],
"properties": {
"merchant_id": {
Expand Down Expand Up @@ -16829,9 +16830,13 @@
},
"is_network_tokenization_enabled": {
"type": "boolean",
"description": "Indicates if is_network_tokenization_enabled is enabled or not.\nIf set to `true` is_network_tokenization_enabled will be checked.",
"description": "Indicates if network tokenization is enabled or not.",
"default": false,
"example": false
},
"should_collect_cvv_during_payment": {
"type": "boolean",
"description": "Indicates if CVV should be collected during payment or not."
}
}
},
Expand Down
4 changes: 2 additions & 2 deletions api-reference/openapi_spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -21369,7 +21369,7 @@
},
"is_network_tokenization_enabled": {
"type": "boolean",
"description": "Indicates if is_network_tokenization_enabled is enabled or not.\nIf set to `true` is_network_tokenization_enabled will be checked."
"description": "Indicates if network tokenization is enabled or not."
},
"is_auto_retries_enabled": {
"type": "boolean",
Expand Down Expand Up @@ -21596,7 +21596,7 @@
},
"is_network_tokenization_enabled": {
"type": "boolean",
"description": "Indicates if is_network_tokenization_enabled is enabled or not.\nIf set to `true` is_network_tokenization_enabled will be checked.",
"description": "Indicates if network tokenization is enabled or not.",
"default": false,
"example": false
},
Expand Down
19 changes: 9 additions & 10 deletions crates/api_models/src/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1980,8 +1980,7 @@ pub struct ProfileCreate {
#[serde(default)]
pub is_tax_connector_enabled: bool,

/// Indicates if is_network_tokenization_enabled is enabled or not.
/// If set to `true` is_network_tokenization_enabled will be checked.
/// Indicates if network tokenization is enabled or not.
#[serde(default)]
pub is_network_tokenization_enabled: bool,

Expand Down Expand Up @@ -2095,8 +2094,7 @@ pub struct ProfileCreate {
#[serde(default)]
pub is_tax_connector_enabled: bool,

/// Indicates if is_network_tokenization_enabled is enabled or not.
/// If set to `true` is_network_tokenization_enabled will be checked.
/// Indicates if network tokenization is enabled or not.
#[serde(default)]
pub is_network_tokenization_enabled: bool,
}
Expand Down Expand Up @@ -2217,8 +2215,7 @@ pub struct ProfileResponse {
/// If set to `true` tax_connector_id will be checked.
pub is_tax_connector_enabled: bool,

/// Indicates if is_network_tokenization_enabled is enabled or not.
/// If set to `true` is_network_tokenization_enabled will be checked.
/// Indicates if network tokenization is enabled or not.
#[schema(default = false, example = false)]
pub is_network_tokenization_enabled: bool,

Expand Down Expand Up @@ -2337,10 +2334,12 @@ pub struct ProfileResponse {
/// If set to `true` tax_connector_id will be checked.
pub is_tax_connector_enabled: bool,

/// Indicates if is_network_tokenization_enabled is enabled or not.
/// If set to `true` is_network_tokenization_enabled will be checked.
/// Indicates if network tokenization is enabled or not.
#[schema(default = false, example = false)]
pub is_network_tokenization_enabled: bool,

/// Indicates if CVV should be collected during payment or not.
pub should_collect_cvv_during_payment: bool,
}

#[cfg(feature = "v1")]
Expand Down Expand Up @@ -2455,7 +2454,7 @@ pub struct ProfileUpdate {
#[serde(default)]
pub dynamic_routing_algorithm: Option<serde_json::Value>,

/// Indicates if is_network_tokenization_enabled is enabled or not.
/// Indicates if network tokenization is enabled or not.
pub is_network_tokenization_enabled: Option<bool>,

/// Indicates if is_auto_retries_enabled is enabled or not.
Expand Down Expand Up @@ -2564,7 +2563,7 @@ pub struct ProfileUpdate {
/// If set to `true` tax_connector_id will be checked.
pub is_tax_connector_enabled: Option<bool>,

/// Indicates if is_network_tokenization_enabled is enabled or not.
/// Indicates if network tokenization is enabled or not.
pub is_network_tokenization_enabled: Option<bool>,
}

Expand Down
8 changes: 0 additions & 8 deletions crates/api_models/src/payment_methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -732,10 +732,6 @@ pub struct PaymentMethodResponse {
#[schema(example = true)]
pub recurring_enabled: bool,

/// You can specify up to 50 keys, with key names up to 40 characters long and values up to 500 characters long. Metadata is useful for storing additional, structured information on an object.
#[schema(value_type = Option<Object>, example = json!({ "city": "NY", "unit": "245" }))]
pub metadata: Option<pii::SecretSerdeValue>,

/// A timestamp (ISO 8601 code) that determines when the customer was created
#[schema(value_type = Option<PrimitiveDateTime>, example = "2023-01-18T11:04:09.922Z")]
#[serde(default, with = "common_utils::custom_serde::iso8601::option")]
Expand Down Expand Up @@ -1707,10 +1703,6 @@ pub struct CustomerPaymentMethod {
#[schema(example = json!({"mask": "0000"}))]
pub bank: Option<MaskedBankDetails>,

/// You can specify up to 50 keys, with key names up to 40 characters long and values up to 500 characters long. Metadata is useful for storing additional, structured information on an object.
#[schema(value_type = Option<Object>,example = json!({ "city": "NY", "unit": "245" }))]
pub metadata: Option<pii::SecretSerdeValue>,

/// A timestamp (ISO 8601 code) that determines when the customer was created
#[schema(value_type = Option<PrimitiveDateTime>,example = "2023-01-18T11:04:09.922Z")]
#[serde(default, with = "common_utils::custom_serde::iso8601::option")]
Expand Down
8 changes: 4 additions & 4 deletions crates/api_models/src/payments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1321,7 +1321,7 @@ pub struct ConnectorMandateReferenceId {
connector_mandate_id: Option<String>,
payment_method_id: Option<String>,
update_history: Option<Vec<UpdateHistory>>,
mandate_metadata: Option<serde_json::Value>,
mandate_metadata: Option<pii::SecretSerdeValue>,
connector_mandate_request_reference_id: Option<String>,
}

Expand All @@ -1330,7 +1330,7 @@ impl ConnectorMandateReferenceId {
connector_mandate_id: Option<String>,
payment_method_id: Option<String>,
update_history: Option<Vec<UpdateHistory>>,
mandate_metadata: Option<serde_json::Value>,
mandate_metadata: Option<pii::SecretSerdeValue>,
connector_mandate_request_reference_id: Option<String>,
) -> Self {
Self {
Expand All @@ -1348,7 +1348,7 @@ impl ConnectorMandateReferenceId {
pub fn get_payment_method_id(&self) -> Option<String> {
self.payment_method_id.clone()
}
pub fn get_mandate_metadata(&self) -> Option<serde_json::Value> {
pub fn get_mandate_metadata(&self) -> Option<pii::SecretSerdeValue> {
self.mandate_metadata.clone()
}
pub fn get_connector_mandate_request_reference_id(&self) -> Option<String> {
Expand All @@ -1360,7 +1360,7 @@ impl ConnectorMandateReferenceId {
connector_mandate_id: Option<String>,
payment_method_id: Option<String>,
update_history: Option<Vec<UpdateHistory>>,
mandate_metadata: Option<serde_json::Value>,
mandate_metadata: Option<pii::SecretSerdeValue>,
connector_mandate_request_reference_id: Option<String>,
) {
self.connector_mandate_id = connector_mandate_id.or(self.connector_mandate_id.clone());
Expand Down
6 changes: 6 additions & 0 deletions crates/diesel_models/src/business_profile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ pub struct Profile {
pub frm_routing_algorithm_id: Option<String>,
pub payout_routing_algorithm_id: Option<common_utils::id_type::RoutingId>,
pub default_fallback_routing: Option<pii::SecretSerdeValue>,
pub should_collect_cvv_during_payment: bool,
pub id: common_utils::id_type::ProfileId,
pub version: common_enums::ApiVersion,
pub dynamic_routing_algorithm: Option<serde_json::Value>,
Expand Down Expand Up @@ -343,6 +344,7 @@ pub struct ProfileNew {
pub frm_routing_algorithm_id: Option<String>,
pub payout_routing_algorithm_id: Option<common_utils::id_type::RoutingId>,
pub default_fallback_routing: Option<pii::SecretSerdeValue>,
pub should_collect_cvv_during_payment: bool,
pub id: common_utils::id_type::ProfileId,
pub version: common_enums::ApiVersion,
pub is_network_tokenization_enabled: bool,
Expand Down Expand Up @@ -386,6 +388,7 @@ pub struct ProfileUpdateInternal {
pub frm_routing_algorithm_id: Option<String>,
pub payout_routing_algorithm_id: Option<common_utils::id_type::RoutingId>,
pub default_fallback_routing: Option<pii::SecretSerdeValue>,
pub should_collect_cvv_during_payment: Option<bool>,
pub is_network_tokenization_enabled: Option<bool>,
pub is_auto_retries_enabled: Option<bool>,
pub max_auto_retries_enabled: Option<i16>,
Expand Down Expand Up @@ -426,6 +429,7 @@ impl ProfileUpdateInternal {
frm_routing_algorithm_id,
payout_routing_algorithm_id,
default_fallback_routing,
should_collect_cvv_during_payment,
is_network_tokenization_enabled,
is_auto_retries_enabled,
max_auto_retries_enabled,
Expand Down Expand Up @@ -485,6 +489,8 @@ impl ProfileUpdateInternal {
payout_routing_algorithm_id: payout_routing_algorithm_id
.or(source.payout_routing_algorithm_id),
default_fallback_routing: default_fallback_routing.or(source.default_fallback_routing),
should_collect_cvv_during_payment: should_collect_cvv_during_payment
.unwrap_or(source.should_collect_cvv_during_payment),
version: source.version,
dynamic_routing_algorithm: None,
is_network_tokenization_enabled: is_network_tokenization_enabled
Expand Down
2 changes: 1 addition & 1 deletion crates/diesel_models/src/payment_attempt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ common_utils::impl_to_sql_from_sql_json!(ConnectorMandateReferenceId);
pub struct ConnectorMandateReferenceId {
pub connector_mandate_id: Option<String>,
pub payment_method_id: Option<String>,
pub mandate_metadata: Option<serde_json::Value>,
pub mandate_metadata: Option<pii::SecretSerdeValue>,
pub connector_mandate_request_reference_id: Option<String>,
}

Expand Down
Loading

0 comments on commit 299dbb5

Please sign in to comment.