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)] #[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "snake_case")] #[serde(rename_all = "snake_case")]
pub enum MandateTxnType { pub enum MandateTransactionType {
NewMandateTxn, NewMandateTransaction,
RecurringMandateTxn, RecurringMandateTransaction,
} }
#[derive(Default, Eq, PartialEq, Debug, serde::Deserialize, serde::Serialize, Clone)] #[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( pub async fn get_token_pm_type_mandate_details(
state: &AppState, state: &AppState,
request: &api::PaymentsRequest, request: &api::PaymentsRequest,
mandate_type: Option<api::MandateTxnType>, mandate_type: Option<api::MandateTransactionType>,
merchant_account: &domain::MerchantAccount, merchant_account: &domain::MerchantAccount,
) -> RouterResult<( ) -> RouterResult<(
Option<String>, Option<String>,
@ -277,7 +277,7 @@ pub async fn get_token_pm_type_mandate_details(
Option<String>, Option<String>,
)> { )> {
match mandate_type { match mandate_type {
Some(api::MandateTxnType::NewMandateTxn) => { Some(api::MandateTransactionType::NewMandateTransaction) => {
let setup_mandate = request let setup_mandate = request
.mandate_data .mandate_data
.clone() .clone()
@ -290,7 +290,7 @@ pub async fn get_token_pm_type_mandate_details(
None, None,
)) ))
} }
Some(api::MandateTxnType::RecurringMandateTxn) => { Some(api::MandateTransactionType::RecurringMandateTransaction) => {
let (token_, payment_method_, payment_method_type_, mandate_connector) = let (token_, payment_method_, payment_method_type_, mandate_connector) =
get_token_for_recurring_mandate(state, request, merchant_account).await?; get_token_for_recurring_mandate(state, request, merchant_account).await?;
Ok(( Ok((
@ -515,20 +515,22 @@ pub fn validate_card_data(
pub fn validate_mandate( pub fn validate_mandate(
req: impl Into<api::MandateValidationFields>, req: impl Into<api::MandateValidationFields>,
is_confirm_operation: bool, is_confirm_operation: bool,
) -> CustomResult<Option<api::MandateTxnType>, errors::ApiErrorResponse> { ) -> CustomResult<Option<api::MandateTransactionType>, errors::ApiErrorResponse> {
let req: api::MandateValidationFields = req.into(); let req: api::MandateValidationFields = req.into();
match req.validate_and_get_mandate_type().change_context( match req.validate_and_get_mandate_type().change_context(
errors::ApiErrorResponse::MandateValidationFailed { errors::ApiErrorResponse::MandateValidationFailed {
reason: "Expected one out of mandate_id and mandate_data but got both".to_string(), 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)?; 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)?; validate_recurring_mandate(req)?;
Ok(Some(api::MandateTxnType::RecurringMandateTxn)) Ok(Some(
api::MandateTransactionType::RecurringMandateTransaction,
))
} }
None => Ok(None), None => Ok(None),
} }
@ -1718,15 +1720,17 @@ pub(crate) fn validate_pm_or_token_given(
payment_method: &Option<api_enums::PaymentMethod>, payment_method: &Option<api_enums::PaymentMethod>,
payment_method_data: &Option<api::PaymentMethodData>, payment_method_data: &Option<api::PaymentMethodData>,
payment_method_type: &Option<api_enums::PaymentMethodType>, payment_method_type: &Option<api_enums::PaymentMethodType>,
mandate_type: &Option<api::MandateTxnType>, mandate_type: &Option<api::MandateTransactionType>,
token: &Option<String>, token: &Option<String>,
) -> Result<(), errors::ApiErrorResponse> { ) -> Result<(), errors::ApiErrorResponse> {
utils::when( utils::when(
!matches!( !matches!(
payment_method_type, payment_method_type,
Some(api_enums::PaymentMethodType::Paypal) Some(api_enums::PaymentMethodType::Paypal)
) && !matches!(mandate_type, Some(api::MandateTxnType::RecurringMandateTxn)) ) && !matches!(
&& token.is_none() mandate_type,
Some(api::MandateTransactionType::RecurringMandateTransaction)
) && token.is_none()
&& (payment_method_data.is_none() || payment_method.is_none()), && (payment_method_data.is_none() || payment_method.is_none()),
|| { || {
Err(errors::ApiErrorResponse::InvalidRequestData { 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 struct ValidateResult<'a> {
pub merchant_id: &'a str, pub merchant_id: &'a str,
pub payment_id: api::PaymentIdType, pub payment_id: api::PaymentIdType,
pub mandate_type: Option<api::MandateTxnType>, pub mandate_type: Option<api::MandateTransactionType>,
pub storage_scheme: enums::MerchantStorageScheme, pub storage_scheme: enums::MerchantStorageScheme,
} }
@ -90,7 +90,7 @@ pub trait GetTracker<F, D, R>: Send {
state: &'a AppState, state: &'a AppState,
payment_id: &api::PaymentIdType, payment_id: &api::PaymentIdType,
request: &R, request: &R,
mandate_type: Option<api::MandateTxnType>, mandate_type: Option<api::MandateTransactionType>,
merchant_account: &domain::MerchantAccount, merchant_account: &domain::MerchantAccount,
mechant_key_store: &domain::MerchantKeyStore, mechant_key_store: &domain::MerchantKeyStore,
) -> RouterResult<(BoxedOperation<'a, F, R>, D, Option<CustomerDetails>)>; ) -> 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, state: &'a AppState,
payment_id: &api::PaymentIdType, payment_id: &api::PaymentIdType,
request: &api::PaymentsCancelRequest, request: &api::PaymentsCancelRequest,
_mandate_type: Option<api::MandateTxnType>, _mandate_type: Option<api::MandateTransactionType>,
merchant_account: &domain::MerchantAccount, merchant_account: &domain::MerchantAccount,
key_store: &domain::MerchantKeyStore, key_store: &domain::MerchantKeyStore,
) -> RouterResult<( ) -> RouterResult<(

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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