Skip to content

Commit

Permalink
fix: surcharge related status and rules fix (#2974)
Browse files Browse the repository at this point in the history
Co-authored-by: Bernard Eugine <[email protected]>
  • Loading branch information
hrithikesh026 and bernard-eugine authored Nov 24, 2023
1 parent d56d805 commit 3db7213
Show file tree
Hide file tree
Showing 15 changed files with 46 additions and 65 deletions.
3 changes: 3 additions & 0 deletions crates/api_models/src/payment_methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,9 @@ impl SurchargeDetailsResponse {
request_surcharge_details.surcharge_amount == self.surcharge_amount
&& request_surcharge_details.tax_amount.unwrap_or(0) == self.tax_on_surcharge_amount
}
pub fn get_total_surcharge_amount(&self) -> i64 {
self.surcharge_amount + self.tax_on_surcharge_amount
}
}

#[derive(Clone, Debug)]
Expand Down
3 changes: 3 additions & 0 deletions crates/api_models/src/payments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,9 @@ impl RequestSurchargeDetails {
final_amount: original_amount + surcharge_amount + tax_on_surcharge_amount,
}
}
pub fn get_total_surcharge_amount(&self) -> i64 {
self.surcharge_amount + self.tax_amount.unwrap_or(0)
}
}

