From 72cc41c038cd64dd0d5b148be4712813fc86f3d3 Mon Sep 17 00:00:00 2001 From: Tejas Mate Date: Thu, 26 Oct 2023 22:48:56 +0530 Subject: [PATCH 01/12] Update transformers.rs --- .../router/src/connector/nmi/transformers.rs | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/crates/router/src/connector/nmi/transformers.rs b/crates/router/src/connector/nmi/transformers.rs index 3f64ff9eaca2..d7f2575e6726 100644 --- a/crates/router/src/connector/nmi/transformers.rs +++ b/crates/router/src/connector/nmi/transformers.rs @@ -279,13 +279,13 @@ impl Response::Approved => ( Ok(types::PaymentsResponseData::TransactionResponse { resource_id: types::ResponseId::ConnectorTransactionId( - item.response.transactionid, + item.response.transactionid.clone() ), redirection_data: None, mandate_reference: None, connector_metadata: None, network_txn_id: None, - connector_response_reference_id: None, + connector_response_reference_id: Some(item.response.transactionid), }), enums::AttemptStatus::CaptureInitiated, ), @@ -372,13 +372,13 @@ impl Response::Approved => ( Ok(types::PaymentsResponseData::TransactionResponse { resource_id: types::ResponseId::ConnectorTransactionId( - item.response.transactionid, + item.response.transactionid.clone() ), redirection_data: None, mandate_reference: None, connector_metadata: None, network_txn_id: None, - connector_response_reference_id: None, + connector_response_reference_id: Some(item.response.transactionid), }), enums::AttemptStatus::Charged, ), @@ -425,13 +425,13 @@ impl TryFrom> Response::Approved => ( Ok(types::PaymentsResponseData::TransactionResponse { resource_id: types::ResponseId::ConnectorTransactionId( - item.response.transactionid, + item.response.transactionid.clone() ), redirection_data: None, mandate_reference: None, connector_metadata: None, network_txn_id: None, - connector_response_reference_id: None, + connector_response_reference_id: Some(item.response.transactionid), }), if let Some(diesel_models::enums::CaptureMethod::Automatic) = item.data.request.capture_method @@ -474,13 +474,13 @@ impl Response::Approved => ( Ok(types::PaymentsResponseData::TransactionResponse { resource_id: types::ResponseId::ConnectorTransactionId( - item.response.transactionid, + item.response.transactionid.clone() ), redirection_data: None, mandate_reference: None, connector_metadata: None, network_txn_id: None, - connector_response_reference_id: None, + connector_response_reference_id: Some(item.response.transactionid), }), enums::AttemptStatus::VoidInitiated, ), @@ -525,13 +525,13 @@ impl TryFrom> status: enums::AttemptStatus::from(NmiStatus::from(response.transaction.condition)), response: Ok(types::PaymentsResponseData::TransactionResponse { resource_id: types::ResponseId::ConnectorTransactionId( - response.transaction.transaction_id, + response.transaction.transaction_id.clone() ), redirection_data: None, mandate_reference: None, connector_metadata: None, network_txn_id: None, - connector_response_reference_id: None, + connector_response_reference_id: Some(response.transaction.transaction_id), }), ..item.data }) From c5e9be8557680a75108e787b852a10dcba067675 Mon Sep 17 00:00:00 2001 From: Tejas Mate Date: Fri, 27 Oct 2023 00:08:49 +0530 Subject: [PATCH 02/12] Update transformers.rs --- crates/router/src/connector/nmi/transformers.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/crates/router/src/connector/nmi/transformers.rs b/crates/router/src/connector/nmi/transformers.rs index d7f2575e6726..768e2cb90bfb 100644 --- a/crates/router/src/connector/nmi/transformers.rs +++ b/crates/router/src/connector/nmi/transformers.rs @@ -279,7 +279,7 @@ impl Response::Approved => ( Ok(types::PaymentsResponseData::TransactionResponse { resource_id: types::ResponseId::ConnectorTransactionId( - item.response.transactionid.clone() + item.response.transactionid.clone(), ), redirection_data: None, mandate_reference: None, @@ -372,7 +372,7 @@ impl Response::Approved => ( Ok(types::PaymentsResponseData::TransactionResponse { resource_id: types::ResponseId::ConnectorTransactionId( - item.response.transactionid.clone() + item.response.transactionid.clone(), ), redirection_data: None, mandate_reference: None, @@ -425,7 +425,7 @@ impl TryFrom> Response::Approved => ( Ok(types::PaymentsResponseData::TransactionResponse { resource_id: types::ResponseId::ConnectorTransactionId( - item.response.transactionid.clone() + item.response.transactionid.clone(), ), redirection_data: None, mandate_reference: None, @@ -474,7 +474,7 @@ impl Response::Approved => ( Ok(types::PaymentsResponseData::TransactionResponse { resource_id: types::ResponseId::ConnectorTransactionId( - item.response.transactionid.clone() + item.response.transactionid.clone(), ), redirection_data: None, mandate_reference: None, @@ -525,7 +525,7 @@ impl TryFrom> status: enums::AttemptStatus::from(NmiStatus::from(response.transaction.condition)), response: Ok(types::PaymentsResponseData::TransactionResponse { resource_id: types::ResponseId::ConnectorTransactionId( - response.transaction.transaction_id.clone() + response.transaction.transaction_id.clone(), ), redirection_data: None, mandate_reference: None, From 7879c192089ae8f87c81efaa448ae7ab6e40e222 Mon Sep 17 00:00:00 2001 From: Tejas Mate Date: Tue, 31 Oct 2023 20:42:09 +0530 Subject: [PATCH 03/12] Update crates/router/src/connector/nmi/transformers.rs Co-authored-by: DEEPANSHU BANSAL <41580413+deepanshu-iiitu@users.noreply.github.com> --- crates/router/src/connector/nmi/transformers.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/router/src/connector/nmi/transformers.rs b/crates/router/src/connector/nmi/transformers.rs index 768e2cb90bfb..e07bab55202c 100644 --- a/crates/router/src/connector/nmi/transformers.rs +++ b/crates/router/src/connector/nmi/transformers.rs @@ -285,7 +285,7 @@ impl mandate_reference: None, connector_metadata: None, network_txn_id: None, - connector_response_reference_id: Some(item.response.transactionid), + connector_response_reference_id: item.response.orderid.or(Some(item.response.transactionid)), }), enums::AttemptStatus::CaptureInitiated, ), From db1501678f0086a0afc825b36faae436782efe3c Mon Sep 17 00:00:00 2001 From: Tejas Mate Date: Tue, 31 Oct 2023 20:42:19 +0530 Subject: [PATCH 04/12] Update crates/router/src/connector/nmi/transformers.rs Co-authored-by: DEEPANSHU BANSAL <41580413+deepanshu-iiitu@users.noreply.github.com> --- crates/router/src/connector/nmi/transformers.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/router/src/connector/nmi/transformers.rs b/crates/router/src/connector/nmi/transformers.rs index e07bab55202c..385704d74ce5 100644 --- a/crates/router/src/connector/nmi/transformers.rs +++ b/crates/router/src/connector/nmi/transformers.rs @@ -378,7 +378,7 @@ impl mandate_reference: None, connector_metadata: None, network_txn_id: None, - connector_response_reference_id: Some(item.response.transactionid), + connector_response_reference_id: item.response.orderid.or(Some(item.response.transactionid)), }), enums::AttemptStatus::Charged, ), From d659375365eac5324837771c2304b0febb368ce9 Mon Sep 17 00:00:00 2001 From: Tejas Mate Date: Tue, 31 Oct 2023 20:42:28 +0530 Subject: [PATCH 05/12] Update crates/router/src/connector/nmi/transformers.rs Co-authored-by: DEEPANSHU BANSAL <41580413+deepanshu-iiitu@users.noreply.github.com> --- crates/router/src/connector/nmi/transformers.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/router/src/connector/nmi/transformers.rs b/crates/router/src/connector/nmi/transformers.rs index 385704d74ce5..f2945badd5b2 100644 --- a/crates/router/src/connector/nmi/transformers.rs +++ b/crates/router/src/connector/nmi/transformers.rs @@ -431,7 +431,7 @@ impl TryFrom> mandate_reference: None, connector_metadata: None, network_txn_id: None, - connector_response_reference_id: Some(item.response.transactionid), + connector_response_reference_id: item.response.orderid.or(Some(item.response.transactionid)), }), if let Some(diesel_models::enums::CaptureMethod::Automatic) = item.data.request.capture_method From b3abd3f9c9fedac2ee92bf12897c1b45116f7fef Mon Sep 17 00:00:00 2001 From: Tejas Mate Date: Tue, 31 Oct 2023 20:43:11 +0530 Subject: [PATCH 06/12] Update crates/router/src/connector/nmi/transformers.rs Co-authored-by: DEEPANSHU BANSAL <41580413+deepanshu-iiitu@users.noreply.github.com> --- crates/router/src/connector/nmi/transformers.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/router/src/connector/nmi/transformers.rs b/crates/router/src/connector/nmi/transformers.rs index f2945badd5b2..bb08b0e7c73c 100644 --- a/crates/router/src/connector/nmi/transformers.rs +++ b/crates/router/src/connector/nmi/transformers.rs @@ -480,7 +480,7 @@ impl mandate_reference: None, connector_metadata: None, network_txn_id: None, - connector_response_reference_id: Some(item.response.transactionid), + connector_response_reference_id: item.response.orderid.or(Some(item.response.transactionid)), }), enums::AttemptStatus::VoidInitiated, ), From a4b77e37e030f9aa3e63bb7e126b98cb74cc81a0 Mon Sep 17 00:00:00 2001 From: Tejas Mate Date: Tue, 31 Oct 2023 20:43:28 +0530 Subject: [PATCH 07/12] Update crates/router/src/connector/nmi/transformers.rs Co-authored-by: DEEPANSHU BANSAL <41580413+deepanshu-iiitu@users.noreply.github.com> --- crates/router/src/connector/nmi/transformers.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/router/src/connector/nmi/transformers.rs b/crates/router/src/connector/nmi/transformers.rs index bb08b0e7c73c..80bef8e88c80 100644 --- a/crates/router/src/connector/nmi/transformers.rs +++ b/crates/router/src/connector/nmi/transformers.rs @@ -531,7 +531,7 @@ impl TryFrom> mandate_reference: None, connector_metadata: None, network_txn_id: None, - connector_response_reference_id: Some(response.transaction.transaction_id), + connector_response_reference_id: item.response.orderid.or(Some(item.response.transactionid)), }), ..item.data }) From 9b8b977cf695f9384e439f91fdfd34222ea643fc Mon Sep 17 00:00:00 2001 From: Tejas Mate Date: Sun, 12 Nov 2023 02:00:59 +0530 Subject: [PATCH 08/12] Update crates/router/src/connector/nmi/transformers.rs Co-authored-by: DEEPANSHU BANSAL <41580413+deepanshu-iiitu@users.noreply.github.com> --- crates/router/src/connector/nmi/transformers.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/router/src/connector/nmi/transformers.rs b/crates/router/src/connector/nmi/transformers.rs index 80bef8e88c80..2152e5d5ac93 100644 --- a/crates/router/src/connector/nmi/transformers.rs +++ b/crates/router/src/connector/nmi/transformers.rs @@ -531,7 +531,7 @@ impl TryFrom> mandate_reference: None, connector_metadata: None, network_txn_id: None, - connector_response_reference_id: item.response.orderid.or(Some(item.response.transactionid)), + connector_response_reference_id: None, }), ..item.data }) From 08b370d9a588eeb9abe50746b982bdbed73a3594 Mon Sep 17 00:00:00 2001 From: Tejas Mate Date: Sun, 12 Nov 2023 02:17:09 +0530 Subject: [PATCH 09/12] Update transformers.rs --- crates/router/src/connector/nmi/transformers.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/router/src/connector/nmi/transformers.rs b/crates/router/src/connector/nmi/transformers.rs index 8cc5b5aa55bc..c3d7c232efd2 100644 --- a/crates/router/src/connector/nmi/transformers.rs +++ b/crates/router/src/connector/nmi/transformers.rs @@ -380,7 +380,7 @@ pub struct StandardResponse { pub transactionid: String, pub avsresponse: Option, pub cvvresponse: Option, - pub orderid: String, + pub orderid: Option, pub response_code: String, } From 7bb059a2f25885b63f331b2aedbec82de5b92ea5 Mon Sep 17 00:00:00 2001 From: Tejas Mate Date: Sun, 12 Nov 2023 03:03:12 +0530 Subject: [PATCH 10/12] Update transformers.rs --- .../router/src/connector/nmi/transformers.rs | 1162 +++++++++-------- 1 file changed, 587 insertions(+), 575 deletions(-) diff --git a/crates/router/src/connector/nmi/transformers.rs b/crates/router/src/connector/nmi/transformers.rs index c3d7c232efd2..9afd53008e42 100644 --- a/crates/router/src/connector/nmi/transformers.rs +++ b/crates/router/src/connector/nmi/transformers.rs @@ -5,9 +5,9 @@ use masking::Secret; use serde::{Deserialize, Serialize}; use crate::{ - connector::utils::{self, PaymentsAuthorizeRequestData}, - core::errors, - types::{self, api, storage::enums, transformers::ForeignFrom, ConnectorAuthType}, +    connector::utils::{self, PaymentsAuthorizeRequestData}, +    core::errors, +    types::{self, api, storage::enums, transformers::ForeignFrom, ConnectorAuthType}, }; type Error = Report; @@ -15,732 +15,744 @@ type Error = Report; #[derive(Debug, Serialize)] #[serde(rename_all = "lowercase")] pub enum TransactionType { - Auth, - Capture, - Refund, - Sale, - Validate, - Void, +    Auth, +    Capture, +    Refund, +    Sale, +    Validate, +    Void, } pub struct NmiAuthType { - pub(super) api_key: Secret, +    pub(super) api_key: Secret, } impl TryFrom<&ConnectorAuthType> for NmiAuthType { - type Error = Error; - fn try_from(auth_type: &ConnectorAuthType) -> Result { - if let types::ConnectorAuthType::HeaderKey { api_key } = auth_type { - Ok(Self { - api_key: api_key.to_owned(), - }) - } else { - Err(errors::ConnectorError::FailedToObtainAuthType.into()) - } - } +    type Error = Error; +    fn try_from(auth_type: &ConnectorAuthType) -> Result { +        if let types::ConnectorAuthType::HeaderKey { api_key } = auth_type { +            Ok(Self { +                api_key: api_key.to_owned(), +            }) +        } else { +            Err(errors::ConnectorError::FailedToObtainAuthType.into()) +        } +    } } #[derive(Debug, Serialize)] pub struct NmiRouterData { - pub amount: f64, - pub router_data: T, +    pub amount: f64, +    pub router_data: T, } impl - TryFrom<( - &types::api::CurrencyUnit, - types::storage::enums::Currency, - i64, - T, - )> for NmiRouterData +    TryFrom<( +        &types::api::CurrencyUnit, +        types::storage::enums::Currency, +        i64, +        T, +    )> for NmiRouterData { - type Error = Report; - - fn try_from( - (_currency_unit, currency, amount, router_data): ( - &types::api::CurrencyUnit, - types::storage::enums::Currency, - i64, - T, - ), - ) -> Result { - Ok(Self { - amount: utils::to_currency_base_unit_asf64(amount, currency)?, - router_data, - }) - } +    type Error = Report; + +    fn try_from( +        (_currency_unit, currency, amount, router_data): ( +            &types::api::CurrencyUnit, +            types::storage::enums::Currency, +            i64, +            T, +        ), +    ) -> Result { +        Ok(Self { +            amount: utils::to_currency_base_unit_asf64(amount, currency)?, +            router_data, +        }) +    } } #[derive(Debug, Serialize)] pub struct NmiPaymentsRequest { - #[serde(rename = "type")] - transaction_type: TransactionType, - amount: f64, - security_key: Secret, - currency: enums::Currency, - #[serde(flatten)] - payment_method: PaymentMethod, - orderid: String, +    #[serde(rename = "type")] +    transaction_type: TransactionType, +    amount: f64, +    security_key: Secret, +    currency: enums::Currency, +    #[serde(flatten)] +    payment_method: PaymentMethod, +    orderid: String, } #[derive(Debug, Serialize)] #[serde(untagged)] pub enum PaymentMethod { - Card(Box), - GPay(Box), - ApplePay(Box), +    Card(Box), +    GPay(Box), +    ApplePay(Box), } #[derive(Debug, Serialize)] pub struct CardData { - ccnumber: CardNumber, - ccexp: Secret, - cvv: Secret, +    ccnumber: CardNumber, +    ccexp: Secret, +    cvv: Secret, } #[derive(Debug, Serialize)] pub struct GooglePayData { - googlepay_payment_data: Secret, +    googlepay_payment_data: Secret, } #[derive(Debug, Serialize)] pub struct ApplePayData { - applepay_payment_data: Secret, +    applepay_payment_data: Secret, } impl TryFrom<&NmiRouterData<&types::PaymentsAuthorizeRouterData>> for NmiPaymentsRequest { - type Error = Error; - fn try_from( - item: &NmiRouterData<&types::PaymentsAuthorizeRouterData>, - ) -> Result { - let transaction_type = match item.router_data.request.is_auto_capture()? { - true => TransactionType::Sale, - false => TransactionType::Auth, - }; - let auth_type: NmiAuthType = (&item.router_data.connector_auth_type).try_into()?; - let amount = item.amount; - let payment_method = - PaymentMethod::try_from(&item.router_data.request.payment_method_data)?; - - Ok(Self { - transaction_type, - security_key: auth_type.api_key, - amount, - currency: item.router_data.request.currency, - payment_method, - orderid: item.router_data.connector_request_reference_id.clone(), - }) - } +    type Error = Error; +    fn try_from( +        item: &NmiRouterData<&types::PaymentsAuthorizeRouterData>, +    ) -> Result { +        let transaction_type = match item.router_data.request.is_auto_capture()? { +            true => TransactionType::Sale, +            false => TransactionType::Auth, +        }; +        let auth_type: NmiAuthType = (&item.router_data.connector_auth_type).try_into()?; +        let amount = item.amount; +        let payment_method = +            PaymentMethod::try_from(&item.router_data.request.payment_method_data)?; + +        Ok(Self { +            transaction_type, +            security_key: auth_type.api_key, +            amount, +            currency: item.router_data.request.currency, +            payment_method, +            orderid: item.router_data.connector_request_reference_id.clone(), +        }) +    } } impl TryFrom<&api_models::payments::PaymentMethodData> for PaymentMethod { - type Error = Error; - fn try_from( - payment_method_data: &api_models::payments::PaymentMethodData, - ) -> Result { - match &payment_method_data { - api::PaymentMethodData::Card(ref card) => Ok(Self::from(card)), - api::PaymentMethodData::Wallet(ref wallet_type) => match wallet_type { - api_models::payments::WalletData::GooglePay(ref googlepay_data) => { - Ok(Self::from(googlepay_data)) - } - api_models::payments::WalletData::ApplePay(ref applepay_data) => { - Ok(Self::from(applepay_data)) - } - api_models::payments::WalletData::AliPayQr(_) - | api_models::payments::WalletData::AliPayRedirect(_) - | api_models::payments::WalletData::AliPayHkRedirect(_) - | api_models::payments::WalletData::MomoRedirect(_) - | api_models::payments::WalletData::KakaoPayRedirect(_) - | api_models::payments::WalletData::GoPayRedirect(_) - | api_models::payments::WalletData::GcashRedirect(_) - | api_models::payments::WalletData::ApplePayRedirect(_) - | api_models::payments::WalletData::ApplePayThirdPartySdk(_) - | api_models::payments::WalletData::DanaRedirect {} - | api_models::payments::WalletData::GooglePayRedirect(_) - | api_models::payments::WalletData::GooglePayThirdPartySdk(_) - | api_models::payments::WalletData::MbWayRedirect(_) - | api_models::payments::WalletData::MobilePayRedirect(_) - | api_models::payments::WalletData::PaypalRedirect(_) - | api_models::payments::WalletData::PaypalSdk(_) - | api_models::payments::WalletData::SamsungPay(_) - | api_models::payments::WalletData::TwintRedirect {} - | api_models::payments::WalletData::VippsRedirect {} - | api_models::payments::WalletData::TouchNGoRedirect(_) - | api_models::payments::WalletData::WeChatPayRedirect(_) - | api_models::payments::WalletData::WeChatPayQr(_) - | api_models::payments::WalletData::CashappQr(_) - | api_models::payments::WalletData::SwishQr(_) => { - Err(errors::ConnectorError::NotSupported { - message: utils::SELECTED_PAYMENT_METHOD.to_string(), - connector: "nmi", - }) - .into_report() - } - }, - api::PaymentMethodData::CardRedirect(_) - | api::PaymentMethodData::PayLater(_) - | api::PaymentMethodData::BankRedirect(_) - | api::PaymentMethodData::BankDebit(_) - | api::PaymentMethodData::BankTransfer(_) - | api::PaymentMethodData::Crypto(_) - | api::PaymentMethodData::MandatePayment - | api::PaymentMethodData::Reward - | api::PaymentMethodData::Upi(_) - | api::PaymentMethodData::Voucher(_) - | api::PaymentMethodData::GiftCard(_) => Err(errors::ConnectorError::NotSupported { - message: utils::SELECTED_PAYMENT_METHOD.to_string(), - connector: "nmi", - }) - .into_report(), - } - } +    type Error = Error; +    fn try_from( +        payment_method_data: &api_models::payments::PaymentMethodData, +    ) -> Result { +        match &payment_method_data { +            api::PaymentMethodData::Card(ref card) => Ok(Self::from(card)), +            api::PaymentMethodData::Wallet(ref wallet_type) => match wallet_type { +                api_models::payments::WalletData::GooglePay(ref googlepay_data) => { +                    Ok(Self::from(googlepay_data)) +                } +                api_models::payments::WalletData::ApplePay(ref applepay_data) => { +                    Ok(Self::from(applepay_data)) +                } +                api_models::payments::WalletData::AliPayQr(_) +                | api_models::payments::WalletData::AliPayRedirect(_) +                | api_models::payments::WalletData::AliPayHkRedirect(_) +                | api_models::payments::WalletData::MomoRedirect(_) +                | api_models::payments::WalletData::KakaoPayRedirect(_) +                | api_models::payments::WalletData::GoPayRedirect(_) +                | api_models::payments::WalletData::GcashRedirect(_) +                | api_models::payments::WalletData::ApplePayRedirect(_) +                | api_models::payments::WalletData::ApplePayThirdPartySdk(_) +                | api_models::payments::WalletData::DanaRedirect {} +                | api_models::payments::WalletData::GooglePayRedirect(_) +                | api_models::payments::WalletData::GooglePayThirdPartySdk(_) +                | api_models::payments::WalletData::MbWayRedirect(_) +                | api_models::payments::WalletData::MobilePayRedirect(_) +                | api_models::payments::WalletData::PaypalRedirect(_) +                | api_models::payments::WalletData::PaypalSdk(_) +                | api_models::payments::WalletData::SamsungPay(_) +                | api_models::payments::WalletData::TwintRedirect {} +                | api_models::payments::WalletData::VippsRedirect {} +                | api_models::payments::WalletData::TouchNGoRedirect(_) +                | api_models::payments::WalletData::WeChatPayRedirect(_) +                | api_models::payments::WalletData::WeChatPayQr(_) +                | api_models::payments::WalletData::CashappQr(_) +                | api_models::payments::WalletData::SwishQr(_) => { +                    Err(errors::ConnectorError::NotSupported { +                        message: utils::SELECTED_PAYMENT_METHOD.to_string(), +                        connector: "nmi", +                    }) +                    .into_report() +                } +            }, +            api::PaymentMethodData::CardRedirect(_) +            | api::PaymentMethodData::PayLater(_) +            | api::PaymentMethodData::BankRedirect(_) +            | api::PaymentMethodData::BankDebit(_) +            | api::PaymentMethodData::BankTransfer(_) +            | api::PaymentMethodData::Crypto(_) +            | api::PaymentMethodData::MandatePayment +            | api::PaymentMethodData::Reward +            | api::PaymentMethodData::Upi(_) +            | api::PaymentMethodData::Voucher(_) +            | api::PaymentMethodData::GiftCard(_) => Err(errors::ConnectorError::NotSupported { +                message: utils::SELECTED_PAYMENT_METHOD.to_string(), +                connector: "nmi", +            }) +            .into_report(), +        } +    } } impl From<&api_models::payments::Card> for PaymentMethod { - fn from(card: &api_models::payments::Card) -> Self { - let ccexp = utils::CardData::get_card_expiry_month_year_2_digit_with_delimiter( - card, - "".to_string(), - ); - let card = CardData { - ccnumber: card.card_number.clone(), - ccexp, - cvv: card.card_cvc.clone(), - }; - Self::Card(Box::new(card)) - } +    fn from(card: &api_models::payments::Card) -> Self { +        let ccexp = utils::CardData::get_card_expiry_month_year_2_digit_with_delimiter( +            card, +            "".to_string(), +        ); +        let card = CardData { +            ccnumber: card.card_number.clone(), +            ccexp, +            cvv: card.card_cvc.clone(), +        }; +        Self::Card(Box::new(card)) +    } } impl From<&api_models::payments::GooglePayWalletData> for PaymentMethod { - fn from(wallet_data: &api_models::payments::GooglePayWalletData) -> Self { - let gpay_data = GooglePayData { - googlepay_payment_data: Secret::new(wallet_data.tokenization_data.token.clone()), - }; - Self::GPay(Box::new(gpay_data)) - } +    fn from(wallet_data: &api_models::payments::GooglePayWalletData) -> Self { +        let gpay_data = GooglePayData { +            googlepay_payment_data: Secret::new(wallet_data.tokenization_data.token.clone()), +        }; +        Self::GPay(Box::new(gpay_data)) +    } } impl From<&api_models::payments::ApplePayWalletData> for PaymentMethod { - fn from(wallet_data: &api_models::payments::ApplePayWalletData) -> Self { - let apple_pay_data = ApplePayData { - applepay_payment_data: Secret::new(wallet_data.payment_data.clone()), - }; - Self::ApplePay(Box::new(apple_pay_data)) - } +    fn from(wallet_data: &api_models::payments::ApplePayWalletData) -> Self { +        let apple_pay_data = ApplePayData { +            applepay_payment_data: Secret::new(wallet_data.payment_data.clone()), +        }; +        Self::ApplePay(Box::new(apple_pay_data)) +    } } impl TryFrom<&types::SetupMandateRouterData> for NmiPaymentsRequest { - type Error = Error; - fn try_from(item: &types::SetupMandateRouterData) -> Result { - let auth_type: NmiAuthType = (&item.connector_auth_type).try_into()?; - let payment_method = PaymentMethod::try_from(&item.request.payment_method_data)?; - Ok(Self { - transaction_type: TransactionType::Validate, - security_key: auth_type.api_key, - amount: 0.0, - currency: item.request.currency, - payment_method, - orderid: item.connector_request_reference_id.clone(), - }) - } +    type Error = Error; +    fn try_from(item: &types::SetupMandateRouterData) -> Result { +        let auth_type: NmiAuthType = (&item.connector_auth_type).try_into()?; +        let payment_method = PaymentMethod::try_from(&item.request.payment_method_data)?; +        Ok(Self { +            transaction_type: TransactionType::Validate, +            security_key: auth_type.api_key, +            amount: 0.0, +            currency: item.request.currency, +            payment_method, +            orderid: item.connector_request_reference_id.clone(), +        }) +    } } #[derive(Debug, Serialize)] pub struct NmiSyncRequest { - pub transaction_id: String, - pub security_key: Secret, +    pub transaction_id: String, +    pub security_key: Secret, } impl TryFrom<&types::PaymentsSyncRouterData> for NmiSyncRequest { - type Error = Error; - fn try_from(item: &types::PaymentsSyncRouterData) -> Result { - let auth = NmiAuthType::try_from(&item.connector_auth_type)?; - Ok(Self { - security_key: auth.api_key, - transaction_id: item - .request - .connector_transaction_id - .get_connector_transaction_id() - .change_context(errors::ConnectorError::MissingConnectorTransactionID)?, - }) - } +    type Error = Error; +    fn try_from(item: &types::PaymentsSyncRouterData) -> Result { +        let auth = NmiAuthType::try_from(&item.connector_auth_type)?; +        Ok(Self { +            security_key: auth.api_key, +            transaction_id: item +                .request +                .connector_transaction_id +                .get_connector_transaction_id() +                .change_context(errors::ConnectorError::MissingConnectorTransactionID)?, +        }) +    } } #[derive(Debug, Serialize)] pub struct NmiCaptureRequest { - #[serde(rename = "type")] - pub transaction_type: TransactionType, - pub security_key: Secret, - pub transactionid: String, - pub amount: Option, +    #[serde(rename = "type")] +    pub transaction_type: TransactionType, +    pub security_key: Secret, +    pub transactionid: String, +    pub amount: Option, } impl TryFrom<&NmiRouterData<&types::PaymentsCaptureRouterData>> for NmiCaptureRequest { - type Error = Error; - fn try_from( - item: &NmiRouterData<&types::PaymentsCaptureRouterData>, - ) -> Result { - let auth = NmiAuthType::try_from(&item.router_data.connector_auth_type)?; - Ok(Self { - transaction_type: TransactionType::Capture, - security_key: auth.api_key, - transactionid: item.router_data.request.connector_transaction_id.clone(), - amount: Some(item.amount), - }) - } +    type Error = Error; +    fn try_from( +        item: &NmiRouterData<&types::PaymentsCaptureRouterData>, +    ) -> Result { +        let auth = NmiAuthType::try_from(&item.router_data.connector_auth_type)?; +        Ok(Self { +            transaction_type: TransactionType::Capture, +            security_key: auth.api_key, +            transactionid: item.router_data.request.connector_transaction_id.clone(), +            amount: Some(item.amount), +        }) +    } } impl - TryFrom< - types::ResponseRouterData< - api::Capture, - StandardResponse, - types::PaymentsCaptureData, - types::PaymentsResponseData, - >, - > for types::RouterData +    TryFrom< +        types::ResponseRouterData< +            api::Capture, +            StandardResponse, +            types::PaymentsCaptureData, +            types::PaymentsResponseData, +        >, +    > for types::RouterData { - type Error = Error; - fn try_from( - item: types::ResponseRouterData< - api::Capture, - StandardResponse, - types::PaymentsCaptureData, - types::PaymentsResponseData, - >, - ) -> Result { - let (response, status) = match item.response.response { - Response::Approved => ( - Ok(types::PaymentsResponseData::TransactionResponse { - resource_id: types::ResponseId::ConnectorTransactionId( - item.response.transactionid.clone(), - ), - redirection_data: None, - mandate_reference: None, - connector_metadata: None, - network_txn_id: None, - connector_response_reference_id: item.response.orderid.or(Some(item.response.transactionid)), - }), - enums::AttemptStatus::CaptureInitiated, - ), - Response::Declined | Response::Error => ( - Err(types::ErrorResponse::foreign_from(( - item.response, - item.http_code, - ))), - enums::AttemptStatus::CaptureFailed, - ), - }; - Ok(Self { - status, - response, - ..item.data - }) - } +    type Error = Error; +    fn try_from( +        item: types::ResponseRouterData< +            api::Capture, +            StandardResponse, +            types::PaymentsCaptureData, +            types::PaymentsResponseData, +        >, +    ) -> Result { +        let (response, status) = match item.response.response { +            Response::Approved => ( +                Ok(types::PaymentsResponseData::TransactionResponse { +                    resource_id: types::ResponseId::ConnectorTransactionId( +                        item.response.transactionid.clone(), +                    ), +                    redirection_data: None, +                    mandate_reference: None, +                    connector_metadata: None, +                    network_txn_id: None, +                    connector_response_reference_id: item +                        .response +                        .orderid +                        .or(Some(item.response.transactionid)), +                }), +                enums::AttemptStatus::CaptureInitiated, +            ), +            Response::Declined | Response::Error => ( +                Err(types::ErrorResponse::foreign_from(( +                    item.response, +                    item.http_code, +                ))), +                enums::AttemptStatus::CaptureFailed, +            ), +        }; +        Ok(Self { +            status, +            response, +            ..item.data +        }) +    } } #[derive(Debug, Serialize)] pub struct NmiCancelRequest { - #[serde(rename = "type")] - pub transaction_type: TransactionType, - pub security_key: Secret, - pub transactionid: String, - pub void_reason: Option, +    #[serde(rename = "type")] +    pub transaction_type: TransactionType, +    pub security_key: Secret, +    pub transactionid: String, +    pub void_reason: Option, } impl TryFrom<&types::PaymentsCancelRouterData> for NmiCancelRequest { - type Error = Error; - fn try_from(item: &types::PaymentsCancelRouterData) -> Result { - let auth = NmiAuthType::try_from(&item.connector_auth_type)?; - Ok(Self { - transaction_type: TransactionType::Void, - security_key: auth.api_key, - transactionid: item.request.connector_transaction_id.clone(), - void_reason: item.request.cancellation_reason.clone(), - }) - } +    type Error = Error; +    fn try_from(item: &types::PaymentsCancelRouterData) -> Result { +        let auth = NmiAuthType::try_from(&item.connector_auth_type)?; +        Ok(Self { +            transaction_type: TransactionType::Void, +            security_key: auth.api_key, +            transactionid: item.request.connector_transaction_id.clone(), +            void_reason: item.request.cancellation_reason.clone(), +        }) +    } } #[derive(Debug, Deserialize)] pub enum Response { - #[serde(alias = "1")] - Approved, - #[serde(alias = "2")] - Declined, - #[serde(alias = "3")] - Error, +    #[serde(alias = "1")] +    Approved, +    #[serde(alias = "2")] +    Declined, +    #[serde(alias = "3")] +    Error, } #[derive(Debug, Deserialize)] pub struct StandardResponse { - pub response: Response, - pub responsetext: String, - pub authcode: Option, - pub transactionid: String, - pub avsresponse: Option, - pub cvvresponse: Option, - pub orderid: Option, - pub response_code: String, +    pub response: Response, +    pub responsetext: String, +    pub authcode: Option, +    pub transactionid: String, +    pub avsresponse: Option, +    pub cvvresponse: Option, +    pub orderid: Option, +    pub response_code: String, } impl - TryFrom< - types::ResponseRouterData< - api::SetupMandate, - StandardResponse, - T, - types::PaymentsResponseData, - >, - > for types::RouterData +    TryFrom< +        types::ResponseRouterData< +            api::SetupMandate, +            StandardResponse, +            T, +            types::PaymentsResponseData, +        >, +    > for types::RouterData { - type Error = Error; - fn try_from( - item: types::ResponseRouterData< - api::SetupMandate, - StandardResponse, - T, - types::PaymentsResponseData, - >, - ) -> Result { - let (response, status) = match item.response.response { - Response::Approved => ( - Ok(types::PaymentsResponseData::TransactionResponse { - resource_id: types::ResponseId::ConnectorTransactionId( - item.response.transactionid.clone(), - ), - redirection_data: None, - mandate_reference: None, - connector_metadata: None, - network_txn_id: None, - connector_response_reference_id: item.response.orderid.or(Some(item.response.transactionid)), - }), - enums::AttemptStatus::Charged, - ), - Response::Declined | Response::Error => ( - Err(types::ErrorResponse::foreign_from(( - item.response, - item.http_code, - ))), - enums::AttemptStatus::Failure, - ), - }; - Ok(Self { - status, - response, - ..item.data - }) - } +    type Error = Error; +    fn try_from( +        item: types::ResponseRouterData< +            api::SetupMandate, +            StandardResponse, +            T, +            types::PaymentsResponseData, +        >, +    ) -> Result { +        let (response, status) = match item.response.response { +            Response::Approved => ( +                Ok(types::PaymentsResponseData::TransactionResponse { +                    resource_id: types::ResponseId::ConnectorTransactionId( +                        item.response.transactionid.clone(), +                    ), +                    redirection_data: None, +                    mandate_reference: None, +                    connector_metadata: None, +                    network_txn_id: None, +                    connector_response_reference_id: item +                        .response +                        .orderid +                        .or(Some(item.response.transactionid)), +                }), +                enums::AttemptStatus::Charged, +            ), +            Response::Declined | Response::Error => ( +                Err(types::ErrorResponse::foreign_from(( +                    item.response, +                    item.http_code, +                ))), +                enums::AttemptStatus::Failure, +            ), +        }; +        Ok(Self { +            status, +            response, +            ..item.data +        }) +    } } impl ForeignFrom<(StandardResponse, u16)> for types::ErrorResponse { - fn foreign_from((response, http_code): (StandardResponse, u16)) -> Self { - Self { - code: response.response_code, - message: response.responsetext, - reason: None, - status_code: http_code, - attempt_status: None, - } - } +    fn foreign_from((response, http_code): (StandardResponse, u16)) -> Self { +        Self { +            code: response.response_code, +            message: response.responsetext, +            reason: None, +            status_code: http_code, +            attempt_status: None, +        } +    } } impl TryFrom> - for types::RouterData +    for types::RouterData { - type Error = Error; - fn try_from( - item: types::ResponseRouterData< - api::Authorize, - StandardResponse, - types::PaymentsAuthorizeData, - types::PaymentsResponseData, - >, - ) -> Result { - let (response, status) = match item.response.response { - Response::Approved => ( - Ok(types::PaymentsResponseData::TransactionResponse { - resource_id: types::ResponseId::ConnectorTransactionId( - item.response.transactionid.clone(), - ), - redirection_data: None, - mandate_reference: None, - connector_metadata: None, - network_txn_id: None, - connector_response_reference_id: item.response.orderid.or(Some(item.response.transactionid)), - }), - if let Some(diesel_models::enums::CaptureMethod::Automatic) = - item.data.request.capture_method - { - enums::AttemptStatus::CaptureInitiated - } else { - enums::AttemptStatus::Authorizing - }, - ), - Response::Declined | Response::Error => ( - Err(types::ErrorResponse::foreign_from(( - item.response, - item.http_code, - ))), - enums::AttemptStatus::Failure, - ), - }; - Ok(Self { - status, - response, - ..item.data - }) - } +    type Error = Error; +    fn try_from( +        item: types::ResponseRouterData< +            api::Authorize, +            StandardResponse, +            types::PaymentsAuthorizeData, +            types::PaymentsResponseData, +        >, +    ) -> Result { +        let (response, status) = match item.response.response { +            Response::Approved => ( +                Ok(types::PaymentsResponseData::TransactionResponse { +                    resource_id: types::ResponseId::ConnectorTransactionId( +                        item.response.transactionid.clone(), +                    ), +                    redirection_data: None, +                    mandate_reference: None, +                    connector_metadata: None, +                    network_txn_id: None, +                    connector_response_reference_id: item +                        .response +                        .orderid +                        .or(Some(item.response.transactionid)), +                }), +                if let Some(diesel_models::enums::CaptureMethod::Automatic) = +                    item.data.request.capture_method +                { +                    enums::AttemptStatus::CaptureInitiated +                } else { +                    enums::AttemptStatus::Authorizing +                }, +            ), +            Response::Declined | Response::Error => ( +                Err(types::ErrorResponse::foreign_from(( +                    item.response, +                    item.http_code, +                ))), +                enums::AttemptStatus::Failure, +            ), +        }; +        Ok(Self { +            status, +            response, +            ..item.data +        }) +    } } impl - TryFrom> - for types::RouterData +    TryFrom> +    for types::RouterData { - type Error = Error; - fn try_from( - item: types::ResponseRouterData< - api::Void, - StandardResponse, - T, - types::PaymentsResponseData, - >, - ) -> Result { - let (response, status) = match item.response.response { - Response::Approved => ( - Ok(types::PaymentsResponseData::TransactionResponse { - resource_id: types::ResponseId::ConnectorTransactionId( - item.response.transactionid.clone(), - ), - redirection_data: None, - mandate_reference: None, - connector_metadata: None, - network_txn_id: None, - connector_response_reference_id: item.response.orderid.or(Some(item.response.transactionid)), - }), - enums::AttemptStatus::VoidInitiated, - ), - Response::Declined | Response::Error => ( - Err(types::ErrorResponse::foreign_from(( - item.response, - item.http_code, - ))), - enums::AttemptStatus::VoidFailed, - ), - }; - Ok(Self { - status, - response, - ..item.data - }) - } +    type Error = Error; +    fn try_from( +        item: types::ResponseRouterData< +            api::Void, +            StandardResponse, +            T, +            types::PaymentsResponseData, +        >, +    ) -> Result { +        let (response, status) = match item.response.response { +            Response::Approved => ( +                Ok(types::PaymentsResponseData::TransactionResponse { +                    resource_id: types::ResponseId::ConnectorTransactionId( +                        item.response.transactionid.clone(), +                    ), +                    redirection_data: None, +                    mandate_reference: None, +                    connector_metadata: None, +                    network_txn_id: None, +                    connector_response_reference_id: item +                        .response +                        .orderid +                        .or(Some(item.response.transactionid)), +                }), +                enums::AttemptStatus::VoidInitiated, +            ), +            Response::Declined | Response::Error => ( +                Err(types::ErrorResponse::foreign_from(( +                    item.response, +                    item.http_code, +                ))), +                enums::AttemptStatus::VoidFailed, +            ), +        }; +        Ok(Self { +            status, +            response, +            ..item.data +        }) +    } } #[derive(Debug, Deserialize)] #[serde(rename_all = "snake_case")] pub enum NmiStatus { - Abandoned, - Cancelled, - Pendingsettlement, - Pending, - Failed, - Complete, - InProgress, - Unknown, +    Abandoned, +    Cancelled, +    Pendingsettlement, +    Pending, +    Failed, +    Complete, +    InProgress, +    Unknown, } impl TryFrom> - for types::PaymentsSyncRouterData +    for types::PaymentsSyncRouterData { - type Error = Error; - fn try_from( - item: types::PaymentsSyncResponseRouterData, - ) -> Result { - let response = SyncResponse::try_from(item.response.response.to_vec())?; - Ok(Self { - status: enums::AttemptStatus::from(NmiStatus::from(response.transaction.condition)), - response: Ok(types::PaymentsResponseData::TransactionResponse { - resource_id: types::ResponseId::ConnectorTransactionId( - response.transaction.transaction_id.clone(), - ), - redirection_data: None, - mandate_reference: None, - connector_metadata: None, - network_txn_id: None, - connector_response_reference_id: None, - }), - ..item.data - }) - } +    type Error = Error; +    fn try_from( +        item: types::PaymentsSyncResponseRouterData, +    ) -> Result { +        let response = SyncResponse::try_from(item.response.response.to_vec())?; +        Ok(Self { +            status: enums::AttemptStatus::from(NmiStatus::from(response.transaction.condition)), +            response: Ok(types::PaymentsResponseData::TransactionResponse { +                resource_id: types::ResponseId::ConnectorTransactionId( +                    response.transaction.transaction_id.clone(), +                ), +                redirection_data: None, +                mandate_reference: None, +                connector_metadata: None, +                network_txn_id: None, +                connector_response_reference_id: None, +            }), +            ..item.data +        }) +    } } impl TryFrom> for SyncResponse { - type Error = Error; - fn try_from(bytes: Vec) -> Result { - let query_response = String::from_utf8(bytes) - .into_report() - .change_context(errors::ConnectorError::ResponseDeserializationFailed)?; - query_response - .parse_xml::() - .into_report() - .change_context(errors::ConnectorError::ResponseDeserializationFailed) - } +    type Error = Error; +    fn try_from(bytes: Vec) -> Result { +        let query_response = String::from_utf8(bytes) +            .into_report() +            .change_context(errors::ConnectorError::ResponseDeserializationFailed)?; +        query_response +            .parse_xml::() +            .into_report() +            .change_context(errors::ConnectorError::ResponseDeserializationFailed) +    } } impl From for enums::AttemptStatus { - fn from(item: NmiStatus) -> Self { - match item { - NmiStatus::Abandoned => Self::AuthenticationFailed, - NmiStatus::Cancelled => Self::Voided, - NmiStatus::Pending => Self::Authorized, - NmiStatus::Pendingsettlement | NmiStatus::Complete => Self::Charged, - NmiStatus::InProgress => Self::AuthenticationPending, - NmiStatus::Failed | NmiStatus::Unknown => Self::Failure, - } - } +    fn from(item: NmiStatus) -> Self { +        match item { +            NmiStatus::Abandoned => Self::AuthenticationFailed, +            NmiStatus::Cancelled => Self::Voided, +            NmiStatus::Pending => Self::Authorized, +            NmiStatus::Pendingsettlement | NmiStatus::Complete => Self::Charged, +            NmiStatus::InProgress => Self::AuthenticationPending, +            NmiStatus::Failed | NmiStatus::Unknown => Self::Failure, +        } +    } } // REFUND : #[derive(Debug, Serialize)] pub struct NmiRefundRequest { - #[serde(rename = "type")] - transaction_type: TransactionType, - security_key: Secret, - transactionid: String, - amount: f64, +    #[serde(rename = "type")] +    transaction_type: TransactionType, +    security_key: Secret, +    transactionid: String, +    amount: f64, } impl TryFrom<&NmiRouterData<&types::RefundsRouterData>> for NmiRefundRequest { - type Error = Error; - fn try_from(item: &NmiRouterData<&types::RefundsRouterData>) -> Result { - let auth_type: NmiAuthType = (&item.router_data.connector_auth_type).try_into()?; - Ok(Self { - transaction_type: TransactionType::Refund, - security_key: auth_type.api_key, - transactionid: item.router_data.request.connector_transaction_id.clone(), - amount: item.amount, - }) - } +    type Error = Error; +    fn try_from(item: &NmiRouterData<&types::RefundsRouterData>) -> Result { +        let auth_type: NmiAuthType = (&item.router_data.connector_auth_type).try_into()?; +        Ok(Self { +            transaction_type: TransactionType::Refund, +            security_key: auth_type.api_key, +            transactionid: item.router_data.request.connector_transaction_id.clone(), +            amount: item.amount, +        }) +    } } impl TryFrom> - for types::RefundsRouterData +    for types::RefundsRouterData { - type Error = Error; - fn try_from( - item: types::RefundsResponseRouterData, - ) -> Result { - let refund_status = enums::RefundStatus::from(item.response.response); - Ok(Self { - response: Ok(types::RefundsResponseData { - connector_refund_id: item.response.transactionid, - refund_status, - }), - ..item.data - }) - } +    type Error = Error; +    fn try_from( +        item: types::RefundsResponseRouterData, +    ) -> Result { +        let refund_status = enums::RefundStatus::from(item.response.response); +        Ok(Self { +            response: Ok(types::RefundsResponseData { +                connector_refund_id: item.response.transactionid, +                refund_status, +            }), +            ..item.data +        }) +    } } impl TryFrom> - for types::RefundsRouterData +    for types::RefundsRouterData { - type Error = Error; - fn try_from( - item: types::RefundsResponseRouterData, - ) -> Result { - let refund_status = enums::RefundStatus::from(item.response.response); - Ok(Self { - response: Ok(types::RefundsResponseData { - connector_refund_id: item.response.transactionid, - refund_status, - }), - ..item.data - }) - } +    type Error = Error; +    fn try_from( +        item: types::RefundsResponseRouterData, +    ) -> Result { +        let refund_status = enums::RefundStatus::from(item.response.response); +        Ok(Self { +            response: Ok(types::RefundsResponseData { +                connector_refund_id: item.response.transactionid, +                refund_status, +            }), +            ..item.data +        }) +    } } impl From for enums::RefundStatus { - fn from(item: Response) -> Self { - match item { - Response::Approved => Self::Pending, - Response::Declined | Response::Error => Self::Failure, - } - } +    fn from(item: Response) -> Self { +        match item { +            Response::Approved => Self::Pending, +            Response::Declined | Response::Error => Self::Failure, +        } +    } } impl TryFrom<&types::RefundSyncRouterData> for NmiSyncRequest { - type Error = Error; - fn try_from(item: &types::RefundSyncRouterData) -> Result { - let auth = NmiAuthType::try_from(&item.connector_auth_type)?; - let transaction_id = item - .request - .connector_refund_id - .clone() - .ok_or(errors::ConnectorError::MissingConnectorRefundID)?; - - Ok(Self { - security_key: auth.api_key, - transaction_id, - }) - } +    type Error = Error; +    fn try_from(item: &types::RefundSyncRouterData) -> Result { +        let auth = NmiAuthType::try_from(&item.connector_auth_type)?; +        let transaction_id = item +            .request +            .connector_refund_id +            .clone() +            .ok_or(errors::ConnectorError::MissingConnectorRefundID)?; + +        Ok(Self { +            security_key: auth.api_key, +            transaction_id, +        }) +    } } impl TryFrom> - for types::RefundsRouterData +    for types::RefundsRouterData { - type Error = Error; - fn try_from( - item: types::RefundsResponseRouterData, - ) -> Result { - let response = SyncResponse::try_from(item.response.response.to_vec())?; - let refund_status = - enums::RefundStatus::from(NmiStatus::from(response.transaction.condition)); - Ok(Self { - response: Ok(types::RefundsResponseData { - connector_refund_id: response.transaction.transaction_id, - refund_status, - }), - ..item.data - }) - } +    type Error = Error; +    fn try_from( +        item: types::RefundsResponseRouterData, +    ) -> Result { +        let response = SyncResponse::try_from(item.response.response.to_vec())?; +        let refund_status = +            enums::RefundStatus::from(NmiStatus::from(response.transaction.condition)); +        Ok(Self { +            response: Ok(types::RefundsResponseData { +                connector_refund_id: response.transaction.transaction_id, +                refund_status, +            }), +            ..item.data +        }) +    } } impl From for enums::RefundStatus { - fn from(item: NmiStatus) -> Self { - match item { - NmiStatus::Abandoned - | NmiStatus::Cancelled - | NmiStatus::Failed - | NmiStatus::Unknown => Self::Failure, - NmiStatus::Pending | NmiStatus::InProgress => Self::Pending, - NmiStatus::Pendingsettlement | NmiStatus::Complete => Self::Success, - } - } +    fn from(item: NmiStatus) -> Self { +        match item { +            NmiStatus::Abandoned +            | NmiStatus::Cancelled +            | NmiStatus::Failed +            | NmiStatus::Unknown => Self::Failure, +            NmiStatus::Pending | NmiStatus::InProgress => Self::Pending, +            NmiStatus::Pendingsettlement | NmiStatus::Complete => Self::Success, +        } +    } } impl From for NmiStatus { - fn from(value: String) -> Self { - match value.as_str() { - "abandoned" => Self::Abandoned, - "canceled" => Self::Cancelled, - "in_progress" => Self::InProgress, - "pendingsettlement" => Self::Pendingsettlement, - "complete" => Self::Complete, - "failed" => Self::Failed, - "unknown" => Self::Unknown, - // Other than above values only pending is possible, since value is a string handling this as default - _ => Self::Pending, - } - } +    fn from(value: String) -> Self { +        match value.as_str() { +            "abandoned" => Self::Abandoned, +            "canceled" => Self::Cancelled, +            "in_progress" => Self::InProgress, +            "pendingsettlement" => Self::Pendingsettlement, +            "complete" => Self::Complete, +            "failed" => Self::Failed, +            "unknown" => Self::Unknown, +            // Other than above values only pending is possible, since value is a string handling this as default +            _ => Self::Pending, +        } +    } } #[derive(Debug, Deserialize)] pub struct SyncTransactionResponse { - transaction_id: String, - condition: String, +    transaction_id: String, +    condition: String, } #[derive(Debug, Deserialize)] struct SyncResponse { - transaction: SyncTransactionResponse, +    transaction: SyncTransactionResponse, } From f4a1f6d2cf8a9f95ac3c8f2456b519db0aa7d567 Mon Sep 17 00:00:00 2001 From: Tejas Mate Date: Sun, 12 Nov 2023 03:13:29 +0530 Subject: [PATCH 11/12] Update transformers.rs --- .../router/src/connector/nmi/transformers.rs | 1174 ++++++++--------- 1 file changed, 587 insertions(+), 587 deletions(-) diff --git a/crates/router/src/connector/nmi/transformers.rs b/crates/router/src/connector/nmi/transformers.rs index 9afd53008e42..b121f7806f2c 100644 --- a/crates/router/src/connector/nmi/transformers.rs +++ b/crates/router/src/connector/nmi/transformers.rs @@ -5,9 +5,9 @@ use masking::Secret; use serde::{Deserialize, Serialize}; use crate::{ -    connector::utils::{self, PaymentsAuthorizeRequestData}, -    core::errors, -    types::{self, api, storage::enums, transformers::ForeignFrom, ConnectorAuthType}, + connector::utils::{self, PaymentsAuthorizeRequestData}, + core::errors, + types::{self, api, storage::enums, transformers::ForeignFrom, ConnectorAuthType}, }; type Error = Report; @@ -15,744 +15,744 @@ type Error = Report; #[derive(Debug, Serialize)] #[serde(rename_all = "lowercase")] pub enum TransactionType { -    Auth, -    Capture, -    Refund, -    Sale, -    Validate, -    Void, + Auth, + Capture, + Refund, + Sale, + Validate, + Void, } pub struct NmiAuthType { -    pub(super) api_key: Secret, + pub(super) api_key: Secret, } impl TryFrom<&ConnectorAuthType> for NmiAuthType { -    type Error = Error; -    fn try_from(auth_type: &ConnectorAuthType) -> Result { -        if let types::ConnectorAuthType::HeaderKey { api_key } = auth_type { -            Ok(Self { -                api_key: api_key.to_owned(), -            }) -        } else { -            Err(errors::ConnectorError::FailedToObtainAuthType.into()) -        } -    } + type Error = Error; + fn try_from(auth_type: &ConnectorAuthType) -> Result { + if let types::ConnectorAuthType::HeaderKey { api_key } = auth_type { + Ok(Self { + api_key: api_key.to_owned(), + }) + } else { + Err(errors::ConnectorError::FailedToObtainAuthType.into()) + } + } } #[derive(Debug, Serialize)] pub struct NmiRouterData { -    pub amount: f64, -    pub router_data: T, + pub amount: f64, + pub router_data: T, } impl -    TryFrom<( -        &types::api::CurrencyUnit, -        types::storage::enums::Currency, -        i64, -        T, -    )> for NmiRouterData + TryFrom<( + &types::api::CurrencyUnit, + types::storage::enums::Currency, + i64, + T, + )> for NmiRouterData { -    type Error = Report; - -    fn try_from( -        (_currency_unit, currency, amount, router_data): ( -            &types::api::CurrencyUnit, -            types::storage::enums::Currency, -            i64, -            T, -        ), -    ) -> Result { -        Ok(Self { -            amount: utils::to_currency_base_unit_asf64(amount, currency)?, -            router_data, -        }) -    } + type Error = Report; + + fn try_from( + (_currency_unit, currency, amount, router_data): ( + &types::api::CurrencyUnit, + types::storage::enums::Currency, + i64, + T, + ), + ) -> Result { + Ok(Self { + amount: utils::to_currency_base_unit_asf64(amount, currency)?, + router_data, + }) + } } #[derive(Debug, Serialize)] pub struct NmiPaymentsRequest { -    #[serde(rename = "type")] -    transaction_type: TransactionType, -    amount: f64, -    security_key: Secret, -    currency: enums::Currency, -    #[serde(flatten)] -    payment_method: PaymentMethod, -    orderid: String, + #[serde(rename = "type")] + transaction_type: TransactionType, + amount: f64, + security_key: Secret, + currency: enums::Currency, + #[serde(flatten)] + payment_method: PaymentMethod, + orderid: String, } #[derive(Debug, Serialize)] #[serde(untagged)] pub enum PaymentMethod { -    Card(Box), -    GPay(Box), -    ApplePay(Box), + Card(Box), + GPay(Box), + ApplePay(Box), } #[derive(Debug, Serialize)] pub struct CardData { -    ccnumber: CardNumber, -    ccexp: Secret, -    cvv: Secret, + ccnumber: CardNumber, + ccexp: Secret, + cvv: Secret, } #[derive(Debug, Serialize)] pub struct GooglePayData { -    googlepay_payment_data: Secret, + googlepay_payment_data: Secret, } #[derive(Debug, Serialize)] pub struct ApplePayData { -    applepay_payment_data: Secret, + applepay_payment_data: Secret, } impl TryFrom<&NmiRouterData<&types::PaymentsAuthorizeRouterData>> for NmiPaymentsRequest { -    type Error = Error; -    fn try_from( -        item: &NmiRouterData<&types::PaymentsAuthorizeRouterData>, -    ) -> Result { -        let transaction_type = match item.router_data.request.is_auto_capture()? { -            true => TransactionType::Sale, -            false => TransactionType::Auth, -        }; -        let auth_type: NmiAuthType = (&item.router_data.connector_auth_type).try_into()?; -        let amount = item.amount; -        let payment_method = -            PaymentMethod::try_from(&item.router_data.request.payment_method_data)?; - -        Ok(Self { -            transaction_type, -            security_key: auth_type.api_key, -            amount, -            currency: item.router_data.request.currency, -            payment_method, -            orderid: item.router_data.connector_request_reference_id.clone(), -        }) -    } + type Error = Error; + fn try_from( + item: &NmiRouterData<&types::PaymentsAuthorizeRouterData>, + ) -> Result { + let transaction_type = match item.router_data.request.is_auto_capture()? { + true => TransactionType::Sale, + false => TransactionType::Auth, + }; + let auth_type: NmiAuthType = (&item.router_data.connector_auth_type).try_into()?; + let amount = item.amount; + let payment_method = + PaymentMethod::try_from(&item.router_data.request.payment_method_data)?; + + Ok(Self { + transaction_type, + security_key: auth_type.api_key, + amount, + currency: item.router_data.request.currency, + payment_method, + orderid: item.router_data.connector_request_reference_id.clone(), + }) + } } impl TryFrom<&api_models::payments::PaymentMethodData> for PaymentMethod { -    type Error = Error; -    fn try_from( -        payment_method_data: &api_models::payments::PaymentMethodData, -    ) -> Result { -        match &payment_method_data { -            api::PaymentMethodData::Card(ref card) => Ok(Self::from(card)), -            api::PaymentMethodData::Wallet(ref wallet_type) => match wallet_type { -                api_models::payments::WalletData::GooglePay(ref googlepay_data) => { -                    Ok(Self::from(googlepay_data)) -                } -                api_models::payments::WalletData::ApplePay(ref applepay_data) => { -                    Ok(Self::from(applepay_data)) -                } -                api_models::payments::WalletData::AliPayQr(_) -                | api_models::payments::WalletData::AliPayRedirect(_) -                | api_models::payments::WalletData::AliPayHkRedirect(_) -                | api_models::payments::WalletData::MomoRedirect(_) -                | api_models::payments::WalletData::KakaoPayRedirect(_) -                | api_models::payments::WalletData::GoPayRedirect(_) -                | api_models::payments::WalletData::GcashRedirect(_) -                | api_models::payments::WalletData::ApplePayRedirect(_) -                | api_models::payments::WalletData::ApplePayThirdPartySdk(_) -                | api_models::payments::WalletData::DanaRedirect {} -                | api_models::payments::WalletData::GooglePayRedirect(_) -                | api_models::payments::WalletData::GooglePayThirdPartySdk(_) -                | api_models::payments::WalletData::MbWayRedirect(_) -                | api_models::payments::WalletData::MobilePayRedirect(_) -                | api_models::payments::WalletData::PaypalRedirect(_) -                | api_models::payments::WalletData::PaypalSdk(_) -                | api_models::payments::WalletData::SamsungPay(_) -                | api_models::payments::WalletData::TwintRedirect {} -                | api_models::payments::WalletData::VippsRedirect {} -                | api_models::payments::WalletData::TouchNGoRedirect(_) -                | api_models::payments::WalletData::WeChatPayRedirect(_) -                | api_models::payments::WalletData::WeChatPayQr(_) -                | api_models::payments::WalletData::CashappQr(_) -                | api_models::payments::WalletData::SwishQr(_) => { -                    Err(errors::ConnectorError::NotSupported { -                        message: utils::SELECTED_PAYMENT_METHOD.to_string(), -                        connector: "nmi", -                    }) -                    .into_report() -                } -            }, -            api::PaymentMethodData::CardRedirect(_) -            | api::PaymentMethodData::PayLater(_) -            | api::PaymentMethodData::BankRedirect(_) -            | api::PaymentMethodData::BankDebit(_) -            | api::PaymentMethodData::BankTransfer(_) -            | api::PaymentMethodData::Crypto(_) -            | api::PaymentMethodData::MandatePayment -            | api::PaymentMethodData::Reward -            | api::PaymentMethodData::Upi(_) -            | api::PaymentMethodData::Voucher(_) -            | api::PaymentMethodData::GiftCard(_) => Err(errors::ConnectorError::NotSupported { -                message: utils::SELECTED_PAYMENT_METHOD.to_string(), -                connector: "nmi", -            }) -            .into_report(), -        } -    } + type Error = Error; + fn try_from( + payment_method_data: &api_models::payments::PaymentMethodData, + ) -> Result { + match &payment_method_data { + api::PaymentMethodData::Card(ref card) => Ok(Self::from(card)), + api::PaymentMethodData::Wallet(ref wallet_type) => match wallet_type { + api_models::payments::WalletData::GooglePay(ref googlepay_data) => { + Ok(Self::from(googlepay_data)) + } + api_models::payments::WalletData::ApplePay(ref applepay_data) => { + Ok(Self::from(applepay_data)) + } + api_models::payments::WalletData::AliPayQr(_) + | api_models::payments::WalletData::AliPayRedirect(_) + | api_models::payments::WalletData::AliPayHkRedirect(_) + | api_models::payments::WalletData::MomoRedirect(_) + | api_models::payments::WalletData::KakaoPayRedirect(_) + | api_models::payments::WalletData::GoPayRedirect(_) + | api_models::payments::WalletData::GcashRedirect(_) + | api_models::payments::WalletData::ApplePayRedirect(_) + | api_models::payments::WalletData::ApplePayThirdPartySdk(_) + | api_models::payments::WalletData::DanaRedirect {} + | api_models::payments::WalletData::GooglePayRedirect(_) + | api_models::payments::WalletData::GooglePayThirdPartySdk(_) + | api_models::payments::WalletData::MbWayRedirect(_) + | api_models::payments::WalletData::MobilePayRedirect(_) + | api_models::payments::WalletData::PaypalRedirect(_) + | api_models::payments::WalletData::PaypalSdk(_) + | api_models::payments::WalletData::SamsungPay(_) + | api_models::payments::WalletData::TwintRedirect {} + | api_models::payments::WalletData::VippsRedirect {} + | api_models::payments::WalletData::TouchNGoRedirect(_) + | api_models::payments::WalletData::WeChatPayRedirect(_) + | api_models::payments::WalletData::WeChatPayQr(_) + | api_models::payments::WalletData::CashappQr(_) + | api_models::payments::WalletData::SwishQr(_) => { + Err(errors::ConnectorError::NotSupported { + message: utils::SELECTED_PAYMENT_METHOD.to_string(), + connector: "nmi", + }) + .into_report() + } + }, + api::PaymentMethodData::CardRedirect(_) + | api::PaymentMethodData::PayLater(_) + | api::PaymentMethodData::BankRedirect(_) + | api::PaymentMethodData::BankDebit(_) + | api::PaymentMethodData::BankTransfer(_) + | api::PaymentMethodData::Crypto(_) + | api::PaymentMethodData::MandatePayment + | api::PaymentMethodData::Reward + | api::PaymentMethodData::Upi(_) + | api::PaymentMethodData::Voucher(_) + | api::PaymentMethodData::GiftCard(_) => Err(errors::ConnectorError::NotSupported { + message: utils::SELECTED_PAYMENT_METHOD.to_string(), + connector: "nmi", + }) + .into_report(), + } + } } impl From<&api_models::payments::Card> for PaymentMethod { -    fn from(card: &api_models::payments::Card) -> Self { -        let ccexp = utils::CardData::get_card_expiry_month_year_2_digit_with_delimiter( -            card, -            "".to_string(), -        ); -        let card = CardData { -            ccnumber: card.card_number.clone(), -            ccexp, -            cvv: card.card_cvc.clone(), -        }; -        Self::Card(Box::new(card)) -    } + fn from(card: &api_models::payments::Card) -> Self { + let ccexp = utils::CardData::get_card_expiry_month_year_2_digit_with_delimiter( + card, + "".to_string(), + ); + let card = CardData { + ccnumber: card.card_number.clone(), + ccexp, + cvv: card.card_cvc.clone(), + }; + Self::Card(Box::new(card)) + } } impl From<&api_models::payments::GooglePayWalletData> for PaymentMethod { -    fn from(wallet_data: &api_models::payments::GooglePayWalletData) -> Self { -        let gpay_data = GooglePayData { -            googlepay_payment_data: Secret::new(wallet_data.tokenization_data.token.clone()), -        }; -        Self::GPay(Box::new(gpay_data)) -    } + fn from(wallet_data: &api_models::payments::GooglePayWalletData) -> Self { + let gpay_data = GooglePayData { + googlepay_payment_data: Secret::new(wallet_data.tokenization_data.token.clone()), + }; + Self::GPay(Box::new(gpay_data)) + } } impl From<&api_models::payments::ApplePayWalletData> for PaymentMethod { -    fn from(wallet_data: &api_models::payments::ApplePayWalletData) -> Self { -        let apple_pay_data = ApplePayData { -            applepay_payment_data: Secret::new(wallet_data.payment_data.clone()), -        }; -        Self::ApplePay(Box::new(apple_pay_data)) -    } + fn from(wallet_data: &api_models::payments::ApplePayWalletData) -> Self { + let apple_pay_data = ApplePayData { + applepay_payment_data: Secret::new(wallet_data.payment_data.clone()), + }; + Self::ApplePay(Box::new(apple_pay_data)) + } } impl TryFrom<&types::SetupMandateRouterData> for NmiPaymentsRequest { -    type Error = Error; -    fn try_from(item: &types::SetupMandateRouterData) -> Result { -        let auth_type: NmiAuthType = (&item.connector_auth_type).try_into()?; -        let payment_method = PaymentMethod::try_from(&item.request.payment_method_data)?; -        Ok(Self { -            transaction_type: TransactionType::Validate, -            security_key: auth_type.api_key, -            amount: 0.0, -            currency: item.request.currency, -            payment_method, -            orderid: item.connector_request_reference_id.clone(), -        }) -    } + type Error = Error; + fn try_from(item: &types::SetupMandateRouterData) -> Result { + let auth_type: NmiAuthType = (&item.connector_auth_type).try_into()?; + let payment_method = PaymentMethod::try_from(&item.request.payment_method_data)?; + Ok(Self { + transaction_type: TransactionType::Validate, + security_key: auth_type.api_key, + amount: 0.0, + currency: item.request.currency, + payment_method, + orderid: item.connector_request_reference_id.clone(), + }) + } } #[derive(Debug, Serialize)] pub struct NmiSyncRequest { -    pub transaction_id: String, -    pub security_key: Secret, + pub transaction_id: String, + pub security_key: Secret, } impl TryFrom<&types::PaymentsSyncRouterData> for NmiSyncRequest { -    type Error = Error; -    fn try_from(item: &types::PaymentsSyncRouterData) -> Result { -        let auth = NmiAuthType::try_from(&item.connector_auth_type)?; -        Ok(Self { -            security_key: auth.api_key, -            transaction_id: item -                .request -                .connector_transaction_id -                .get_connector_transaction_id() -                .change_context(errors::ConnectorError::MissingConnectorTransactionID)?, -        }) -    } + type Error = Error; + fn try_from(item: &types::PaymentsSyncRouterData) -> Result { + let auth = NmiAuthType::try_from(&item.connector_auth_type)?; + Ok(Self { + security_key: auth.api_key, + transaction_id: item + .request + .connector_transaction_id + .get_connector_transaction_id() + .change_context(errors::ConnectorError::MissingConnectorTransactionID)?, + }) + } } #[derive(Debug, Serialize)] pub struct NmiCaptureRequest { -    #[serde(rename = "type")] -    pub transaction_type: TransactionType, -    pub security_key: Secret, -    pub transactionid: String, -    pub amount: Option, + #[serde(rename = "type")] + pub transaction_type: TransactionType, + pub security_key: Secret, + pub transactionid: String, + pub amount: Option, } impl TryFrom<&NmiRouterData<&types::PaymentsCaptureRouterData>> for NmiCaptureRequest { -    type Error = Error; -    fn try_from( -        item: &NmiRouterData<&types::PaymentsCaptureRouterData>, -    ) -> Result { -        let auth = NmiAuthType::try_from(&item.router_data.connector_auth_type)?; -        Ok(Self { -            transaction_type: TransactionType::Capture, -            security_key: auth.api_key, -            transactionid: item.router_data.request.connector_transaction_id.clone(), -            amount: Some(item.amount), -        }) -    } + type Error = Error; + fn try_from( + item: &NmiRouterData<&types::PaymentsCaptureRouterData>, + ) -> Result { + let auth = NmiAuthType::try_from(&item.router_data.connector_auth_type)?; + Ok(Self { + transaction_type: TransactionType::Capture, + security_key: auth.api_key, + transactionid: item.router_data.request.connector_transaction_id.clone(), + amount: Some(item.amount), + }) + } } impl -    TryFrom< -        types::ResponseRouterData< -            api::Capture, -            StandardResponse, -            types::PaymentsCaptureData, -            types::PaymentsResponseData, -        >, -    > for types::RouterData + TryFrom< + types::ResponseRouterData< + api::Capture, + StandardResponse, + types::PaymentsCaptureData, + types::PaymentsResponseData, + >, + > for types::RouterData { -    type Error = Error; -    fn try_from( -        item: types::ResponseRouterData< -            api::Capture, -            StandardResponse, -            types::PaymentsCaptureData, -            types::PaymentsResponseData, -        >, -    ) -> Result { -        let (response, status) = match item.response.response { -            Response::Approved => ( -                Ok(types::PaymentsResponseData::TransactionResponse { -                    resource_id: types::ResponseId::ConnectorTransactionId( -                        item.response.transactionid.clone(), -                    ), -                    redirection_data: None, -                    mandate_reference: None, -                    connector_metadata: None, -                    network_txn_id: None, -                    connector_response_reference_id: item -                        .response -                        .orderid -                        .or(Some(item.response.transactionid)), -                }), -                enums::AttemptStatus::CaptureInitiated, -            ), -            Response::Declined | Response::Error => ( -                Err(types::ErrorResponse::foreign_from(( -                    item.response, -                    item.http_code, -                ))), -                enums::AttemptStatus::CaptureFailed, -            ), -        }; -        Ok(Self { -            status, -            response, -            ..item.data -        }) -    } + type Error = Error; + fn try_from( + item: types::ResponseRouterData< + api::Capture, + StandardResponse, + types::PaymentsCaptureData, + types::PaymentsResponseData, + >, + ) -> Result { + let (response, status) = match item.response.response { + Response::Approved => ( + Ok(types::PaymentsResponseData::TransactionResponse { + resource_id: types::ResponseId::ConnectorTransactionId( + item.response.transactionid.clone(), + ), + redirection_data: None, + mandate_reference: None, + connector_metadata: None, + network_txn_id: None, + connector_response_reference_id: item + .response + .orderid + .or(Some(item.response.transactionid)), + }), + enums::AttemptStatus::CaptureInitiated, + ), + Response::Declined | Response::Error => ( + Err(types::ErrorResponse::foreign_from(( + item.response, + item.http_code, + ))), + enums::AttemptStatus::CaptureFailed, + ), + }; + Ok(Self { + status, + response, + ..item.data + }) + } } #[derive(Debug, Serialize)] pub struct NmiCancelRequest { -    #[serde(rename = "type")] -    pub transaction_type: TransactionType, -    pub security_key: Secret, -    pub transactionid: String, -    pub void_reason: Option, + #[serde(rename = "type")] + pub transaction_type: TransactionType, + pub security_key: Secret, + pub transactionid: String, + pub void_reason: Option, } impl TryFrom<&types::PaymentsCancelRouterData> for NmiCancelRequest { -    type Error = Error; -    fn try_from(item: &types::PaymentsCancelRouterData) -> Result { -        let auth = NmiAuthType::try_from(&item.connector_auth_type)?; -        Ok(Self { -            transaction_type: TransactionType::Void, -            security_key: auth.api_key, -            transactionid: item.request.connector_transaction_id.clone(), -            void_reason: item.request.cancellation_reason.clone(), -        }) -    } + type Error = Error; + fn try_from(item: &types::PaymentsCancelRouterData) -> Result { + let auth = NmiAuthType::try_from(&item.connector_auth_type)?; + Ok(Self { + transaction_type: TransactionType::Void, + security_key: auth.api_key, + transactionid: item.request.connector_transaction_id.clone(), + void_reason: item.request.cancellation_reason.clone(), + }) + } } #[derive(Debug, Deserialize)] pub enum Response { -    #[serde(alias = "1")] -    Approved, -    #[serde(alias = "2")] -    Declined, -    #[serde(alias = "3")] -    Error, + #[serde(alias = "1")] + Approved, + #[serde(alias = "2")] + Declined, + #[serde(alias = "3")] + Error, } #[derive(Debug, Deserialize)] pub struct StandardResponse { -    pub response: Response, -    pub responsetext: String, -    pub authcode: Option, -    pub transactionid: String, -    pub avsresponse: Option, -    pub cvvresponse: Option, -    pub orderid: Option, -    pub response_code: String, + pub response: Response, + pub responsetext: String, + pub authcode: Option, + pub transactionid: String, + pub avsresponse: Option, + pub cvvresponse: Option, + pub orderid: Option, + pub response_code: String, } impl -    TryFrom< -        types::ResponseRouterData< -            api::SetupMandate, -            StandardResponse, -            T, -            types::PaymentsResponseData, -        >, -    > for types::RouterData + TryFrom< + types::ResponseRouterData< + api::SetupMandate, + StandardResponse, + T, + types::PaymentsResponseData, + >, + > for types::RouterData { -    type Error = Error; -    fn try_from( -        item: types::ResponseRouterData< -            api::SetupMandate, -            StandardResponse, -            T, -            types::PaymentsResponseData, -        >, -    ) -> Result { -        let (response, status) = match item.response.response { -            Response::Approved => ( -                Ok(types::PaymentsResponseData::TransactionResponse { -                    resource_id: types::ResponseId::ConnectorTransactionId( -                        item.response.transactionid.clone(), -                    ), -                    redirection_data: None, -                    mandate_reference: None, -                    connector_metadata: None, -                    network_txn_id: None, -                    connector_response_reference_id: item -                        .response -                        .orderid -                        .or(Some(item.response.transactionid)), -                }), -                enums::AttemptStatus::Charged, -            ), -            Response::Declined | Response::Error => ( -                Err(types::ErrorResponse::foreign_from(( -                    item.response, -                    item.http_code, -                ))), -                enums::AttemptStatus::Failure, -            ), -        }; -        Ok(Self { -            status, -            response, -            ..item.data -        }) -    } + type Error = Error; + fn try_from( + item: types::ResponseRouterData< + api::SetupMandate, + StandardResponse, + T, + types::PaymentsResponseData, + >, + ) -> Result { + let (response, status) = match item.response.response { + Response::Approved => ( + Ok(types::PaymentsResponseData::TransactionResponse { + resource_id: types::ResponseId::ConnectorTransactionId( + item.response.transactionid.clone(), + ), + redirection_data: None, + mandate_reference: None, + connector_metadata: None, + network_txn_id: None, + connector_response_reference_id: item + .response + .orderid + .or(Some(item.response.transactionid)), + }), + enums::AttemptStatus::Charged, + ), + Response::Declined | Response::Error => ( + Err(types::ErrorResponse::foreign_from(( + item.response, + item.http_code, + ))), + enums::AttemptStatus::Failure, + ), + }; + Ok(Self { + status, + response, + ..item.data + }) + } } impl ForeignFrom<(StandardResponse, u16)> for types::ErrorResponse { -    fn foreign_from((response, http_code): (StandardResponse, u16)) -> Self { -        Self { -            code: response.response_code, -            message: response.responsetext, -            reason: None, -            status_code: http_code, -            attempt_status: None, -        } -    } + fn foreign_from((response, http_code): (StandardResponse, u16)) -> Self { + Self { + code: response.response_code, + message: response.responsetext, + reason: None, + status_code: http_code, + attempt_status: None, + } + } } impl TryFrom> -    for types::RouterData + for types::RouterData { -    type Error = Error; -    fn try_from( -        item: types::ResponseRouterData< -            api::Authorize, -            StandardResponse, -            types::PaymentsAuthorizeData, -            types::PaymentsResponseData, -        >, -    ) -> Result { -        let (response, status) = match item.response.response { -            Response::Approved => ( -                Ok(types::PaymentsResponseData::TransactionResponse { -                    resource_id: types::ResponseId::ConnectorTransactionId( -                        item.response.transactionid.clone(), -                    ), -                    redirection_data: None, -                    mandate_reference: None, -                    connector_metadata: None, -                    network_txn_id: None, -                    connector_response_reference_id: item -                        .response -                        .orderid -                        .or(Some(item.response.transactionid)), -                }), -                if let Some(diesel_models::enums::CaptureMethod::Automatic) = -                    item.data.request.capture_method -                { -                    enums::AttemptStatus::CaptureInitiated -                } else { -                    enums::AttemptStatus::Authorizing -                }, -            ), -            Response::Declined | Response::Error => ( -                Err(types::ErrorResponse::foreign_from(( -                    item.response, -                    item.http_code, -                ))), -                enums::AttemptStatus::Failure, -            ), -        }; -        Ok(Self { -            status, -            response, -            ..item.data -        }) -    } + type Error = Error; + fn try_from( + item: types::ResponseRouterData< + api::Authorize, + StandardResponse, + types::PaymentsAuthorizeData, + types::PaymentsResponseData, + >, + ) -> Result { + let (response, status) = match item.response.response { + Response::Approved => ( + Ok(types::PaymentsResponseData::TransactionResponse { + resource_id: types::ResponseId::ConnectorTransactionId( + item.response.transactionid.clone(), + ), + redirection_data: None, + mandate_reference: None, + connector_metadata: None, + network_txn_id: None, + connector_response_reference_id: item + .response + .orderid + .or(Some(item.response.transactionid)), + }), + if let Some(diesel_models::enums::CaptureMethod::Automatic) = + item.data.request.capture_method + { + enums::AttemptStatus::CaptureInitiated + } else { + enums::AttemptStatus::Authorizing + }, + ), + Response::Declined | Response::Error => ( + Err(types::ErrorResponse::foreign_from(( + item.response, + item.http_code, + ))), + enums::AttemptStatus::Failure, + ), + }; + Ok(Self { + status, + response, + ..item.data + }) + } } impl -    TryFrom> -    for types::RouterData + TryFrom> + for types::RouterData { -    type Error = Error; -    fn try_from( -        item: types::ResponseRouterData< -            api::Void, -            StandardResponse, -            T, -            types::PaymentsResponseData, -        >, -    ) -> Result { -        let (response, status) = match item.response.response { -            Response::Approved => ( -                Ok(types::PaymentsResponseData::TransactionResponse { -                    resource_id: types::ResponseId::ConnectorTransactionId( -                        item.response.transactionid.clone(), -                    ), -                    redirection_data: None, -                    mandate_reference: None, -                    connector_metadata: None, -                    network_txn_id: None, -                    connector_response_reference_id: item -                        .response -                        .orderid -                        .or(Some(item.response.transactionid)), -                }), -                enums::AttemptStatus::VoidInitiated, -            ), -            Response::Declined | Response::Error => ( -                Err(types::ErrorResponse::foreign_from(( -                    item.response, -                    item.http_code, -                ))), -                enums::AttemptStatus::VoidFailed, -            ), -        }; -        Ok(Self { -            status, -            response, -            ..item.data -        }) -    } + type Error = Error; + fn try_from( + item: types::ResponseRouterData< + api::Void, + StandardResponse, + T, + types::PaymentsResponseData, + >, + ) -> Result { + let (response, status) = match item.response.response { + Response::Approved => ( + Ok(types::PaymentsResponseData::TransactionResponse { + resource_id: types::ResponseId::ConnectorTransactionId( + item.response.transactionid.clone(), + ), + redirection_data: None, + mandate_reference: None, + connector_metadata: None, + network_txn_id: None, + connector_response_reference_id: item + .response + .orderid + .or(Some(item.response.transactionid)), + }), + enums::AttemptStatus::VoidInitiated, + ), + Response::Declined | Response::Error => ( + Err(types::ErrorResponse::foreign_from(( + item.response, + item.http_code, + ))), + enums::AttemptStatus::VoidFailed, + ), + }; + Ok(Self { + status, + response, + ..item.data + }) + } } #[derive(Debug, Deserialize)] #[serde(rename_all = "snake_case")] pub enum NmiStatus { -    Abandoned, -    Cancelled, -    Pendingsettlement, -    Pending, -    Failed, -    Complete, -    InProgress, -    Unknown, + Abandoned, + Cancelled, + Pendingsettlement, + Pending, + Failed, + Complete, + InProgress, + Unknown, } impl TryFrom> -    for types::PaymentsSyncRouterData + for types::PaymentsSyncRouterData { -    type Error = Error; -    fn try_from( -        item: types::PaymentsSyncResponseRouterData, -    ) -> Result { -        let response = SyncResponse::try_from(item.response.response.to_vec())?; -        Ok(Self { -            status: enums::AttemptStatus::from(NmiStatus::from(response.transaction.condition)), -            response: Ok(types::PaymentsResponseData::TransactionResponse { -                resource_id: types::ResponseId::ConnectorTransactionId( -                    response.transaction.transaction_id.clone(), -                ), -                redirection_data: None, -                mandate_reference: None, -                connector_metadata: None, -                network_txn_id: None, -                connector_response_reference_id: None, -            }), -            ..item.data -        }) -    } + type Error = Error; + fn try_from( + item: types::PaymentsSyncResponseRouterData, + ) -> Result { + let response = SyncResponse::try_from(item.response.response.to_vec())?; + Ok(Self { + status: enums::AttemptStatus::from(NmiStatus::from(response.transaction.condition)), + response: Ok(types::PaymentsResponseData::TransactionResponse { + resource_id: types::ResponseId::ConnectorTransactionId( + response.transaction.transaction_id.clone(), + ), + redirection_data: None, + mandate_reference: None, + connector_metadata: None, + network_txn_id: None, + connector_response_reference_id: None, + }), + ..item.data + }) + } } impl TryFrom> for SyncResponse { -    type Error = Error; -    fn try_from(bytes: Vec) -> Result { -        let query_response = String::from_utf8(bytes) -            .into_report() -            .change_context(errors::ConnectorError::ResponseDeserializationFailed)?; -        query_response -            .parse_xml::() -            .into_report() -            .change_context(errors::ConnectorError::ResponseDeserializationFailed) -    } + type Error = Error; + fn try_from(bytes: Vec) -> Result { + let query_response = String::from_utf8(bytes) + .into_report() + .change_context(errors::ConnectorError::ResponseDeserializationFailed)?; + query_response + .parse_xml::() + .into_report() + .change_context(errors::ConnectorError::ResponseDeserializationFailed) + } } impl From for enums::AttemptStatus { -    fn from(item: NmiStatus) -> Self { -        match item { -            NmiStatus::Abandoned => Self::AuthenticationFailed, -            NmiStatus::Cancelled => Self::Voided, -            NmiStatus::Pending => Self::Authorized, -            NmiStatus::Pendingsettlement | NmiStatus::Complete => Self::Charged, -            NmiStatus::InProgress => Self::AuthenticationPending, -            NmiStatus::Failed | NmiStatus::Unknown => Self::Failure, -        } -    } + fn from(item: NmiStatus) -> Self { + match item { + NmiStatus::Abandoned => Self::AuthenticationFailed, + NmiStatus::Cancelled => Self::Voided, + NmiStatus::Pending => Self::Authorized, + NmiStatus::Pendingsettlement | NmiStatus::Complete => Self::Charged, + NmiStatus::InProgress => Self::AuthenticationPending, + NmiStatus::Failed | NmiStatus::Unknown => Self::Failure, + } + } } // REFUND : #[derive(Debug, Serialize)] pub struct NmiRefundRequest { -    #[serde(rename = "type")] -    transaction_type: TransactionType, -    security_key: Secret, -    transactionid: String, -    amount: f64, + #[serde(rename = "type")] + transaction_type: TransactionType, + security_key: Secret, + transactionid: String, + amount: f64, } impl TryFrom<&NmiRouterData<&types::RefundsRouterData>> for NmiRefundRequest { -    type Error = Error; -    fn try_from(item: &NmiRouterData<&types::RefundsRouterData>) -> Result { -        let auth_type: NmiAuthType = (&item.router_data.connector_auth_type).try_into()?; -        Ok(Self { -            transaction_type: TransactionType::Refund, -            security_key: auth_type.api_key, -            transactionid: item.router_data.request.connector_transaction_id.clone(), -            amount: item.amount, -        }) -    } + type Error = Error; + fn try_from(item: &NmiRouterData<&types::RefundsRouterData>) -> Result { + let auth_type: NmiAuthType = (&item.router_data.connector_auth_type).try_into()?; + Ok(Self { + transaction_type: TransactionType::Refund, + security_key: auth_type.api_key, + transactionid: item.router_data.request.connector_transaction_id.clone(), + amount: item.amount, + }) + } } impl TryFrom> -    for types::RefundsRouterData + for types::RefundsRouterData { -    type Error = Error; -    fn try_from( -        item: types::RefundsResponseRouterData, -    ) -> Result { -        let refund_status = enums::RefundStatus::from(item.response.response); -        Ok(Self { -            response: Ok(types::RefundsResponseData { -                connector_refund_id: item.response.transactionid, -                refund_status, -            }), -            ..item.data -        }) -    } + type Error = Error; + fn try_from( + item: types::RefundsResponseRouterData, + ) -> Result { + let refund_status = enums::RefundStatus::from(item.response.response); + Ok(Self { + response: Ok(types::RefundsResponseData { + connector_refund_id: item.response.transactionid, + refund_status, + }), + ..item.data + }) + } } impl TryFrom> -    for types::RefundsRouterData + for types::RefundsRouterData { -    type Error = Error; -    fn try_from( -        item: types::RefundsResponseRouterData, -    ) -> Result { -        let refund_status = enums::RefundStatus::from(item.response.response); -        Ok(Self { -            response: Ok(types::RefundsResponseData { -                connector_refund_id: item.response.transactionid, -                refund_status, -            }), -            ..item.data -        }) -    } + type Error = Error; + fn try_from( + item: types::RefundsResponseRouterData, + ) -> Result { + let refund_status = enums::RefundStatus::from(item.response.response); + Ok(Self { + response: Ok(types::RefundsResponseData { + connector_refund_id: item.response.transactionid, + refund_status, + }), + ..item.data + }) + } } impl From for enums::RefundStatus { -    fn from(item: Response) -> Self { -        match item { -            Response::Approved => Self::Pending, -            Response::Declined | Response::Error => Self::Failure, -        } -    } + fn from(item: Response) -> Self { + match item { + Response::Approved => Self::Pending, + Response::Declined | Response::Error => Self::Failure, + } + } } impl TryFrom<&types::RefundSyncRouterData> for NmiSyncRequest { -    type Error = Error; -    fn try_from(item: &types::RefundSyncRouterData) -> Result { -        let auth = NmiAuthType::try_from(&item.connector_auth_type)?; -        let transaction_id = item -            .request -            .connector_refund_id -            .clone() -            .ok_or(errors::ConnectorError::MissingConnectorRefundID)?; - -        Ok(Self { -            security_key: auth.api_key, -            transaction_id, -        }) -    } + type Error = Error; + fn try_from(item: &types::RefundSyncRouterData) -> Result { + let auth = NmiAuthType::try_from(&item.connector_auth_type)?; + let transaction_id = item + .request + .connector_refund_id + .clone() + .ok_or(errors::ConnectorError::MissingConnectorRefundID)?; + + Ok(Self { + security_key: auth.api_key, + transaction_id, + }) + } } impl TryFrom> -    for types::RefundsRouterData + for types::RefundsRouterData { -    type Error = Error; -    fn try_from( -        item: types::RefundsResponseRouterData, -    ) -> Result { -        let response = SyncResponse::try_from(item.response.response.to_vec())?; -        let refund_status = -            enums::RefundStatus::from(NmiStatus::from(response.transaction.condition)); -        Ok(Self { -            response: Ok(types::RefundsResponseData { -                connector_refund_id: response.transaction.transaction_id, -                refund_status, -            }), -            ..item.data -        }) -    } + type Error = Error; + fn try_from( + item: types::RefundsResponseRouterData, + ) -> Result { + let response = SyncResponse::try_from(item.response.response.to_vec())?; + let refund_status = + enums::RefundStatus::from(NmiStatus::from(response.transaction.condition)); + Ok(Self { + response: Ok(types::RefundsResponseData { + connector_refund_id: response.transaction.transaction_id, + refund_status, + }), + ..item.data + }) + } } impl From for enums::RefundStatus { -    fn from(item: NmiStatus) -> Self { -        match item { -            NmiStatus::Abandoned -            | NmiStatus::Cancelled -            | NmiStatus::Failed -            | NmiStatus::Unknown => Self::Failure, -            NmiStatus::Pending | NmiStatus::InProgress => Self::Pending, -            NmiStatus::Pendingsettlement | NmiStatus::Complete => Self::Success, -        } -    } + fn from(item: NmiStatus) -> Self { + match item { + NmiStatus::Abandoned + | NmiStatus::Cancelled + | NmiStatus::Failed + | NmiStatus::Unknown => Self::Failure, + NmiStatus::Pending | NmiStatus::InProgress => Self::Pending, + NmiStatus::Pendingsettlement | NmiStatus::Complete => Self::Success, + } + } } impl From for NmiStatus { -    fn from(value: String) -> Self { -        match value.as_str() { -            "abandoned" => Self::Abandoned, -            "canceled" => Self::Cancelled, -            "in_progress" => Self::InProgress, -            "pendingsettlement" => Self::Pendingsettlement, -            "complete" => Self::Complete, -            "failed" => Self::Failed, -            "unknown" => Self::Unknown, -            // Other than above values only pending is possible, since value is a string handling this as default -            _ => Self::Pending, -        } -    } + fn from(value: String) -> Self { + match value.as_str() { + "abandoned" => Self::Abandoned, + "canceled" => Self::Cancelled, + "in_progress" => Self::InProgress, + "pendingsettlement" => Self::Pendingsettlement, + "complete" => Self::Complete, + "failed" => Self::Failed, + "unknown" => Self::Unknown, + // Other than above values only pending is possible, since value is a string handling this as default + _ => Self::Pending, + } + } } #[derive(Debug, Deserialize)] pub struct SyncTransactionResponse { -    transaction_id: String, -    condition: String, + transaction_id: String, + condition: String, } #[derive(Debug, Deserialize)] struct SyncResponse { -    transaction: SyncTransactionResponse, + transaction: SyncTransactionResponse, } From f49890e061d079629eabad3e4d0c6aeda3a1dbbf Mon Sep 17 00:00:00 2001 From: swangi-kumari Date: Mon, 5 Feb 2024 12:37:14 +0530 Subject: [PATCH 12/12] refactor: remove unecessary clone --- crates/router/src/connector/nmi/transformers.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/router/src/connector/nmi/transformers.rs b/crates/router/src/connector/nmi/transformers.rs index cada4b6ecf4e..926f2c300d2e 100644 --- a/crates/router/src/connector/nmi/transformers.rs +++ b/crates/router/src/connector/nmi/transformers.rs @@ -885,7 +885,7 @@ impl TryFrom> status: enums::AttemptStatus::from(NmiStatus::from(response.transaction.condition)), response: Ok(types::PaymentsResponseData::TransactionResponse { resource_id: types::ResponseId::ConnectorTransactionId( - response.transaction.transaction_id.clone(), + response.transaction.transaction_id, ), redirection_data: None, mandate_reference: None,