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(payment_methods): refactor customer payment methods list v2 code to follow better code practices #6433

Merged
merged 25 commits into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
1ea8323
refactor(profile): add `should_collect_cvv_during_payment` field
SanchithHegde Oct 7, 2024
01a9445
refactor(api_models): improve doc comments for `is_network_tokenizati…
SanchithHegde Oct 8, 2024
763cfa9
refactor(payment_methods): rename `business_profile` to `profile` in …
SanchithHegde Oct 9, 2024
bf04f19
refactor(payment_methods): rename `requires_cvv` to `collect_cvv_duri…
SanchithHegde Oct 9, 2024
a24617f
refactor(payment_methods): accept merchant account by reference inste…
SanchithHegde Oct 14, 2024
9c02f4d
refactor(hyperswitch_domain_models): update variants toggling a field…
SanchithHegde Oct 20, 2024
40459cc
refactor: pass profile to `form_payments_info()` instead of fetching …
SanchithHegde Oct 21, 2024
6ffd4ff
refactor(payment_methods): move `PaymentsMandateReference` from `rout…
SanchithHegde Oct 23, 2024
5aa9651
refactor(payment_methods): use concrete type instead of `serde_json::…
SanchithHegde Oct 23, 2024
c86426c
refactor(payment_methods): refactor `get_mca_status()` function to re…
SanchithHegde Oct 23, 2024
bce9819
refactor(payment_methods): use `serialize_and_set_key_with_expiry()` …
SanchithHegde Oct 23, 2024
1735421
refactor(payment_methods): replace usages of `create_payment_method()…
SanchithHegde Oct 24, 2024
a222400
refactor(payment_methods): drop column `metadata` in v2 code since it…
SanchithHegde Oct 24, 2024
c086430
refactor(payment_methods): use `collect()` to collect `Vec<Result>` t…
SanchithHegde Oct 24, 2024
cc4d116
refactor(payment_methods): use `match` instead of `if let Some` to ma…
SanchithHegde Nov 3, 2024
6b77f14
Merge branch 'main' into customer-payment-method-list-v2
SanchithHegde Nov 4, 2024
dd5fbc3
refactor(payment_methods): pass profile from middleware for `list_cus…
SanchithHegde Nov 4, 2024
48dbafa
refactor(payment_methods): extract logic to check if merchant connect…
SanchithHegde Nov 4, 2024
1348111
Merge branch 'main' into customer-payment-method-list-v2
SanchithHegde Nov 4, 2024
89a2b84
Merge branch 'main' into customer-payment-method-list-v2
SanchithHegde Nov 5, 2024
9178c6f
refactor: wrap the `mandate_metadata` field within a `Secret`
SanchithHegde Nov 5, 2024
87fe5fa
Merge branch 'main' into customer-payment-method-list-v2
SanchithHegde Nov 5, 2024
19998e4
chore: update `Cargo.lock`
SanchithHegde Nov 5, 2024
b426451
Merge branch 'main' into customer-payment-method-list-v2
SanchithHegde Nov 8, 2024
f2a0725
fix: fix failing v2 builds
SanchithHegde Nov 8, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.lock

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

11 changes: 8 additions & 3 deletions api-reference-v2/openapi_spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -16623,7 +16623,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 @@ -16655,7 +16655,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 @@ -16828,9 +16829,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 @@ -21368,7 +21368,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 @@ -21595,7 +21595,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
Loading