From 5df2ef4e48393dc7da04a951fd7aed6d5b3701f0 Mon Sep 17 00:00:00 2001 From: Branislav Kontur Date: Thu, 18 Jan 2024 22:33:18 +0100 Subject: [PATCH] chore: address pr review comments --- .../src/connector/coinbase/transformers.rs | 5 +- crates/router/tests/connectors/coinbase.rs | 115 +----------------- 2 files changed, 9 insertions(+), 111 deletions(-) diff --git a/crates/router/src/connector/coinbase/transformers.rs b/crates/router/src/connector/coinbase/transformers.rs index 3e25b50683c3..b1435e50df9d 100644 --- a/crates/router/src/connector/coinbase/transformers.rs +++ b/crates/router/src/connector/coinbase/transformers.rs @@ -270,7 +270,10 @@ fn get_crypto_specific_payment_data( let name = billing_address.and_then(|add| add.get_first_name().ok().map(|name| name.to_owned())); let description = item.get_description().ok(); - let connector_meta = CoinbaseConnectorMeta::try_from(&item.connector_meta_data)?; + let connector_meta = CoinbaseConnectorMeta::try_from(&item.connector_meta_data) + .change_context(errors::ConnectorError::InvalidConnectorConfig { + config: "Merchant connector account metadata", + })?; let pricing_type = connector_meta.pricing_type; let local_price = get_local_price(item); let redirect_url = item.request.get_return_url()?; diff --git a/crates/router/tests/connectors/coinbase.rs b/crates/router/tests/connectors/coinbase.rs index 5efca484b6f7..73ee93178c01 100644 --- a/crates/router/tests/connectors/coinbase.rs +++ b/crates/router/tests/connectors/coinbase.rs @@ -1,13 +1,6 @@ -use std::marker::PhantomData; - use api_models::payments::CryptoData; -use common_utils::pii; use masking::Secret; -use router::{ - connector::coinbase::transformers::{CoinbasePaymentsRequest, LocalPrice}, - core::errors::ConnectorError, - types::{self, api, storage::enums, PaymentAddress}, -}; +use router::types::{self, api, storage::enums, PaymentAddress}; use serde_json::json; use crate::{ @@ -71,8 +64,8 @@ fn get_default_payment_info() -> Option { }) } -fn payment_method_details() -> types::PaymentsAuthorizeData { - types::PaymentsAuthorizeData { +fn payment_method_details() -> Option { + Some(types::PaymentsAuthorizeData { amount: 1, currency: enums::Currency::USD, payment_method_data: types::api::PaymentMethodData::Crypto(CryptoData { @@ -103,62 +96,14 @@ fn payment_method_details() -> types::PaymentsAuthorizeData { surcharge_details: None, request_incremental_authorization: false, metadata: None, - } -} - -fn construct_payment_router_data( - connector_meta_data: Option, -) -> types::PaymentsAuthorizeRouterData { - let connector_auth_type = types::ConnectorAuthType::HeaderKey { - api_key: Secret::new("api_key".to_string()), - }; - - types::RouterData { - flow: PhantomData, - merchant_id: String::from("Coinbase"), - customer_id: Some(String::from("Coinbase")), - connector: "Coinbase".to_string(), - payment_id: uuid::Uuid::new_v4().to_string(), - attempt_id: uuid::Uuid::new_v4().to_string(), - status: Default::default(), - auth_type: enums::AuthenticationType::NoThreeDs, - payment_method: enums::PaymentMethod::Card, - connector_auth_type, - description: Some("This is a test".to_string()), - return_url: None, - request: payment_method_details(), - response: Err(Default::default()), - payment_method_id: None, - address: Default::default(), - connector_meta_data, - amount_captured: None, - access_token: None, - session_token: None, - reference_id: None, - payment_method_token: None, - connector_customer: None, - recurring_mandate_payment_data: None, - preprocessing_id: None, - connector_request_reference_id: uuid::Uuid::new_v4().to_string(), - #[cfg(feature = "payouts")] - payout_method_data: None, - #[cfg(feature = "payouts")] - quote_id: None, - test_mode: None, - payment_method_balance: None, - connector_api_version: None, - connector_http_status_code: None, - apple_pay_flow: None, - external_latency: None, - frm_metadata: None, - } + }) } // Creates a payment using the manual capture flow #[actix_web::test] async fn should_only_authorize_payment() { let response = CONNECTOR - .authorize_payment(Some(payment_method_details()), get_default_payment_info()) + .authorize_payment(payment_method_details(), get_default_payment_info()) .await .expect("Authorize payment response"); assert_eq!(response.status, enums::AttemptStatus::AuthenticationPending); @@ -247,53 +192,3 @@ async fn should_sync_cancelled_payment() { .expect("PSync response"); assert_eq!(response.status, enums::AttemptStatus::Voided); } - -#[test] -fn coinbase_payments_request_try_from_works() { - // `connector_meta_data` as `None` - should fail - assert_eq!( - CoinbasePaymentsRequest::try_from(&construct_payment_router_data(None)) - .unwrap_err() - .current_context(), - &ConnectorError::InvalidConnectorConfig { config: "metadata" }, - ); - - // `connector_meta_data` as empty json - should fail - assert_eq!( - CoinbasePaymentsRequest::try_from(&construct_payment_router_data(Some(Secret::new( - serde_json::json!({}) - )))) - .unwrap_err() - .current_context(), - &ConnectorError::InvalidConnectorConfig { config: "metadata" }, - ); - - // `connector_meta_data` as json with missing `pricing_type` - should fail - assert_eq!( - CoinbasePaymentsRequest::try_from(&construct_payment_router_data(Some(Secret::new( - serde_json::json!({ "wrong_type" : "blah" }) - )))) - .unwrap_err() - .current_context(), - &ConnectorError::InvalidConnectorConfig { config: "metadata" }, - ); - - // `connector_meta_data` as json with correct `pricing_type` - ok - assert_eq!( - CoinbasePaymentsRequest::try_from(&construct_payment_router_data(Some(Secret::new( - serde_json::json!({ "pricing_type" : "fixed_price" }) - )))) - .unwrap(), - CoinbasePaymentsRequest { - name: None, - description: Some("This is a test".to_string()), - pricing_type: "fixed_price".to_string(), - local_price: LocalPrice { - amount: "1".to_string(), - currency: "USD".to_string() - }, - redirect_url: "https://google.com/".to_string(), - cancel_url: "https://google.com/".to_string(), - } - ); -}