Skip to content

Commit

Permalink
refactor(router): remove the payment type column in payment intent (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
vspecky authored Oct 5, 2023
1 parent 80f3b1e commit 980aa44
Show file tree
Hide file tree
Showing 10 changed files with 14 additions and 37 deletions.
2 changes: 0 additions & 2 deletions crates/data_models/src/payments/payment_intent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ pub struct PaymentIntent {
// Manual review can occur when the transaction is marked as risky by the frm_processor, payment processor or when there is underpayment/over payment incase of crypto payment
pub merchant_decision: Option<String>,
pub payment_confirm_source: Option<storage_enums::PaymentSource>,
pub payment_type: Option<storage_enums::PaymentType>,
}

#[derive(Clone, Debug, Default, Eq, PartialEq, Serialize, Deserialize)]
Expand Down Expand Up @@ -145,7 +144,6 @@ pub struct PaymentIntentNew {
pub profile_id: Option<String>,
pub merchant_decision: Option<String>,
pub payment_confirm_source: Option<storage_enums::PaymentSource>,
pub payment_type: Option<storage_enums::PaymentType>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
Expand Down
2 changes: 0 additions & 2 deletions crates/diesel_models/src/payment_intent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ pub struct PaymentIntent {
// Manual review can occur when the transaction is marked as risky by the frm_processor, payment processor or when there is underpayment/over payment incase of crypto payment
pub merchant_decision: Option<String>,
pub payment_confirm_source: Option<storage_enums::PaymentSource>,
pub payment_type: Option<storage_enums::PaymentType>,
}

#[derive(
Expand Down Expand Up @@ -99,7 +98,6 @@ pub struct PaymentIntentNew {
pub profile_id: Option<String>,
pub merchant_decision: Option<String>,
pub payment_confirm_source: Option<storage_enums::PaymentSource>,
pub payment_type: Option<storage_enums::PaymentType>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
Expand Down
1 change: 0 additions & 1 deletion crates/diesel_models/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,6 @@ diesel::table! {
#[max_length = 64]
merchant_decision -> Nullable<Varchar>,
payment_confirm_source -> Nullable<PaymentSource>,
payment_type -> Nullable<PaymentType>,
}
}

Expand Down
15 changes: 14 additions & 1 deletion crates/router/src/core/payment_methods/cards.rs
Original file line number Diff line number Diff line change
Expand Up @@ -861,6 +861,19 @@ pub async fn list_payment_methods(
.await
.transpose()?;

let payment_type = payment_attempt.as_ref().map(|pa| {
let amount = api::Amount::from(pa.amount);
let mandate_type = if pa.mandate_id.is_some() {
Some(api::MandateTransactionType::RecurringMandateTransaction)
} else if pa.mandate_details.is_some() {
Some(api::MandateTransactionType::NewMandateTransaction)
} else {
None
};

helpers::infer_payment_type(&amount, mandate_type.as_ref())
});

let all_mcas = db
.find_merchant_connector_account_by_merchant_id_and_disabled_list(
&merchant_account.merchant_id,
Expand Down Expand Up @@ -1280,8 +1293,8 @@ pub async fn list_payment_methods(
api::PaymentMethodListResponse {
redirect_url: merchant_account.return_url,
merchant_name: merchant_account.merchant_name,
payment_type,
payment_methods: payment_method_responses,
payment_type: payment_intent.as_ref().and_then(|pi| pi.payment_type),
mandate_payment: payment_attempt.and_then(|inner| inner.mandate_details).map(
|d| match d {
data_models::mandates::MandateDataType::SingleUse(i) => {
Expand Down
3 changes: 0 additions & 3 deletions crates/router/src/core/payments/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2398,7 +2398,6 @@ mod tests {
profile_id: None,
merchant_decision: None,
payment_confirm_source: None,
payment_type: Some(api_enums::PaymentType::Normal),
};
let req_cs = Some("1".to_string());
let merchant_fulfillment_time = Some(900);
Expand Down Expand Up @@ -2446,7 +2445,6 @@ mod tests {
profile_id: None,
merchant_decision: None,
payment_confirm_source: None,
payment_type: Some(api_enums::PaymentType::Normal),
};
let req_cs = Some("1".to_string());
let merchant_fulfillment_time = Some(10);
Expand Down Expand Up @@ -2494,7 +2492,6 @@ mod tests {
profile_id: None,
merchant_decision: None,
payment_confirm_source: None,
payment_type: Some(api_enums::PaymentType::Normal),
};
let req_cs = Some("1".to_string());
let merchant_fulfillment_time = Some(10);
Expand Down
5 changes: 0 additions & 5 deletions crates/router/src/core/payments/operations/payment_create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,6 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsRequest> for Pa
core_utils::validate_and_get_business_profile(db, request.profile_id.as_ref(), merchant_id)
.await?;

let payment_type = helpers::infer_payment_type(&amount, mandate_type.as_ref());

let (
token,
payment_method,
Expand Down Expand Up @@ -147,7 +145,6 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsRequest> for Pa
request,
shipping_address.clone().map(|x| x.address_id),
billing_address.clone().map(|x| x.address_id),
payment_type,
attempt_id,
state,
)
Expand Down Expand Up @@ -606,7 +603,6 @@ impl PaymentCreate {
request: &api::PaymentsRequest,
shipping_address_id: Option<String>,
billing_address_id: Option<String>,
payment_type: enums::PaymentType,
active_attempt_id: String,
state: &AppState,
) -> RouterResult<storage::PaymentIntentNew> {
Expand Down Expand Up @@ -681,7 +677,6 @@ impl PaymentCreate {
profile_id: Some(profile_id),
merchant_decision: None,
payment_confirm_source: None,
payment_type: Some(payment_type),
})
}

Expand Down
1 change: 0 additions & 1 deletion crates/storage_impl/src/mock_db/payment_intent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ impl PaymentIntentInterface for MockDb {
profile_id: new.profile_id,
merchant_decision: new.merchant_decision,
payment_confirm_source: new.payment_confirm_source,
payment_type: new.payment_type,
};
payment_intents.push(payment_intent.clone());
Ok(payment_intent)
Expand Down
5 changes: 0 additions & 5 deletions crates/storage_impl/src/payments/payment_intent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ impl<T: DatabaseStore> PaymentIntentInterface for KVRouterStore<T> {
profile_id: new.profile_id.clone(),
merchant_decision: new.merchant_decision.clone(),
payment_confirm_source: new.payment_confirm_source,
payment_type: new.payment_type,
};

match self
Expand Down Expand Up @@ -708,7 +707,6 @@ impl DataModelExt for PaymentIntentNew {
profile_id: self.profile_id,
merchant_decision: self.merchant_decision,
payment_confirm_source: self.payment_confirm_source,
payment_type: self.payment_type,
}
}

Expand Down Expand Up @@ -746,7 +744,6 @@ impl DataModelExt for PaymentIntentNew {
profile_id: storage_model.profile_id,
merchant_decision: storage_model.merchant_decision,
payment_confirm_source: storage_model.payment_confirm_source,
payment_type: storage_model.payment_type,
}
}
}
Expand Down Expand Up @@ -789,7 +786,6 @@ impl DataModelExt for PaymentIntent {
profile_id: self.profile_id,
merchant_decision: self.merchant_decision,
payment_confirm_source: self.payment_confirm_source,
payment_type: self.payment_type,
}
}

Expand Down Expand Up @@ -828,7 +824,6 @@ impl DataModelExt for PaymentIntent {
profile_id: storage_model.profile_id,
merchant_decision: storage_model.merchant_decision,
payment_confirm_source: storage_model.payment_confirm_source,
payment_type: storage_model.payment_type,
}
}
}
Expand Down

This file was deleted.

This file was deleted.

0 comments on commit 980aa44

Please sign in to comment.