fix: fixing TODO/FIXMEs from router/core (#257)

This commit is contained in:
Nishant Joshi
2022-12-29 16:05:42 +05:30
committed by GitHub
parent 7348d76cad
commit 8535cecd7d
16 changed files with 83 additions and 84 deletions

View File

@ -43,7 +43,6 @@ pub async fn get_address_for_payment_request(
merchant_id: &str,
customer_id: &Option<String>,
) -> CustomResult<Option<storage::Address>, errors::ApiErrorResponse> {
// TODO: Refactor this function for more readability (TryFrom)
Ok(match req_address {
Some(address) => {
match address_id {
@ -60,17 +59,10 @@ pub async fn get_address_for_payment_request(
.as_deref()
.get_required_value("customer_id")
.change_context(errors::ApiErrorResponse::CustomerNotFound)?;
let address_details = address.address.clone().unwrap_or_default();
Some(
db.insert_address(storage::AddressNew {
city: address.address.as_ref().and_then(|a| a.city.clone()),
country: address.address.as_ref().and_then(|a| a.country.clone()),
line1: address.address.as_ref().and_then(|a| a.line1.clone()),
line2: address.address.as_ref().and_then(|a| a.line2.clone()),
line3: address.address.as_ref().and_then(|a| a.line3.clone()),
state: address.address.as_ref().and_then(|a| a.state.clone()),
zip: address.address.as_ref().and_then(|a| a.zip.clone()),
first_name: address.address.as_ref().and_then(|a| a.first_name.clone()),
last_name: address.address.as_ref().and_then(|a| a.last_name.clone()),
phone_number: address.phone.as_ref().and_then(|a| a.number.clone()),
country_code: address
.phone
@ -78,7 +70,8 @@ pub async fn get_address_for_payment_request(
.and_then(|a| a.country_code.clone()),
customer_id: customer_id.to_string(),
merchant_id: merchant_id.to_string(),
..storage::AddressNew::default()
..address_details.foreign_into()
})
.await
.map_err(|_| errors::ApiErrorResponse::InternalServerError)?,
@ -172,7 +165,7 @@ pub async fn get_token_for_recurring_mandate(
};
verify_mandate_details(
req.amount.get_required_value("amount")?.into(),
req.currency.clone().get_required_value("currency")?,
req.currency.get_required_value("currency")?,
mandate.clone(),
)?;
@ -360,7 +353,7 @@ fn validate_recurring_mandate(req: api::MandateValidationFields) -> RouterResult
pub fn verify_mandate_details(
request_amount: i64,
request_currency: String,
request_currency: api_enums::Currency,
mandate: storage::Mandate,
) -> RouterResult<()> {
match mandate.mandate_type {
@ -392,7 +385,7 @@ pub fn verify_mandate_details(
utils::when(
mandate
.mandate_currency
.map(|mandate_currency| mandate_currency.to_string() != request_currency)
.map(|mandate_currency| mandate_currency != request_currency.foreign_into())
.unwrap_or(false),
|| {
Err(report!(errors::ApiErrorResponse::MandateValidationFailed {
@ -488,7 +481,6 @@ pub(crate) async fn call_payment_method(
Some(pm_data) => match payment_method_type {
Some(payment_method_type) => match pm_data {
api::PaymentMethod::Card(card) => {
//TODO: get it from temp_card
let card_detail = api::CardDetail {
card_number: card.card_number.clone(),
card_exp_month: card.card_exp_month.clone(),