refactor(core): rename MandateTxnType to MandateTransactionType (#1322)

This commit is contained in:
Shankar Singh C
2023-06-22 17:09:22 +05:30
committed by GitHub
parent c1e8ad194f
commit 10691728d2
14 changed files with 39 additions and 35 deletions

View File

@ -341,9 +341,9 @@ pub struct VerifyRequest {
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum MandateTxnType {
NewMandateTxn,
RecurringMandateTxn,
pub enum MandateTransactionType {
NewMandateTransaction,
RecurringMandateTransaction,
}
#[derive(Default, Eq, PartialEq, Debug, serde::Deserialize, serde::Serialize, Clone)]

View File

@ -267,7 +267,7 @@ pub async fn get_address_by_id(
pub async fn get_token_pm_type_mandate_details(
state: &AppState,
request: &api::PaymentsRequest,
mandate_type: Option<api::MandateTxnType>,
mandate_type: Option<api::MandateTransactionType>,
merchant_account: &domain::MerchantAccount,
) -> RouterResult<(
Option<String>,
@ -277,7 +277,7 @@ pub async fn get_token_pm_type_mandate_details(
Option<String>,
)> {
match mandate_type {
Some(api::MandateTxnType::NewMandateTxn) => {
Some(api::MandateTransactionType::NewMandateTransaction) => {
let setup_mandate = request
.mandate_data
.clone()
@ -290,7 +290,7 @@ pub async fn get_token_pm_type_mandate_details(
None,
))
}
Some(api::MandateTxnType::RecurringMandateTxn) => {
Some(api::MandateTransactionType::RecurringMandateTransaction) => {
let (token_, payment_method_, payment_method_type_, mandate_connector) =
get_token_for_recurring_mandate(state, request, merchant_account).await?;
Ok((
@ -515,20 +515,22 @@ pub fn validate_card_data(
pub fn validate_mandate(
req: impl Into<api::MandateValidationFields>,
is_confirm_operation: bool,
) -> CustomResult<Option<api::MandateTxnType>, errors::ApiErrorResponse> {
) -> CustomResult<Option<api::MandateTransactionType>, errors::ApiErrorResponse> {
let req: api::MandateValidationFields = req.into();
match req.validate_and_get_mandate_type().change_context(
errors::ApiErrorResponse::MandateValidationFailed {
reason: "Expected one out of mandate_id and mandate_data but got both".to_string(),
},
)? {
Some(api::MandateTxnType::NewMandateTxn) => {
Some(api::MandateTransactionType::NewMandateTransaction) => {
validate_new_mandate_request(req, is_confirm_operation)?;
Ok(Some(api::MandateTxnType::NewMandateTxn))
Ok(Some(api::MandateTransactionType::NewMandateTransaction))
}
Some(api::MandateTxnType::RecurringMandateTxn) => {
Some(api::MandateTransactionType::RecurringMandateTransaction) => {
validate_recurring_mandate(req)?;
Ok(Some(api::MandateTxnType::RecurringMandateTxn))
Ok(Some(
api::MandateTransactionType::RecurringMandateTransaction,
))
}
None => Ok(None),
}
@ -1718,15 +1720,17 @@ pub(crate) fn validate_pm_or_token_given(
payment_method: &Option<api_enums::PaymentMethod>,
payment_method_data: &Option<api::PaymentMethodData>,
payment_method_type: &Option<api_enums::PaymentMethodType>,
mandate_type: &Option<api::MandateTxnType>,
mandate_type: &Option<api::MandateTransactionType>,
token: &Option<String>,
) -> Result<(), errors::ApiErrorResponse> {
utils::when(
!matches!(
payment_method_type,
Some(api_enums::PaymentMethodType::Paypal)
) && !matches!(mandate_type, Some(api::MandateTxnType::RecurringMandateTxn))
&& token.is_none()
) && !matches!(
mandate_type,
Some(api::MandateTransactionType::RecurringMandateTransaction)
) && token.is_none()
&& (payment_method_data.is_none() || payment_method.is_none()),
|| {
Err(errors::ApiErrorResponse::InvalidRequestData {

View File

@ -69,7 +69,7 @@ pub trait Operation<F: Clone, T>: Send + std::fmt::Debug {
pub struct ValidateResult<'a> {
pub merchant_id: &'a str,
pub payment_id: api::PaymentIdType,
pub mandate_type: Option<api::MandateTxnType>,
pub mandate_type: Option<api::MandateTransactionType>,
pub storage_scheme: enums::MerchantStorageScheme,
}
@ -90,7 +90,7 @@ pub trait GetTracker<F, D, R>: Send {
state: &'a AppState,
payment_id: &api::PaymentIdType,
request: &R,
mandate_type: Option<api::MandateTxnType>,
mandate_type: Option<api::MandateTransactionType>,
merchant_account: &domain::MerchantAccount,
mechant_key_store: &domain::MerchantKeyStore,
) -> RouterResult<(BoxedOperation<'a, F, R>, D, Option<CustomerDetails>)>;

View File

@ -34,7 +34,7 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsCancelRequest>
state: &'a AppState,
payment_id: &api::PaymentIdType,
request: &api::PaymentsCancelRequest,
_mandate_type: Option<api::MandateTxnType>,
_mandate_type: Option<api::MandateTransactionType>,
merchant_account: &domain::MerchantAccount,
key_store: &domain::MerchantKeyStore,
) -> RouterResult<(

View File

@ -35,7 +35,7 @@ impl<F: Send + Clone> GetTracker<F, payments::PaymentData<F>, api::PaymentsCaptu
state: &'a AppState,
payment_id: &api::PaymentIdType,
request: &api::PaymentsCaptureRequest,
_mandate_type: Option<api::MandateTxnType>,
_mandate_type: Option<api::MandateTransactionType>,
merchant_account: &domain::MerchantAccount,
key_store: &domain::MerchantKeyStore,
) -> RouterResult<(

View File

@ -36,7 +36,7 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsRequest> for Co
state: &'a AppState,
payment_id: &api::PaymentIdType,
request: &api::PaymentsRequest,
mandate_type: Option<api::MandateTxnType>,
mandate_type: Option<api::MandateTransactionType>,
merchant_account: &domain::MerchantAccount,
key_store: &domain::MerchantKeyStore,
) -> RouterResult<(

View File

@ -37,7 +37,7 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsRequest> for Pa
state: &'a AppState,
payment_id: &api::PaymentIdType,
request: &api::PaymentsRequest,
mandate_type: Option<api::MandateTxnType>,
mandate_type: Option<api::MandateTransactionType>,
merchant_account: &domain::MerchantAccount,
key_store: &domain::MerchantKeyStore,
) -> RouterResult<(

View File

@ -45,7 +45,7 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsRequest> for Pa
state: &'a AppState,
payment_id: &api::PaymentIdType,
request: &api::PaymentsRequest,
mandate_type: Option<api::MandateTxnType>,
mandate_type: Option<api::MandateTransactionType>,
merchant_account: &domain::MerchantAccount,
merchant_key_store: &domain::MerchantKeyStore,
) -> RouterResult<(

View File

@ -69,7 +69,7 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::VerifyRequest> for Paym
state: &'a AppState,
payment_id: &api::PaymentIdType,
request: &api::VerifyRequest,
_mandate_type: Option<api::MandateTxnType>,
_mandate_type: Option<api::MandateTransactionType>,
merchant_account: &domain::MerchantAccount,
_mechant_key_store: &domain::MerchantKeyStore,
) -> RouterResult<(

View File

@ -37,7 +37,7 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsSessionRequest>
state: &'a AppState,
payment_id: &api::PaymentIdType,
request: &api::PaymentsSessionRequest,
_mandate_type: Option<api::MandateTxnType>,
_mandate_type: Option<api::MandateTransactionType>,
merchant_account: &domain::MerchantAccount,
key_store: &domain::MerchantKeyStore,
) -> RouterResult<(

View File

@ -33,7 +33,7 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsStartRequest> f
state: &'a AppState,
payment_id: &api::PaymentIdType,
_request: &api::PaymentsStartRequest,
_mandate_type: Option<api::MandateTxnType>,
_mandate_type: Option<api::MandateTransactionType>,
merchant_account: &domain::MerchantAccount,
mechant_key_store: &domain::MerchantKeyStore,
) -> RouterResult<(

View File

@ -158,7 +158,7 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsRetrieveRequest
state: &'a AppState,
payment_id: &api::PaymentIdType,
request: &api::PaymentsRetrieveRequest,
_mandate_type: Option<api::MandateTxnType>,
_mandate_type: Option<api::MandateTransactionType>,
merchant_account: &domain::MerchantAccount,
key_store: &domain::MerchantKeyStore,
) -> RouterResult<(

View File

@ -36,7 +36,7 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsRequest> for Pa
state: &'a AppState,
payment_id: &api::PaymentIdType,
request: &api::PaymentsRequest,
mandate_type: Option<api::MandateTxnType>,
mandate_type: Option<api::MandateTransactionType>,
merchant_account: &domain::MerchantAccount,
key_store: &domain::MerchantKeyStore,
) -> RouterResult<(

View File

@ -1,6 +1,6 @@
pub use api_models::payments::{
AcceptanceType, Address, AddressDetails, Amount, AuthenticationForStartResponse, Card,
CustomerAcceptance, MandateData, MandateTxnType, MandateType, MandateValidationFields,
CustomerAcceptance, MandateData, MandateTransactionType, MandateType, MandateValidationFields,
NextActionType, OnlineMandate, PayLaterData, PaymentIdType, PaymentListConstraints,
PaymentListResponse, PaymentMethodData, PaymentMethodDataResponse, PaymentOp,
PaymentRetrieveBody, PaymentRetrieveBodyWithCredentials, PaymentsCancelRequest,
@ -20,15 +20,15 @@ use crate::{
};
pub(crate) trait PaymentsRequestExt {
fn is_mandate(&self) -> Option<MandateTxnType>;
fn is_mandate(&self) -> Option<MandateTransactionType>;
}
impl PaymentsRequestExt for PaymentsRequest {
fn is_mandate(&self) -> Option<MandateTxnType> {
fn is_mandate(&self) -> Option<MandateTransactionType> {
match (&self.mandate_data, &self.mandate_id) {
(None, None) => None,
(_, Some(_)) => Some(MandateTxnType::RecurringMandateTxn),
(Some(_), _) => Some(MandateTxnType::NewMandateTxn),
(_, Some(_)) => Some(MandateTransactionType::RecurringMandateTransaction),
(Some(_), _) => Some(MandateTransactionType::NewMandateTransaction),
}
}
}
@ -115,21 +115,21 @@ impl PaymentIdTypeExt for PaymentIdType {
pub(crate) trait MandateValidationFieldsExt {
fn validate_and_get_mandate_type(
&self,
) -> errors::CustomResult<Option<MandateTxnType>, errors::ValidationError>;
) -> errors::CustomResult<Option<MandateTransactionType>, errors::ValidationError>;
}
impl MandateValidationFieldsExt for MandateValidationFields {
fn validate_and_get_mandate_type(
&self,
) -> errors::CustomResult<Option<MandateTxnType>, errors::ValidationError> {
) -> errors::CustomResult<Option<MandateTransactionType>, errors::ValidationError> {
match (&self.mandate_data, &self.mandate_id) {
(None, None) => Ok(None),
(Some(_), Some(_)) => Err(errors::ValidationError::InvalidValue {
message: "Expected one out of mandate_id and mandate_data but got both".to_string(),
})
.into_report(),
(_, Some(_)) => Ok(Some(MandateTxnType::RecurringMandateTxn)),
(Some(_), _) => Ok(Some(MandateTxnType::NewMandateTxn)),
(_, Some(_)) => Ok(Some(MandateTransactionType::RecurringMandateTransaction)),
(Some(_), _) => Ok(Some(MandateTransactionType::NewMandateTransaction)),
}
}
}