refactor(router): added a new type minor unit to amount (#4629)

Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
Co-authored-by: Hrithikesh <61539176+hrithikesh026@users.noreply.github.com>
This commit is contained in:
Sahkal Poddar
2024-05-21 15:40:05 +05:30
committed by GitHub
parent 2cd360e6a9
commit 443b7e6ea2
61 changed files with 679 additions and 436 deletions

View File

@ -1,5 +1,5 @@
use api_models::enums::{AuthenticationType, Connector, PaymentMethod, PaymentMethodType};
use common_utils::{errors::CustomResult, fallback_reverse_lookup_not_found};
use common_utils::{errors::CustomResult, fallback_reverse_lookup_not_found, types::MinorUnit};
use diesel_models::{
enums::{
MandateAmountData as DieselMandateAmountData, MandateDataType as DieselMandateType,
@ -1073,7 +1073,7 @@ impl DataModelExt for MandateAmountData {
fn to_storage_model(self) -> Self::StorageModel {
DieselMandateAmountData {
amount: self.amount,
amount: self.amount.get_amount_as_i64(),
currency: self.currency,
start_date: self.start_date,
end_date: self.end_date,
@ -1083,7 +1083,7 @@ impl DataModelExt for MandateAmountData {
fn from_storage_model(storage_model: Self::StorageModel) -> Self {
Self {
amount: storage_model.amount,
amount: MinorUnit::new(storage_model.amount),
currency: storage_model.currency,
start_date: storage_model.start_date,
end_date: storage_model.end_date,
@ -1141,15 +1141,19 @@ impl DataModelExt for PaymentAttempt {
merchant_id: self.merchant_id,
attempt_id: self.attempt_id,
status: self.status,
amount: self.amount,
net_amount: Some(self.net_amount),
amount: self.amount.get_amount_as_i64(),
net_amount: Some(self.net_amount.get_amount_as_i64()),
currency: self.currency,
save_to_locker: self.save_to_locker,
connector: self.connector,
error_message: self.error_message,
offer_amount: self.offer_amount,
surcharge_amount: self.surcharge_amount,
tax_amount: self.tax_amount,
offer_amount: self
.offer_amount
.map(|offer_amt| offer_amt.get_amount_as_i64()),
surcharge_amount: self
.surcharge_amount
.map(|surcharge_amt| surcharge_amt.get_amount_as_i64()),
tax_amount: self.tax_amount.map(|tax_amt| tax_amt.get_amount_as_i64()),
payment_method_id: self.payment_method_id,
payment_method: self.payment_method,
connector_transaction_id: self.connector_transaction_id,
@ -1161,7 +1165,9 @@ impl DataModelExt for PaymentAttempt {
modified_at: self.modified_at,
last_synced: self.last_synced,
cancellation_reason: self.cancellation_reason,
amount_to_capture: self.amount_to_capture,
amount_to_capture: self
.amount_to_capture
.map(|capture_amt| capture_amt.get_amount_as_i64()),
mandate_id: self.mandate_id,
browser_info: self.browser_info,
error_code: self.error_code,
@ -1177,7 +1183,7 @@ impl DataModelExt for PaymentAttempt {
error_reason: self.error_reason,
multiple_capture_count: self.multiple_capture_count,
connector_response_reference_id: self.connector_response_reference_id,
amount_capturable: self.amount_capturable,
amount_capturable: self.amount_capturable.get_amount_as_i64(),
updated_by: self.updated_by,
authentication_data: self.authentication_data,
encoded_data: self.encoded_data,
@ -1198,20 +1204,20 @@ impl DataModelExt for PaymentAttempt {
fn from_storage_model(storage_model: Self::StorageModel) -> Self {
Self {
net_amount: storage_model.get_or_calculate_net_amount(),
net_amount: MinorUnit::new(storage_model.get_or_calculate_net_amount()),
id: storage_model.id,
payment_id: storage_model.payment_id,
merchant_id: storage_model.merchant_id,
attempt_id: storage_model.attempt_id,
status: storage_model.status,
amount: storage_model.amount,
amount: MinorUnit::new(storage_model.amount),
currency: storage_model.currency,
save_to_locker: storage_model.save_to_locker,
connector: storage_model.connector,
error_message: storage_model.error_message,
offer_amount: storage_model.offer_amount,
surcharge_amount: storage_model.surcharge_amount,
tax_amount: storage_model.tax_amount,
offer_amount: storage_model.offer_amount.map(MinorUnit::new),
surcharge_amount: storage_model.surcharge_amount.map(MinorUnit::new),
tax_amount: storage_model.tax_amount.map(MinorUnit::new),
payment_method_id: storage_model.payment_method_id,
payment_method: storage_model.payment_method,
connector_transaction_id: storage_model.connector_transaction_id,
@ -1223,7 +1229,7 @@ impl DataModelExt for PaymentAttempt {
modified_at: storage_model.modified_at,
last_synced: storage_model.last_synced,
cancellation_reason: storage_model.cancellation_reason,
amount_to_capture: storage_model.amount_to_capture,
amount_to_capture: storage_model.amount_to_capture.map(MinorUnit::new),
mandate_id: storage_model.mandate_id,
browser_info: storage_model.browser_info,
error_code: storage_model.error_code,
@ -1241,7 +1247,7 @@ impl DataModelExt for PaymentAttempt {
error_reason: storage_model.error_reason,
multiple_capture_count: storage_model.multiple_capture_count,
connector_response_reference_id: storage_model.connector_response_reference_id,
amount_capturable: storage_model.amount_capturable,
amount_capturable: MinorUnit::new(storage_model.amount_capturable),
updated_by: storage_model.updated_by,
authentication_data: storage_model.authentication_data,
encoded_data: storage_model.encoded_data,
@ -1268,19 +1274,23 @@ impl DataModelExt for PaymentAttemptNew {
fn to_storage_model(self) -> Self::StorageModel {
DieselPaymentAttemptNew {
net_amount: Some(self.net_amount),
net_amount: Some(self.net_amount.get_amount_as_i64()),
payment_id: self.payment_id,
merchant_id: self.merchant_id,
attempt_id: self.attempt_id,
status: self.status,
amount: self.amount,
amount: self.amount.get_amount_as_i64(),
currency: self.currency,
save_to_locker: self.save_to_locker,
connector: self.connector,
error_message: self.error_message,
offer_amount: self.offer_amount,
surcharge_amount: self.surcharge_amount,
tax_amount: self.tax_amount,
offer_amount: self
.offer_amount
.map(|offer_amt| offer_amt.get_amount_as_i64()),
surcharge_amount: self
.surcharge_amount
.map(|surcharge_amt| surcharge_amt.get_amount_as_i64()),
tax_amount: self.tax_amount.map(|tax_amt| tax_amt.get_amount_as_i64()),
payment_method_id: self.payment_method_id,
payment_method: self.payment_method,
capture_method: self.capture_method,
@ -1291,7 +1301,9 @@ impl DataModelExt for PaymentAttemptNew {
modified_at: self.modified_at,
last_synced: self.last_synced,
cancellation_reason: self.cancellation_reason,
amount_to_capture: self.amount_to_capture,
amount_to_capture: self
.amount_to_capture
.map(|capture_amt| capture_amt.get_amount_as_i64()),
mandate_id: self.mandate_id,
browser_info: self.browser_info,
payment_token: self.payment_token,
@ -1307,7 +1319,7 @@ impl DataModelExt for PaymentAttemptNew {
error_reason: self.error_reason,
connector_response_reference_id: self.connector_response_reference_id,
multiple_capture_count: self.multiple_capture_count,
amount_capturable: self.amount_capturable,
amount_capturable: self.amount_capturable.get_amount_as_i64(),
updated_by: self.updated_by,
authentication_data: self.authentication_data,
encoded_data: self.encoded_data,
@ -1328,19 +1340,19 @@ impl DataModelExt for PaymentAttemptNew {
fn from_storage_model(storage_model: Self::StorageModel) -> Self {
Self {
net_amount: storage_model.get_or_calculate_net_amount(),
net_amount: MinorUnit::new(storage_model.get_or_calculate_net_amount()),
payment_id: storage_model.payment_id,
merchant_id: storage_model.merchant_id,
attempt_id: storage_model.attempt_id,
status: storage_model.status,
amount: storage_model.amount,
amount: MinorUnit::new(storage_model.amount),
currency: storage_model.currency,
save_to_locker: storage_model.save_to_locker,
connector: storage_model.connector,
error_message: storage_model.error_message,
offer_amount: storage_model.offer_amount,
surcharge_amount: storage_model.surcharge_amount,
tax_amount: storage_model.tax_amount,
offer_amount: storage_model.offer_amount.map(MinorUnit::new),
surcharge_amount: storage_model.surcharge_amount.map(MinorUnit::new),
tax_amount: storage_model.tax_amount.map(MinorUnit::new),
payment_method_id: storage_model.payment_method_id,
payment_method: storage_model.payment_method,
capture_method: storage_model.capture_method,
@ -1351,7 +1363,7 @@ impl DataModelExt for PaymentAttemptNew {
modified_at: storage_model.modified_at,
last_synced: storage_model.last_synced,
cancellation_reason: storage_model.cancellation_reason,
amount_to_capture: storage_model.amount_to_capture,
amount_to_capture: storage_model.amount_to_capture.map(MinorUnit::new),
mandate_id: storage_model.mandate_id,
browser_info: storage_model.browser_info,
payment_token: storage_model.payment_token,
@ -1369,7 +1381,7 @@ impl DataModelExt for PaymentAttemptNew {
error_reason: storage_model.error_reason,
connector_response_reference_id: storage_model.connector_response_reference_id,
multiple_capture_count: storage_model.multiple_capture_count,
amount_capturable: storage_model.amount_capturable,
amount_capturable: MinorUnit::new(storage_model.amount_capturable),
updated_by: storage_model.updated_by,
authentication_data: storage_model.authentication_data,
encoded_data: storage_model.encoded_data,
@ -1415,7 +1427,7 @@ impl DataModelExt for PaymentAttemptUpdate {
payment_method_billing_address_id,
updated_by,
} => DieselPaymentAttemptUpdate::Update {
amount,
amount: amount.get_amount_as_i64(),
currency,
status,
authentication_type,
@ -1425,10 +1437,12 @@ impl DataModelExt for PaymentAttemptUpdate {
payment_method_type,
payment_experience,
business_sub_label,
amount_to_capture,
amount_to_capture: amount_to_capture
.map(|capture_amt| capture_amt.get_amount_as_i64()),
capture_method,
surcharge_amount,
tax_amount,
surcharge_amount: surcharge_amount
.map(|surcharge_amt| surcharge_amt.get_amount_as_i64()),
tax_amount: tax_amount.map(|tax_amt| tax_amt.get_amount_as_i64()),
fingerprint_id,
payment_method_billing_address_id,
updated_by,
@ -1446,9 +1460,11 @@ impl DataModelExt for PaymentAttemptUpdate {
payment_token,
connector,
straight_through_algorithm,
amount_capturable,
surcharge_amount,
tax_amount,
amount_capturable: amount_capturable
.map(|amount_capturable| amount_capturable.get_amount_as_i64()),
surcharge_amount: surcharge_amount
.map(|surcharge_amt| surcharge_amt.get_amount_as_i64()),
tax_amount: tax_amount.map(|tax_amt| tax_amt.get_amount_as_i64()),
updated_by,
merchant_connector_id,
},
@ -1508,7 +1524,7 @@ impl DataModelExt for PaymentAttemptUpdate {
client_source,
client_version,
} => DieselPaymentAttemptUpdate::ConfirmUpdate {
amount,
amount: amount.get_amount_as_i64(),
currency,
status,
authentication_type,
@ -1524,9 +1540,11 @@ impl DataModelExt for PaymentAttemptUpdate {
straight_through_algorithm,
error_code,
error_message,
amount_capturable,
surcharge_amount,
tax_amount,
amount_capturable: amount_capturable
.map(|capture_amt| capture_amt.get_amount_as_i64()),
surcharge_amount: surcharge_amount
.map(|surcharge_amt| surcharge_amt.get_amount_as_i64()),
tax_amount: tax_amount.map(|tax_amt| tax_amt.get_amount_as_i64()),
fingerprint_id,
updated_by,
merchant_connector_id: connector_id,
@ -1580,7 +1598,8 @@ impl DataModelExt for PaymentAttemptUpdate {
error_message,
error_reason,
connector_response_reference_id,
amount_capturable,
amount_capturable: amount_capturable
.map(|capture_amt| capture_amt.get_amount_as_i64()),
updated_by,
authentication_data,
encoded_data,
@ -1630,7 +1649,8 @@ impl DataModelExt for PaymentAttemptUpdate {
error_code,
error_message,
error_reason,
amount_capturable,
amount_capturable: amount_capturable
.map(|capture_amt| capture_amt.get_amount_as_i64()),
updated_by,
unified_code,
unified_message,
@ -1644,7 +1664,8 @@ impl DataModelExt for PaymentAttemptUpdate {
} => DieselPaymentAttemptUpdate::CaptureUpdate {
multiple_capture_count,
updated_by,
amount_to_capture,
amount_to_capture: amount_to_capture
.map(|capture_amt| capture_amt.get_amount_as_i64()),
},
Self::PreprocessingUpdate {
status,
@ -1680,7 +1701,7 @@ impl DataModelExt for PaymentAttemptUpdate {
updated_by,
} => DieselPaymentAttemptUpdate::AmountToCaptureUpdate {
status,
amount_capturable,
amount_capturable: amount_capturable.get_amount_as_i64(),
updated_by,
},
Self::ConnectorResponse {
@ -1700,8 +1721,8 @@ impl DataModelExt for PaymentAttemptUpdate {
amount,
amount_capturable,
} => DieselPaymentAttemptUpdate::IncrementalAuthorizationAmountUpdate {
amount,
amount_capturable,
amount: amount.get_amount_as_i64(),
amount_capturable: amount_capturable.get_amount_as_i64(),
},
Self::AuthenticationUpdate {
status,
@ -1740,7 +1761,7 @@ impl DataModelExt for PaymentAttemptUpdate {
updated_by,
payment_method_billing_address_id,
} => Self::Update {
amount,
amount: MinorUnit::new(amount),
currency,
status,
authentication_type,
@ -1750,10 +1771,10 @@ impl DataModelExt for PaymentAttemptUpdate {
payment_method_type,
payment_experience,
business_sub_label,
amount_to_capture,
amount_to_capture: amount_to_capture.map(MinorUnit::new),
capture_method,
surcharge_amount,
tax_amount,
surcharge_amount: surcharge_amount.map(MinorUnit::new),
tax_amount: tax_amount.map(MinorUnit::new),
fingerprint_id,
payment_method_billing_address_id,
updated_by,
@ -1771,9 +1792,9 @@ impl DataModelExt for PaymentAttemptUpdate {
payment_token,
connector,
straight_through_algorithm,
amount_capturable,
surcharge_amount,
tax_amount,
amount_capturable: amount_capturable.map(MinorUnit::new),
surcharge_amount: surcharge_amount.map(MinorUnit::new),
tax_amount: tax_amount.map(MinorUnit::new),
updated_by,
merchant_connector_id: connector_id,
},
@ -1815,7 +1836,7 @@ impl DataModelExt for PaymentAttemptUpdate {
client_source,
client_version,
} => Self::ConfirmUpdate {
amount,
amount: MinorUnit::new(amount),
currency,
status,
authentication_type,
@ -1831,9 +1852,9 @@ impl DataModelExt for PaymentAttemptUpdate {
straight_through_algorithm,
error_code,
error_message,
amount_capturable,
surcharge_amount,
tax_amount,
amount_capturable: amount_capturable.map(MinorUnit::new),
surcharge_amount: surcharge_amount.map(MinorUnit::new),
tax_amount: tax_amount.map(MinorUnit::new),
fingerprint_id,
updated_by,
merchant_connector_id: connector_id,
@ -1905,7 +1926,7 @@ impl DataModelExt for PaymentAttemptUpdate {
error_message,
error_reason,
connector_response_reference_id,
amount_capturable,
amount_capturable: amount_capturable.map(MinorUnit::new),
updated_by,
authentication_data,
encoded_data,
@ -1955,7 +1976,7 @@ impl DataModelExt for PaymentAttemptUpdate {
error_code,
error_message,
error_reason,
amount_capturable,
amount_capturable: amount_capturable.map(MinorUnit::new),
updated_by,
unified_code,
unified_message,
@ -1967,7 +1988,7 @@ impl DataModelExt for PaymentAttemptUpdate {
multiple_capture_count,
updated_by,
} => Self::CaptureUpdate {
amount_to_capture,
amount_to_capture: amount_to_capture.map(MinorUnit::new),
multiple_capture_count,
updated_by,
},
@ -2005,7 +2026,7 @@ impl DataModelExt for PaymentAttemptUpdate {
updated_by,
} => Self::AmountToCaptureUpdate {
status,
amount_capturable,
amount_capturable: MinorUnit::new(amount_capturable),
updated_by,
},
DieselPaymentAttemptUpdate::ConnectorResponse {
@ -2025,8 +2046,8 @@ impl DataModelExt for PaymentAttemptUpdate {
amount,
amount_capturable,
} => Self::IncrementalAuthorizationAmountUpdate {
amount,
amount_capturable,
amount: MinorUnit::new(amount),
amount_capturable: MinorUnit::new(amount_capturable),
},
DieselPaymentAttemptUpdate::AuthenticationUpdate {
status,