Skip to content

Commit

Permalink
check in redis only if surcharge not found in payment attempt
Browse files Browse the repository at this point in the history
  • Loading branch information
hrithikesh026 committed Nov 10, 2023
1 parent 5033f88 commit cd21892
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 31 deletions.
52 changes: 26 additions & 26 deletions crates/router/src/core/payments/operations/payment_confirm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -692,33 +692,33 @@ impl PaymentConfirm {
{
return invalid_surcharge_details_error;
}
} else {
// if not sent in payment create
// verify that any calculated surcharge sent in session flow is same as the one sent in confirm
return match get_individual_surcharge_detail_from_redis(
state,
&payment_method_type.into(),
&payment_method_type,
None,
&payment_attempt.attempt_id,
)
.await
{
Ok(surcharge_details) => utils::when(
!surcharge_details
.is_request_surcharge_matching(request_surcharge_details),
|| invalid_surcharge_details_error,
),
Err(err) if err.current_context() == &RedisError::NotFound => {
utils::when(!request_surcharge_details.is_surcharge_zero(), || {
invalid_surcharge_details_error
})
}
Err(err) => Err(err)
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("Failed to fetch redis value"),
};
}
// is not sent in payment create
// verify that any calculated surcharge sent in session flow is same as the one sent in confirm
let result = match get_individual_surcharge_detail_from_redis(
state,
&payment_method_type.into(),
&payment_method_type,
None,
&payment_attempt.attempt_id,
)
.await
{
Ok(surcharge_details) => utils::when(
!surcharge_details
.is_request_surcharge_matching(request_surcharge_details),
|| invalid_surcharge_details_error,
),
Err(err) if err.current_context() == &RedisError::NotFound => {
utils::when(!request_surcharge_details.is_surcharge_zero(), || {
invalid_surcharge_details_error
})
}
Err(err) => Err(err)
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("Failed to fetch redis value"),
};
return result;
}
Ok(())
}
Expand Down
6 changes: 1 addition & 5 deletions crates/router/src/services/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,7 @@ pub trait ConnectorValidation: ConnectorCommon {
}

fn validate_if_surcharge_implemented(&self) -> CustomResult<(), errors::ConnectorError> {
Err(errors::ConnectorError::NotImplemented(format!(
"Surcharge not implemented for {}",
self.id()
))
.into())
Err(errors::ConnectorError::NotImplemented(format!("Surcharge for {}", self.id())).into())
}
}

Expand Down

0 comments on commit cd21892

Please sign in to comment.