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(derive): introduce `ApplyChangeset` derive macro and migrate diesel `UpdateInternal` structs to use it (#12751)

Hrithikesh97f1ed17266d
diff --git a/crates/common_utils/src/ext_traits.rs b/crates/common_utils/src/ext_traits.rs
index a5fcdfecaa..dfe14154fe 100644
--- a/crates/common_utils/src/ext_traits.rs
+++ b/crates/common_utils/src/ext_traits.rs
@@ -563,6 +563,34 @@ pub trait OptionExt<T> {
fn update_value(&mut self, value: Option<T>);
}
+/// Helper trait for the `apply_changeset` proc-macro.
+///
+/// This trait is an implementation detail and should not be used directly.
+#[doc(hidden)]
+pub trait ApplyOptionField<Target> {
+ /// Apply `self` to the given mutable reference, replacing the value
+ /// only when `self` is `Some`.
+ fn apply(self, target: &mut Target);
+}
+
+#[doc(hidden)]
+impl<T> ApplyOptionField<T> for Option<T> {
+ fn apply(self, target: &mut T) {
+ if let Some(v) = self {
+ *target = v;
+ }
+ }
+}
+
+#[doc(hidden)]
+impl<T> ApplyOptionField<Self> for Option<T> {
+ fn apply(self, target: &mut Self) {
+ if self.is_some() {
+ *target = self;
+ }
+ }
+}
+
impl<T> OptionExt<T> for Option<T>
where
T: std::fmt::Debug,
diff --git a/crates/common_utils/src/lib.rs b/crates/common_utils/src/lib.rs
index dc71867ccf..215c73d8f0 100644
--- a/crates/common_utils/src/lib.rs
+++ b/crates/common_utils/src/lib.rs
@@ -362,6 +362,15 @@ pub fn merge_json_values(
}
}
+pub use ext_traits::ApplyOptionField;
+
+/// Module for tokenization-related functionality
+///
+/// This module provides types and functions for handling tokenized payment data,
+/// including response structures and token generation utilities.
+#[cfg(all(feature = "v2", feature = "tokenization_v2"))]
+pub mod tokenization;
+
#[cfg(test)]
mod nanoid_tests {
use super::*;
@@ -388,10 +397,3 @@ mod nanoid_tests {
assert!(ref_id.is_ok())
}
}
-
-/// Module for tokenization-related functionality
-///
-/// This module provides types and functions for handling tokenized payment data,
-/// including response structures and token generation utilities.
-#[cfg(all(feature = "v2", feature = "tokenization_v2"))]
-pub mod tokenization;
diff --git a/crates/diesel_models/src/address.rs b/crates/diesel_models/src/address.rs
index 2d8fe990ae..f1f1b361f0 100644
--- a/crates/diesel_models/src/address.rs
+++ b/crates/diesel_models/src/address.rs
@@ -72,6 +72,7 @@ pub struct EncryptableAddress {
#[derive(Clone, Debug, AsChangeset, router_derive::DebugAsDisplay, Serialize, Deserialize)]
#[diesel(table_name = address)]
+#[router_derive::apply_changeset(target = Address)]
pub struct AddressUpdateInternal {
pub city: Option<String>,
pub country: Option<enums::CountryAlpha2>,
@@ -89,25 +90,3 @@ pub struct AddressUpdateInternal {
pub email: Option<Encryption>,
pub origin_zip: Option<Encryption>,
}
-
-impl AddressUpdateInternal {
- pub fn create_address(self, source: Address) -> Address {
- Address {
- city: self.city,
- country: self.country,
- line1: self.line1,
- line2: self.line2,
- line3: self.line3,
- state: self.state,
- zip: self.zip,
- first_name: self.first_name,
- last_name: self.last_name,
- phone_number: self.phone_number,
- country_code: self.country_code,
- modified_at: self.modified_at,
- updated_by: self.updated_by,
- origin_zip: self.origin_zip,
- ..source
- }
- }
-}
diff --git a/crates/diesel_models/src/authentication.rs b/crates/diesel_models/src/authentication.rs
index f035faa7fe..fe10723ddf 100644
--- a/crates/diesel_models/src/authentication.rs
+++ b/crates/diesel_models/src/authentication.rs
@@ -370,6 +370,7 @@ impl Default for AuthenticationUpdateInternal {
#[derive(Clone, Debug, Eq, PartialEq, AsChangeset, Serialize, Deserialize)]
#[diesel(table_name = authentication)]
+#[router_derive::apply_changeset(target = Authentication)]
pub struct AuthenticationUpdateInternal {
pub connector_authentication_id: Option<String>,
// pub authentication_data: Option<serde_json::Value>,
@@ -434,156 +435,6 @@ pub struct AuthenticationUpdateInternal {
pub updated_by: String,
}
-impl AuthenticationUpdateInternal {
- pub fn apply_changeset(self, source: Authentication) -> Authentication {
- let Self {
- connector_authentication_id,
- payment_method_id,
- authentication_type,
- authentication_status,
- authentication_lifecycle_status,
- modified_at: _,
- error_code,
- error_message,
- connector_metadata,
- maximum_supported_version,
- threeds_server_transaction_id,
- authentication_flow_type,
- message_version,
- eci,
- trans_status,
- acquirer_bin,
- acquirer_merchant_id,
- three_ds_method_data,
- three_ds_method_url,
- acs_url,
- challenge_request,
- acs_reference_number,
- acs_trans_id,
- acs_signed_content,
- ds_trans_id,
- directory_server_id,
- acquirer_country_code,
- service_details,
- force_3ds_challenge,
- psd2_sca_exemption_type,
- billing_address,
- shipping_address,
- browser_info,
- email,
- profile_acquirer_id,
- challenge_code,
- challenge_cancel,
- challenge_code_reason,
- message_extension,
- challenge_request_key,
- customer_details,
- earliest_supported_version,
- latest_supported_version,
- mcc,
- platform,
- device_type,
- device_brand,
- device_os,
- device_display,
- browser_name,
- browser_version,
- scheme_name,
- exemption_requested,
- exemption_accepted,
- issuer_id,
- issuer_country,
- merchant_country_code,
- billing_country,
- shipping_country,
- updated_by,
- } = self;
- Authentication {
- connector_authentication_id: connector_authentication_id
- .or(source.connector_authentication_id),
- payment_method_id: payment_method_id.unwrap_or(source.payment_method_id),
- authentication_type: authentication_type.or(source.authentication_type),
- authentication_status: authentication_status.unwrap_or(source.authentication_status),
- authentication_lifecycle_status: authentication_lifecycle_status
- .unwrap_or(source.authentication_lifecycle_status),
- modified_at: common_utils::date_time::now(),
- error_code: error_code.or(source.error_code),
- error_message: error_message.or(source.error_message),
- connector_metadata: connector_metadata.or(source.connector_metadata),
- maximum_supported_version: maximum_supported_version
- .or(source.maximum_supported_version),
- threeds_server_transaction_id: threeds_server_transaction_id
- .or(source.threeds_server_transaction_id),
- authentication_flow_type: authentication_flow_type.or(source.authentication_flow_type),
- message_version: message_version.or(source.message_version),
- eci: eci.or(source.eci),
- trans_status: trans_status.or(source.trans_status),
- acquirer_bin: acquirer_bin.or(source.acquirer_bin),
- acquirer_merchant_id: acquirer_merchant_id.or(source.acquirer_merchant_id),
- three_ds_method_data: three_ds_method_data.or(source.three_ds_method_data),
- three_ds_method_url: three_ds_method_url.or(source.three_ds_method_url),
- acs_url: acs_url.or(source.acs_url),
- challenge_request: challenge_request.or(source.challenge_request),
- acs_reference_number: acs_reference_number.or(source.acs_reference_number),
- acs_trans_id: acs_trans_id.or(source.acs_trans_id),
- acs_signed_content: acs_signed_content.or(source.acs_signed_content),
- ds_trans_id: ds_trans_id.or(source.ds_trans_id),
- directory_server_id: directory_server_id.or(source.directory_server_id),
- acquirer_country_code: acquirer_country_code.or(source.acquirer_country_code),
- service_details: service_details.or(source.service_details),
- force_3ds_challenge: force_3ds_challenge.or(source.force_3ds_challenge),
- psd2_sca_exemption_type: psd2_sca_exemption_type.or(source.psd2_sca_exemption_type),
- billing_address: billing_address.or(source.billing_address),
- shipping_address: shipping_address.or(source.shipping_address),
- browser_info: browser_info.or(source.browser_info),
- email: email.or(source.email),
- profile_acquirer_id: profile_acquirer_id.or(source.profile_acquirer_id),
- challenge_code: challenge_code.or(source.challenge_code),
- challenge_cancel: challenge_cancel.or(source.challenge_cancel),
- challenge_code_reason: challenge_code_reason.or(source.challenge_code_reason),
- message_extension: message_extension.or(source.message_extension),
- challenge_request_key: challenge_request_key.or(source.challenge_request_key),
- customer_details: customer_details.or(source.customer_details),
- earliest_supported_version: earliest_supported_version
- .or(source.earliest_supported_version),
- latest_supported_version: latest_supported_version.or(source.latest_supported_version),
- mcc: mcc.or(source.mcc),
- platform: platform.or(source.platform),
- device_type: device_type.or(source.device_type),
- device_brand: device_brand.or(source.device_brand),
- device_os: device_os.or(source.device_os),
- device_display: device_display.or(source.device_display),
- browser_name: browser_name.or(source.browser_name),
- browser_version: browser_version.or(source.browser_version),
- scheme_name: scheme_name.or(source.scheme_name),
- exemption_requested: exemption_requested.or(source.exemption_requested),
- exemption_accepted: exemption_accepted.or(source.exemption_accepted),
- issuer_id: issuer_id.or(source.issuer_id),
- issuer_country: issuer_country.or(source.issuer_country),
- merchant_country_code: merchant_country_code.or(source.merchant_country_code),
- authentication_id: source.authentication_id,
- merchant_id: source.merchant_id,
- authentication_connector: source.authentication_connector,
- authentication_data: source.authentication_data,
- created_at: source.created_at,
- cavv: source.cavv,
- profile_id: source.profile_id,
- payment_id: source.payment_id,
- merchant_connector_id: source.merchant_connector_id,
- organization_id: source.organization_id,
- authentication_client_secret: source.authentication_client_secret,
- return_url: source.return_url,
- amount: source.amount,
- currency: source.currency,
- billing_country: billing_country.or(source.billing_country),
- shipping_country: shipping_country.or(source.shipping_country),
- processor_merchant_id: source.processor_merchant_id,
- created_by: source.created_by,
- updated_by: Some(updated_by),
- }
- }
-}
-
impl From<AuthenticationUpdate> for AuthenticationUpdateInternal {
fn from(auth_update: AuthenticationUpdate) -> Self {
match auth_update {
diff --git a/crates/diesel_models/src/business_profile.rs b/crates/diesel_models/src/business_profile.rs
index 5e4efef74f..6d5bb81787 100644
--- a/crates/diesel_models/src/business_profile.rs
+++ b/crates/diesel_models/src/business_profile.rs
@@ -160,6 +160,7 @@ pub struct ProfileNew {
#[cfg(feature = "v1")]
#[derive(Clone, Debug, AsChangeset, router_derive::DebugAsDisplay)]
#[diesel(table_name = business_profile)]
+#[router_derive::apply_changeset(target = Profile)]
pub struct ProfileUpdateInternal {
pub profile_name: Option<String>,
pub modified_at: time::PrimitiveDateTime,
@@ -225,174 +226,6 @@ pub struct ProfileUpdateInternal {
pub surcharge_connector_details: Option<SurchargeConnectorDetails>,
}
-#[cfg(feature = "v1")]
-impl ProfileUpdateInternal {
- pub fn apply_changeset(self, source: Profile) -> Profile {
- let Self {
- profile_name,
- modified_at,
- return_url,
- enable_payment_response_hash,
- payment_response_hash_key,
- redirect_to_merchant_with_http_post,
- webhook_details,
- metadata,
- routing_algorithm,
- intent_fulfillment_time,
- frm_routing_algorithm,
- payout_routing_algorithm,
- is_recon_enabled,
- applepay_verified_domains,
- payment_link_config,
- session_expiry,
- authentication_connector_details,
- payout_link_config,
- is_extended_card_info_enabled,
- extended_card_info_config,
- is_connector_agnostic_mit_enabled,
- use_billing_as_payment_method_billing,
- collect_shipping_details_from_wallet_connector,
- collect_billing_details_from_wallet_connector,
- outgoing_webhook_custom_http_headers,
- always_collect_billing_details_from_wallet_connector,
- always_collect_shipping_details_from_wallet_connector,
- tax_connector_id,
- is_tax_connector_enabled,
- is_l2_l3_enabled,
- dynamic_routing_algorithm,
- is_network_tokenization_enabled,
- is_auto_retries_enabled,
- max_auto_retries_enabled,
- always_request_extended_authorization,
- is_click_to_pay_enabled,
- authentication_product_ids,
- card_testing_guard_config,
- card_testing_secret_key,
- is_clear_pan_retries_enabled,
- force_3ds_challenge,
- is_debit_routing_enabled,
- merchant_business_country,
- is_iframe_redirection_enabled,
- is_pre_network_tokenization_enabled,
- three_ds_decision_rule_algorithm,
- acquirer_config_map,
- merchant_category_code,
- merchant_country_code,
- dispute_polling_interval,
- is_manual_retry_enabled,
- always_enable_overcapture,
- is_external_vault_enabled,
- external_vault_connector_details,
- billing_processor_id,
- surcharge_connector_details,
- network_tokenization_credentials,
- payment_method_blocking,
- default_fallback_routing,
- } = self;
- Profile {
- profile_id: source.profile_id,
- merchant_id: source.merchant_id,
- profile_name: profile_name.unwrap_or(source.profile_name),
- created_at: source.created_at,
- modified_at,
- return_url: return_url.or(source.return_url),
- enable_payment_response_hash: enable_payment_response_hash
- .unwrap_or(source.enable_payment_response_hash),
- payment_response_hash_key: payment_response_hash_key
- .or(source.payment_response_hash_key),
- redirect_to_merchant_with_http_post: redirect_to_merchant_with_http_post
- .unwrap_or(source.redirect_to_merchant_with_http_post),
- webhook_details: webhook_details.or(source.webhook_details),
- metadata: metadata.or(source.metadata),
- routing_algorithm: routing_algorithm.or(source.routing_algorithm),
- intent_fulfillment_time: intent_fulfillment_time.or(source.intent_fulfillment_time),
- frm_routing_algorithm: frm_routing_algorithm.or(source.frm_routing_algorithm),
- payout_routing_algorithm: payout_routing_algorithm.or(source.payout_routing_algorithm),
- is_recon_enabled: is_recon_enabled.unwrap_or(source.is_recon_enabled),
- applepay_verified_domains: applepay_verified_domains
- .or(source.applepay_verified_domains),
- payment_link_config: payment_link_config.or(source.payment_link_config),
- session_expiry: session_expiry.or(source.session_expiry),
- authentication_connector_details: authentication_connector_details
- .or(source.authentication_connector_details),
- payout_link_config: payout_link_config.or(source.payout_link_config),
- is_extended_card_info_enabled: is_extended_card_info_enabled
- .or(source.is_extended_card_info_enabled),
- is_connector_agnostic_mit_enabled: is_connector_agnostic_mit_enabled
- .or(source.is_connector_agnostic_mit_enabled),
- extended_card_info_config: extended_card_info_config
- .or(source.extended_card_info_config),
- use_billing_as_payment_method_billing: use_billing_as_payment_method_billing
- .or(source.use_billing_as_payment_method_billing),
- collect_shipping_details_from_wallet_connector:
- collect_shipping_details_from_wallet_connector
- .or(source.collect_shipping_details_from_wallet_connector),
- collect_billing_details_from_wallet_connector:
- collect_billing_details_from_wallet_connector
- .or(source.collect_billing_details_from_wallet_connector),
- outgoing_webhook_custom_http_headers: outgoing_webhook_custom_http_headers
- .or(source.outgoing_webhook_custom_http_headers),
- always_collect_billing_details_from_wallet_connector:
- always_collect_billing_details_from_wallet_connector
- .or(source.always_collect_billing_details_from_wallet_connector),
- always_collect_shipping_details_from_wallet_connector:
- always_collect_shipping_details_from_wallet_connector
- .or(source.always_collect_shipping_details_from_wallet_connector),
- tax_connector_id: tax_connector_id.or(source.tax_connector_id),
- is_tax_connector_enabled: is_tax_connector_enabled.or(source.is_tax_connector_enabled),
- is_l2_l3_enabled: is_l2_l3_enabled.or(source.is_l2_l3_enabled),
- version: source.version,
- dynamic_routing_algorithm: dynamic_routing_algorithm
- .or(source.dynamic_routing_algorithm),
- is_network_tokenization_enabled: is_network_tokenization_enabled
- .unwrap_or(source.is_network_tokenization_enabled),
- is_auto_retries_enabled: is_auto_retries_enabled.or(source.is_auto_retries_enabled),
- max_auto_retries_enabled: max_auto_retries_enabled.or(source.max_auto_retries_enabled),
- always_request_extended_authorization: always_request_extended_authorization
- .or(source.always_request_extended_authorization),
- is_click_to_pay_enabled: is_click_to_pay_enabled
- .unwrap_or(source.is_click_to_pay_enabled),
- authentication_product_ids: authentication_product_ids
- .or(source.authentication_product_ids),
- card_testing_guard_config: card_testing_guard_config
- .or(source.card_testing_guard_config),
- card_testing_secret_key,
- is_clear_pan_retries_enabled: is_clear_pan_retries_enabled
- .unwrap_or(source.is_clear_pan_retries_enabled),
- force_3ds_challenge,
- id: source.id,
- is_debit_routing_enabled: is_debit_routing_enabled
- .unwrap_or(source.is_debit_routing_enabled),
- merchant_business_country: merchant_business_country
- .or(source.merchant_business_country),
- is_iframe_redirection_enabled: is_iframe_redirection_enabled
- .or(source.is_iframe_redirection_enabled),
- is_pre_network_tokenization_enabled: is_pre_network_tokenization_enabled
- .or(source.is_pre_network_tokenization_enabled),
- three_ds_decision_rule_algorithm: three_ds_decision_rule_algorithm
- .or(source.three_ds_decision_rule_algorithm),
- acquirer_config_map: acquirer_config_map.or(source.acquirer_config_map),
- merchant_category_code: merchant_category_code.or(source.merchant_category_code),
- merchant_country_code: merchant_country_code.or(source.merchant_country_code),
- dispute_polling_interval: dispute_polling_interval.or(source.dispute_polling_interval),
- is_manual_retry_enabled: is_manual_retry_enabled.or(source.is_manual_retry_enabled),
- always_enable_overcapture: always_enable_overcapture
- .or(source.always_enable_overcapture),
- is_external_vault_enabled: is_external_vault_enabled
- .or(source.is_external_vault_enabled),
- external_vault_connector_details: external_vault_connector_details
- .or(source.external_vault_connector_details),
- billing_processor_id: billing_processor_id.or(source.billing_processor_id),
- surcharge_connector_details: surcharge_connector_details
- .or(source.surcharge_connector_details),
- network_tokenization_credentials: network_tokenization_credentials
- .or(source.network_tokenization_credentials),
- payment_method_blocking: payment_method_blocking.or(source.payment_method_blocking),
- default_fallback_routing: default_fallback_routing.or(source.default_fallback_routing),
- }
- }
-}
-
/// Note: The order of fields in the struct is important.
/// This should be in the same order as the fields in the schema.rs file, otherwise the code will
/// not compile
@@ -559,6 +392,7 @@ pub struct ProfileNew {
#[cfg(feature = "v2")]
#[derive(Clone, Debug, AsChangeset, router_derive::DebugAsDisplay)]
#[diesel(table_name = business_profile)]
+#[router_derive::apply_changeset(target = Profile)]
pub struct ProfileUpdateInternal {
pub profile_name: Option<String>,
pub modified_at: time::PrimitiveDateTime,
@@ -619,173 +453,6 @@ pub struct ProfileUpdateInternal {
pub split_txns_enabled: Option<common_enums::SplitTxnsEnabled>,
}
-#[cfg(feature = "v2")]
-impl ProfileUpdateInternal {
- pub fn apply_changeset(self, source: Profile) -> Profile {
- let Self {
- profile_name,
- modified_at,
- return_url,
- enable_payment_response_hash,
- payment_response_hash_key,
- redirect_to_merchant_with_http_post,
- webhook_details,
- metadata,
- is_recon_enabled,
- applepay_verified_domains,
- payment_link_config,
- session_expiry,
- authentication_connector_details,
- payout_link_config,
- is_extended_card_info_enabled,
- extended_card_info_config,
- is_connector_agnostic_mit_enabled,
- use_billing_as_payment_method_billing,
- collect_shipping_details_from_wallet_connector,
- collect_billing_details_from_wallet_connector,
- outgoing_webhook_custom_http_headers,
- always_collect_billing_details_from_wallet_connector,
- always_collect_shipping_details_from_wallet_connector,
- tax_connector_id,
- is_tax_connector_enabled,
- billing_processor_id,
- surcharge_connector_details,
- routing_algorithm_id,
- order_fulfillment_time,
- order_fulfillment_time_origin,
- 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,
- is_click_to_pay_enabled,
- authentication_product_ids,
- three_ds_decision_manager_config,
- card_testing_guard_config,
- card_testing_secret_key,
- is_clear_pan_retries_enabled,
- is_debit_routing_enabled,
- merchant_business_country,
- revenue_recovery_retry_algorithm_type,
- revenue_recovery_retry_algorithm_data,
- is_iframe_redirection_enabled,
- is_external_vault_enabled,
- external_vault_connector_details,
- merchant_category_code,
- merchant_country_code,
- split_txns_enabled,
- is_l2_l3_enabled,
- } = self;
- Profile {
- id: source.id,
- merchant_id: source.merchant_id,
- profile_name: profile_name.unwrap_or(source.profile_name),
- created_at: source.created_at,
- modified_at,
- return_url: return_url.or(source.return_url),
- enable_payment_response_hash: enable_payment_response_hash
- .unwrap_or(source.enable_payment_response_hash),
- payment_response_hash_key: payment_response_hash_key
- .or(source.payment_response_hash_key),
- redirect_to_merchant_with_http_post: redirect_to_merchant_with_http_post
- .unwrap_or(source.redirect_to_merchant_with_http_post),
- webhook_details: webhook_details.or(source.webhook_details),
- metadata: metadata.or(source.metadata),
- is_recon_enabled: is_recon_enabled.unwrap_or(source.is_recon_enabled),
- applepay_verified_domains: applepay_verified_domains
- .or(source.applepay_verified_domains),
- payment_link_config: payment_link_config.or(source.payment_link_config),
- session_expiry: session_expiry.or(source.session_expiry),
- authentication_connector_details: authentication_connector_details
- .or(source.authentication_connector_details),
- payout_link_config: payout_link_config.or(source.payout_link_config),
- is_extended_card_info_enabled: is_extended_card_info_enabled
- .or(source.is_extended_card_info_enabled),
- is_connector_agnostic_mit_enabled: is_connector_agnostic_mit_enabled
- .or(source.is_connector_agnostic_mit_enabled),
- extended_card_info_config: extended_card_info_config
- .or(source.extended_card_info_config),
- use_billing_as_payment_method_billing: use_billing_as_payment_method_billing
- .or(source.use_billing_as_payment_method_billing),
- collect_shipping_details_from_wallet_connector:
- collect_shipping_details_from_wallet_connector
- .or(source.collect_shipping_details_from_wallet_connector),
- collect_billing_details_from_wallet_connector:
- collect_billing_details_from_wallet_connector
- .or(source.collect_billing_details_from_wallet_connector),
- outgoing_webhook_custom_http_headers: outgoing_webhook_custom_http_headers
- .or(source.outgoing_webhook_custom_http_headers),
- always_collect_billing_details_from_wallet_connector:
- always_collect_billing_details_from_wallet_connector
- .or(always_collect_billing_details_from_wallet_connector),
- always_collect_shipping_details_from_wallet_connector:
- always_collect_shipping_details_from_wallet_connector
- .or(always_collect_shipping_details_from_wallet_connector),
- tax_connector_id: tax_connector_id.or(source.tax_connector_id),
- is_tax_connector_enabled: is_tax_connector_enabled.or(source.is_tax_connector_enabled),
- routing_algorithm_id: routing_algorithm_id.or(source.routing_algorithm_id),
- order_fulfillment_time: order_fulfillment_time.or(source.order_fulfillment_time),
- order_fulfillment_time_origin: order_fulfillment_time_origin
- .or(source.order_fulfillment_time_origin),
- frm_routing_algorithm_id: frm_routing_algorithm_id.or(source.frm_routing_algorithm_id),
- 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
- .or(source.should_collect_cvv_during_payment),
- version: source.version,
- dynamic_routing_algorithm: None,
- is_network_tokenization_enabled: is_network_tokenization_enabled
- .unwrap_or(source.is_network_tokenization_enabled),
- is_auto_retries_enabled: is_auto_retries_enabled.or(source.is_auto_retries_enabled),
- max_auto_retries_enabled: max_auto_retries_enabled.or(source.max_auto_retries_enabled),
- always_request_extended_authorization: None,
- is_click_to_pay_enabled: is_click_to_pay_enabled
- .unwrap_or(source.is_click_to_pay_enabled),
- authentication_product_ids: authentication_product_ids
- .or(source.authentication_product_ids),
- three_ds_decision_manager_config: three_ds_decision_manager_config
- .or(source.three_ds_decision_manager_config),
- card_testing_guard_config: card_testing_guard_config
- .or(source.card_testing_guard_config),
- card_testing_secret_key: card_testing_secret_key.or(source.card_testing_secret_key),
- is_clear_pan_retries_enabled: is_clear_pan_retries_enabled
- .unwrap_or(source.is_clear_pan_retries_enabled),
- force_3ds_challenge: None,
- is_debit_routing_enabled: is_debit_routing_enabled
- .unwrap_or(source.is_debit_routing_enabled),
- merchant_business_country: merchant_business_country
- .or(source.merchant_business_country),
- revenue_recovery_retry_algorithm_type: revenue_recovery_retry_algorithm_type
- .or(source.revenue_recovery_retry_algorithm_type),
- revenue_recovery_retry_algorithm_data: revenue_recovery_retry_algorithm_data
- .or(source.revenue_recovery_retry_algorithm_data),
- is_iframe_redirection_enabled: is_iframe_redirection_enabled
- .or(source.is_iframe_redirection_enabled),
- is_external_vault_enabled: is_external_vault_enabled
- .or(source.is_external_vault_enabled),
- external_vault_connector_details: external_vault_connector_details
- .or(source.external_vault_connector_details),
- three_ds_decision_rule_algorithm: None,
- acquirer_config_map: None,
- merchant_category_code: merchant_category_code.or(source.merchant_category_code),
- merchant_country_code: merchant_country_code.or(source.merchant_country_code),
- dispute_polling_interval: None,
- split_txns_enabled: split_txns_enabled.or(source.split_txns_enabled),
- is_manual_retry_enabled: None,
- always_enable_overcapture: None,
- is_l2_l3_enabled: None,
- billing_processor_id: billing_processor_id.or(source.billing_processor_id),
- surcharge_connector_details: surcharge_connector_details
- .or(source.surcharge_connector_details),
- network_tokenization_credentials: source.network_tokenization_credentials,
- payment_method_blocking: None,
- }
- }
-}
-
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize, diesel::AsExpression)]
#[diesel(sql_type = diesel::sql_types::Jsonb)]
pub struct AuthenticationConnectorDetails {
diff --git a/crates/diesel_models/src/capture.rs b/crates/diesel_models/src/capture.rs
index 367382b98b..6414c09657 100644
--- a/crates/diesel_models/src/capture.rs
+++ b/crates/diesel_models/src/capture.rs
@@ -80,6 +80,7 @@ pub enum CaptureUpdate {
#[derive(Clone, Debug, Default, AsChangeset, router_derive::DebugAsDisplay)]
#[diesel(table_name = captures)]
+#[router_derive::apply_changeset(target = Capture)]
pub struct CaptureUpdateInternal {
pub status: Option<storage_enums::CaptureStatus>,
pub error_message: Option<String>,
@@ -91,33 +92,6 @@ pub struct CaptureUpdateInternal {
pub processor_capture_data: Option<String>,
}
-impl CaptureUpdate {
- pub fn apply_changeset(self, source: Capture) -> Capture {
- let CaptureUpdateInternal {
- status,
- error_message,
- error_code,
- error_reason,
- modified_at: _,
- connector_capture_id,
- connector_response_reference_id,
- processor_capture_data,
- } = self.into();
- Capture {
- status: status.unwrap_or(source.status),
- error_message: error_message.or(source.error_message),
- error_code: error_code.or(source.error_code),
- error_reason: error_reason.or(source.error_reason),
- modified_at: common_utils::date_time::now(),
- connector_capture_id: connector_capture_id.or(source.connector_capture_id),
- connector_response_reference_id: connector_response_reference_id
- .or(source.connector_response_reference_id),
- processor_capture_data: processor_capture_data.or(source.processor_capture_data),
- ..source
- }
- }
-}
-
impl From<CaptureUpdate> for CaptureUpdateInternal {
fn from(payment_attempt_child_update: CaptureUpdate) -> Self {
let now = Some(common_utils::date_time::now());
diff --git a/crates/diesel_models/src/customers.rs b/crates/diesel_models/src/customers.rs
index 0b8e1a4fa1..22c49b0851 100644
--- a/crates/diesel_models/src/customers.rs
+++ b/crates/diesel_models/src/customers.rs
@@ -215,6 +215,7 @@ pub struct CustomerGlobalIdMigrationRow {
Clone, Debug, AsChangeset, router_derive::DebugAsDisplay, serde::Deserialize, serde::Serialize,
)]
#[diesel(table_name = customers)]
+#[router_derive::apply_changeset(target = Customer)]
pub struct CustomerUpdateInternal {
pub name: Option<Encryption>,
pub email: Option<Encryption>,
@@ -232,51 +233,12 @@ pub struct CustomerUpdateInternal {
pub document_details: Option<Encryption>,
}
-#[cfg(feature = "v1")]
-impl CustomerUpdateInternal {
- pub fn apply_changeset(self, source: Customer) -> Customer {
- let Self {
- name,
- email,
- phone,
- description,
- phone_country_code,
- metadata,
- connector_customer,
- address_id,
- default_payment_method_id,
- tax_registration_id,
- document_details,
- last_modified_by,
- ..
- } = self;
-
- Customer {
- name: name.map_or(source.name, Some),
- email: email.map_or(source.email, Some),
- phone: phone.map_or(source.phone, Some),
- description: description.map_or(source.description, Some),
- phone_country_code: phone_country_code.map_or(source.phone_country_code, Some),
- metadata: metadata.map_or(source.metadata, Some),
- modified_at: common_utils::date_time::now(),
- connector_customer: connector_customer.map_or(source.connector_customer, Some),
- address_id: address_id.map_or(source.address_id, Some),
- default_payment_method_id: default_payment_method_id
- .flatten()
- .map_or(source.default_payment_method_id, Some),
- tax_registration_id: tax_registration_id.map_or(source.tax_registration_id, Some),
- document_details: document_details.map_or(source.document_details, Some),
- last_modified_by: last_modified_by.or(source.last_modified_by),
- ..source
- }
- }
-}
-
#[cfg(feature = "v2")]
#[derive(
Clone, Debug, AsChangeset, router_derive::DebugAsDisplay, serde::Deserialize, serde::Serialize,
)]
#[diesel(table_name = customers)]
+#[router_derive::apply_changeset(target = Customer)]
pub struct CustomerUpdateInternal {
pub name: Option<Encryption>,
pub email: Option<Encryption>,
@@ -295,49 +257,3 @@ pub struct CustomerUpdateInternal {
pub last_modified_by: Option<String>,
pub document_details: Option<Encryption>,
}
-
-#[cfg(feature = "v2")]
-impl CustomerUpdateInternal {
- pub fn apply_changeset(self, source: Customer) -> Customer {
- let Self {
- name,
- email,
- phone,
- description,
- phone_country_code,
- metadata,
- connector_customer,
- default_payment_method_id,
- default_billing_address,
- default_shipping_address,
- status,
- tax_registration_id,
- document_details,
- last_modified_by,
- ..
- } = self;
-
- Customer {
- name: name.map_or(source.name, Some),
- email: email.map_or(source.email, Some),
- phone: phone.map_or(source.phone, Some),
- description: description.map_or(source.description, Some),
- phone_country_code: phone_country_code.map_or(source.phone_country_code, Some),
- metadata: metadata.map_or(source.metadata, Some),
- modified_at: common_utils::date_time::now(),
- connector_customer: connector_customer.map_or(source.connector_customer, Some),
- default_payment_method_id: default_payment_method_id
- .flatten()
- .map_or(source.default_payment_method_id, Some),
- default_billing_address: default_billing_address
- .map_or(source.default_billing_address, Some),
- default_shipping_address: default_shipping_address
- .map_or(source.default_shipping_address, Some),
- status: status.unwrap_or(source.status),
- tax_registration_id: tax_registration_id.map_or(source.tax_registration_id, Some),
- document_details: document_details.map_or(source.document_details, Some),
- last_modified_by: last_modified_by.or(source.last_modified_by),
- ..source
- }
- }
-}
diff --git a/crates/diesel_models/src/mandate.rs b/crates/diesel_models/src/mandate.rs
index cd61c98a1f..16d8f96655 100644
--- a/crates/diesel_models/src/mandate.rs
+++ b/crates/diesel_models/src/mandate.rs
@@ -148,6 +148,7 @@ pub struct SingleUseMandate {
serde::Deserialize,
)]
#[diesel(table_name = mandate)]
+#[router_derive::apply_changeset(target = Mandate)]
pub struct MandateUpdateInternal {
mandate_status: Option<storage_enums::MandateStatus>,
amount_captured: Option<i64>,
@@ -201,31 +202,6 @@ impl From<MandateUpdate> for MandateUpdateInternal {
}
}
-impl MandateUpdateInternal {
- pub fn apply_changeset(self, source: Mandate) -> Mandate {
- let Self {
- mandate_status,
- amount_captured,
- connector_mandate_ids,
- connector_mandate_id,
- payment_method_id,
- original_payment_id,
- updated_by,
- } = self;
-
- Mandate {
- mandate_status: mandate_status.unwrap_or(source.mandate_status),
- amount_captured: amount_captured.map_or(source.amount_captured, Some),
- connector_mandate_ids: connector_mandate_ids.map_or(source.connector_mandate_ids, Some),
- connector_mandate_id: connector_mandate_id.map_or(source.connector_mandate_id, Some),
- payment_method_id: payment_method_id.unwrap_or(source.payment_method_id),
- original_payment_id: original_payment_id.map_or(source.original_payment_id, Some),
- updated_by: updated_by.map_or(source.updated_by, Some),
- ..source
- }
- }
-}
-
impl From<&MandateNew> for Mandate {
fn from(mandate_new: &MandateNew) -> Self {
Self {
diff --git a/crates/diesel_models/src/merchant_account.rs b/crates/diesel_models/src/merchant_account.rs
index 39f8530e79..5366390e33 100644
--- a/crates/diesel_models/src/merchant_account.rs
+++ b/crates/diesel_models/src/merchant_account.rs
@@ -284,6 +284,7 @@ pub struct MerchantAccountNew {
#[cfg(feature = "v2")]
#[derive(Clone, Debug, AsChangeset, router_derive::DebugAsDisplay)]
#[diesel(table_name = merchant_account)]
+#[router_derive::apply_changeset(target = MerchantAccount)]
pub struct MerchantAccountUpdateInternal {
pub merchant_name: Option<Encryption>,
pub merchant_details: Option<Encryption>,
@@ -297,45 +298,10 @@ pub struct MerchantAccountUpdateInternal {
pub product_type: Option<common_enums::MerchantProductType>,
}
-#[cfg(feature = "v2")]
-impl MerchantAccountUpdateInternal {
- pub fn apply_changeset(self, source: MerchantAccount) -> MerchantAccount {
- let Self {
- merchant_name,
- merchant_details,
- publishable_key,
- storage_scheme,
- metadata,
- modified_at,
- organization_id,
- recon_status,
- is_platform_account,
- product_type,
- } = self;
-
- MerchantAccount {
- merchant_name: merchant_name.or(source.merchant_name),
- merchant_details: merchant_details.or(source.merchant_details),
- publishable_key: publishable_key.or(source.publishable_key),
- storage_scheme: storage_scheme.unwrap_or(source.storage_scheme),
- metadata: metadata.or(source.metadata),
- created_at: source.created_at,
- modified_at,
- organization_id: organization_id.unwrap_or(source.organization_id),
- recon_status: recon_status.unwrap_or(source.recon_status),
- version: source.version,
- id: source.id,
- is_platform_account: is_platform_account.unwrap_or(source.is_platform_account),
- product_type: product_type.or(source.product_type),
- merchant_account_type: source.merchant_account_type,
- network_tokenization_credentials: source.network_tokenization_credentials,
- }
- }
-}
-
#[cfg(feature = "v1")]
#[derive(Clone, Debug, AsChangeset, router_derive::DebugAsDisplay)]
#[diesel(table_name = merchant_account)]
+#[router_derive::apply_changeset(target = MerchantAccount)]
pub struct MerchantAccountUpdateInternal {
pub merchant_name: Option<Encryption>,
pub merchant_details: Option<Encryption>,
@@ -366,80 +332,3 @@ pub struct MerchantAccountUpdateInternal {
pub product_type: Option<common_enums::MerchantProductType>,
pub network_tokenization_credentials: Option<Encryption>,
}
-
-#[cfg(feature = "v1")]
-impl MerchantAccountUpdateInternal {
- pub fn apply_changeset(self, source: MerchantAccount) -> MerchantAccount {
- let Self {
- merchant_name,
- merchant_details,
- return_url,
- webhook_details,
- sub_merchants_enabled,
- parent_merchant_id,
- enable_payment_response_hash,
- payment_response_hash_key,
- redirect_to_merchant_with_http_post,
- publishable_key,
- storage_scheme,
- locker_id,
- metadata,
- routing_algorithm,
- primary_business_details,
- modified_at,
- intent_fulfillment_time,
- frm_routing_algorithm,
- payout_routing_algorithm,
- organization_id,
- is_recon_enabled,
- default_profile,
- recon_status,
- payment_link_config,
- pm_collect_link_config,
- is_platform_account,
- product_type,
- network_tokenization_credentials,
- } = self;
-
- MerchantAccount {
- merchant_id: source.merchant_id,
- return_url: return_url.or(source.return_url),
- enable_payment_response_hash: enable_payment_response_hash
- .unwrap_or(source.enable_payment_response_hash),
- payment_response_hash_key: payment_response_hash_key
- .or(source.payment_response_hash_key),
- redirect_to_merchant_with_http_post: redirect_to_merchant_with_http_post
- .unwrap_or(source.redirect_to_merchant_with_http_post),
- merchant_name: merchant_name.or(source.merchant_name),
- merchant_details: merchant_details.or(source.merchant_details),
- webhook_details: webhook_details.or(source.webhook_details),
- sub_merchants_enabled: sub_merchants_enabled.or(source.sub_merchants_enabled),
- parent_merchant_id: parent_merchant_id.or(source.parent_merchant_id),
- publishable_key: publishable_key.or(source.publishable_key),
- storage_scheme: storage_scheme.unwrap_or(source.storage_scheme),
- locker_id: locker_id.or(source.locker_id),
- metadata: metadata.or(source.metadata),
- routing_algorithm: routing_algorithm.or(source.routing_algorithm),
- primary_business_details: primary_business_details
- .unwrap_or(source.primary_business_details),
- intent_fulfillment_time: intent_fulfillment_time.or(source.intent_fulfillment_time),
- created_at: source.created_at,
- modified_at,
- frm_routing_algorithm: frm_routing_algorithm.or(source.frm_routing_algorithm),
- payout_routing_algorithm: payout_routing_algorithm.or(source.payout_routing_algorithm),
- organization_id: organization_id.unwrap_or(source.organization_id),
- is_recon_enabled: is_recon_enabled.unwrap_or(source.is_recon_enabled),
- default_profile: default_profile.unwrap_or(source.default_profile),
- recon_status: recon_status.unwrap_or(source.recon_status),
- payment_link_config: payment_link_config.or(source.payment_link_config),
- pm_collect_link_config: pm_collect_link_config.or(source.pm_collect_link_config),
- version: source.version,
- is_platform_account: is_platform_account.unwrap_or(source.is_platform_account),
- id: source.id,
- product_type: product_type.or(source.product_type),
- merchant_account_type: source.merchant_account_type,
- network_tokenization_credentials: network_tokenization_credentials
- .or(source.network_tokenization_credentials),
- }
- }
-}
diff --git a/crates/diesel_models/src/payment_attempt.rs b/crates/diesel_models/src/payment_attempt.rs
index 1060fe7514..f534c2936f 100644
--- a/crates/diesel_models/src/payment_attempt.rs
+++ b/crates/diesel_models/src/payment_attempt.rs
@@ -1007,6 +1007,7 @@ pub enum PaymentAttemptUpdate {
#[cfg(feature = "v2")]
#[derive(Clone, Debug, AsChangeset, router_derive::DebugAsDisplay, Serialize, Deserialize)]
#[diesel(table_name = payment_attempt)]
+#[router_derive::apply_changeset(target = PaymentAttempt)]
pub struct PaymentAttemptUpdateInternal {
pub status: Option<storage_enums::AttemptStatus>,
pub authentication_type: Option<storage_enums::AuthenticationType>,
@@ -1016,7 +1017,7 @@ pub struct PaymentAttemptUpdateInternal {
pub payment_method_id: Option<id_type::GlobalPaymentMethodId>,
pub cancellation_reason: Option<String>,
pub modified_at: PrimitiveDateTime,
- pub browser_info: Option<serde_json::Value>,
+ pub browser_info: Option<common_utils::types::BrowserInformation>,
// payment_token: Option<String>,
pub error_code: Option<String>,
pub connector_metadata: Option<pii::SecretSerdeValue>,
@@ -1055,139 +1056,10 @@ pub struct PaymentAttemptUpdateInternal {
pub connector_request_reference_id: Option<String>,
pub amount_captured: Option<MinorUnit>,
}
-
-#[cfg(feature = "v2")]
-impl PaymentAttemptUpdateInternal {
- pub fn apply_changeset(self, source: PaymentAttempt) -> PaymentAttempt {
- let Self {
- status,
- authentication_type,
- error_message,
- connector_payment_id,
- connector_payment_data,
- modified_at,
- browser_info,
- error_code,
- cancellation_reason,
- connector_metadata,
- payment_method_data,
- error_reason,
- amount_capturable,
- amount_to_capture,
- updated_by,
- merchant_connector_id,
- connector,
- redirection_data,
- unified_code,
- unified_message,
- connector_token_details,
- feature_metadata,
- network_decline_code,
- network_advice_code,
- network_error_message,
- payment_method_id,
- connector_request_reference_id,
- connector_response_reference_id,
- amount_captured,
- } = self;
-
- PaymentAttempt {
- payment_id: source.payment_id,
- merchant_id: source.merchant_id,
- status: status.unwrap_or(source.status),
- connector: connector.or(source.connector),
- error_message: error_message.or(source.error_message),
- surcharge_amount: source.surcharge_amount,
- payment_method_id: payment_method_id.or(source.payment_method_id),
- authentication_type: authentication_type.unwrap_or(source.authentication_type),
- created_at: source.created_at,
- modified_at: common_utils::date_time::now(),
- last_synced: source.last_synced,
- cancellation_reason: source.cancellation_reason,
- amount_to_capture: amount_to_capture.or(source.amount_to_capture),
- browser_info: browser_info
- .and_then(|val| {
- serde_json::from_value::<common_utils::types::BrowserInformation>(val).ok()
- })
- .or(source.browser_info),
- error_code: error_code.or(source.error_code),
- payment_token: source.payment_token,
- connector_metadata: connector_metadata.or(source.connector_metadata),
- payment_experience: source.payment_experience,
- payment_method_data: payment_method_data.or(source.payment_method_data),
- preprocessing_step_id: source.preprocessing_step_id,
- error_reason: error_reason.or(source.error_reason),
- multiple_capture_count: source.multiple_capture_count,
- connector_response_reference_id: connector_response_reference_id
- .or(source.connector_response_reference_id),
- amount_capturable: amount_capturable.unwrap_or(source.amount_capturable),
- updated_by,
- merchant_connector_id: merchant_connector_id.or(source.merchant_connector_id),
- encoded_data: source.encoded_data,
- unified_code: unified_code.or(source.unified_code),
- unified_message: unified_message.or(source.unified_message),
- net_amount: source.net_amount,
- external_three_ds_authentication_attempted: source
- .external_three_ds_authentication_attempted,
- external_threeds_authentication_type: source.external_threeds_authentication_type,
- authentication_connector: source.authentication_connector,
- authentication_id: source.authentication_id,
- fingerprint_id: source.fingerprint_id,
- client_source: source.client_source,
- client_version: source.client_version,
- customer_acceptance: source.customer_acceptance,
- profile_id: source.profile_id,
- organization_id: source.organization_id,
- card_network: source.card_network,
- shipping_cost: source.shipping_cost,
- order_tax_amount: source.order_tax_amount,
- request_extended_authorization: source.request_extended_authorization,
- extended_authorization_applied: source.extended_authorization_applied,
- extended_authorization_last_applied_at: source.extended_authorization_last_applied_at,
- tokenization: source.tokenization,
- capture_before: source.capture_before,
- card_discovery: source.card_discovery,
- charges: source.charges,
- processor_merchant_id: source.processor_merchant_id,
- created_by: source.created_by,
- payment_method_type_v2: source.payment_method_type_v2,
- network_transaction_id: source.network_transaction_id,
- network_transaction_link_id: source.network_transaction_link_id,
- connector_payment_id: connector_payment_id.or(source.connector_payment_id),
- payment_method_subtype: source.payment_method_subtype,
- routing_result: source.routing_result,
- authentication_applied: source.authentication_applied,
- external_reference_id: source.external_reference_id,
- external_surcharge_details: source.external_surcharge_details,
- tax_on_surcharge: source.tax_on_surcharge,
- payment_method_billing_address: source.payment_method_billing_address,
- redirection_data: redirection_data.or(source.redirection_data),
- connector_payment_data: connector_payment_data.or(source.connector_payment_data),
- connector_token_details: connector_token_details.or(source.connector_token_details),
- id: source.id,
- feature_metadata: feature_metadata.or(source.feature_metadata),
- network_advice_code: network_advice_code.or(source.network_advice_code),
- network_decline_code: network_decline_code.or(source.network_decline_code),
- network_error_message: network_error_message.or(source.network_error_message),
- connector_request_reference_id: connector_request_reference_id
- .or(source.connector_request_reference_id),
- is_overcapture_enabled: source.is_overcapture_enabled,
- network_details: source.network_details,
- attempts_group_id: source.attempts_group_id,
- is_stored_credential: source.is_stored_credential,
- authorized_amount: source.authorized_amount,
- amount_captured: amount_captured.or(source.amount_captured),
- encrypted_payment_method_data: source.encrypted_payment_method_data,
- error_details: source.error_details,
- retry_type: source.retry_type,
- installment_data: source.installment_data,
- sender_payment_instrument_id: source.sender_payment_instrument_id,
- }
- }
-}
#[cfg(feature = "v1")]
#[derive(Clone, Debug, AsChangeset, router_derive::DebugAsDisplay)]
#[diesel(table_name = payment_attempt)]
+#[router_derive::apply_changeset(target = PaymentAttempt)]
pub struct PaymentAttemptUpdateInternal {
pub amount: Option<MinorUnit>,
pub net_amount: Option<MinorUnit>,
@@ -1309,265 +1181,15 @@ impl PaymentAttemptUpdateInternal {
#[cfg(feature = "v2")]
impl PaymentAttemptUpdate {
- pub fn apply_changeset(self, _source: PaymentAttempt) -> PaymentAttempt {
- todo!()
- // let PaymentAttemptUpdateInternal {
- // net_amount,
- // status,
- // authentication_type,
- // error_message,
- // payment_method_id,
- // cancellation_reason,
- // modified_at: _,
- // browser_info,
- // payment_token,
- // error_code,
- // connector_metadata,
- // payment_method_data,
- // payment_experience,
- // straight_through_algorithm,
- // preprocessing_step_id,
- // error_reason,
- // connector_response_reference_id,
- // multiple_capture_count,
- // surcharge_amount,
- // tax_amount,
- // amount_capturable,
- // updated_by,
- // merchant_connector_id,
- // authentication_data,
- // encoded_data,
- // unified_code,
- // unified_message,
- // external_three_ds_authentication_attempted,
- // authentication_connector,
- // authentication_id,
- // payment_method_billing_address_id,
- // fingerprint_id,
- // charge_id,
- // client_source,
- // client_version,
- // customer_acceptance,
- // card_network,
- // } = PaymentAttemptUpdateInternal::from(self).populate_derived_fields(&source);
- // PaymentAttempt {
- // net_amount: net_amount.or(source.net_amount),
- // status: status.unwrap_or(source.status),
- // authentication_type: authentication_type.or(source.authentication_type),
- // error_message: error_message.unwrap_or(source.error_message),
- // payment_method_id: payment_method_id.or(source.payment_method_id),
- // cancellation_reason: cancellation_reason.or(source.cancellation_reason),
- // modified_at: common_utils::date_time::now(),
- // browser_info: browser_info.or(source.browser_info),
- // payment_token: payment_token.or(source.payment_token),
- // error_code: error_code.unwrap_or(source.error_code),
- // connector_metadata: connector_metadata.or(source.connector_metadata),
- // payment_method_data: payment_method_data.or(source.payment_method_data),
- // payment_experience: payment_experience.or(source.payment_experience),
- // straight_through_algorithm: straight_through_algorithm
- // .or(source.straight_through_algorithm),
- // preprocessing_step_id: preprocessing_step_id.or(source.preprocessing_step_id),
- // error_reason: error_reason.unwrap_or(source.error_reason),
- // connector_response_reference_id: connector_response_reference_id
- // .or(source.connector_response_reference_id),
- // multiple_capture_count: multiple_capture_count.or(source.multiple_capture_count),
- // surcharge_amount: surcharge_amount.or(source.surcharge_amount),
- // tax_amount: tax_amount.or(source.tax_amount),
- // amount_capturable: amount_capturable.unwrap_or(source.amount_capturable),
- // updated_by,
- // merchant_connector_id: merchant_connector_id.unwrap_or(source.merchant_connector_id),
- // authentication_data: authentication_data.or(source.authentication_data),
- // encoded_data: encoded_data.or(source.encoded_data),
- // unified_code: unified_code.unwrap_or(source.unified_code),
- // unified_message: unified_message.unwrap_or(source.unified_message),
- // external_three_ds_authentication_attempted: external_three_ds_authentication_attempted
- // .or(source.external_three_ds_authentication_attempted),
- // authentication_connector: authentication_connector.or(source.authentication_connector),
- // authentication_id: authentication_id.or(source.authentication_id),
- // payment_method_billing_address_id: payment_method_billing_address_id
- // .or(source.payment_method_billing_address_id),
- // fingerprint_id: fingerprint_id.or(source.fingerprint_id),
- // charge_id: charge_id.or(source.charge_id),
- // client_source: client_source.or(source.client_source),
- // client_version: client_version.or(source.client_version),
- // customer_acceptance: customer_acceptance.or(source.customer_acceptance),
- // card_network: card_network.or(source.card_network),
- // ..source
- // }
+ pub fn apply_changeset(self, source: PaymentAttempt) -> PaymentAttempt {
+ PaymentAttemptUpdateInternal::from(self).apply_changeset(source)
}
}
#[cfg(feature = "v1")]
impl PaymentAttemptUpdate {
pub fn apply_changeset(self, source: PaymentAttempt) -> PaymentAttempt {
- let PaymentAttemptUpdateInternal {
- amount,
- net_amount,
- currency,
- status,
- connector_transaction_id,
- amount_to_capture,
- connector,
- authentication_type,
- payment_method,
- error_message,
- payment_method_id,
- cancellation_reason,
- modified_at: _,
- mandate_id,
- browser_info,
- payment_token,
- error_code,
- connector_metadata,
- payment_method_data,
- payment_method_type,
- payment_experience,
- business_sub_label,
- straight_through_algorithm,
- preprocessing_step_id,
- error_reason,
- capture_method,
- connector_response_reference_id,
- multiple_capture_count,
- surcharge_amount,
- tax_amount,
- amount_capturable,
- updated_by,
- merchant_connector_id,
- authentication_data,
- encoded_data,
- unified_code,
- unified_message,
- external_three_ds_authentication_attempted,
- external_threeds_authentication_type,
- authentication_connector,
- authentication_id,
- payment_method_billing_address_id,
- fingerprint_id,
- client_source,
- client_version,
- customer_acceptance,
- card_network,
- shipping_cost,
- order_tax_amount,
- processor_transaction_data,
- connector_mandate_detail,
- capture_before,
- extended_authorization_applied,
- extended_authorization_last_applied_at,
- tokenization,
- encrypted_payment_method_data,
- card_discovery,
- charges,
- issuer_error_code,
- issuer_error_message,
- setup_future_usage_applied,
- routing_approach,
- connector_request_reference_id,
- network_transaction_id,
- network_transaction_link_id,
- is_overcapture_enabled,
- network_details,
- is_stored_credential,
- request_extended_authorization,
- authorized_amount,
- error_details,
- installment_data,
- sender_payment_instrument_id,
- external_surcharge_details,
- } = PaymentAttemptUpdateInternal::from(self).populate_derived_fields(&source);
- PaymentAttempt {
- amount: amount.unwrap_or(source.amount),
- net_amount: net_amount.or(source.net_amount),
- currency: currency.or(source.currency),
- status: status.unwrap_or(source.status),
- connector_transaction_id: connector_transaction_id.or(source.connector_transaction_id),
- amount_to_capture: amount_to_capture.or(source.amount_to_capture),
- connector: connector.unwrap_or(source.connector),
- authentication_type: authentication_type.or(source.authentication_type),
- payment_method: payment_method.or(source.payment_method),
- error_message: error_message.unwrap_or(source.error_message),
- payment_method_id: payment_method_id.or(source.payment_method_id),
- cancellation_reason: cancellation_reason.or(source.cancellation_reason),
- modified_at: common_utils::date_time::now(),
- mandate_id: mandate_id.or(source.mandate_id),
- browser_info: browser_info.or(source.browser_info),
- payment_token: payment_token.or(source.payment_token),
- error_code: error_code.unwrap_or(source.error_code),
- connector_metadata: connector_metadata.or(source.connector_metadata),
- payment_method_data: payment_method_data.or(source.payment_method_data),
- encrypted_payment_method_data: encrypted_payment_method_data
- .or(source.encrypted_payment_method_data),
- payment_method_type: payment_method_type.or(source.payment_method_type),
- payment_experience: payment_experience.or(source.payment_experience),
- business_sub_label: business_sub_label.or(source.business_sub_label),
- straight_through_algorithm: straight_through_algorithm
- .or(source.straight_through_algorithm),
- preprocessing_step_id: preprocessing_step_id.or(source.preprocessing_step_id),
- error_reason: error_reason.unwrap_or(source.error_reason),
- capture_method: capture_method.or(source.capture_method),
- connector_response_reference_id: connector_response_reference_id
- .or(source.connector_response_reference_id),
- multiple_capture_count: multiple_capture_count.or(source.multiple_capture_count),
- surcharge_amount: surcharge_amount.or(source.surcharge_amount),
- tax_amount: tax_amount.or(source.tax_amount),
- amount_capturable: amount_capturable.unwrap_or(source.amount_capturable),
- updated_by,
- merchant_connector_id: merchant_connector_id.unwrap_or(source.merchant_connector_id),
- authentication_data: authentication_data.or(source.authentication_data),
- encoded_data: encoded_data.or(source.encoded_data),
- unified_code: unified_code.unwrap_or(source.unified_code),
- unified_message: unified_message.unwrap_or(source.unified_message),
- external_three_ds_authentication_attempted: external_three_ds_authentication_attempted
- .or(source.external_three_ds_authentication_attempted),
- external_threeds_authentication_type: external_threeds_authentication_type
- .or(source.external_threeds_authentication_type),
- authentication_connector: authentication_connector.or(source.authentication_connector),
- authentication_id: authentication_id.or(source.authentication_id),
- payment_method_billing_address_id: payment_method_billing_address_id
- .or(source.payment_method_billing_address_id),
- fingerprint_id: fingerprint_id.or(source.fingerprint_id),
- client_source: client_source.or(source.client_source),
- client_version: client_version.or(source.client_version),
- customer_acceptance: customer_acceptance.or(source.customer_acceptance),
- card_network: card_network.or(source.card_network),
- shipping_cost: shipping_cost.or(source.shipping_cost),
- order_tax_amount: order_tax_amount.or(source.order_tax_amount),
- installment_data: installment_data.or(source.installment_data),
- processor_transaction_data: processor_transaction_data
- .or(source.processor_transaction_data),
- connector_mandate_detail: connector_mandate_detail.or(source.connector_mandate_detail),
- capture_before: capture_before.or(source.capture_before),
- extended_authorization_applied: extended_authorization_applied
- .or(source.extended_authorization_applied),
- extended_authorization_last_applied_at: extended_authorization_last_applied_at
- .or(source.extended_authorization_last_applied_at),
- card_discovery: card_discovery.or(source.card_discovery),
- charges: charges.or(source.charges),
- issuer_error_code: issuer_error_code.or(source.issuer_error_code),
- issuer_error_message: issuer_error_message.or(source.issuer_error_message),
- setup_future_usage_applied: setup_future_usage_applied
- .or(source.setup_future_usage_applied),
- routing_approach: routing_approach.or(source.routing_approach),
- connector_request_reference_id: connector_request_reference_id
- .or(source.connector_request_reference_id),
- network_transaction_id: network_transaction_id.or(source.network_transaction_id),
- network_transaction_link_id: network_transaction_link_id
- .or(source.network_transaction_link_id),
- is_overcapture_enabled: is_overcapture_enabled.or(source.is_overcapture_enabled),
- network_details: network_details.or(source.network_details),
- is_stored_credential: is_stored_credential.or(source.is_stored_credential),
- request_extended_authorization: request_extended_authorization
- .or(source.request_extended_authorization),
- authorized_amount: authorized_amount.or(source.authorized_amount),
- tokenization: tokenization.or(source.tokenization),
- error_details: error_details.unwrap_or(source.error_details),
- sender_payment_instrument_id: sender_payment_instrument_id
- .or(source.sender_payment_instrument_id),
- external_surcharge_details: external_surcharge_details
- .or(source.external_surcharge_details),
- ..source
- }
+ PaymentAttemptUpdateInternal::from(self).apply_changeset(source)
}
}
diff --git a/crates/diesel_models/src/payment_intent.rs b/crates/diesel_models/src/payment_intent.rs
index 77a8a7fcda..a2096e7391 100644
--- a/crates/diesel_models/src/payment_intent.rs
+++ b/crates/diesel_models/src/payment_intent.rs
@@ -5,7 +5,6 @@ use common_types::{
};
use common_utils::{encryption::Encryption, pii, types::MinorUnit};
use diesel::{AsChangeset, Identifiable, Insertable, Queryable, Selectable};
-use hyperswitch_masking::ExposeInterface;
use serde::{Deserialize, Serialize};
use time::PrimitiveDateTime;
@@ -149,7 +148,7 @@ pub struct PaymentIntent {
pub order_details: Option<Vec<pii::SecretSerdeValue>>,
pub allowed_payment_method_types: Option<serde_json::Value>,
pub connector_metadata: Option<serde_json::Value>,
- pub feature_metadata: Option<serde_json::Value>,
+ pub feature_metadata: Option<pii::SecretSerdeValue>,
pub attempt_count: i16,
pub profile_id: Option<common_utils::id_type::ProfileId>,
// Denotes the action(approve or reject) taken by merchant in case of manual review.
@@ -464,7 +463,7 @@ pub struct PaymentIntentNew {
pub order_details: Option<Vec<pii::SecretSerdeValue>>,
pub allowed_payment_method_types: Option<serde_json::Value>,
pub connector_metadata: Option<serde_json::Value>,
- pub feature_metadata: Option<serde_json::Value>,
+ pub feature_metadata: Option<pii::SecretSerdeValue>,
pub attempt_count: i16,
pub profile_id: Option<common_utils::id_type::ProfileId>,
pub merchant_decision: Option<String>,
@@ -699,7 +698,7 @@ pub struct PaymentIntentUpdateFields {
pub force_3ds_challenge: Option<bool>,
pub is_iframe_redirection_enabled: Option<bool>,
pub payment_channel: Option<common_enums::PaymentChannel>,
- pub feature_metadata: Option<hyperswitch_masking::Secret<serde_json::Value>>,
+ pub feature_metadata: Option<pii::SecretSerdeValue>,
pub tax_status: Option<common_enums::TaxStatus>,
pub discount_amount: Option<MinorUnit>,
pub order_date: Option<PrimitiveDateTime>,
@@ -718,6 +717,7 @@ pub struct PaymentIntentUpdateFields {
#[cfg(feature = "v2")]
#[derive(Clone, Debug, AsChangeset, router_derive::DebugAsDisplay, Serialize, Deserialize)]
#[diesel(table_name = payment_intent)]
+#[router_derive::apply_changeset(target = PaymentIntent)]
pub struct PaymentIntentUpdateInternal {
pub status: Option<storage_enums::IntentStatus>,
pub prerouting_algorithm: Option<serde_json::Value>,
@@ -765,154 +765,10 @@ pub struct PaymentIntentUpdateInternal {
pub external_surcharge_applicable: Option<bool>,
}
-#[cfg(feature = "v2")]
-impl PaymentIntentUpdateInternal {
- pub fn apply_changeset(self, source: PaymentIntent) -> PaymentIntent {
- let Self {
- status,
- prerouting_algorithm,
- amount_captured,
- modified_at: _, // This will be ignored from self
- active_attempt_id,
- active_attempts_group_id,
- active_attempt_id_type,
- amount,
- currency,
- shipping_cost,
- tax_details,
- skip_external_tax_calculation,
- surcharge_applicable,
- surcharge_amount,
- tax_on_surcharge,
- routing_algorithm_id,
- capture_method,
- authentication_type,
- billing_address,
- shipping_address,
- customer_present,
- description,
- return_url,
- setup_future_usage,
- apply_mit_exemption,
- statement_descriptor,
- order_details,
- allowed_payment_method_types,
- metadata,
- connector_metadata,
- feature_metadata,
- payment_link_config,
- request_incremental_authorization,
- session_expiry,
- frm_metadata,
- request_external_three_ds_authentication,
- updated_by,
- force_3ds_challenge,
- is_iframe_redirection_enabled,
- enable_partial_authorization,
- state_metadata,
- profile_acquirer_id,
- external_surcharge_strategy,
- external_surcharge_applicable,
- } = self;
-
- PaymentIntent {
- status: status.unwrap_or(source.status),
- prerouting_algorithm: prerouting_algorithm.or(source.prerouting_algorithm),
- amount_captured: amount_captured.or(source.amount_captured),
- modified_at: common_utils::date_time::now(),
- active_attempt_id: match active_attempt_id {
- Some(v_option) => v_option,
- None => source.active_attempt_id,
- },
- active_attempt_id_type: active_attempt_id_type.or(source.active_attempt_id_type),
- active_attempts_group_id: active_attempts_group_id.or(source.active_attempts_group_id),
- amount: amount.unwrap_or(source.amount),
- currency: currency.unwrap_or(source.currency),
- shipping_cost: shipping_cost.or(source.shipping_cost),
- tax_details: tax_details.or(source.tax_details),
- skip_external_tax_calculation: skip_external_tax_calculation
- .or(source.skip_external_tax_calculation),
- surcharge_applicable: surcharge_applicable.or(source.surcharge_applicable),
- surcharge_amount: surcharge_amount.or(source.surcharge_amount),
- tax_on_surcharge: tax_on_surcharge.or(source.tax_on_surcharge),
- routing_algorithm_id: routing_algorithm_id.or(source.routing_algorithm_id),
- capture_method: capture_method.or(source.capture_method),
- authentication_type: authentication_type.or(source.authentication_type),
- billing_address: billing_address.or(source.billing_address),
- shipping_address: shipping_address.or(source.shipping_address),
- customer_present: customer_present.or(source.customer_present),
- description: description.or(source.description),
- return_url: return_url.or(source.return_url),
- setup_future_usage: setup_future_usage.or(source.setup_future_usage),
- apply_mit_exemption: apply_mit_exemption.or(source.apply_mit_exemption),
- statement_descriptor: statement_descriptor.or(source.statement_descriptor),
- order_details: order_details.or(source.order_details),
- allowed_payment_method_types: allowed_payment_method_types
- .or(source.allowed_payment_method_types),
- metadata: metadata.or(source.metadata),
- connector_metadata: connector_metadata.or(source.connector_metadata),
- feature_metadata: feature_metadata.or(source.feature_metadata),
- payment_link_config: payment_link_config.or(source.payment_link_config),
- request_incremental_authorization: request_incremental_authorization
- .or(source.request_incremental_authorization),
- session_expiry: session_expiry.unwrap_or(source.session_expiry),
- frm_metadata: frm_metadata.or(source.frm_metadata),
- request_external_three_ds_authentication: request_external_three_ds_authentication
- .or(source.request_external_three_ds_authentication),
- profile_acquirer_id: profile_acquirer_id.or(source.profile_acquirer_id),
- external_surcharge_strategy: external_surcharge_strategy
- .or(source.external_surcharge_strategy),
- external_surcharge_applicable: external_surcharge_applicable
- .or(source.external_surcharge_applicable),
- updated_by,
- force_3ds_challenge: force_3ds_challenge.or(source.force_3ds_challenge),
- is_iframe_redirection_enabled: is_iframe_redirection_enabled
- .or(source.is_iframe_redirection_enabled),
- // Fields from source
- merchant_id: source.merchant_id,
- customer_id: source.customer_id,
- created_at: source.created_at,
- last_synced: source.last_synced,
- attempt_count: source.attempt_count,
- profile_id: source.profile_id,
- payment_link_id: source.payment_link_id,
- authorization_count: source.authorization_count,
- customer_details: source.customer_details,
- organization_id: source.organization_id,
- request_extended_authorization: source.request_extended_authorization,
- psd2_sca_exemption_type: source.psd2_sca_exemption_type,
- split_payments: source.split_payments,
- platform_merchant_id: source.platform_merchant_id,
- force_3ds_challenge_trigger: source.force_3ds_challenge_trigger,
- processor_merchant_id: source.processor_merchant_id,
- created_by: source.created_by,
- merchant_reference_id: source.merchant_reference_id,
- frm_merchant_decision: source.frm_merchant_decision,
- enable_payment_link: source.enable_payment_link,
- id: source.id,
- is_payment_id_from_merchant: source.is_payment_id_from_merchant,
- payment_channel: source.payment_channel,
- tax_status: source.tax_status,
- discount_amount: source.discount_amount,
- shipping_amount_tax: source.shipping_amount_tax,
- duty_amount: source.duty_amount,
- order_date: source.order_date,
- enable_partial_authorization: source.enable_partial_authorization,
- split_txns_enabled: source.split_txns_enabled,
- enable_overcapture: None,
- mit_category: None,
- billing_descriptor: source.billing_descriptor,
- tokenization: None,
- partner_merchant_identifier_details: source.partner_merchant_identifier_details,
- state_metadata,
- installment_options: source.installment_options,
- }
- }
-}
-
#[cfg(feature = "v1")]
#[derive(Clone, Debug, AsChangeset, router_derive::DebugAsDisplay)]
#[diesel(table_name = payment_intent)]
+#[router_derive::apply_changeset(target = PaymentIntent)]
pub struct PaymentIntentUpdateInternal {
pub amount: Option<MinorUnit>,
pub currency: Option<storage_enums::Currency>,
@@ -955,7 +811,7 @@ pub struct PaymentIntentUpdateInternal {
pub is_iframe_redirection_enabled: Option<bool>,
pub extended_return_url: Option<String>,
pub payment_channel: Option<common_enums::PaymentChannel>,
- pub feature_metadata: Option<hyperswitch_masking::Secret<serde_json::Value>>,
+ pub feature_metadata: Option<pii::SecretSerdeValue>,
pub tax_status: Option<common_enums::TaxStatus>,
pub discount_amount: Option<MinorUnit>,
pub order_date: Option<PrimitiveDateTime>,
@@ -974,131 +830,7 @@ pub struct PaymentIntentUpdateInternal {
#[cfg(feature = "v1")]
impl PaymentIntentUpdate {
pub fn apply_changeset(self, source: PaymentIntent) -> PaymentIntent {
- let PaymentIntentUpdateInternal {
- amount,
- currency,
- status,
- amount_captured,
- customer_id,
- return_url,
- setup_future_usage,
- off_session,
- metadata,
- billing_address_id,
- shipping_address_id,
- modified_at: _,
- active_attempt_id,
- business_country,
- business_label,
- description,
- statement_descriptor_name,
- statement_descriptor_suffix,
- order_details,
- attempt_count,
- merchant_decision,
- payment_confirm_source,
- updated_by,
- surcharge_applicable,
- incremental_authorization_allowed,
- authorization_count,
- session_expiry,
- fingerprint_id,
- request_external_three_ds_authentication,
- frm_metadata,
- customer_details,
- billing_details,
- merchant_order_reference_id,
- shipping_details,
- is_payment_processor_token_flow,
- tax_details,
- force_3ds_challenge,
- is_iframe_redirection_enabled,
- extended_return_url,
- payment_channel,
- feature_metadata,
- tax_status,
- discount_amount,
- order_date,
- shipping_amount_tax,
- duty_amount,
- enable_partial_authorization,
- enable_overcapture,
- shipping_cost,
- state_metadata: _,
- installment_options: _,
- profile_acquirer_id,
- external_surcharge_strategy,
- external_surcharge_applicable,
- ..
- } = self.into();
- PaymentIntent {
- amount: amount.unwrap_or(source.amount),
- currency: currency.or(source.currency),
- status: status.unwrap_or(source.status),
- amount_captured: amount_captured.or(source.amount_captured),
- customer_id: customer_id.or(source.customer_id),
- return_url: return_url.or(source.return_url),
- setup_future_usage: setup_future_usage.or(source.setup_future_usage),
- off_session: off_session.or(source.off_session),
- metadata: metadata.or(source.metadata),
- billing_address_id: billing_address_id.or(source.billing_address_id),
- shipping_address_id: shipping_address_id.or(source.shipping_address_id),
- modified_at: common_utils::date_time::now(),
- active_attempt_id: active_attempt_id.unwrap_or(source.active_attempt_id),
- business_country: business_country.or(source.business_country),
- business_label: business_label.or(source.business_label),
- description: description.or(source.description),
- statement_descriptor_name: statement_descriptor_name
- .or(source.statement_descriptor_name),
- statement_descriptor_suffix: statement_descriptor_suffix
- .or(source.statement_descriptor_suffix),
- order_details: order_details.or(source.order_details),
- attempt_count: attempt_count.unwrap_or(source.attempt_count),
- merchant_decision: merchant_decision.or(source.merchant_decision),
- payment_confirm_source: payment_confirm_source.or(source.payment_confirm_source),
- updated_by,
- surcharge_applicable: surcharge_applicable.or(source.surcharge_applicable),
-
- incremental_authorization_allowed: incremental_authorization_allowed
- .or(source.incremental_authorization_allowed),
- authorization_count: authorization_count.or(source.authorization_count),
- fingerprint_id: fingerprint_id.or(source.fingerprint_id),
- session_expiry: session_expiry.or(source.session_expiry),
- request_external_three_ds_authentication: request_external_three_ds_authentication
- .or(source.request_external_three_ds_authentication),
- frm_metadata: frm_metadata.or(source.frm_metadata),
- customer_details: customer_details.or(source.customer_details),
- billing_details: billing_details.or(source.billing_details),
- merchant_order_reference_id: merchant_order_reference_id
- .or(source.merchant_order_reference_id),
- shipping_details: shipping_details.or(source.shipping_details),
- is_payment_processor_token_flow: is_payment_processor_token_flow
- .or(source.is_payment_processor_token_flow),
- tax_details: tax_details.or(source.tax_details),
- force_3ds_challenge: force_3ds_challenge.or(source.force_3ds_challenge),
- is_iframe_redirection_enabled: is_iframe_redirection_enabled
- .or(source.is_iframe_redirection_enabled),
- extended_return_url: extended_return_url.or(source.extended_return_url),
- payment_channel: payment_channel.or(source.payment_channel),
- feature_metadata: feature_metadata
- .map(|value| value.expose())
- .or(source.feature_metadata),
- tax_status: tax_status.or(source.tax_status),
- discount_amount: discount_amount.or(source.discount_amount),
- order_date: order_date.or(source.order_date),
- shipping_amount_tax: shipping_amount_tax.or(source.shipping_amount_tax),
- duty_amount: duty_amount.or(source.duty_amount),
- enable_partial_authorization: enable_partial_authorization
- .or(source.enable_partial_authorization),
- enable_overcapture: enable_overcapture.or(source.enable_overcapture),
- shipping_cost: shipping_cost.or(source.shipping_cost),
- profile_acquirer_id: profile_acquirer_id.or(source.profile_acquirer_id),
- external_surcharge_strategy: external_surcharge_strategy
- .or(source.external_surcharge_strategy),
- external_surcharge_applicable: external_surcharge_applicable
- .or(source.external_surcharge_applicable),
- ..source
- }
+ PaymentIntentUpdateInternal::from(self).apply_changeset(source)
}
}
diff --git a/crates/diesel_models/src/payment_method.rs b/crates/diesel_models/src/payment_method.rs
index d3c66dd339..e5d2454b7b 100644
--- a/crates/diesel_models/src/payment_method.rs
+++ b/crates/diesel_models/src/payment_method.rs
@@ -302,7 +302,7 @@ pub enum PaymentMethodUpdate {
network_tokenization_data: Option<Encryption>,
},
ConnectorMandateDetailsUpdate {
- connector_mandate_details: Option<serde_json::Value>,
+ connector_mandate_details: Option<pii::SecretSerdeValue>,
last_modified_by: Option<String>,
},
NetworkTokenDataUpdate {
@@ -416,6 +416,7 @@ impl PaymentMethodUpdate {
#[cfg(feature = "v2")]
#[derive(Clone, Debug, AsChangeset, router_derive::DebugAsDisplay, Serialize, Deserialize)]
#[diesel(table_name = payment_methods)]
+#[router_derive::apply_changeset(target = PaymentMethod)]
pub struct PaymentMethodUpdateInternal {
payment_method_data: Option<Encryption>,
last_used_at: Option<PrimitiveDateTime>,
@@ -440,77 +441,6 @@ pub struct PaymentMethodUpdateInternal {
compatibility_updated_at: Option<PrimitiveDateTime>,
}
-#[cfg(feature = "v2")]
-impl PaymentMethodUpdateInternal {
- pub fn apply_changeset(self, source: PaymentMethod) -> PaymentMethod {
- let Self {
- payment_method_data,
- last_used_at,
- network_transaction_id,
- network_transaction_link_id,
- status,
- locker_id,
- payment_method_type_v2,
- connector_mandate_details,
- updated_by,
- payment_method_subtype,
- last_modified,
- payment_method,
- payment_method_type,
- network_token_requestor_reference_id,
- network_token_locker_id,
- network_token_payment_method_data,
- locker_fingerprint_id,
- external_vault_source,
- last_modified_by,
- customer_details,
- compatibility_updated_at,
- } = self;
-
- PaymentMethod {
- customer_id: source.customer_id,
- merchant_id: source.merchant_id,
- created_at: source.created_at,
- last_modified,
- payment_method: payment_method.or(source.payment_method),
- payment_method_type: payment_method_type.or(source.payment_method_type),
- payment_method_data: payment_method_data.or(source.payment_method_data),
- locker_id: locker_id.or(source.locker_id),
- last_used_at: last_used_at.unwrap_or(source.last_used_at),
- connector_mandate_details: connector_mandate_details
- .or(source.connector_mandate_details),
- customer_acceptance: source.customer_acceptance,
- status: status.unwrap_or(source.status),
- network_transaction_id: network_transaction_id.or(source.network_transaction_id),
- network_transaction_link_id: network_transaction_link_id
- .or(source.network_transaction_link_id),
- client_secret: source.client_secret,
- payment_method_billing_address: source.payment_method_billing_address,
- updated_by: updated_by.or(source.updated_by),
- locker_fingerprint_id: locker_fingerprint_id.or(source.locker_fingerprint_id),
- payment_method_type_v2: payment_method_type_v2.or(source.payment_method_type_v2),
- payment_method_subtype: payment_method_subtype.or(source.payment_method_subtype),
- id: source.id,
- payment_method_id: source.payment_method_id,
- version: source.version,
- network_token_requestor_reference_id: network_token_requestor_reference_id
- .or(source.network_token_requestor_reference_id),
- network_token_locker_id: network_token_locker_id.or(source.network_token_locker_id),
- network_token_payment_method_data: network_token_payment_method_data
- .or(source.network_token_payment_method_data),
- external_vault_source: external_vault_source.or(source.external_vault_source),
- external_vault_token_data: source.external_vault_token_data,
- vault_type: source.vault_type,
- created_by: source.created_by,
- last_modified_by: last_modified_by.or(source.last_modified_by),
- customer_details: customer_details.or(source.customer_details),
- network_tokenization_data: source.network_tokenization_data,
- auxiliary_fingerprint_id: source.auxiliary_fingerprint_id,
- compatibility_updated_at,
- }
- }
-}
-
#[cfg(feature = "v1")]
#[derive(Clone, Debug, AsChangeset, router_derive::DebugAsDisplay, Serialize, Deserialize)]
// Diesel derive assumes `id` as primary key unless explicitly configured.
@@ -519,8 +449,9 @@ impl PaymentMethodUpdateInternal {
// Ref: https://diesel.rs/guides/all-about-updates/
#[diesel(table_name = payment_methods)]
#[diesel(primary_key(payment_method_id))]
+#[router_derive::apply_changeset(target = PaymentMethod)]
pub struct PaymentMethodUpdateInternal {
- metadata: Option<serde_json::Value>,
+ metadata: Option<pii::SecretSerdeValue>,
payment_method_data: Option<Encryption>,
last_used_at: Option<PrimitiveDateTime>,
network_transaction_id: Option<String>,
@@ -541,99 +472,11 @@ pub struct PaymentMethodUpdateInternal {
customer_details: Option<Encryption>,
network_tokenization_data: Option<Encryption>,
payment_method_type_v2: Option<storage_enums::PaymentMethod>,
- payment_method_subtype: Option<storage_enums::PaymentMethodType>,
+ payment_method_subtype: Option<String>,
id: Option<String>,
compatibility_updated_at: Option<PrimitiveDateTime>,
}
-#[cfg(feature = "v1")]
-impl PaymentMethodUpdateInternal {
- pub fn apply_changeset(self, source: PaymentMethod) -> PaymentMethod {
- let Self {
- metadata,
- payment_method_data,
- last_used_at,
- network_transaction_id,
- network_transaction_link_id,
- status,
- locker_id,
- network_token_requestor_reference_id,
- payment_method,
- connector_mandate_details,
- updated_by,
- payment_method_type,
- payment_method_issuer,
- last_modified,
- network_token_locker_id,
- network_token_payment_method_data,
- scheme,
- last_modified_by,
- customer_details,
- network_tokenization_data,
- payment_method_type_v2,
- payment_method_subtype,
- id,
- compatibility_updated_at,
- } = self;
-
- PaymentMethod {
- customer_id: source.customer_id,
- merchant_id: source.merchant_id,
- payment_method_id: source.payment_method_id,
- accepted_currency: source.accepted_currency,
- scheme: scheme.or(source.scheme),
- token: source.token,
- cardholder_name: source.cardholder_name,
- issuer_name: source.issuer_name,
- issuer_country: source.issuer_country,
- payer_country: source.payer_country,
- is_stored: source.is_stored,
- swift_code: source.swift_code,
- direct_debit_token: source.direct_debit_token,
- created_at: source.created_at,
- locker_fingerprint_id: source.locker_fingerprint_id,
- last_modified,
- payment_method: payment_method.or(source.payment_method),
- payment_method_type: payment_method_type.or(source.payment_method_type),
- payment_method_issuer: payment_method_issuer.or(source.payment_method_issuer),
- payment_method_issuer_code: source.payment_method_issuer_code,
- metadata: metadata.map_or(source.metadata, |v| Some(v.into())),
- payment_method_data: payment_method_data.or(source.payment_method_data),
- locker_id: locker_id.or(source.locker_id),
- last_used_at: last_used_at.unwrap_or(source.last_used_at),
- connector_mandate_details: connector_mandate_details
- .or(source.connector_mandate_details),
- customer_acceptance: source.customer_acceptance,
- status: status.unwrap_or(source.status),
- network_transaction_id: network_transaction_id.or(source.network_transaction_id),
- network_transaction_link_id: network_transaction_link_id
- .or(source.network_transaction_link_id),
- client_secret: source.client_secret,
- payment_method_billing_address: source.payment_method_billing_address,
- updated_by: updated_by.or(source.updated_by),
- version: source.version,
- network_token_requestor_reference_id: network_token_requestor_reference_id
- .or(source.network_token_requestor_reference_id),
- network_token_locker_id: network_token_locker_id.or(source.network_token_locker_id),
- network_token_payment_method_data: network_token_payment_method_data
- .or(source.network_token_payment_method_data),
- external_vault_source: source.external_vault_source,
- vault_type: source.vault_type,
- created_by: source.created_by,
- last_modified_by: last_modified_by.or(source.last_modified_by),
- customer_details: customer_details.or(source.customer_details),
- network_tokenization_data: network_tokenization_data
- .or(source.network_tokenization_data),
- payment_method_type_v2: payment_method_type_v2.or(source.payment_method_type_v2),
- payment_method_subtype: payment_method_subtype
- .map(|payment_method_subtype| payment_method_subtype.to_string())
- .or(source.payment_method_subtype),
- id: id.or(source.id),
- compatibility_updated_at: compatibility_updated_at.or(source.compatibility_updated_at),
- }
- }
-}
-
#[cfg(feature = "v1")]
impl From<PaymentMethodUpdate> for PaymentMethodUpdateInternal {
fn from(payment_method_update: PaymentMethodUpdate) -> Self {
@@ -643,7 +486,7 @@ impl From<PaymentMethodUpdate> for PaymentMethodUpdateInternal {
last_used_at,
last_modified_by,
} => Self {
- metadata,
+ metadata: metadata.map(Secret::new),
payment_method_data: None,
last_used_at: Some(last_used_at),
network_transaction_id: None,
@@ -859,7 +702,7 @@ impl From<PaymentMethodUpdate> for PaymentMethodUpdateInternal {
connector_mandate_details,
network_tokenization_data,
} => Self {
- metadata,
+ metadata: metadata.map(Secret::new),
payment_method_data,
last_used_at,
network_transaction_id: None,
@@ -896,7 +739,7 @@ impl From<PaymentMethodUpdate> for PaymentMethodUpdateInternal {
locker_id: None,
network_token_requestor_reference_id: None,
payment_method: None,
- connector_mandate_details,
+ connector_mandate_details: connector_mandate_details.map(|v| v.expose()),
network_transaction_id: None,
network_transaction_link_id: None,
updated_by: None,
@@ -1041,7 +884,7 @@ impl From<PaymentMethodUpdate> for PaymentMethodUpdateInternal {
customer_details: None,
network_tokenization_data: None,
payment_method_type_v2,
- payment_method_subtype,
+ payment_method_subtype: payment_method_subtype.map(|x| x.to_string()),
id: Some(id),
compatibility_updated_at: Some(now),
}
diff --git a/crates/diesel_models/src/payment_methods_session.rs b/crates/diesel_models/src/payment_methods_session.rs
index 0685413ef5..5e6394308a 100644
--- a/crates/diesel_models/src/payment_methods_session.rs
+++ b/crates/diesel_models/src/payment_methods_session.rs
@@ -21,43 +21,7 @@ pub struct PaymentMethodSession {
}
#[cfg(feature = "v2")]
-impl PaymentMethodSession {
- pub fn apply_changeset(self, update_session: PaymentMethodsSessionUpdateInternal) -> Self {
- let Self {
- id,
- customer_id,
- billing,
- psp_tokenization,
- network_tokenization,
- tokenization_data,
- expires_at,
- return_url,
- associated_payment_methods,
- associated_payment,
- associated_token_id,
- storage_type,
- keep_alive,
- } = self;
-
- Self {
- id,
- customer_id,
- billing: update_session.billing.or(billing),
- psp_tokenization: update_session.psp_tokenization.or(psp_tokenization),
- network_tokenization: update_session.network_tokenization.or(network_tokenization),
- tokenization_data: update_session.tokenization_data.or(tokenization_data),
- expires_at,
- return_url,
- associated_payment_methods,
- associated_payment,
- associated_token_id,
- storage_type,
- keep_alive,
- }
- }
-}
-
-#[cfg(feature = "v2")]
+#[router_derive::apply_changeset(target = PaymentMethodSession)]
pub struct PaymentMethodsSessionUpdateInternal {
pub billing: Option<common_utils::encryption::Encryption>,
pub psp_tokenization: Option<common_types::payment_methods::PspTokenization>,
diff --git a/crates/diesel_models/src/payout_attempt.rs b/crates/diesel_models/src/payout_attempt.rs
index 6bb951352f..5a7a7ca28a 100644
--- a/crates/diesel_models/src/payout_attempt.rs
+++ b/crates/diesel_models/src/payout_attempt.rs
@@ -133,6 +133,7 @@ pub enum PayoutAttemptUpdate {
#[derive(Clone, Debug, AsChangeset, router_derive::DebugAsDisplay)]
#[diesel(table_name = payout_attempt)]
+#[router_derive::apply_changeset(target = PayoutAttempt)]
pub struct PayoutAttemptUpdateInternal {
pub payout_token: Option<String>,
pub connector_payout_id: Option<String>,
@@ -266,56 +267,6 @@ impl From<PayoutAttemptUpdate> for PayoutAttemptUpdateInternal {
impl PayoutAttemptUpdate {
pub fn apply_changeset(self, source: PayoutAttempt) -> PayoutAttempt {
- let PayoutAttemptUpdateInternal {
- payout_token,
- connector_payout_id,
- status,
- error_message,
- error_code,
- is_eligible,
- business_country,
- business_label,
- connector,
- routing_info,
- last_modified_at,
- address_id,
- customer_id,
- merchant_connector_id,
- unified_code,
- unified_message,
- additional_payout_method_data,
- merchant_order_reference_id,
- payout_connector_metadata,
- source_bank_data_token,
- additional_source_bank_data,
- } = self.into();
- PayoutAttempt {
- payout_token: payout_token.or(source.payout_token),
- connector_payout_id: connector_payout_id.or(source.connector_payout_id),
- status: status.unwrap_or(source.status),
- error_message: error_message.or(source.error_message),
- error_code: error_code.or(source.error_code),
- is_eligible: is_eligible.or(source.is_eligible),
- business_country: business_country.or(source.business_country),
- business_label: business_label.or(source.business_label),
- connector: connector.or(source.connector),
- routing_info: routing_info.or(source.routing_info),
- last_modified_at,
- address_id: address_id.or(source.address_id),
- customer_id: customer_id.or(source.customer_id),
- merchant_connector_id: merchant_connector_id.or(source.merchant_connector_id),
- unified_code: unified_code.or(source.unified_code),
- unified_message: unified_message.or(source.unified_message),
- additional_payout_method_data: additional_payout_method_data
- .or(source.additional_payout_method_data),
- merchant_order_reference_id: merchant_order_reference_id
- .or(source.merchant_order_reference_id),
- payout_connector_metadata: payout_connector_metadata
- .or(source.payout_connector_metadata),
- source_bank_data_token: source_bank_data_token.or(source.source_bank_data_token),
- additional_source_bank_data: additional_source_bank_data
- .or(source.additional_source_bank_data),
- ..source
- }
+ PayoutAttemptUpdateInternal::from(self).apply_changeset(source)
}
}
diff --git a/crates/diesel_models/src/payouts.rs b/crates/diesel_models/src/payouts.rs
index 54cd59308a..5211637a44 100644
--- a/crates/diesel_models/src/payouts.rs
+++ b/crates/diesel_models/src/payouts.rs
@@ -124,6 +124,7 @@ pub enum PayoutsUpdate {
#[derive(Clone, Debug, AsChangeset, router_derive::DebugAsDisplay)]
#[diesel(table_name = payouts)]
+#[router_derive::apply_changeset(target = Payouts)]
pub struct PayoutsUpdateInternal {
pub amount: Option<MinorUnit>,
pub destination_currency: Option<storage_enums::Currency>,
@@ -233,46 +234,6 @@ impl From<PayoutsUpdate> for PayoutsUpdateInternal {
impl PayoutsUpdate {
pub fn apply_changeset(self, source: Payouts) -> Payouts {
- let PayoutsUpdateInternal {
- amount,
- destination_currency,
- source_currency,
- description,
- recurring,
- auto_fulfill,
- return_url,
- entity_type,
- metadata,
- payout_method_id,
- profile_id,
- status,
- last_modified_at,
- attempt_count,
- confirm,
- payout_type,
- address_id,
- customer_id,
- } = self.into();
- Payouts {
- amount: amount.unwrap_or(source.amount),
- destination_currency: destination_currency.unwrap_or(source.destination_currency),
- source_currency: source_currency.unwrap_or(source.source_currency),
- description: description.or(source.description),
- recurring: recurring.unwrap_or(source.recurring),
- auto_fulfill: auto_fulfill.unwrap_or(source.auto_fulfill),
- return_url: return_url.or(source.return_url),
- entity_type: entity_type.unwrap_or(source.entity_type),
- metadata: metadata.or(source.metadata),
- payout_method_id: payout_method_id.or(source.payout_method_id),
- profile_id: profile_id.unwrap_or(source.profile_id),
- status: status.unwrap_or(source.status),
- last_modified_at,
- attempt_count: attempt_count.unwrap_or(source.attempt_count),
- confirm: confirm.or(source.confirm),
- payout_type: payout_type.or(source.payout_type),
- address_id: address_id.or(source.address_id),
- customer_id: customer_id.or(source.customer_id),
- ..source
- }
+ PayoutsUpdateInternal::from(self).apply_changeset(source)
}
}
diff --git a/crates/diesel_models/src/refund.rs b/crates/diesel_models/src/refund.rs
index 47082d1336..73dd31da49 100644
--- a/crates/diesel_models/src/refund.rs
+++ b/crates/diesel_models/src/refund.rs
@@ -347,6 +347,7 @@ pub enum RefundUpdate {
#[cfg(feature = "v1")]
#[derive(Clone, Debug, AsChangeset, router_derive::DebugAsDisplay)]
#[diesel(table_name = refund)]
+#[router_derive::apply_changeset(target = Refund)]
pub struct RefundUpdateInternal {
connector_refund_id: Option<ConnectorTransactionId>,
refund_status: Option<storage_enums::RefundStatus>,
@@ -368,6 +369,7 @@ pub struct RefundUpdateInternal {
#[cfg(feature = "v2")]
#[derive(Clone, Debug, AsChangeset, router_derive::DebugAsDisplay)]
#[diesel(table_name = refund)]
+#[router_derive::apply_changeset(target = Refund)]
pub struct RefundUpdateInternal {
connector_refund_id: Option<ConnectorTransactionId>,
refund_status: Option<storage_enums::RefundStatus>,
@@ -673,78 +675,14 @@ impl From<RefundUpdate> for RefundUpdateInternal {
#[cfg(feature = "v1")]
impl RefundUpdate {
pub fn apply_changeset(self, source: Refund) -> Refund {
- let RefundUpdateInternal {
- connector_refund_id,
- refund_status,
- sent_to_gateway,
- refund_error_message,
- refund_arn,
- metadata,
- refund_reason,
- refund_error_code,
- updated_by,
- modified_at: _,
- processor_refund_data,
- unified_code,
- unified_message,
- issuer_error_code,
- issuer_error_message,
- } = self.into();
- Refund {
- connector_refund_id: connector_refund_id.or(source.connector_refund_id),
- refund_status: refund_status.unwrap_or(source.refund_status),
- sent_to_gateway: sent_to_gateway.unwrap_or(source.sent_to_gateway),
- refund_error_message: refund_error_message.map_or(source.refund_error_message, |v| v),
- refund_error_code: refund_error_code.map_or(source.refund_error_code, |v| v),
- refund_arn: refund_arn.or(source.refund_arn),
- metadata: metadata.or(source.metadata),
- refund_reason: refund_reason.or(source.refund_reason),
- updated_by,
- modified_at: common_utils::date_time::now(),
- processor_refund_data: processor_refund_data.or(source.processor_refund_data),
- unified_code: unified_code.or(source.unified_code),
- unified_message: unified_message.or(source.unified_message),
- issuer_error_code: issuer_error_code.or(source.issuer_error_code),
- issuer_error_message: issuer_error_message.or(source.issuer_error_message),
- ..source
- }
+ RefundUpdateInternal::from(self).apply_changeset(source)
}
}
#[cfg(feature = "v2")]
impl RefundUpdate {
pub fn apply_changeset(self, source: Refund) -> Refund {
- let RefundUpdateInternal {
- connector_refund_id,
- refund_status,
- sent_to_gateway,
- refund_error_message,
- refund_arn,
- metadata,
- refund_reason,
- refund_error_code,
- updated_by,
- modified_at: _,
- processor_refund_data,
- unified_code,
- unified_message,
- } = self.into();
- Refund {
- connector_refund_id: connector_refund_id.or(source.connector_refund_id),
- refund_status: refund_status.unwrap_or(source.refund_status),
- sent_to_gateway: sent_to_gateway.unwrap_or(source.sent_to_gateway),
- refund_error_message: refund_error_message.map_or(source.refund_error_message, |v| v),
- refund_error_code: refund_error_code.map_or(source.refund_error_code, |v| v),
- refund_arn: refund_arn.or(source.refund_arn),
- metadata: metadata.or(source.metadata),
- refund_reason: refund_reason.or(source.refund_reason),
- updated_by,
- modified_at: common_utils::date_time::now(),
- processor_refund_data: processor_refund_data.or(source.processor_refund_data),
- unified_code: unified_code.or(source.unified_code),
- unified_message: unified_message.or(source.unified_message),
- ..source
- }
+ RefundUpdateInternal::from(self).apply_changeset(source)
}
pub fn build_error_update_for_unified_error_and_message(
diff --git a/crates/hyperswitch_domain_models/src/payment_methods.rs b/crates/hyperswitch_domain_models/src/payment_methods.rs
index a0d44552d7..3f07b8679d 100644
--- a/crates/hyperswitch_domain_models/src/payment_methods.rs
+++ b/crates/hyperswitch_domain_models/src/payment_methods.rs
@@ -1342,44 +1342,7 @@ impl From<PaymentMethodsSessionUpdateEnum> for PaymentMethodsSessionUpdateIntern
}
#[cfg(feature = "v2")]
-impl PaymentMethodSession {
- pub fn apply_changeset(self, update_session: PaymentMethodsSessionUpdateInternal) -> Self {
- let Self {
- id,
- customer_id,
- billing,
- psp_tokenization,
- network_tokenization,
- tokenization_data,
- expires_at,
- return_url,
- associated_payment_methods,
- associated_payment,
- associated_token_id,
- storage_type,
- keep_alive,
- } = self;
- Self {
- id,
- customer_id,
- billing: update_session.billing.or(billing),
- psp_tokenization: update_session.psp_tokenization.or(psp_tokenization),
- network_tokenization: update_session.network_tokenization.or(network_tokenization),
- tokenization_data: update_session.tokenization_data.or(tokenization_data),
- expires_at,
- return_url,
- associated_payment_methods: update_session
- .associated_payment_methods
- .or(associated_payment_methods),
- associated_payment,
- associated_token_id,
- storage_type,
- keep_alive,
- }
- }
-}
-
-#[cfg(feature = "v2")]
+#[router_derive::apply_changeset(target = PaymentMethodSession)]
pub struct PaymentMethodsSessionUpdateInternal {
pub billing: Option<Encryptable<Address>>,
pub psp_tokenization: Option<common_types::payment_methods::PspTokenization>,
diff --git a/crates/hyperswitch_domain_models/src/payments.rs b/crates/hyperswitch_domain_models/src/payments.rs
index 64513876a8..f343b22937 100644
--- a/crates/hyperswitch_domain_models/src/payments.rs
+++ b/crates/hyperswitch_domain_models/src/payments.rs
@@ -99,7 +99,7 @@ pub struct PaymentIntent {
pub order_details: Option<Vec<pii::SecretSerdeValue>>,
pub allowed_payment_method_types: Option<Value>,
pub connector_metadata: Option<Value>,
- pub feature_metadata: Option<Value>,
+ pub feature_metadata: Option<pii::SecretSerdeValue>,
pub attempt_count: i16,
pub profile_id: Option<id_type::ProfileId>,
pub payment_link_id: Option<String>,
diff --git a/crates/router/src/core/payment_methods/cards.rs b/crates/router/src/core/payment_methods/cards.rs
index 44cc927883..fe57f48e7b 100644
--- a/crates/router/src/core/payment_methods/cards.rs
+++ b/crates/router/src/core/payment_methods/cards.rs
@@ -3161,7 +3161,7 @@ pub async fn update_payment_method_connector_mandate_details(
.transpose()?;
let pm_update = payment_method::PaymentMethodUpdate::ConnectorMandateDetailsUpdate {
- connector_mandate_details: connector_mandate_details_value,
+ connector_mandate_details: connector_mandate_details_value.map(Secret::new),
last_modified_by: initiator
.and_then(|initiator| initiator.to_created_by())
.map(|last_modified_by| last_modified_by.to_string()),
diff --git a/crates/router/src/core/payments/operations/payment_cancel.rs b/crates/router/src/core/payments/operations/payment_cancel.rs
index 41ba08a3b5..b415331f43 100644
--- a/crates/router/src/core/payments/operations/payment_cancel.rs
+++ b/crates/router/src/core/payments/operations/payment_cancel.rs
@@ -264,11 +264,7 @@ impl<F: Clone + Sync> UpdateTracker<F, PaymentData<F>, api::PaymentsCancelReques
status: enums::IntentStatus::Cancelled,
updated_by: storage_scheme.to_string(),
incremental_authorization_allowed: None,
- feature_metadata: payment_data
- .payment_intent
- .feature_metadata
- .clone()
- .map(hyperswitch_masking::Secret::new),
+ feature_metadata: payment_data.payment_intent.feature_metadata.clone(),
};
(Some(payment_intent_update), enums::AttemptStatus::Voided)
} else {
diff --git a/crates/router/src/core/payments/operations/payment_complete_authorize.rs b/crates/router/src/core/payments/operations/payment_complete_authorize.rs
index 3d099a6a5a..574cd0ab8f 100644
--- a/crates/router/src/core/payments/operations/payment_complete_authorize.rs
+++ b/crates/router/src/core/payments/operations/payment_complete_authorize.rs
@@ -295,6 +295,7 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, api::PaymentsRequest>
.get_feature_metadata_as_value()
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("Error converting feature_metadata to Value")?
+ .map(hyperswitch_masking::Secret::new)
.or(payment_intent.feature_metadata);
payment_intent.metadata = request.metadata.clone().or(payment_intent.metadata);
diff --git a/crates/router/src/core/payments/operations/payment_confirm.rs b/crates/router/src/core/payments/operations/payment_confirm.rs
index 267146c9e9..edf3538642 100644
--- a/crates/router/src/core/payments/operations/payment_confirm.rs
+++ b/crates/router/src/core/payments/operations/payment_confirm.rs
@@ -493,6 +493,7 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, api::PaymentsRequest>
.get_feature_metadata_as_value()
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("Error converting feature_metadata to Value")?
+ .map(hyperswitch_masking::Secret::new)
.or(payment_intent.feature_metadata);
payment_intent.metadata = request.metadata.clone().or(payment_intent.metadata);
payment_intent.frm_metadata = request.frm_metadata.clone().or(payment_intent.frm_metadata);
@@ -2869,11 +2870,7 @@ impl<F: Clone + Sync> UpdateTracker<F, PaymentData<F>, api::PaymentsRequest> for
.is_iframe_redirection_enabled,
is_confirm_operation: true, // Indicates that this is a confirm operation
payment_channel: payment_data.payment_intent.payment_channel,
- feature_metadata: payment_data
- .payment_intent
- .feature_metadata
- .clone()
- .map(hyperswitch_masking::Secret::new),
+ feature_metadata: payment_data.payment_intent.feature_metadata.clone(),
tax_status: payment_data.payment_intent.tax_status,
discount_amount: payment_data.payment_intent.discount_amount,
order_date: payment_data.payment_intent.order_date,
diff --git a/crates/router/src/core/payments/operations/payment_create.rs b/crates/router/src/core/payments/operations/payment_create.rs
index d1928729f8..0703cb892d 100644
--- a/crates/router/src/core/payments/operations/payment_create.rs
+++ b/crates/router/src/core/payments/operations/payment_create.rs
@@ -1939,7 +1939,7 @@ impl PaymentCreate {
connector_id: None,
allowed_payment_method_types,
connector_metadata,
- feature_metadata,
+ feature_metadata: feature_metadata.map(Secret::new),
attempt_count: 1,
profile_id: Some(profile_id),
merchant_decision: None,
diff --git a/crates/router/src/core/payments/operations/payment_response.rs b/crates/router/src/core/payments/operations/payment_response.rs
index c3ec3ed75e..9914bc9aa8 100644
--- a/crates/router/src/core/payments/operations/payment_response.rs
+++ b/crates/router/src/core/payments/operations/payment_response.rs
@@ -1392,7 +1392,7 @@ impl<F: Clone> PostUpdateTracker<F, PaymentData<F>, types::PaymentsUpdateMetadat
.payment_intent
.metadata
.clone(),
- feature_metadata: payment_intent.feature_metadata.clone().map(hyperswitch_masking::Secret::new),
+ feature_metadata: payment_intent.feature_metadata.clone(),
updated_by: payment_data.payment_intent.updated_by.clone(),
};
@@ -3081,11 +3081,7 @@ fn get_payment_intent_update_data<F: Clone, T: types::Capturable>(
),
updated_by: processor.get_account().storage_scheme.to_string(),
incremental_authorization_allowed: Some(false),
- feature_metadata: payment_data
- .payment_intent
- .feature_metadata
- .clone()
- .map(hyperswitch_masking::Secret::new),
+ feature_metadata: payment_data.payment_intent.feature_metadata.clone(),
},
Ok(types::PaymentsResponseData::PostCaptureVoidResponse {
post_capture_void_status,
@@ -3120,11 +3116,7 @@ fn get_payment_intent_update_data<F: Clone, T: types::Capturable>(
incremental_authorization_allowed: payment_data
.payment_intent
.incremental_authorization_allowed,
- feature_metadata: payment_data
- .payment_intent
- .feature_metadata
- .clone()
- .map(hyperswitch_masking::Secret::new),
+ feature_metadata: payment_data.payment_intent.feature_metadata.clone(),
},
}
}
diff --git a/crates/router/src/core/payments/operations/payment_session.rs b/crates/router/src/core/payments/operations/payment_session.rs
index d259a40dca..a0d801ef96 100644
--- a/crates/router/src/core/payments/operations/payment_session.rs
+++ b/crates/router/src/core/payments/operations/payment_session.rs
@@ -271,11 +271,7 @@ impl<F: Clone + Sync> UpdateTracker<F, PaymentData<F>, api::PaymentsSessionReque
let key_store = processor.get_key_store();
let metadata = payment_data.payment_intent.metadata.clone();
- let feature_metadata = payment_data
- .payment_intent
- .feature_metadata
- .clone()
- .map(hyperswitch_masking::Secret::new);
+ let feature_metadata = payment_data.payment_intent.feature_metadata.clone();
payment_data.payment_intent = match metadata {
Some(metadata) => state
.store
diff --git a/crates/router/src/core/payments/operations/payment_update.rs b/crates/router/src/core/payments/operations/payment_update.rs
index fd8cf426e3..0be232a5ba 100644
--- a/crates/router/src/core/payments/operations/payment_update.rs
+++ b/crates/router/src/core/payments/operations/payment_update.rs
@@ -290,6 +290,7 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, api::PaymentsRequest>
.get_feature_metadata_as_value()
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("Error converting feature_metadata to Value")?
+ .map(hyperswitch_masking::Secret::new)
.or(payment_intent.feature_metadata);
payment_intent.metadata = request.metadata.clone().or(payment_intent.metadata);
payment_intent.frm_metadata = request.frm_metadata.clone().or(payment_intent.frm_metadata);
@@ -1098,11 +1099,7 @@ impl<F: Clone + Sync> UpdateTracker<F, PaymentData<F>, api::PaymentsRequest> for
.is_iframe_redirection_enabled,
is_confirm_operation: false, // this is not a confirm operation
payment_channel: payment_data.payment_intent.payment_channel,
- feature_metadata: payment_data
- .payment_intent
- .feature_metadata
- .clone()
- .map(hyperswitch_masking::Secret::new),
+ feature_metadata: payment_data.payment_intent.feature_metadata.clone(),
tax_status: payment_data.payment_intent.tax_status,
discount_amount: payment_data.payment_intent.discount_amount,
order_date: payment_data.payment_intent.order_date,
diff --git a/crates/router/src/core/payments/operations/payment_update_metadata.rs b/crates/router/src/core/payments/operations/payment_update_metadata.rs
index ccecab1c72..6e8757c343 100644
--- a/crates/router/src/core/payments/operations/payment_update_metadata.rs
+++ b/crates/router/src/core/payments/operations/payment_update_metadata.rs
@@ -140,7 +140,8 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, api::PaymentsUpdateMe
payment_intent.feature_metadata = Some(
serde_json::to_value(merged_feature_metadata)
.change_context(errors::ApiErrorResponse::InternalServerError)
- .attach_printable("Failed to serialize feature metadata")?,
+ .attach_printable("Failed to serialize feature metadata")?
+ .into(),
);
}
@@ -293,11 +294,7 @@ impl<F: Clone + Sync> UpdateTracker<F, PaymentData<F>, api::PaymentsUpdateMetada
let storage_scheme = processor.get_account().storage_scheme;
let key_store = processor.get_key_store();
let metadata = payment_data.payment_intent.metadata.clone();
- let feature_metadata = payment_data
- .payment_intent
- .feature_metadata
- .clone()
- .map(hyperswitch_masking::Secret::new);
+ let feature_metadata = payment_data.payment_intent.feature_metadata.clone();
payment_data.payment_intent = state
.store
diff --git a/crates/router/src/core/payouts.rs b/crates/router/src/core/payouts.rs
index 0db8a4cc16..b2384284e3 100644
--- a/crates/router/src/core/payouts.rs
+++ b/crates/router/src/core/payouts.rs
@@ -2445,7 +2445,9 @@ pub async fn create_recipient_disburse_account(
let pm_update =
diesel_models::PaymentMethodUpdate::ConnectorMandateDetailsUpdate {
#[cfg(feature = "v1")]
- connector_mandate_details: Some(connector_mandate_details_value),
+ connector_mandate_details: Some(Secret::new(
+ connector_mandate_details_value,
+ )),
#[cfg(feature = "v2")]
connector_mandate_details: Some(common_connector_mandate),
diff --git a/crates/router/src/core/unified_connector_service.rs b/crates/router/src/core/unified_connector_service.rs
index 5c3c005882..8cf0f1bcf0 100644
--- a/crates/router/src/core/unified_connector_service.rs
+++ b/crates/router/src/core/unified_connector_service.rs
@@ -645,7 +645,7 @@ where
.and_then(|metadata| {
// Try to parse the JSON value as FeatureMetadata
// Log errors but don't fail the flow for corrupted metadata
- match serde_json::from_value::<FeatureMetadata>(metadata.clone()) {
+ match serde_json::from_value::<FeatureMetadata>(metadata.clone().expose()) {
Ok(feature_metadata) => feature_metadata.gateway_system,
Err(err) => {
router_env::logger::warn!(
@@ -677,7 +677,7 @@ where
let existing_metadata = payment_intent.feature_metadata.as_ref();
let mut feature_metadata = match existing_metadata {
- Some(metadata) => serde_json::from_value::<FeatureMetadata>(metadata.clone())
+ Some(metadata) => serde_json::from_value::<FeatureMetadata>(metadata.clone().expose())
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable(
"Failed to deserialize existing feature metadata while updating gateway system",
@@ -691,7 +691,7 @@ where
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("Failed to serialize feature metadata")?;
- payment_intent.feature_metadata = Some(updated_metadata.clone());
+ payment_intent.feature_metadata = Some(Secret::new(updated_metadata));
payment_data.set_payment_intent(payment_intent);
Ok(())
diff --git a/crates/router/src/db/address.rs b/crates/router/src/db/address.rs
index 7fc80f0df6..4ed9ebdb15 100644
--- a/crates/router/src/db/address.rs
+++ b/crates/router/src/db/address.rs
@@ -481,7 +481,7 @@ mod storage {
AddressUpdateInternal::from(address_update.clone());
let updated_address = address_update_internal
.clone()
- .create_address(address.clone());
+ .apply_changeset(address.clone());
let redis_value = serde_json::to_string(&updated_address)
.change_context(errors::StorageError::KVError)?;
@@ -776,7 +776,7 @@ impl AddressInterface for MockDb {
.find(|address| address.address_id == address_id)
.map(|a| {
let address_updated =
- AddressUpdateInternal::from(address_update).create_address(a.clone());
+ AddressUpdateInternal::from(address_update).apply_changeset(a.clone());
*a = address_updated.clone();
address_updated
});
@@ -813,7 +813,7 @@ impl AddressInterface for MockDb {
.find(|address| address.address_id == this.address.address_id)
.map(|a| {
let address_updated =
- AddressUpdateInternal::from(address_update).create_address(a.clone());
+ AddressUpdateInternal::from(address_update).apply_changeset(a.clone());
*a = address_updated.clone();
address_updated
});
@@ -902,7 +902,7 @@ impl AddressInterface for MockDb {
})
.map(|a| {
let address_updated =
- AddressUpdateInternal::from(address_update).create_address(a.clone());
+ AddressUpdateInternal::from(address_update).apply_changeset(a.clone());
*a = address_updated.clone();
address_updated
});
diff --git a/crates/router/src/db/capture.rs b/crates/router/src/db/capture.rs
index d74da15e54..4813e5dfe1 100644
--- a/crates/router/src/db/capture.rs
+++ b/crates/router/src/db/capture.rs
@@ -152,14 +152,16 @@ mod storage {
}
enums::MerchantStorageScheme::RedisKv => {
let key_str = key.to_string();
- let updated_capture = capture.clone().apply_changeset(this.clone());
+ let capture_id = this.capture_id.clone();
+ let updated_capture =
+ CaptureUpdateInternal::from(capture.clone()).apply_changeset(this.clone());
let redis_value = serde_json::to_string(&updated_capture)
.change_context(errors::StorageError::SerializationFailed)?;
let mut query_gen_conn = connection::pg_connection_write(self).await?;
let drainer_query = capture
- .generate_drainer_update_query(&mut query_gen_conn, this.capture_id.clone())
+ .generate_drainer_update_query(&mut query_gen_conn, capture_id)
.await
.change_context(errors::StorageError::KVError)
.attach_printable("Failed to generate capture update query")?;
diff --git a/crates/router/src/db/payment_method_session.rs b/crates/router/src/db/payment_method_session.rs
index e2a8c21a5d..8b30cf3ad4 100644
--- a/crates/router/src/db/payment_method_session.rs
+++ b/crates/router/src/db/payment_method_session.rs
@@ -130,7 +130,7 @@ mod storage {
let internal_obj = hyperswitch_domain_models::payment_methods::PaymentMethodsSessionUpdateInternal::from(update_request);
- let update_state = current_session.apply_changeset(internal_obj);
+ let update_state = internal_obj.apply_changeset(current_session);
let db_model = update_state
.construct_new()
diff --git a/crates/router/src/services/kafka/payment_intent.rs b/crates/router/src/services/kafka/payment_intent.rs
index 89a87dc199..719c0ccb72 100644
--- a/crates/router/src/services/kafka/payment_intent.rs
+++ b/crates/router/src/services/kafka/payment_intent.rs
@@ -102,7 +102,7 @@ impl<'a> KafkaPaymentIntent<'a> {
.and_then(|obj| obj.get("email"))
.and_then(|email| email.as_str())
.map(|email| HashedString::from(Secret::new(email.to_string()))),
- feature_metadata: intent.feature_metadata.as_ref(),
+ feature_metadata: intent.feature_metadata.as_ref().map(|s| s.peek()),
merchant_order_reference_id: intent.merchant_order_reference_id.as_ref(),
organization_id: &intent.organization_id,
processor_merchant_id: &intent.processor_merchant_id,
diff --git a/crates/router/src/services/kafka/payment_intent_event.rs b/crates/router/src/services/kafka/payment_intent_event.rs
index cebc6ce2b6..5e4c2ba17b 100644
--- a/crates/router/src/services/kafka/payment_intent_event.rs
+++ b/crates/router/src/services/kafka/payment_intent_event.rs
@@ -194,7 +194,7 @@ impl<'a> KafkaPaymentIntentEvent<'a> {
.and_then(|obj| obj.get("email"))
.and_then(|email| email.as_str())
.map(|email| HashedString::from(Secret::new(email.to_string()))),
- feature_metadata: intent.feature_metadata.as_ref(),
+ feature_metadata: intent.feature_metadata.as_ref().map(|s| s.peek()),
merchant_order_reference_id: intent.merchant_order_reference_id.as_ref(),
organization_id: &intent.organization_id,
processor_merchant_id: &intent.processor_merchant_id,
diff --git a/crates/router/src/workflows/payment_sync.rs b/crates/router/src/workflows/payment_sync.rs
index 851e05ec64..0758688bf0 100644
--- a/crates/router/src/workflows/payment_sync.rs
+++ b/crates/router/src/workflows/payment_sync.rs
@@ -155,7 +155,7 @@ impl ProcessTrackerWorkflow<SessionState> for PaymentsSyncWorkflow {
.as_ref()
.is_none()
{
- let payment_intent_update = hyperswitch_domain_models::payments::payment_intent::PaymentIntentUpdate::PGStatusUpdate { status: api_models::enums::IntentStatus::Failed,updated_by: merchant_account.storage_scheme.to_string(), incremental_authorization_allowed: Some(false), feature_metadata: payment_data.payment_intent.feature_metadata.clone().map(hyperswitch_masking::Secret::new), };
+ let payment_intent_update = hyperswitch_domain_models::payments::payment_intent::PaymentIntentUpdate::PGStatusUpdate { status: api_models::enums::IntentStatus::Failed,updated_by: merchant_account.storage_scheme.to_string(), incremental_authorization_allowed: Some(false), feature_metadata: payment_data.payment_intent.feature_metadata.clone(), };
let payment_attempt_update =
hyperswitch_domain_models::payments::payment_attempt::PaymentAttemptUpdate::ErrorUpdate {
connector: None,
diff --git a/crates/router_derive/src/lib.rs b/crates/router_derive/src/lib.rs
index 5e422dcda5..e1833c41d8 100644
--- a/crates/router_derive/src/lib.rs
+++ b/crates/router_derive/src/lib.rs
@@ -765,7 +765,44 @@ pub fn derive_to_encryption_attr(input: proc_macro::TokenStream) -> proc_macro::
.into()
}
-/// Derives validation functionality for structs with string-based fields that have
+/// Attribute macro that generates `apply_changeset` on the annotated struct.
+///
+/// Place `#[apply_changeset(target = TargetType)]` on an update struct.
+/// The macro re-emits the struct unchanged and generates:
+///
+/// ```ignore
+/// impl UpdateStruct {
+/// pub fn apply_changeset(self, mut target: TargetType) -> TargetType { ... }
+/// }
+/// ```
+///
+/// For every field:
+/// - `Option<T>` fields use a helper trait that writes `Some(v)` into the target
+/// field when the update value is `Some`, leaving it untouched on `None`.
+/// - Non-`Option` fields are directly assigned (`target.field = self.field`).
+///
+/// # Example
+///
+/// ```ignore
+/// use router_derive::apply_changeset;
+///
+/// #[apply_changeset(target = PaymentAttempt)]
+/// struct PaymentAttemptUpdateInternal {
+/// status: Option<AttemptStatus>,
+/// amount: Option<MinorUnit>,
+/// }
+/// ```
+#[proc_macro_attribute]
+pub fn apply_changeset(
+ args: proc_macro::TokenStream,
+ input: proc_macro::TokenStream,
+) -> proc_macro::TokenStream {
+ let args = proc_macro2::TokenStream::from(args);
+ let input = proc_macro2::TokenStream::from(input);
+ macros::apply_changeset_attribute(args, input)
+ .unwrap_or_else(|error| error.to_compile_error())
+ .into()
+}
/// schema attributes specifying constraints like minimum and maximum lengths.
///
/// This macro generates a `validate()` method that checks if string based fields
@@ -790,10 +827,10 @@ pub fn derive_to_encryption_attr(input: proc_macro::TokenStream) -> proc_macro::
/// pub struct PaymentRequest {
/// #[schema(min_length = 10, max_length = 255)]
/// pub description: String,
-///
+///
/// #[schema(example = "https://example.com/return", max_length = 255)]
/// pub return_url: Option<Url>,
-///
+///
/// // Field without constraints
/// pub amount: u64,
/// }
diff --git a/crates/router_derive/src/macros.rs b/crates/router_derive/src/macros.rs
index 42afb638cf..b03b868159 100644
--- a/crates/router_derive/src/macros.rs
+++ b/crates/router_derive/src/macros.rs
@@ -1,4 +1,5 @@
pub(crate) mod api_error;
+pub(crate) mod apply_changeset;
pub(crate) mod diesel;
pub(crate) mod generate_permissions;
pub(crate) mod generate_schema;
@@ -16,6 +17,7 @@ use syn::DeriveInput;
pub(crate) use self::{
api_error::api_error_derive_inner,
+ apply_changeset::apply_changeset_attribute,
diesel::{diesel_enum_derive_inner, diesel_enum_text_derive_inner},
generate_permissions::generate_permissions_inner,
generate_schema::polymorphic_macro_derive_inner,
diff --git a/crates/router_derive/src/macros/apply_changeset.rs b/crates/router_derive/src/macros/apply_changeset.rs
new file mode 100644
index 0000000000..2a53249e93
--- /dev/null
+++ b/crates/router_derive/src/macros/apply_changeset.rs
@@ -0,0 +1,106 @@
+use quote::quote;
+use syn::{parse::Parse, ItemStruct, Path, Token};
+
+/// Parsed contents of `#[apply_changeset(target = TargetType)]`
+struct ApplyChangesetAttr {
+ target: Path,
+}
+
+impl Parse for ApplyChangesetAttr {
+ fn parse(input: syn::parse::ParseStream<'_>) -> syn::Result<Self> {
+ let ident: syn::Ident = input.parse()?;
+ if ident != "target" {
+ return Err(syn::Error::new(ident.span(), "expected `target = Type`"));
+ }
+ input.parse::<Token![=]>()?;
+ let target: Path = input.parse()?;
+ Ok(Self { target })
+ }
+}
+
+pub(crate) fn apply_changeset_attribute(
+ args: proc_macro2::TokenStream,
+ input: proc_macro2::TokenStream,
+) -> syn::Result<proc_macro2::TokenStream> {
+ let apply_attr: ApplyChangesetAttr = syn::parse2(args)?;
+ let target_type = apply_attr.target;
+
+ // Parse the annotated struct
+ let mut item: ItemStruct = syn::parse2(input)?;
+ let struct_name = &item.ident;
+ let generics = &item.generics;
+ let (impl_generics, ty_generics, where_clause) = generics.split_for_impl();
+
+ // Strip the #[apply_changeset(...)] attribute so it isn't re-emitted
+ item.attrs
+ .retain(|attr| !attr.path().is_ident("apply_changeset"));
+
+ // Extract named fields
+ let fields = match &item.fields {
+ syn::Fields::Named(named) => named.named.iter().collect::<Vec<_>>(),
+ _ => {
+ return Err(syn::Error::new(
+ item.ident.span(),
+ "#[apply_changeset] only supports structs with named fields",
+ ))
+ }
+ };
+
+ let mut option_assignments = Vec::new();
+ let mut direct_assignments = Vec::new();
+
+ for field in &fields {
+ let Some(field_name) = field.ident.as_ref() else {
+ continue;
+ };
+ let ty = &field.ty;
+
+ if is_option_type(ty) {
+ option_assignments.push(field_name);
+ } else {
+ direct_assignments.push(field_name);
+ }
+ }
+
+ Ok(quote! {
+ #item
+
+ #[automatically_derived]
+ impl #impl_generics #struct_name #ty_generics #where_clause {
+ /// Applies the fields of this update struct to the given target,
+ /// returning the modified target.
+ ///
+ /// Fields of type `Option<T>` are only applied when `Some`, leaving
+ /// the original value unchanged when `None`.
+ pub fn apply_changeset(self, mut target: #target_type) -> #target_type {
+ fn __set<Target, Source: ::core::convert::Into<Target>>(
+ source: Source,
+ target: &mut Target,
+ ) {
+ *target = source.into();
+ }
+
+ #(
+ __set(self.#direct_assignments, &mut target.#direct_assignments);
+ )*
+ #(
+ ::common_utils::ApplyOptionField::apply(
+ self.#option_assignments, &mut target.#option_assignments
+ );
+ )*
+
+ target
+ }
+ }
+ })
+}
+
+/// Heuristic: does `ty` look like `Option<T>`?
+fn is_option_type(ty: &syn::Type) -> bool {
+ if let syn::Type::Path(type_path) = ty {
+ if let Some(segment) = type_path.path.segments.last() {
+ return segment.ident == "Option";
+ }
+ }
+ false
+}
diff --git a/crates/router_derive/tests/apply_changeset.rs b/crates/router_derive/tests/apply_changeset.rs
new file mode 100644
index 0000000000..57241c8d82
--- /dev/null
+++ b/crates/router_derive/tests/apply_changeset.rs
@@ -0,0 +1,393 @@
+use router_derive::apply_changeset;
+
+// A representative target struct with a mix of Option and non-Option fields.
+#[derive(Debug, Clone, PartialEq)]
+pub struct Target {
+ pub id: u64,
+ pub name: String,
+ pub description: Option<String>,
+ pub count: i32,
+ pub maybe_count: Option<i32>,
+}
+
+#[apply_changeset(target = Target)]
+pub struct TargetUpdate {
+ pub name: String,
+ pub description: Option<String>,
+ pub count: i32,
+ pub maybe_count: Option<i32>,
+}
+
+#[test]
+fn test_full_update() {
+ let target = Target {
+ id: 1,
+ name: "original".to_string(),
+ description: Some("original desc".to_string()),
+ count: 10,
+ maybe_count: Some(100),
+ };
+
+ let update = TargetUpdate {
+ name: "updated".to_string(),
+ description: Some("updated desc".to_string()),
+ count: 20,
+ maybe_count: Some(200),
+ };
+
+ let result = update.apply_changeset(target);
+
+ assert_eq!(result.id, 1);
+ assert_eq!(result.name, "updated");
+ assert_eq!(result.description, Some("updated desc".to_string()));
+ assert_eq!(result.count, 20);
+ assert_eq!(result.maybe_count, Some(200));
+}
+
+#[test]
+fn test_partial_update_with_none_options() {
+ let target = Target {
+ id: 1,
+ name: "original".to_string(),
+ description: Some("original desc".to_string()),
+ count: 10,
+ maybe_count: Some(100),
+ };
+
+ let update = TargetUpdate {
+ name: "updated".to_string(),
+ description: None,
+ count: 20,
+ maybe_count: None,
+ };
+
+ let result = update.apply_changeset(target.clone());
+
+ assert_eq!(result.id, 1);
+ assert_eq!(result.name, "updated");
+ // Option fields with None should leave the original value intact
+ assert_eq!(result.description, Some("original desc".to_string()));
+ assert_eq!(result.count, 20);
+ assert_eq!(result.maybe_count, Some(100));
+}
+
+#[test]
+fn test_all_none_options() {
+ let target = Target {
+ id: 1,
+ name: "original".to_string(),
+ description: Some("original desc".to_string()),
+ count: 10,
+ maybe_count: Some(100),
+ };
+
+ let update = TargetUpdate {
+ name: "updated".to_string(),
+ description: None,
+ count: 15,
+ maybe_count: None,
+ };
+
+ let result = update.apply_changeset(target.clone());
+
+ assert_eq!(result.id, 1);
+ assert_eq!(result.name, "updated");
+ assert_eq!(result.description, Some("original desc".to_string()));
+ assert_eq!(result.count, 15);
+ assert_eq!(result.maybe_count, Some(100));
+}
+
+#[test]
+fn test_overwrite_some_with_none() {
+ let target = Target {
+ id: 1,
+ name: "original".to_string(),
+ description: Some("original desc".to_string()),
+ count: 10,
+ maybe_count: Some(100),
+ };
+
+ // Even though description is None, the macro treats Option specially:
+ // None means "don't change", not "set to None".
+ let update = TargetUpdate {
+ name: "updated".to_string(),
+ description: None,
+ count: 20,
+ maybe_count: None,
+ };
+
+ let result = update.apply_changeset(target.clone());
+
+ // Original values should be preserved for Option fields when update is None
+ assert_eq!(result.description, Some("original desc".to_string()));
+ assert_eq!(result.maybe_count, Some(100));
+}
+
+#[test]
+fn test_non_option_fields_always_overwritten() {
+ let target = Target {
+ id: 1,
+ name: "original".to_string(),
+ description: None,
+ count: 10,
+ maybe_count: None,
+ };
+
+ let update = TargetUpdate {
+ name: "new name".to_string(),
+ description: None,
+ count: 99,
+ maybe_count: None,
+ };
+
+ let result = update.apply_changeset(target);
+
+ // Non-option fields are always overwritten regardless of value
+ assert_eq!(result.name, "new name");
+ assert_eq!(result.count, 99);
+}
+
+// Struct with only optional fields
+#[derive(Debug, Clone, PartialEq)]
+pub struct AllOptionalTarget {
+ pub a: Option<String>,
+ pub b: Option<i32>,
+}
+
+#[apply_changeset(target = AllOptionalTarget)]
+pub struct AllOptionalUpdate {
+ pub a: Option<String>,
+ pub b: Option<i32>,
+}
+
+#[test]
+fn test_all_optional_struct_some_updates() {
+ let target = AllOptionalTarget {
+ a: Some("a".to_string()),
+ b: Some(1),
+ };
+
+ let update = AllOptionalUpdate {
+ a: Some("new a".to_string()),
+ b: Some(2),
+ };
+
+ let result = update.apply_changeset(target);
+
+ assert_eq!(result.a, Some("new a".to_string()));
+ assert_eq!(result.b, Some(2));
+}
+
+#[test]
+fn test_all_optional_struct_none_updates() {
+ let target = AllOptionalTarget {
+ a: Some("a".to_string()),
+ b: Some(1),
+ };
+
+ let update = AllOptionalUpdate { a: None, b: None };
+
+ let result = update.apply_changeset(target.clone());
+
+ // None means don't change for Option fields
+ assert_eq!(result.a, Some("a".to_string()));
+ assert_eq!(result.b, Some(1));
+}
+
+// Target has non-Option field, update struct has Option field for it.
+#[derive(Debug, Clone, PartialEq)]
+pub struct MismatchedTarget {
+ pub id: u64,
+ pub name: String,
+ pub count: i32,
+}
+
+#[apply_changeset(target = MismatchedTarget)]
+pub struct MismatchedUpdate {
+ pub id: u64,
+ pub name: Option<String>,
+ pub count: Option<i32>,
+}
+
+#[test]
+fn test_optional_update_for_non_optional_target_some() {
+ let target = MismatchedTarget {
+ id: 1,
+ name: "original".to_string(),
+ count: 10,
+ };
+
+ let update = MismatchedUpdate {
+ id: 2,
+ name: Some("updated".to_string()),
+ count: Some(20),
+ };
+
+ let result = update.apply_changeset(target);
+
+ assert_eq!(result.id, 2);
+ assert_eq!(result.name, "updated");
+ assert_eq!(result.count, 20);
+}
+
+#[test]
+fn test_optional_update_for_non_optional_target_none() {
+ let target = MismatchedTarget {
+ id: 1,
+ name: "original".to_string(),
+ count: 10,
+ };
+
+ let update = MismatchedUpdate {
+ id: 2,
+ name: None,
+ count: None,
+ };
+
+ let result = update.apply_changeset(target);
+
+ assert_eq!(result.id, 2);
+ // Because the update field is Option<T>, the macro's special handling applies:
+ // None means "don't change", so the target keeps its original value.
+ assert_eq!(result.name, "original");
+ assert_eq!(result.count, 10);
+}
+
+// Edge case: target initially has None, update provides Some
+#[test]
+fn test_none_to_some_transition() {
+ let target = AllOptionalTarget { a: None, b: None };
+
+ let update = AllOptionalUpdate {
+ a: Some("now present".to_string()),
+ b: Some(42),
+ };
+
+ let result = update.apply_changeset(target);
+
+ assert_eq!(result.a, Some("now present".to_string()));
+ assert_eq!(result.b, Some(42));
+}
+
+// Target field is Option<T> but update struct uses Option<Option<T>> to distinguish:
+// None → don't change
+// Some(None) → explicitly set target to None
+// Some(Some(v))→ set target to Some(v)
+#[derive(Debug, Clone, PartialEq)]
+pub struct NestedOptionalTarget {
+ pub id: u64,
+ pub nickname: Option<String>,
+}
+
+#[apply_changeset(target = NestedOptionalTarget)]
+pub struct NestedOptionalUpdate {
+ pub id: u64,
+ pub nickname: Option<Option<String>>,
+}
+
+#[test]
+fn test_nested_option_none_means_no_change() {
+ let target = NestedOptionalTarget {
+ id: 1,
+ nickname: Some("alice".to_string()),
+ };
+
+ let update = NestedOptionalUpdate {
+ id: 2,
+ nickname: None,
+ };
+
+ let result = update.apply_changeset(target);
+
+ assert_eq!(result.id, 2);
+ // None means "don't change" for Option<Option<T>>
+ assert_eq!(result.nickname, Some("alice".to_string()));
+}
+
+#[test]
+fn test_nested_option_some_none_sets_none() {
+ let target = NestedOptionalTarget {
+ id: 1,
+ nickname: Some("alice".to_string()),
+ };
+
+ let update = NestedOptionalUpdate {
+ id: 2,
+ nickname: Some(None),
+ };
+
+ let result = update.apply_changeset(target);
+
+ assert_eq!(result.id, 2);
+ // Some(None) explicitly sets the target field to None
+ assert_eq!(result.nickname, None);
+}
+
+#[test]
+fn test_nested_option_some_some_sets_value() {
+ let target = NestedOptionalTarget {
+ id: 1,
+ nickname: Some("alice".to_string()),
+ };
+
+ let update = NestedOptionalUpdate {
+ id: 2,
+ nickname: Some(Some("bob".to_string())),
+ };
+
+ let result = update.apply_changeset(target);
+
+ assert_eq!(result.id, 2);
+ // Some(Some(v)) sets the target to Some(v)
+ assert_eq!(result.nickname, Some("bob".to_string()));
+}
+
+// Target has Option<T> fields, update struct has non-Option T fields.
+// The macro should automatically wrap the assigned value in Some(...).
+#[derive(Debug, Clone, PartialEq)]
+pub struct OptionTargetWithNonOptionalUpdate {
+ pub name: Option<String>,
+ pub count: Option<i32>,
+}
+
+#[apply_changeset(target = OptionTargetWithNonOptionalUpdate)]
+pub struct NonOptionalToOptionUpdate {
+ pub name: String,
+ pub count: i32,
+}
+
+#[test]
+fn test_non_optional_update_for_optional_target_none_start() {
+ let target = OptionTargetWithNonOptionalUpdate {
+ name: None,
+ count: None,
+ };
+
+ let update = NonOptionalToOptionUpdate {
+ name: "new name".to_string(),
+ count: 42,
+ };
+
+ let result = update.apply_changeset(target);
+
+ assert_eq!(result.name, Some("new name".to_string()));
+ assert_eq!(result.count, Some(42));
+}
+
+#[test]
+fn test_non_optional_update_for_optional_target_some_start() {
+ let target = OptionTargetWithNonOptionalUpdate {
+ name: Some("original".to_string()),
+ count: Some(10),
+ };
+
+ let update = NonOptionalToOptionUpdate {
+ name: "updated".to_string(),
+ count: 20,
+ };
+
+ let result = update.apply_changeset(target);
+
+ assert_eq!(result.name, Some("updated".to_string()));
+ assert_eq!(result.count, Some(20));
+}