Skip to content

Commit 9eb342e

Browse files
committed
chore: update domain models
1 parent 6f98a4a commit 9eb342e

File tree

4 files changed

+234
-221
lines changed

4 files changed

+234
-221
lines changed

crates/hyperswitch_domain_models/src/customer.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ impl behaviour::Conversion for Customer {
246246
default_billing_address: self.default_billing_address,
247247
default_shipping_address: self.default_shipping_address,
248248
version: self.version,
249-
status: self.status,
249+
status: Some(self.status),
250250
})
251251
}
252252

@@ -259,6 +259,8 @@ impl behaviour::Conversion for Customer {
259259
where
260260
Self: Sized,
261261
{
262+
use common_utils::ext_traits::OptionExt;
263+
262264
let decrypted = types::crypto_operation(
263265
state,
264266
common_utils::type_name!(Self::DstType),
@@ -307,7 +309,7 @@ impl behaviour::Conversion for Customer {
307309
default_billing_address: item.default_billing_address,
308310
default_shipping_address: item.default_shipping_address,
309311
version: item.version,
310-
status: item.status,
312+
status: item.status.get_required_value("status")?,
311313
})
312314
}
313315

crates/hyperswitch_domain_models/src/merchant_connector_account.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,7 @@ impl behaviour::Conversion for MerchantConnectorAccount {
607607
created_at: self.created_at,
608608
modified_at: self.modified_at,
609609
connector_webhook_details: self.connector_webhook_details,
610-
profile_id: self.profile_id,
610+
profile_id: Some(self.profile_id),
611611
applepay_verified_domains: self.applepay_verified_domains,
612612
pm_auth_config: self.pm_auth_config,
613613
status: self.status,
@@ -625,6 +625,8 @@ impl behaviour::Conversion for MerchantConnectorAccount {
625625
key: &Secret<Vec<u8>>,
626626
_key_manager_identifier: Identifier,
627627
) -> CustomResult<Self, ValidationError> {
628+
use common_utils::ext_traits::OptionExt;
629+
628630
let identifier = Identifier::Merchant(other.merchant_id.clone());
629631

630632
let decrypted_data = crypto_operation(
@@ -666,7 +668,7 @@ impl behaviour::Conversion for MerchantConnectorAccount {
666668
created_at: other.created_at,
667669
modified_at: other.modified_at,
668670
connector_webhook_details: other.connector_webhook_details,
669-
profile_id: other.profile_id,
671+
profile_id: other.profile_id.get_required_value("prodile_id")?,
670672
applepay_verified_domains: other.applepay_verified_domains,
671673
pm_auth_config: other.pm_auth_config,
672674
status: other.status,

crates/hyperswitch_domain_models/src/payments/payment_attempt.rs

Lines changed: 102 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -2274,9 +2274,9 @@ impl behaviour::Conversion for PaymentAttempt {
22742274
status,
22752275
error_message: error.as_ref().map(|details| details.message.clone()),
22762276
payment_method_id,
2277-
payment_method_type_v2: payment_method_type,
2277+
payment_method_type_v2: Some(payment_method_type),
22782278
connector_payment_id,
2279-
authentication_type,
2279+
authentication_type: Some(authentication_type),
22802280
created_at,
22812281
modified_at,
22822282
last_synced,
@@ -2304,7 +2304,7 @@ impl behaviour::Conversion for PaymentAttempt {
23042304
unified_message: error
23052305
.as_ref()
23062306
.and_then(|details| details.unified_message.clone()),
2307-
net_amount,
2307+
net_amount: Some(net_amount),
23082308
external_three_ds_authentication_attempted,
23092309
authentication_connector,
23102310
authentication_id,
@@ -2356,11 +2356,10 @@ impl behaviour::Conversion for PaymentAttempt {
23562356
where
23572357
Self: Sized,
23582358
{
2359-
async {
2360-
let connector_payment_id = storage_model
2361-
.get_optional_connector_transaction_id()
2362-
.cloned();
2363-
2359+
let connector_payment_id = storage_model
2360+
.get_optional_connector_transaction_id()
2361+
.cloned();
2362+
let decrypted_data = async {
23642363
let decrypted_data = crypto_operation(
23652364
state,
23662365
common_utils::type_name!(Self::DstType),
@@ -2376,102 +2375,106 @@ impl behaviour::Conversion for PaymentAttempt {
23762375
.await
23772376
.and_then(|val| val.try_into_batchoperation())?;
23782377

2379-
let decrypted_data = EncryptedPaymentAttempt::from_encryptable(decrypted_data)
2378+
EncryptedPaymentAttempt::from_encryptable(decrypted_data)
23802379
.change_context(common_utils::errors::CryptoError::DecodingFailed)
2381-
.attach_printable("Invalid batch operation data")?;
2382-
2383-
let payment_method_billing_address = decrypted_data
2384-
.payment_method_billing_address
2385-
.map(|billing| {
2386-
billing.deserialize_inner_value(|value| value.parse_value("Address"))
2387-
})
2388-
.transpose()
2389-
.change_context(common_utils::errors::CryptoError::DecodingFailed)
2390-
.attach_printable("Error while deserializing Address")?;
2391-
2392-
let amount_details = AttemptAmountDetails {
2393-
net_amount: storage_model.net_amount,
2394-
tax_on_surcharge: storage_model.tax_on_surcharge,
2395-
surcharge_amount: storage_model.surcharge_amount,
2396-
order_tax_amount: storage_model.order_tax_amount,
2397-
shipping_cost: storage_model.shipping_cost,
2398-
amount_capturable: storage_model.amount_capturable,
2399-
amount_to_capture: storage_model.amount_to_capture,
2400-
};
2401-
2402-
let error = storage_model
2403-
.error_code
2404-
.zip(storage_model.error_message)
2405-
.map(|(error_code, error_message)| ErrorDetails {
2406-
code: error_code,
2407-
message: error_message,
2408-
reason: storage_model.error_reason,
2409-
unified_code: storage_model.unified_code,
2410-
unified_message: storage_model.unified_message,
2411-
network_advice_code: storage_model.network_advice_code,
2412-
network_decline_code: storage_model.network_decline_code,
2413-
network_error_message: storage_model.network_error_message,
2414-
});
2415-
2416-
Ok::<Self, error_stack::Report<common_utils::errors::CryptoError>>(Self {
2417-
payment_id: storage_model.payment_id,
2418-
merchant_id: storage_model.merchant_id.clone(),
2419-
id: storage_model.id,
2420-
status: storage_model.status,
2421-
amount_details,
2422-
error,
2423-
payment_method_id: storage_model.payment_method_id,
2424-
payment_method_type: storage_model.payment_method_type_v2,
2425-
connector_payment_id,
2426-
authentication_type: storage_model.authentication_type,
2427-
created_at: storage_model.created_at,
2428-
modified_at: storage_model.modified_at,
2429-
last_synced: storage_model.last_synced,
2430-
cancellation_reason: storage_model.cancellation_reason,
2431-
browser_info: storage_model.browser_info,
2432-
payment_token: storage_model.payment_token,
2433-
connector_metadata: storage_model.connector_metadata,
2434-
payment_experience: storage_model.payment_experience,
2435-
payment_method_data: storage_model.payment_method_data,
2436-
routing_result: storage_model.routing_result,
2437-
preprocessing_step_id: storage_model.preprocessing_step_id,
2438-
multiple_capture_count: storage_model.multiple_capture_count,
2439-
connector_response_reference_id: storage_model.connector_response_reference_id,
2440-
updated_by: storage_model.updated_by,
2441-
redirection_data: storage_model.redirection_data.map(From::from),
2442-
encoded_data: storage_model.encoded_data,
2443-
merchant_connector_id: storage_model.merchant_connector_id,
2444-
external_three_ds_authentication_attempted: storage_model
2445-
.external_three_ds_authentication_attempted,
2446-
authentication_connector: storage_model.authentication_connector,
2447-
authentication_id: storage_model.authentication_id,
2448-
fingerprint_id: storage_model.fingerprint_id,
2449-
charges: storage_model.charges,
2450-
client_source: storage_model.client_source,
2451-
client_version: storage_model.client_version,
2452-
customer_acceptance: storage_model.customer_acceptance,
2453-
profile_id: storage_model.profile_id,
2454-
organization_id: storage_model.organization_id,
2455-
payment_method_subtype: storage_model.payment_method_subtype,
2456-
authentication_applied: storage_model.authentication_applied,
2457-
external_reference_id: storage_model.external_reference_id,
2458-
connector: storage_model.connector,
2459-
payment_method_billing_address,
2460-
connector_token_details: storage_model.connector_token_details,
2461-
card_discovery: storage_model.card_discovery,
2462-
feature_metadata: storage_model.feature_metadata.map(From::from),
2463-
processor_merchant_id: storage_model
2464-
.processor_merchant_id
2465-
.unwrap_or(storage_model.merchant_id),
2466-
created_by: storage_model
2467-
.created_by
2468-
.and_then(|created_by| created_by.parse::<CreatedBy>().ok()),
2469-
connector_request_reference_id: storage_model.connector_request_reference_id,
2470-
})
2380+
.attach_printable("Invalid batch operation data")
24712381
}
24722382
.await
24732383
.change_context(ValidationError::InvalidValue {
24742384
message: "Failed while decrypting payment attempt".to_string(),
2385+
})?;
2386+
2387+
let payment_method_billing_address = decrypted_data
2388+
.payment_method_billing_address
2389+
.map(|billing| billing.deserialize_inner_value(|value| value.parse_value("Address")))
2390+
.transpose()
2391+
.change_context(ValidationError::InvalidValue {
2392+
message: "Failed to deserialize payment_method_billing_address".to_string(),
2393+
})
2394+
.attach_printable("Error while deserializing Address")?;
2395+
2396+
let amount_details = AttemptAmountDetails {
2397+
net_amount: storage_model.net_amount.get_required_value("net_amount")?,
2398+
tax_on_surcharge: storage_model.tax_on_surcharge,
2399+
surcharge_amount: storage_model.surcharge_amount,
2400+
order_tax_amount: storage_model.order_tax_amount,
2401+
shipping_cost: storage_model.shipping_cost,
2402+
amount_capturable: storage_model.amount_capturable,
2403+
amount_to_capture: storage_model.amount_to_capture,
2404+
};
2405+
2406+
let error = storage_model
2407+
.error_code
2408+
.zip(storage_model.error_message)
2409+
.map(|(error_code, error_message)| ErrorDetails {
2410+
code: error_code,
2411+
message: error_message,
2412+
reason: storage_model.error_reason,
2413+
unified_code: storage_model.unified_code,
2414+
unified_message: storage_model.unified_message,
2415+
network_advice_code: storage_model.network_advice_code,
2416+
network_decline_code: storage_model.network_decline_code,
2417+
network_error_message: storage_model.network_error_message,
2418+
});
2419+
2420+
Ok(Self {
2421+
payment_id: storage_model.payment_id,
2422+
merchant_id: storage_model.merchant_id.clone(),
2423+
id: storage_model.id,
2424+
status: storage_model.status,
2425+
amount_details,
2426+
error,
2427+
payment_method_id: storage_model.payment_method_id,
2428+
payment_method_type: storage_model
2429+
.payment_method_type_v2
2430+
.get_required_value("payment_method_type")?,
2431+
connector_payment_id,
2432+
authentication_type: storage_model
2433+
.authentication_type
2434+
.get_required_value("authentication_type")?,
2435+
created_at: storage_model.created_at,
2436+
modified_at: storage_model.modified_at,
2437+
last_synced: storage_model.last_synced,
2438+
cancellation_reason: storage_model.cancellation_reason,
2439+
browser_info: storage_model.browser_info,
2440+
payment_token: storage_model.payment_token,
2441+
connector_metadata: storage_model.connector_metadata,
2442+
payment_experience: storage_model.payment_experience,
2443+
payment_method_data: storage_model.payment_method_data,
2444+
routing_result: storage_model.routing_result,
2445+
preprocessing_step_id: storage_model.preprocessing_step_id,
2446+
multiple_capture_count: storage_model.multiple_capture_count,
2447+
connector_response_reference_id: storage_model.connector_response_reference_id,
2448+
updated_by: storage_model.updated_by,
2449+
redirection_data: storage_model.redirection_data.map(From::from),
2450+
encoded_data: storage_model.encoded_data,
2451+
merchant_connector_id: storage_model.merchant_connector_id,
2452+
external_three_ds_authentication_attempted: storage_model
2453+
.external_three_ds_authentication_attempted,
2454+
authentication_connector: storage_model.authentication_connector,
2455+
authentication_id: storage_model.authentication_id,
2456+
fingerprint_id: storage_model.fingerprint_id,
2457+
charges: storage_model.charges,
2458+
client_source: storage_model.client_source,
2459+
client_version: storage_model.client_version,
2460+
customer_acceptance: storage_model.customer_acceptance,
2461+
profile_id: storage_model.profile_id,
2462+
organization_id: storage_model.organization_id,
2463+
payment_method_subtype: storage_model.payment_method_subtype,
2464+
authentication_applied: storage_model.authentication_applied,
2465+
external_reference_id: storage_model.external_reference_id,
2466+
connector: storage_model.connector,
2467+
payment_method_billing_address,
2468+
connector_token_details: storage_model.connector_token_details,
2469+
card_discovery: storage_model.card_discovery,
2470+
feature_metadata: storage_model.feature_metadata.map(From::from),
2471+
processor_merchant_id: storage_model
2472+
.processor_merchant_id
2473+
.unwrap_or(storage_model.merchant_id),
2474+
created_by: storage_model
2475+
.created_by
2476+
.and_then(|created_by| created_by.parse::<CreatedBy>().ok()),
2477+
connector_request_reference_id: storage_model.connector_request_reference_id,
24752478
})
24762479
}
24772480

0 commit comments

Comments
 (0)