#[derive(Default, Debug, Clone, Copy)]
Expand Down
6 changes: 2 additions & 4 deletions crates/data_models/src/payments/payment_attempt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,8 @@ pub enum PaymentAttemptUpdate {
error_message: Option<Option<String>>,
amount_capturable: Option<i64>,
updated_by: String,
surcharge_amount: Option<i64>,
tax_amount: Option<i64>,
merchant_connector_id: Option<String>,
},
RejectUpdate {
Expand Down Expand Up @@ -291,8 +293,6 @@ pub enum PaymentAttemptUpdate {
error_reason: Option<Option<String>>,
connector_response_reference_id: Option<String>,
amount_capturable: Option<i64>,
surcharge_amount: Option<i64>,
tax_amount: Option<i64>,
updated_by: String,
authentication_data: Option<serde_json::Value>,
encoded_data: Option<String>,
Expand Down Expand Up @@ -321,8 +321,6 @@ pub enum PaymentAttemptUpdate {
error_message: Option<Option<String>>,
error_reason: Option<Option<String>>,
amount_capturable: Option<i64>,
surcharge_amount: Option<i64>,
tax_amount: Option<i64>,
updated_by: String,
unified_code: Option<Option<String>>,
unified_message: Option<Option<String>>,
Expand Down
18 changes: 6 additions & 12 deletions crates/diesel_models/src/payment_attempt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,8 @@ pub enum PaymentAttemptUpdate {
error_code: Option<Option<String>>,
error_message: Option<Option<String>>,
amount_capturable: Option<i64>,
surcharge_amount: Option<i64>,
tax_amount: Option<i64>,
updated_by: String,
merchant_connector_id: Option<String>,
},
Expand Down Expand Up @@ -208,8 +210,6 @@ pub enum PaymentAttemptUpdate {
error_reason: Option<Option<String>>,
connector_response_reference_id: Option<String>,
amount_capturable: Option<i64>,
surcharge_amount: Option<i64>,
tax_amount: Option<i64>,
updated_by: String,
authentication_data: Option<serde_json::Value>,
encoded_data: Option<String>,
Expand Down Expand Up @@ -238,8 +238,6 @@ pub enum PaymentAttemptUpdate {
error_message: Option<Option<String>>,
error_reason: Option<Option<String>>,
amount_capturable: Option<i64>,
surcharge_amount: Option<i64>,
tax_amount: Option<i64>,
updated_by: String,
unified_code: Option<Option<String>>,
unified_message: Option<Option<String>>,
Expand Down Expand Up @@ -443,6 +441,8 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {
amount_capturable,
updated_by,
merchant_connector_id,
surcharge_amount,
tax_amount,
} => Self {
amount: Some(amount),
currency: Some(currency),
Expand All @@ -463,6 +463,8 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {
amount_capturable,
updated_by,
merchant_connector_id,
surcharge_amount,
tax_amount,
..Default::default()
},
PaymentAttemptUpdate::VoidUpdate {
Expand Down Expand Up @@ -501,8 +503,6 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {
error_reason,
connector_response_reference_id,
amount_capturable,
surcharge_amount,
tax_amount,
updated_by,
authentication_data,
encoded_data,
Expand All @@ -524,8 +524,6 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {
connector_response_reference_id,
amount_capturable,
updated_by,
surcharge_amount,
tax_amount,
authentication_data,
encoded_data,
unified_code,
Expand All @@ -539,8 +537,6 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {
error_message,
error_reason,
amount_capturable,
surcharge_amount,
tax_amount,
updated_by,
unified_code,
unified_message,
Expand All @@ -554,8 +550,6 @@ impl From<PaymentAttemptUpdate> for PaymentAttemptUpdateInternal {
error_reason,
amount_capturable,
updated_by,
surcharge_amount,
tax_amount,
unified_code,
unified_message,
connector_transaction_id,
Expand Down
4 changes: 4 additions & 0 deletions crates/euclid/src/backend/vir_interpreter/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ impl Context {
}
}

if let Some(card_network) = payment_method.card_network {
enum_values.insert(EuclidValue::CardNetwork(card_network));
}

if let Some(at) = payment.authentication_type {
enum_values.insert(EuclidValue::AuthenticationType(at));
}
Expand Down
3 changes: 2 additions & 1 deletion crates/router/src/connector/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ where
enums::AttemptStatus::Charged => {
let captured_amount =
types::Capturable::get_capture_amount(&self.request, payment_data);
if Some(payment_data.payment_attempt.get_total_amount()) == captured_amount {
let total_capturable_amount = payment_data.payment_attempt.get_total_amount();
if Some(total_capturable_amount) == captured_amount {
enums::AttemptStatus::Charged
} else if captured_amount.is_some() {
enums::AttemptStatus::PartialCharged
Expand Down
3 changes: 2 additions & 1 deletion crates/router/src/core/payments/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1693,7 +1693,8 @@ pub(crate) fn validate_status_with_capture_method(
field_name: "payment.status".to_string(),
current_flow: "captured".to_string(),
current_value: status.to_string(),
states: "requires_capture, partially_captured, processing".to_string()
states: "requires_capture, partially_captured_and_capturable, processing"
.to_string()
}))
},
)
Expand Down
11 changes: 11 additions & 0 deletions crates/router/src/core/payments/operations/payment_confirm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,15 @@ impl<F: Clone, Ctx: PaymentMethodRetrieve>
let m_error_message = error_message.clone();
let m_db = state.clone().store;

let surcharge_amount = payment_data
.surcharge_details
.as_ref()
.map(|surcharge_details| surcharge_details.surcharge_amount);
let tax_amount = payment_data
.surcharge_details
.as_ref()
.map(|surcharge_details| surcharge_details.tax_on_surcharge_amount);

let payment_attempt_fut = tokio::spawn(
async move {
m_db.update_payment_attempt_with_attempt_id(
Expand All @@ -716,6 +725,8 @@ impl<F: Clone, Ctx: PaymentMethodRetrieve>
amount_capturable: Some(authorized_amount),
updated_by: storage_scheme.to_string(),
merchant_connector_id,
surcharge_amount,
tax_amount,
},
storage_scheme,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -372,8 +372,6 @@ async fn payment_response_update_tracker<F: Clone, T: types::Capturable>(
} else {
None
},
surcharge_amount: router_data.request.get_surcharge_amount(),
tax_amount: router_data.request.get_tax_on_surcharge_amount(),
updated_by: storage_scheme.to_string(),
unified_code: option_gsm.clone().map(|gsm| gsm.unified_code),
unified_message: option_gsm.map(|gsm| gsm.unified_message),
Expand Down Expand Up @@ -497,8 +495,6 @@ async fn payment_response_update_tracker<F: Clone, T: types::Capturable>(
} else {
None
},
surcharge_amount: router_data.request.get_surcharge_amount(),
tax_amount: router_data.request.get_tax_on_surcharge_amount(),
updated_by: storage_scheme.to_string(),
authentication_data,
encoded_data,
Expand Down
4 changes: 0 additions & 4 deletions crates/router/src/core/payments/retry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -382,8 +382,6 @@ where
} else {
None
},
surcharge_amount: None,
tax_amount: None,
updated_by: storage_scheme.to_string(),
authentication_data,
encoded_data,
Expand All @@ -410,8 +408,6 @@ where
status: storage_enums::AttemptStatus::Failure,
error_reason: Some(error_response.reason.clone()),
amount_capturable: Some(0),
surcharge_amount: None,
tax_amount: None,
updated_by: storage_scheme.to_string(),
unified_code: option_gsm.clone().map(|gsm| gsm.unified_code),
unified_message: option_gsm.map(|gsm| gsm.unified_message),
Expand Down
18 changes: 1 addition & 17 deletions crates/router/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -551,12 +551,6 @@ pub trait Capturable {
{
None
}
fn get_surcharge_amount(&self) -> Option<i64> {
None
}
fn get_tax_on_surcharge_amount(&self) -> Option<i64> {
None
}
}

impl Capturable for PaymentsAuthorizeData {
Expand All @@ -570,16 +564,6 @@ impl Capturable for PaymentsAuthorizeData {
.map(|surcharge_details| surcharge_details.final_amount);
final_amount.or(Some(self.amount))
}
fn get_surcharge_amount(&self) -> Option<i64> {
self.surcharge_details
.as_ref()
.map(|surcharge_details| surcharge_details.surcharge_amount)
}
fn get_tax_on_surcharge_amount(&self) -> Option<i64> {
self.surcharge_details
.as_ref()
.map(|surcharge_details| surcharge_details.tax_on_surcharge_amount)
}
}

impl Capturable for PaymentsCaptureData {
Expand Down Expand Up @@ -620,7 +604,7 @@ impl Capturable for PaymentsSyncData {
payment_data
.payment_attempt
.amount_to_capture
.or(Some(payment_data.payment_attempt.get_total_amount()))
.or_else(|| Some(payment_data.payment_attempt.get_total_amount()))
}
}

Expand Down
2 changes: 0 additions & 2 deletions crates/router/src/workflows/payment_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,6 @@ impl ProcessTrackerWorkflow<AppState> for PaymentsSyncWorkflow {
consts::REQUEST_TIMEOUT_ERROR_MESSAGE_FROM_PSYNC.to_string(),
)),
amount_capturable: Some(0),
surcharge_amount: None,
tax_amount: None,
updated_by: merchant_account.storage_scheme.to_string(),
unified_code: None,
unified_message: None,
Expand Down
24 changes: 8 additions & 16 deletions crates/storage_impl/src/payments/payment_attempt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1215,6 +1215,8 @@ impl DataModelExt for PaymentAttemptUpdate {
error_code,
error_message,
amount_capturable,
surcharge_amount,
tax_amount,
updated_by,
merchant_connector_id: connector_id,
} => DieselPaymentAttemptUpdate::ConfirmUpdate {
Expand All @@ -1234,6 +1236,8 @@ impl DataModelExt for PaymentAttemptUpdate {
error_code,
error_message,
amount_capturable,
surcharge_amount,
tax_amount,
updated_by,
merchant_connector_id: connector_id,
},
Expand Down Expand Up @@ -1261,8 +1265,6 @@ impl DataModelExt for PaymentAttemptUpdate {
connector_response_reference_id,
amount_capturable,
updated_by,
surcharge_amount,
tax_amount,
authentication_data,
encoded_data,
unified_code,
Expand All @@ -1282,8 +1284,6 @@ impl DataModelExt for PaymentAttemptUpdate {
connector_response_reference_id,
amount_capturable,
updated_by,
surcharge_amount,
tax_amount,
authentication_data,
encoded_data,
unified_code,
Expand Down Expand Up @@ -1320,8 +1320,6 @@ impl DataModelExt for PaymentAttemptUpdate {
error_message,
error_reason,
amount_capturable,
tax_amount,
surcharge_amount,
updated_by,
unified_code,
unified_message,
Expand All @@ -1333,8 +1331,6 @@ impl DataModelExt for PaymentAttemptUpdate {
error_message,
error_reason,
amount_capturable,
surcharge_amount,
tax_amount,
updated_by,
unified_code,
unified_message,
Expand Down Expand Up @@ -1480,6 +1476,8 @@ impl DataModelExt for PaymentAttemptUpdate {
error_code,
error_message,
amount_capturable,
surcharge_amount,
tax_amount,
updated_by,
merchant_connector_id: connector_id,
} => Self::ConfirmUpdate {
Expand All @@ -1499,6 +1497,8 @@ impl DataModelExt for PaymentAttemptUpdate {
error_code,
error_message,
amount_capturable,
surcharge_amount,
tax_amount,
updated_by,
merchant_connector_id: connector_id,
},
Expand Down Expand Up @@ -1526,8 +1526,6 @@ impl DataModelExt for PaymentAttemptUpdate {
connector_response_reference_id,
amount_capturable,
updated_by,
surcharge_amount,
tax_amount,
authentication_data,
encoded_data,
unified_code,
Expand All @@ -1547,8 +1545,6 @@ impl DataModelExt for PaymentAttemptUpdate {
connector_response_reference_id,
amount_capturable,
updated_by,
surcharge_amount,
tax_amount,
authentication_data,
encoded_data,
unified_code,
Expand Down Expand Up @@ -1585,8 +1581,6 @@ impl DataModelExt for PaymentAttemptUpdate {
error_message,
error_reason,
amount_capturable,
surcharge_amount,
tax_amount,
updated_by,
unified_code,
unified_message,
Expand All @@ -1599,8 +1593,6 @@ impl DataModelExt for PaymentAttemptUpdate {
error_reason,
amount_capturable,
updated_by,
surcharge_amount,
tax_amount,
unified_code,
unified_message,
connector_transaction_id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@
},
"raw_json_formatted": {
"client_secret": "{{client_secret}}",
"surcharge_details": {
"surcharge_amount": 5,
"tax_amount": 5
},
"payment_method": "card",
"payment_method_data": {
"card": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
"description": "Its my first payment request",
"authentication_type": "no_three_ds",
"return_url": "https://duck.com",
"surcharge_details": {
"surcharge_amount": 5,
"tax_amount": 5
},
"billing": {
"address": {
"line1": "1467",
Expand Down

0 comments on commit 3db7213

Please sign in to comment.