From 357839d129259457d14281194dc0e92aab9011d0 Mon Sep 17 00:00:00 2001 From: prajjwalkumar17 Date: Thu, 29 Feb 2024 08:50:11 +0530 Subject: [PATCH 01/32] chore: updated payment's response with pm_id --- crates/api_models/src/payments.rs | 3 ++ .../src/core/payments/flows/authorize_flow.rs | 38 ++++++++++--------- .../router/src/core/payments/transformers.rs | 1 + 3 files changed, 24 insertions(+), 18 deletions(-) diff --git a/crates/api_models/src/payments.rs b/crates/api_models/src/payments.rs index 91a289652b87..dde12e1cd6e0 100644 --- a/crates/api_models/src/payments.rs +++ b/crates/api_models/src/payments.rs @@ -2524,6 +2524,9 @@ pub struct PaymentsResponse { /// Payment Fingerprint pub fingerprint: Option, + + /// Payment Method Id + pub payment_method_id: Option, } #[derive(Clone, Debug, serde::Deserialize, ToSchema, serde::Serialize)] diff --git a/crates/router/src/core/payments/flows/authorize_flow.rs b/crates/router/src/core/payments/flows/authorize_flow.rs index d7d122c3252c..da857ebcfcdb 100644 --- a/crates/router/src/core/payments/flows/authorize_flow.rs +++ b/crates/router/src/core/payments/flows/authorize_flow.rs @@ -76,7 +76,7 @@ impl Feature for types::PaymentsAu if self.should_proceed_with_authorize() { self.decide_authentication_type(); logger::debug!(auth_type=?self.auth_type); - let resp = services::execute_connector_processing_step( + let mut resp = services::execute_connector_processing_step( state, connector_integration, &self, @@ -102,6 +102,9 @@ impl Feature for types::PaymentsAu is_mandate, )) .await?; + + resp.payment_method_id = payment_method_id.clone(); + Ok(mandate::mandate_procedure( state, resp, @@ -120,25 +123,24 @@ impl Feature for types::PaymentsAu logger::info!("Initiating async call to save_payment_method in locker"); - tokio::spawn(async move { - logger::info!("Starting async call to save_payment_method in locker"); + logger::info!("Starting async call to save_payment_method in locker"); - let result = Box::pin(tokenization::save_payment_method( - &state, - &connector, - response, - &maybe_customer, - &merchant_account, - self.request.payment_method_type, - &key_store, - is_mandate, - )) - .await; + let payment_method_id = Box::pin(tokenization::save_payment_method( + &state, + &connector, + response, + &maybe_customer, + &merchant_account, + self.request.payment_method_type, + &key_store, + is_mandate, + )) + .await; - if let Err(err) = result { - logger::error!("Asynchronously saving card in locker failed : {:?}", err); - } - }); + resp.payment_method_id = payment_method_id.as_ref().unwrap().clone(); + // if let Err(err) = payment_method_id { + // logger::error!("Asynchronously saving card in locker failed : {:?}", err); + // } Ok(resp) } diff --git a/crates/router/src/core/payments/transformers.rs b/crates/router/src/core/payments/transformers.rs index 6cf547f668ff..b34187fdd264 100644 --- a/crates/router/src/core/payments/transformers.rs +++ b/crates/router/src/core/payments/transformers.rs @@ -711,6 +711,7 @@ where .set_authorization_count(payment_intent.authorization_count) .set_incremental_authorizations(incremental_authorizations_response) .set_expires_on(payment_intent.session_expiry) + .set_payment_method_id(payment_attempt.payment_method_id) .to_owned(), headers, )) From 4caaa73e9cba51e6962ac66a86e6273e68841ea1 Mon Sep 17 00:00:00 2001 From: "hyperswitch-bot[bot]" <148525504+hyperswitch-bot[bot]@users.noreply.github.com> Date: Thu, 29 Feb 2024 03:24:16 +0000 Subject: [PATCH 02/32] docs(openapi): re-generate OpenAPI specification --- openapi/openapi_spec.json | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/openapi/openapi_spec.json b/openapi/openapi_spec.json index 3fcf6bca79f5..2b727097bf5b 100644 --- a/openapi/openapi_spec.json +++ b/openapi/openapi_spec.json @@ -13881,6 +13881,11 @@ "type": "string", "description": "Payment Fingerprint", "nullable": true + }, + "payment_method_id": { + "type": "string", + "description": "Payment Method Id", + "nullable": true } } }, From eecca8f0b3a8538fab6a75cfe65627a6bd208ae2 Mon Sep 17 00:00:00 2001 From: prajjwalkumar17 Date: Thu, 29 Feb 2024 11:22:13 +0530 Subject: [PATCH 03/32] chore: updated payment's response with pm_status --- crates/api_models/src/payments.rs | 4 ++++ crates/common_enums/src/enums.rs | 10 ++++++++++ .../src/core/payments/flows/authorize_flow.rs | 13 ++++--------- .../src/core/payments/flows/setup_mandate_flow.rs | 6 +++--- crates/router/src/core/payments/tokenization.rs | 8 +++++--- crates/router/src/core/payments/transformers.rs | 3 ++- 6 files changed, 28 insertions(+), 16 deletions(-) diff --git a/crates/api_models/src/payments.rs b/crates/api_models/src/payments.rs index dde12e1cd6e0..e467df500b9d 100644 --- a/crates/api_models/src/payments.rs +++ b/crates/api_models/src/payments.rs @@ -2527,6 +2527,10 @@ pub struct PaymentsResponse { /// Payment Method Id pub payment_method_id: Option, + + /// Payment Method Status + pub payment_method_status: Option, + // pub payment_method_status: Option, } #[derive(Clone, Debug, serde::Deserialize, ToSchema, serde::Serialize)] diff --git a/crates/common_enums/src/enums.rs b/crates/common_enums/src/enums.rs index e0b6a1cc5a12..071d6992cbeb 100644 --- a/crates/common_enums/src/enums.rs +++ b/crates/common_enums/src/enums.rs @@ -1203,6 +1203,16 @@ pub enum PaymentMethodStatus { Processing, } +impl From for PaymentMethodStatus { + fn from(attempt_status: AttemptStatus) -> Self { + match attempt_status { + AttemptStatus::Charged => PaymentMethodStatus::Active, + AttemptStatus::Failure => PaymentMethodStatus::Inactive, + _ => PaymentMethodStatus::Processing, + } + } +} + /// To indicate the type of payment experience that the customer would go through #[derive( Eq, diff --git a/crates/router/src/core/payments/flows/authorize_flow.rs b/crates/router/src/core/payments/flows/authorize_flow.rs index da857ebcfcdb..40aac88015f1 100644 --- a/crates/router/src/core/payments/flows/authorize_flow.rs +++ b/crates/router/src/core/payments/flows/authorize_flow.rs @@ -101,7 +101,7 @@ impl Feature for types::PaymentsAu key_store, is_mandate, )) - .await?; + .await?.0; resp.payment_method_id = payment_method_id.clone(); @@ -121,9 +121,7 @@ impl Feature for types::PaymentsAu let key_store = key_store.clone(); let state = state.clone(); - logger::info!("Initiating async call to save_payment_method in locker"); - - logger::info!("Starting async call to save_payment_method in locker"); + logger::info!("Call to save_payment_method in locker"); let payment_method_id = Box::pin(tokenization::save_payment_method( &state, @@ -135,12 +133,9 @@ impl Feature for types::PaymentsAu &key_store, is_mandate, )) - .await; + .await?.0; - resp.payment_method_id = payment_method_id.as_ref().unwrap().clone(); - // if let Err(err) = payment_method_id { - // logger::error!("Asynchronously saving card in locker failed : {:?}", err); - // } + resp.payment_method_id = payment_method_id.clone(); Ok(resp) } diff --git a/crates/router/src/core/payments/flows/setup_mandate_flow.rs b/crates/router/src/core/payments/flows/setup_mandate_flow.rs index 3f43204b986f..fef84814deaf 100644 --- a/crates/router/src/core/payments/flows/setup_mandate_flow.rs +++ b/crates/router/src/core/payments/flows/setup_mandate_flow.rs @@ -109,7 +109,7 @@ impl Feature for types::Setup key_store, is_mandate, )) - .await?; + .await?.0; mandate::mandate_procedure( state, resp, @@ -246,7 +246,7 @@ impl types::SetupMandateRouterData { key_store, is_mandate, )) - .await?; + .await?.0; Ok(mandate::mandate_procedure( state, @@ -331,7 +331,7 @@ impl types::SetupMandateRouterData { key_store, is_mandate, )) - .await?; + .await?.0; let mandate = state .store .find_mandate_by_merchant_id_mandate_id(&merchant_account.merchant_id, &mandate_id) diff --git a/crates/router/src/core/payments/tokenization.rs b/crates/router/src/core/payments/tokenization.rs index d08f0208500c..a9f44f4dca66 100644 --- a/crates/router/src/core/payments/tokenization.rs +++ b/crates/router/src/core/payments/tokenization.rs @@ -34,7 +34,7 @@ pub async fn save_payment_method( payment_method_type: Option, key_store: &domain::MerchantKeyStore, is_mandate: bool, -) -> RouterResult> +) -> RouterResult<(Option, Option)> where FData: mandate::MandateBehaviour, { @@ -75,6 +75,8 @@ where }) .unwrap_or(false); + let pm_status = common_enums::PaymentMethodStatus::from(resp.status); + let pm_id = if future_usage_validation { let customer = maybe_customer.to_owned().get_required_value("customer")?; let payment_method_create_request = helpers::get_payment_method_create_request( @@ -363,9 +365,9 @@ where } else { None }; - Ok(pm_id) + Ok((pm_id, Some(pm_status))) } - Err(_) => Ok(None), + Err(_) => Ok((None, None)), } } diff --git a/crates/router/src/core/payments/transformers.rs b/crates/router/src/core/payments/transformers.rs index b34187fdd264..f390aeb3eb17 100644 --- a/crates/router/src/core/payments/transformers.rs +++ b/crates/router/src/core/payments/transformers.rs @@ -711,7 +711,8 @@ where .set_authorization_count(payment_intent.authorization_count) .set_incremental_authorizations(incremental_authorizations_response) .set_expires_on(payment_intent.session_expiry) - .set_payment_method_id(payment_attempt.payment_method_id) + .set_payment_method_id(payment_attempt.payment_method_id.clone()) + .set_payment_method_status(payment_attempt.payment_method_id) .to_owned(), headers, )) From bde1ef52014acd9117da11dab8ba3c972dce7a70 Mon Sep 17 00:00:00 2001 From: "hyperswitch-bot[bot]" <148525504+hyperswitch-bot[bot]@users.noreply.github.com> Date: Thu, 29 Feb 2024 05:53:19 +0000 Subject: [PATCH 04/32] chore: run formatter --- crates/router/src/core/payments/flows/authorize_flow.rs | 6 ++++-- .../router/src/core/payments/flows/setup_mandate_flow.rs | 9 ++++++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/crates/router/src/core/payments/flows/authorize_flow.rs b/crates/router/src/core/payments/flows/authorize_flow.rs index 40aac88015f1..91e838679a09 100644 --- a/crates/router/src/core/payments/flows/authorize_flow.rs +++ b/crates/router/src/core/payments/flows/authorize_flow.rs @@ -101,7 +101,8 @@ impl Feature for types::PaymentsAu key_store, is_mandate, )) - .await?.0; + .await? + .0; resp.payment_method_id = payment_method_id.clone(); @@ -133,7 +134,8 @@ impl Feature for types::PaymentsAu &key_store, is_mandate, )) - .await?.0; + .await? + .0; resp.payment_method_id = payment_method_id.clone(); diff --git a/crates/router/src/core/payments/flows/setup_mandate_flow.rs b/crates/router/src/core/payments/flows/setup_mandate_flow.rs index fef84814deaf..5a6c2a24d006 100644 --- a/crates/router/src/core/payments/flows/setup_mandate_flow.rs +++ b/crates/router/src/core/payments/flows/setup_mandate_flow.rs @@ -109,7 +109,8 @@ impl Feature for types::Setup key_store, is_mandate, )) - .await?.0; + .await? + .0; mandate::mandate_procedure( state, resp, @@ -246,7 +247,8 @@ impl types::SetupMandateRouterData { key_store, is_mandate, )) - .await?.0; + .await? + .0; Ok(mandate::mandate_procedure( state, @@ -331,7 +333,8 @@ impl types::SetupMandateRouterData { key_store, is_mandate, )) - .await?.0; + .await? + .0; let mandate = state .store .find_mandate_by_merchant_id_mandate_id(&merchant_account.merchant_id, &mandate_id) From a4b55c43e7e6daeddfe8626b1eed80e06fef856e Mon Sep 17 00:00:00 2001 From: "hyperswitch-bot[bot]" <148525504+hyperswitch-bot[bot]@users.noreply.github.com> Date: Thu, 29 Feb 2024 05:55:36 +0000 Subject: [PATCH 05/32] docs(openapi): re-generate OpenAPI specification --- openapi/openapi_spec.json | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/openapi/openapi_spec.json b/openapi/openapi_spec.json index 2b727097bf5b..fd9471528029 100644 --- a/openapi/openapi_spec.json +++ b/openapi/openapi_spec.json @@ -13886,6 +13886,11 @@ "type": "string", "description": "Payment Method Id", "nullable": true + }, + "payment_method_status": { + "type": "string", + "description": "Payment Method Status", + "nullable": true } } }, From 4fe11d593b7fafd17665050a743e88f03187503c Mon Sep 17 00:00:00 2001 From: prajjwalkumar17 Date: Fri, 1 Mar 2024 15:13:08 +0530 Subject: [PATCH 06/32] chore: updated payment's response with pm_status --- crates/api_models/src/payments.rs | 3 +- .../src/payments/payment_attempt.rs | 1 + crates/diesel_models/src/payment_attempt.rs | 3 + .../core/fraud_check/flows/checkout_flow.rs | 1 + .../fraud_check/flows/fulfillment_flow.rs | 1 + .../core/fraud_check/flows/record_return.rs | 1 + .../src/core/fraud_check/flows/sale_flow.rs | 1 + .../fraud_check/flows/transaction_flow.rs | 1 + crates/router/src/core/mandate/utils.rs | 1 + crates/router/src/core/payment_methods.rs | 123 +++++++++++------- crates/router/src/core/payments.rs | 12 +- .../src/core/payments/flows/authorize_flow.rs | 48 +++---- .../core/payments/flows/setup_mandate_flow.rs | 9 +- crates/router/src/core/payments/helpers.rs | 24 ++-- crates/router/src/core/payments/operations.rs | 11 +- .../payments/operations/payment_approve.rs | 1 + .../payments/operations/payment_cancel.rs | 1 + .../payments/operations/payment_capture.rs | 1 + .../operations/payment_complete_authorize.rs | 6 +- .../payments/operations/payment_confirm.rs | 8 +- .../payments/operations/payment_create.rs | 2 + .../payments/operations/payment_reject.rs | 1 + .../payments/operations/payment_response.rs | 5 +- .../payments/operations/payment_session.rs | 4 +- .../core/payments/operations/payment_start.rs | 4 +- .../payments/operations/payment_status.rs | 2 + .../payments/operations/payment_update.rs | 2 + .../payments_incremental_authorization.rs | 4 +- .../router/src/core/payments/transformers.rs | 5 +- crates/router/src/core/utils.rs | 7 + crates/router/src/core/webhooks/utils.rs | 1 + crates/router/src/types.rs | 3 + .../router/src/types/api/verify_connector.rs | 1 + crates/router/tests/connectors/aci.rs | 6 +- crates/router/tests/connectors/utils.rs | 3 +- .../src/payments/payment_attempt.rs | 4 + 36 files changed, 210 insertions(+), 101 deletions(-) diff --git a/crates/api_models/src/payments.rs b/crates/api_models/src/payments.rs index e467df500b9d..9586ddd1c157 100644 --- a/crates/api_models/src/payments.rs +++ b/crates/api_models/src/payments.rs @@ -2529,8 +2529,7 @@ pub struct PaymentsResponse { pub payment_method_id: Option, /// Payment Method Status - pub payment_method_status: Option, - // pub payment_method_status: Option, + pub payment_method_status: Option, } #[derive(Clone, Debug, serde::Deserialize, ToSchema, serde::Serialize)] diff --git a/crates/data_models/src/payments/payment_attempt.rs b/crates/data_models/src/payments/payment_attempt.rs index 3e187e25bc5e..8cff8407c6b7 100644 --- a/crates/data_models/src/payments/payment_attempt.rs +++ b/crates/data_models/src/payments/payment_attempt.rs @@ -311,6 +311,7 @@ pub enum PaymentAttemptUpdate { tax_amount: Option, merchant_connector_id: Option, fingerprint_id: Option, + payment_method_id: Option, }, RejectUpdate { status: storage_enums::AttemptStatus, diff --git a/crates/diesel_models/src/payment_attempt.rs b/crates/diesel_models/src/payment_attempt.rs index 927a05bfa566..53545773c5dc 100644 --- a/crates/diesel_models/src/payment_attempt.rs +++ b/crates/diesel_models/src/payment_attempt.rs @@ -218,6 +218,7 @@ pub enum PaymentAttemptUpdate { fingerprint_id: Option, updated_by: String, merchant_connector_id: Option, + payment_method_id: Option, }, VoidUpdate { status: storage_enums::AttemptStatus, @@ -537,6 +538,7 @@ impl From for PaymentAttemptUpdateInternal { surcharge_amount, tax_amount, fingerprint_id, + payment_method_id, } => Self { amount: Some(amount), currency: Some(currency), @@ -560,6 +562,7 @@ impl From for PaymentAttemptUpdateInternal { surcharge_amount, tax_amount, fingerprint_id, + payment_method_id: payment_method_id.map(Some), ..Default::default() }, PaymentAttemptUpdate::VoidUpdate { diff --git a/crates/router/src/core/fraud_check/flows/checkout_flow.rs b/crates/router/src/core/fraud_check/flows/checkout_flow.rs index 8b3eed45f9e8..67684ab4b1a9 100644 --- a/crates/router/src/core/fraud_check/flows/checkout_flow.rs +++ b/crates/router/src/core/fraud_check/flows/checkout_flow.rs @@ -64,6 +64,7 @@ impl ConstructFlowSpecificData( auth_type: payment_attempt.authentication_type.unwrap_or_default(), connector_meta_data: merchant_connector_account.get_metadata(), amount_captured: payment_intent.amount_captured, + payment_method_status: None, request: FraudCheckFulfillmentData { amount: payment_attempt.amount, order_details: payment_intent.order_details.clone(), diff --git a/crates/router/src/core/fraud_check/flows/record_return.rs b/crates/router/src/core/fraud_check/flows/record_return.rs index 2de6aaab7c73..1af1e5fc9fdd 100644 --- a/crates/router/src/core/fraud_check/flows/record_return.rs +++ b/crates/router/src/core/fraud_check/flows/record_return.rs @@ -84,6 +84,7 @@ impl ConstructFlowSpecificData, customer: &Option, - ) -> RouterResult>; + ) -> ( + RouterResult>, + Option, + ); } #[async_trait::async_trait] @@ -128,69 +131,99 @@ impl PaymentMethodRetrieve for Oss { payment_intent: &PaymentIntent, card_token_data: Option<&CardToken>, customer: &Option, - ) -> RouterResult> { + ) -> ( + RouterResult>, + Option, + ) { match token_data { storage::PaymentTokenData::TemporaryGeneric(generic_token) => { - helpers::retrieve_payment_method_with_temporary_token( - state, - &generic_token.token, - payment_intent, - merchant_key_store, - card_token_data, + ( + helpers::retrieve_payment_method_with_temporary_token( + state, + &generic_token.token, + payment_intent, + merchant_key_store, + card_token_data, + ) + .await, + None, ) - .await } storage::PaymentTokenData::Temporary(generic_token) => { - helpers::retrieve_payment_method_with_temporary_token( - state, - &generic_token.token, - payment_intent, - merchant_key_store, - card_token_data, + ( + helpers::retrieve_payment_method_with_temporary_token( + state, + &generic_token.token, + payment_intent, + merchant_key_store, + card_token_data, + ) + .await, + None, ) - .await } storage::PaymentTokenData::Permanent(card_token) => { - helpers::retrieve_card_with_permanent_token( - state, - card_token.locker_id.as_ref().unwrap_or(&card_token.token), - card_token - .payment_method_id - .as_ref() - .unwrap_or(&card_token.token), - payment_intent, - card_token_data, + ( + helpers::retrieve_card_with_permanent_token( + state, + card_token.locker_id.as_ref().unwrap_or(&card_token.token), + card_token + .payment_method_id + .as_ref() + .unwrap_or(&card_token.token), + payment_intent, + card_token_data, + ) + .await + .map(|card| Some((card, enums::PaymentMethod::Card))), + Some( + card_token + .payment_method_id + .as_ref() + .unwrap_or(&card_token.token) + .to_string(), + ), ) - .await - .map(|card| Some((card, enums::PaymentMethod::Card))) } storage::PaymentTokenData::PermanentCard(card_token) => { - helpers::retrieve_card_with_permanent_token( - state, - card_token.locker_id.as_ref().unwrap_or(&card_token.token), - card_token - .payment_method_id - .as_ref() - .unwrap_or(&card_token.token), - payment_intent, - card_token_data, + ( + helpers::retrieve_card_with_permanent_token( + state, + card_token.locker_id.as_ref().unwrap_or(&card_token.token), + card_token + .payment_method_id + .as_ref() + .unwrap_or(&card_token.token), + payment_intent, + card_token_data, + ) + .await + .map(|card| Some((card, enums::PaymentMethod::Card))), + Some( + card_token + .payment_method_id + .as_ref() + .unwrap_or(&card_token.token) + .to_string(), + ), ) - .await - .map(|card| Some((card, enums::PaymentMethod::Card))) } storage::PaymentTokenData::AuthBankDebit(auth_token) => { - core_pm_auth::retrieve_payment_method_from_auth_service( - state, - merchant_key_store, - auth_token, - payment_intent, - customer, + ( + core_pm_auth::retrieve_payment_method_from_auth_service( + state, + merchant_key_store, + auth_token, + payment_intent, + customer, + ) + .await, + None, ) - .await } } } diff --git a/crates/router/src/core/payments.rs b/crates/router/src/core/payments.rs index 782d1814cc6a..2e8d6bf2005d 100644 --- a/crates/router/src/core/payments.rs +++ b/crates/router/src/core/payments.rs @@ -258,6 +258,7 @@ where None, ) .await?; + let operation = Box::new(PaymentResponse); connector_http_status_code = router_data.connector_http_status_code; @@ -1923,7 +1924,7 @@ where let connector_tokenization_action = match payment_method_action { TokenizationAction::TokenizeInRouter => { - let (_operation, payment_method_data) = operation + let (_operation, payment_method_data, pm_id) = operation .to_domain()? .make_pm_data( state, @@ -1934,12 +1935,14 @@ where ) .await?; payment_data.payment_method_data = payment_method_data; + payment_data.payment_attempt.payment_method_id = pm_id; + TokenizationAction::SkipConnectorTokenization } TokenizationAction::TokenizeInConnector => TokenizationAction::TokenizeInConnector, TokenizationAction::TokenizeInConnectorAndRouter => { - let (_operation, payment_method_data) = operation + let (_operation, payment_method_data, pm_id) = operation .to_domain()? .make_pm_data( state, @@ -1951,6 +1954,7 @@ where .await?; payment_data.payment_method_data = payment_method_data; + payment_data.payment_attempt.payment_method_id = pm_id; TokenizationAction::TokenizeInConnector } TokenizationAction::ConnectorToken(token) => { @@ -1992,7 +1996,7 @@ where { // On confirm is false and only router related let payment_data = if !is_operation_confirm(operation) { - let (_operation, payment_method_data) = operation + let (_operation, payment_method_data, pm_id) = operation .to_domain()? .make_pm_data( state, @@ -2003,6 +2007,7 @@ where ) .await?; payment_data.payment_method_data = payment_method_data; + payment_data.payment_attempt.payment_method_id = pm_id; payment_data } else { payment_data @@ -2071,6 +2076,7 @@ where pub incremental_authorization_details: Option, pub authorizations: Vec, pub frm_metadata: Option, + pub payment_method_status: Option, } #[derive(Debug, Default, Clone)] diff --git a/crates/router/src/core/payments/flows/authorize_flow.rs b/crates/router/src/core/payments/flows/authorize_flow.rs index 40aac88015f1..a403b03d6af4 100644 --- a/crates/router/src/core/payments/flows/authorize_flow.rs +++ b/crates/router/src/core/payments/flows/authorize_flow.rs @@ -91,19 +91,21 @@ impl Feature for types::PaymentsAu let is_mandate = resp.request.setup_mandate_details.is_some(); if is_mandate { - let payment_method_id = Box::pin(tokenization::save_payment_method( - state, - connector, - resp.to_owned(), - maybe_customer, - merchant_account, - self.request.payment_method_type, - key_store, - is_mandate, - )) - .await?.0; + let (payment_method_id, payment_method_status) = + Box::pin(tokenization::save_payment_method( + state, + connector, + resp.to_owned(), + maybe_customer, + merchant_account, + self.request.payment_method_type, + key_store, + is_mandate, + )) + .await?; resp.payment_method_id = payment_method_id.clone(); + resp.payment_method_status = payment_method_status; Ok(mandate::mandate_procedure( state, @@ -123,19 +125,21 @@ impl Feature for types::PaymentsAu logger::info!("Call to save_payment_method in locker"); - let payment_method_id = Box::pin(tokenization::save_payment_method( - &state, - &connector, - response, - &maybe_customer, - &merchant_account, - self.request.payment_method_type, - &key_store, - is_mandate, - )) - .await?.0; + let (payment_method_id, payment_method_status) = + Box::pin(tokenization::save_payment_method( + &state, + &connector, + response, + &maybe_customer, + &merchant_account, + self.request.payment_method_type, + &key_store, + is_mandate, + )) + .await?; resp.payment_method_id = payment_method_id.clone(); + resp.payment_method_status = payment_method_status; Ok(resp) } diff --git a/crates/router/src/core/payments/flows/setup_mandate_flow.rs b/crates/router/src/core/payments/flows/setup_mandate_flow.rs index fef84814deaf..5a6c2a24d006 100644 --- a/crates/router/src/core/payments/flows/setup_mandate_flow.rs +++ b/crates/router/src/core/payments/flows/setup_mandate_flow.rs @@ -109,7 +109,8 @@ impl Feature for types::Setup key_store, is_mandate, )) - .await?.0; + .await? + .0; mandate::mandate_procedure( state, resp, @@ -246,7 +247,8 @@ impl types::SetupMandateRouterData { key_store, is_mandate, )) - .await?.0; + .await? + .0; Ok(mandate::mandate_procedure( state, @@ -331,7 +333,8 @@ impl types::SetupMandateRouterData { key_store, is_mandate, )) - .await?.0; + .await? + .0; let mandate = state .store .find_mandate_by_merchant_id_mandate_id(&merchant_account.merchant_id, &mandate_id) diff --git a/crates/router/src/core/payments/helpers.rs b/crates/router/src/core/payments/helpers.rs index e0b8a5f62321..88857db9e77f 100644 --- a/crates/router/src/core/payments/helpers.rs +++ b/crates/router/src/core/payments/helpers.rs @@ -1609,6 +1609,7 @@ pub async fn make_pm_data<'a, F: Clone, R, Ctx: PaymentMethodRetrieve>( ) -> RouterResult<( BoxedOperation<'a, F, R, Ctx>, Option, + Option, )> { let request = &payment_data.payment_method_data.clone(); @@ -1687,9 +1688,9 @@ pub async fn make_pm_data<'a, F: Clone, R, Ctx: PaymentMethodRetrieve>( }; // TODO: Handle case where payment method and token both are present in request properly. - let payment_method = match (request, hyperswitch_token) { + let (payment_method, pm_id) = match (request, hyperswitch_token) { (_, Some(hyperswitch_token)) => { - let payment_method_details = Ctx::retrieve_payment_method_with_token( + let (payment_method_details, pm_id) = Ctx::retrieve_payment_method_with_token( state, merchant_key_store, &hyperswitch_token, @@ -1697,15 +1698,17 @@ pub async fn make_pm_data<'a, F: Clone, R, Ctx: PaymentMethodRetrieve>( card_token_data.as_ref(), customer, ) - .await - .attach_printable("in 'make_pm_data'")?; + .await; + + let payment_method_details = + payment_method_details.attach_printable("in 'make_pm_data'")?; Ok::<_, error_stack::Report>( if let Some((payment_method_data, payment_method)) = payment_method_details { payment_data.payment_attempt.payment_method = Some(payment_method); - Some(payment_method_data) + (Some(payment_method_data), pm_id) } else { - None + (None, None) }, ) } @@ -1722,12 +1725,12 @@ pub async fn make_pm_data<'a, F: Clone, R, Ctx: PaymentMethodRetrieve>( payment_data.token = payment_method_data.1; - Ok(payment_method_data.0) + Ok((payment_method_data.0, None)) } - _ => Ok(None), + _ => Ok((None, None)), }?; - Ok((operation, payment_method)) + Ok((operation, payment_method, pm_id)) } pub async fn store_in_vault_and_generate_ppmt( @@ -2964,7 +2967,7 @@ pub async fn get_merchant_connector_account( /// # Arguments /// /// * `router_data` - original router data -/// * `request` - new request +/// * `request` - new requestcore/helper /// * `response` - new response pub fn router_data_type_conversion( router_data: RouterData, @@ -2991,6 +2994,7 @@ pub fn router_data_type_conversion( attempt_id: router_data.attempt_id, access_token: router_data.access_token, session_token: router_data.session_token, + payment_method_status: router_data.payment_method_status, reference_id: router_data.reference_id, payment_method_token: router_data.payment_method_token, customer_id: router_data.customer_id, diff --git a/crates/router/src/core/payments/operations.rs b/crates/router/src/core/payments/operations.rs index 379725a04c6b..f0e526d2e21a 100644 --- a/crates/router/src/core/payments/operations.rs +++ b/crates/router/src/core/payments/operations.rs @@ -136,6 +136,7 @@ pub trait Domain: Send + Sync { ) -> RouterResult<( BoxedOperation<'a, F, R, Ctx>, Option, + Option, )>; async fn add_task_to_process_tracker<'a>( @@ -267,6 +268,7 @@ where ) -> RouterResult<( BoxedOperation<'a, F, api::PaymentsRetrieveRequest, Ctx>, Option, + Option, )> { helpers::make_pm_data( Box::new(self), @@ -335,8 +337,9 @@ where ) -> RouterResult<( BoxedOperation<'a, F, api::PaymentsCaptureRequest, Ctx>, Option, + Option, )> { - Ok((Box::new(self), None)) + Ok((Box::new(self), None, None)) } async fn get_connector<'a>( @@ -408,8 +411,9 @@ where ) -> RouterResult<( BoxedOperation<'a, F, api::PaymentsCancelRequest, Ctx>, Option, + Option, )> { - Ok((Box::new(self), None)) + Ok((Box::new(self), None, None)) } async fn get_connector<'a>( @@ -471,8 +475,9 @@ where ) -> RouterResult<( BoxedOperation<'a, F, api::PaymentsRejectRequest, Ctx>, Option, + Option, )> { - Ok((Box::new(self), None)) + Ok((Box::new(self), None, None)) } async fn get_connector<'a>( diff --git a/crates/router/src/core/payments/operations/payment_approve.rs b/crates/router/src/core/payments/operations/payment_approve.rs index ce3998506c9e..51cf78a78212 100644 --- a/crates/router/src/core/payments/operations/payment_approve.rs +++ b/crates/router/src/core/payments/operations/payment_approve.rs @@ -154,6 +154,7 @@ impl sessions_token: vec![], card_cvc: None, creds_identifier: None, + payment_method_status: None, pm_token: None, connector_customer_id: None, recurring_mandate_payment_data: None, diff --git a/crates/router/src/core/payments/operations/payment_cancel.rs b/crates/router/src/core/payments/operations/payment_cancel.rs index fecf3971019a..b89b42926aa4 100644 --- a/crates/router/src/core/payments/operations/payment_cancel.rs +++ b/crates/router/src/core/payments/operations/payment_cancel.rs @@ -164,6 +164,7 @@ impl card_cvc: None, creds_identifier, pm_token: None, + payment_method_status: None, connector_customer_id: None, recurring_mandate_payment_data: None, ephemeral_key: None, diff --git a/crates/router/src/core/payments/operations/payment_capture.rs b/crates/router/src/core/payments/operations/payment_capture.rs index acf2ce431195..25b4182b1611 100644 --- a/crates/router/src/core/payments/operations/payment_capture.rs +++ b/crates/router/src/core/payments/operations/payment_capture.rs @@ -207,6 +207,7 @@ impl sessions_token: vec![], card_cvc: None, creds_identifier, + payment_method_status: None, pm_token: None, connector_customer_id: None, recurring_mandate_payment_data: None, diff --git a/crates/router/src/core/payments/operations/payment_complete_authorize.rs b/crates/router/src/core/payments/operations/payment_complete_authorize.rs index 6bbe1c89a471..4b9759f94cd1 100644 --- a/crates/router/src/core/payments/operations/payment_complete_authorize.rs +++ b/crates/router/src/core/payments/operations/payment_complete_authorize.rs @@ -250,6 +250,7 @@ impl multiple_capture_data: None, redirect_response, surcharge_details: None, + payment_method_status: None, frm_message: None, payment_link_data: None, incremental_authorization_details: None, @@ -316,8 +317,9 @@ impl Domain RouterResult<( BoxedOperation<'a, F, api::PaymentsRequest, Ctx>, Option, + Option, )> { - let (op, payment_method_data) = helpers::make_pm_data( + let (op, payment_method_data, pm_id) = helpers::make_pm_data( Box::new(self), state, payment_data, @@ -325,7 +327,7 @@ impl Domain card_cvc: request.card_cvc.clone(), creds_identifier, pm_token: None, + payment_method_status: None, connector_customer_id: None, recurring_mandate_payment_data, ephemeral_key: None, @@ -554,15 +555,16 @@ impl Domain RouterResult<( BoxedOperation<'a, F, api::PaymentsRequest, Ctx>, Option, + Option, )> { - let (op, payment_method_data) = + let (op, payment_method_data, pm_id) = helpers::make_pm_data(Box::new(self), state, payment_data, key_store, customer).await?; utils::when(payment_method_data.is_none(), || { Err(errors::ApiErrorResponse::PaymentMethodNotFound) })?; - Ok((op, payment_method_data)) + Ok((op, payment_method_data, pm_id)) } #[instrument(skip_all)] @@ -731,6 +733,7 @@ impl .unwrap_or(payment_data.payment_attempt.amount); let m_payment_data_payment_attempt = payment_data.payment_attempt.clone(); + let m_payment_method_id = payment_data.payment_attempt.payment_method_id.clone(); let m_browser_info = browser_info.clone(); let m_connector = connector.clone(); let m_payment_token = payment_token.clone(); @@ -776,6 +779,7 @@ impl surcharge_amount, tax_amount, fingerprint_id: m_fingerprint_id, + payment_method_id: m_payment_method_id, }, storage_scheme, ) diff --git a/crates/router/src/core/payments/operations/payment_create.rs b/crates/router/src/core/payments/operations/payment_create.rs index 2eaa11f44ee8..8aeff36b6c8a 100644 --- a/crates/router/src/core/payments/operations/payment_create.rs +++ b/crates/router/src/core/payments/operations/payment_create.rs @@ -372,6 +372,7 @@ impl connector_customer_id: None, recurring_mandate_payment_data, ephemeral_key, + payment_method_status: None, multiple_capture_data: None, redirect_response: None, surcharge_details, @@ -433,6 +434,7 @@ impl Domain RouterResult<( BoxedOperation<'a, F, api::PaymentsRequest, Ctx>, Option, + Option, )> { helpers::make_pm_data( Box::new(self), diff --git a/crates/router/src/core/payments/operations/payment_reject.rs b/crates/router/src/core/payments/operations/payment_reject.rs index 02d2e953c19c..a495883ba18a 100644 --- a/crates/router/src/core/payments/operations/payment_reject.rs +++ b/crates/router/src/core/payments/operations/payment_reject.rs @@ -160,6 +160,7 @@ impl surcharge_details: None, frm_message: frm_response.ok(), payment_link_data: None, + payment_method_status: None, incremental_authorization_details: None, authorizations: vec![], frm_metadata: None, diff --git a/crates/router/src/core/payments/operations/payment_response.rs b/crates/router/src/core/payments/operations/payment_response.rs index 099eae71800b..cf1e2bd6e1e8 100644 --- a/crates/router/src/core/payments/operations/payment_response.rs +++ b/crates/router/src/core/payments/operations/payment_response.rs @@ -609,6 +609,8 @@ async fn payment_response_update_tracker( metrics::SUCCESSFUL_PAYMENT.add(&metrics::CONTEXT, 1, &[]); } + let payment_method_id = payment_data.payment_attempt.payment_method_id.clone(); + utils::add_apple_pay_payment_status_metrics( router_data.status, router_data.apple_pay_flow.clone(), @@ -641,7 +643,7 @@ async fn payment_response_update_tracker( amount_capturable: router_data .request .get_amount_capturable(&payment_data, updated_attempt_status), - payment_method_id: Some(router_data.payment_method_id), + payment_method_id: Some(payment_method_id), mandate_id: payment_data .mandate_id .clone() @@ -858,6 +860,7 @@ async fn payment_response_update_tracker( )?; payment_data.payment_intent = payment_intent; + payment_data.payment_method_status = router_data.payment_method_status; Ok(payment_data) } diff --git a/crates/router/src/core/payments/operations/payment_session.rs b/crates/router/src/core/payments/operations/payment_session.rs index 7db174313d92..77cc52be607b 100644 --- a/crates/router/src/core/payments/operations/payment_session.rs +++ b/crates/router/src/core/payments/operations/payment_session.rs @@ -176,6 +176,7 @@ impl sessions_token: vec![], card_cvc: None, creds_identifier, + payment_method_status: None, pm_token: None, connector_customer_id: None, recurring_mandate_payment_data: None, @@ -317,9 +318,10 @@ where ) -> RouterResult<( BoxedOperation<'b, F, api::PaymentsSessionRequest, Ctx>, Option, + Option, )> { //No payment method data for this operation - Ok((Box::new(self), None)) + Ok((Box::new(self), None, None)) } /// Returns `Vec` diff --git a/crates/router/src/core/payments/operations/payment_start.rs b/crates/router/src/core/payments/operations/payment_start.rs index 79130b211a78..b88775888561 100644 --- a/crates/router/src/core/payments/operations/payment_start.rs +++ b/crates/router/src/core/payments/operations/payment_start.rs @@ -161,6 +161,7 @@ impl redirect_response: None, surcharge_details: None, frm_message: None, + payment_method_status: None, payment_link_data: None, incremental_authorization_details: None, authorizations: vec![], @@ -283,6 +284,7 @@ where ) -> RouterResult<( BoxedOperation<'a, F, api::PaymentsStartRequest, Ctx>, Option, + Option, )> { if payment_data .payment_attempt @@ -300,7 +302,7 @@ where ) .await } else { - Ok((Box::new(self), None)) + Ok((Box::new(self), None, None)) } } diff --git a/crates/router/src/core/payments/operations/payment_status.rs b/crates/router/src/core/payments/operations/payment_status.rs index 81dfb7127db3..db47f2a8309b 100644 --- a/crates/router/src/core/payments/operations/payment_status.rs +++ b/crates/router/src/core/payments/operations/payment_status.rs @@ -100,6 +100,7 @@ impl Domain RouterResult<( BoxedOperation<'a, F, api::PaymentsRequest, Ctx>, Option, + Option, )> { helpers::make_pm_data( Box::new(self), @@ -422,6 +423,7 @@ async fn get_tracker_for_sync< card_cvc: None, creds_identifier, pm_token: None, + payment_method_status: None, connector_customer_id: None, recurring_mandate_payment_data: None, ephemeral_key: None, diff --git a/crates/router/src/core/payments/operations/payment_update.rs b/crates/router/src/core/payments/operations/payment_update.rs index 071d919eb191..c6bba01f8386 100644 --- a/crates/router/src/core/payments/operations/payment_update.rs +++ b/crates/router/src/core/payments/operations/payment_update.rs @@ -374,6 +374,7 @@ impl redirect_response: None, surcharge_details, frm_message: None, + payment_method_status: None, payment_link_data: None, incremental_authorization_details: None, authorizations: vec![], @@ -431,6 +432,7 @@ impl Domain RouterResult<( BoxedOperation<'a, F, api::PaymentsRequest, Ctx>, Option, + Option, )> { helpers::make_pm_data( Box::new(self), diff --git a/crates/router/src/core/payments/operations/payments_incremental_authorization.rs b/crates/router/src/core/payments/operations/payments_incremental_authorization.rs index 36095a1b7e8a..cc83f8301ad9 100644 --- a/crates/router/src/core/payments/operations/payments_incremental_authorization.rs +++ b/crates/router/src/core/payments/operations/payments_incremental_authorization.rs @@ -134,6 +134,7 @@ impl sessions_token: vec![], card_cvc: None, creds_identifier: None, + payment_method_status: None, pm_token: None, connector_customer_id: None, recurring_mandate_payment_data: None, @@ -314,8 +315,9 @@ impl ) -> RouterResult<( BoxedOperation<'a, F, PaymentsIncrementalAuthorizationRequest, Ctx>, Option, + Option, )> { - Ok((Box::new(self), None)) + Ok((Box::new(self), None, None)) } async fn get_connector<'a>( diff --git a/crates/router/src/core/payments/transformers.rs b/crates/router/src/core/payments/transformers.rs index f390aeb3eb17..78ad396f2c0d 100644 --- a/crates/router/src/core/payments/transformers.rs +++ b/crates/router/src/core/payments/transformers.rs @@ -147,6 +147,7 @@ where access_token: None, session_token: None, reference_id: None, + payment_method_status: payment_data.payment_method_status, payment_method_token: payment_data.pm_token.map(types::PaymentMethodToken::Token), connector_customer: payment_data.connector_customer_id, recurring_mandate_payment_data: payment_data.recurring_mandate_payment_data, @@ -711,8 +712,8 @@ where .set_authorization_count(payment_intent.authorization_count) .set_incremental_authorizations(incremental_authorizations_response) .set_expires_on(payment_intent.session_expiry) - .set_payment_method_id(payment_attempt.payment_method_id.clone()) - .set_payment_method_status(payment_attempt.payment_method_id) + .set_payment_method_id(payment_attempt.payment_method_id) + .set_payment_method_status(payment_data.payment_method_status) .to_owned(), headers, )) diff --git a/crates/router/src/core/utils.rs b/crates/router/src/core/utils.rs index d749163aa289..30eb7f07b31e 100644 --- a/crates/router/src/core/utils.rs +++ b/crates/router/src/core/utils.rs @@ -148,6 +148,7 @@ pub async fn construct_payout_router_data<'a, F>( auth_type: enums::AuthenticationType::default(), connector_meta_data: merchant_connector_account.get_metadata(), amount_captured: None, + payment_method_status: None, request: types::PayoutsData { payout_id: payouts.payout_id.to_owned(), amount: payouts.amount, @@ -298,6 +299,7 @@ pub async fn construct_refund_router_data<'a, F>( auth_type: payment_attempt.authentication_type.unwrap_or_default(), connector_meta_data: merchant_connector_account.get_metadata(), amount_captured: payment_intent.amount_captured, + payment_method_status: None, request: types::RefundsData { refund_id: refund.refund_id.clone(), connector_transaction_id: refund.connector_transaction_id.clone(), @@ -541,6 +543,7 @@ pub async fn construct_accept_dispute_router_data<'a>( auth_type: payment_attempt.authentication_type.unwrap_or_default(), connector_meta_data: merchant_connector_account.get_metadata(), amount_captured: payment_intent.amount_captured, + payment_method_status: None, request: types::AcceptDisputeRequestData { dispute_id: dispute.dispute_id.clone(), connector_dispute_id: dispute.connector_dispute_id.clone(), @@ -645,6 +648,7 @@ pub async fn construct_submit_evidence_router_data<'a>( recurring_mandate_payment_data: None, preprocessing_id: None, payment_method_balance: None, + payment_method_status: None, connector_request_reference_id: get_connector_request_reference_id( &state.conf, &merchant_account.merchant_id, @@ -725,6 +729,7 @@ pub async fn construct_upload_file_router_data<'a>( auth_type: payment_attempt.authentication_type.unwrap_or_default(), connector_meta_data: merchant_connector_account.get_metadata(), amount_captured: payment_intent.amount_captured, + payment_method_status: None, request: types::UploadFileRequestData { file_key, file: create_file_request.file.clone(), @@ -820,6 +825,7 @@ pub async fn construct_defend_dispute_router_data<'a>( auth_type: payment_attempt.authentication_type.unwrap_or_default(), connector_meta_data: merchant_connector_account.get_metadata(), amount_captured: payment_intent.amount_captured, + payment_method_status: None, request: types::DefendDisputeRequestData { dispute_id: dispute.dispute_id.clone(), connector_dispute_id: dispute.connector_dispute_id.clone(), @@ -907,6 +913,7 @@ pub async fn construct_retrieve_file_router_data<'a>( auth_type: diesel_models::enums::AuthenticationType::default(), connector_meta_data: merchant_connector_account.get_metadata(), amount_captured: None, + payment_method_status: None, request: types::RetrieveFileRequestData { provider_file_id: file_metadata .provider_file_id diff --git a/crates/router/src/core/webhooks/utils.rs b/crates/router/src/core/webhooks/utils.rs index 75d37f942798..86fd1d311713 100644 --- a/crates/router/src/core/webhooks/utils.rs +++ b/crates/router/src/core/webhooks/utils.rs @@ -109,6 +109,7 @@ pub async fn construct_webhook_router_data<'a>( quote_id: None, test_mode: None, payment_method_balance: None, + payment_method_status: None, connector_api_version: None, connector_http_status_code: None, external_latency: None, diff --git a/crates/router/src/types.rs b/crates/router/src/types.rs index 07691879d4ad..dd86b4c58a50 100644 --- a/crates/router/src/types.rs +++ b/crates/router/src/types.rs @@ -322,6 +322,7 @@ pub struct RouterData { pub dispute_id: Option, pub refund_id: Option, + pub payment_method_status: Option, } #[derive(Debug, Clone, serde::Deserialize)] @@ -1465,6 +1466,7 @@ impl From<(&RouterData, T2)> #[cfg(feature = "payouts")] quote_id: data.quote_id.clone(), test_mode: data.test_mode, + payment_method_status: None, payment_method_balance: data.payment_method_balance.clone(), connector_api_version: data.connector_api_version.clone(), connector_http_status_code: data.connector_http_status_code, @@ -1524,6 +1526,7 @@ impl quote_id: data.quote_id.clone(), test_mode: data.test_mode, payment_method_balance: None, + payment_method_status: None, connector_api_version: None, connector_http_status_code: data.connector_http_status_code, external_latency: data.external_latency, diff --git a/crates/router/src/types/api/verify_connector.rs b/crates/router/src/types/api/verify_connector.rs index e4c347187cbc..4bf74420c49d 100644 --- a/crates/router/src/types/api/verify_connector.rs +++ b/crates/router/src/types/api/verify_connector.rs @@ -86,6 +86,7 @@ impl VerifyConnectorData { payment_method_token: None, connector_api_version: None, recurring_mandate_payment_data: None, + payment_method_status: None, connector_request_reference_id: attempt_id, address: types::PaymentAddress { shipping: None, diff --git a/crates/router/tests/connectors/aci.rs b/crates/router/tests/connectors/aci.rs index d3f8147fb262..976add58abe9 100644 --- a/crates/router/tests/connectors/aci.rs +++ b/crates/router/tests/connectors/aci.rs @@ -31,6 +31,8 @@ fn construct_payment_router_data() -> types::PaymentsAuthorizeRouterData { connector_auth_type: utils::to_connector_auth_type(auth.into()), description: Some("This is a test".to_string()), return_url: None, + payment_method_status: None, + payment_method_id: None, request: types::PaymentsAuthorizeData { amount: 1000, currency: enums::Currency::USD, @@ -74,7 +76,6 @@ fn construct_payment_router_data() -> types::PaymentsAuthorizeRouterData { metadata: None, }, response: Err(types::ErrorResponse::default()), - payment_method_id: None, address: PaymentAddress::default(), connector_meta_data: None, amount_captured: None, @@ -115,6 +116,8 @@ fn construct_refund_router_data() -> types::RefundsRouterData { connector: "aci".to_string(), payment_id: uuid::Uuid::new_v4().to_string(), attempt_id: uuid::Uuid::new_v4().to_string(), + payment_method_id: None, + payment_method_status: None, status: enums::AttemptStatus::default(), payment_method: enums::PaymentMethod::Card, auth_type: enums::AuthenticationType::NoThreeDs, @@ -134,7 +137,6 @@ fn construct_refund_router_data() -> types::RefundsRouterData { connector_refund_id: None, browser_info: None, }, - payment_method_id: None, response: Err(types::ErrorResponse::default()), address: PaymentAddress::default(), connector_meta_data: None, diff --git a/crates/router/tests/connectors/utils.rs b/crates/router/tests/connectors/utils.rs index 8f749a0b2ffd..89d6132346f5 100644 --- a/crates/router/tests/connectors/utils.rs +++ b/crates/router/tests/connectors/utils.rs @@ -480,6 +480,7 @@ pub trait ConnectorActions: Connector { payment_id: uuid::Uuid::new_v4().to_string(), attempt_id: uuid::Uuid::new_v4().to_string(), status: enums::AttemptStatus::default(), + payment_method_id: None, auth_type: info .clone() .map_or(enums::AuthenticationType::NoThreeDs, |a| { @@ -490,9 +491,9 @@ pub trait ConnectorActions: Connector { connector_auth_type: self.get_auth_token(), description: Some("This is a test".to_string()), return_url: info.clone().and_then(|a| a.return_url), + payment_method_status: None, request: req, response: Err(types::ErrorResponse::default()), - payment_method_id: None, address: info .clone() .and_then(|a| a.address) diff --git a/crates/storage_impl/src/payments/payment_attempt.rs b/crates/storage_impl/src/payments/payment_attempt.rs index a51f95e1e749..024cd2b12105 100644 --- a/crates/storage_impl/src/payments/payment_attempt.rs +++ b/crates/storage_impl/src/payments/payment_attempt.rs @@ -1383,6 +1383,7 @@ impl DataModelExt for PaymentAttemptUpdate { fingerprint_id, updated_by, merchant_connector_id: connector_id, + payment_method_id, } => DieselPaymentAttemptUpdate::ConfirmUpdate { amount, currency, @@ -1405,6 +1406,7 @@ impl DataModelExt for PaymentAttemptUpdate { fingerprint_id, updated_by, merchant_connector_id: connector_id, + payment_method_id, }, Self::VoidUpdate { status, @@ -1655,6 +1657,7 @@ impl DataModelExt for PaymentAttemptUpdate { fingerprint_id, updated_by, merchant_connector_id: connector_id, + payment_method_id, } => Self::ConfirmUpdate { amount, currency, @@ -1677,6 +1680,7 @@ impl DataModelExt for PaymentAttemptUpdate { fingerprint_id, updated_by, merchant_connector_id: connector_id, + payment_method_id }, DieselPaymentAttemptUpdate::VoidUpdate { status, From 25975353e9127a6878630c011fe83f948b271113 Mon Sep 17 00:00:00 2001 From: "hyperswitch-bot[bot]" <148525504+hyperswitch-bot[bot]@users.noreply.github.com> Date: Fri, 1 Mar 2024 09:49:55 +0000 Subject: [PATCH 07/32] chore: run formatter --- crates/router/src/core/payment_methods.rs | 150 ++++++++---------- .../payments/operations/payment_confirm.rs | 2 +- .../src/payments/payment_attempt.rs | 2 +- 3 files changed, 72 insertions(+), 82 deletions(-) diff --git a/crates/router/src/core/payment_methods.rs b/crates/router/src/core/payment_methods.rs index 9e889790850a..96ee61aae195 100644 --- a/crates/router/src/core/payment_methods.rs +++ b/crates/router/src/core/payment_methods.rs @@ -136,95 +136,85 @@ impl PaymentMethodRetrieve for Oss { Option, ) { match token_data { - storage::PaymentTokenData::TemporaryGeneric(generic_token) => { - ( - helpers::retrieve_payment_method_with_temporary_token( - state, - &generic_token.token, - payment_intent, - merchant_key_store, - card_token_data, - ) - .await, - None, + storage::PaymentTokenData::TemporaryGeneric(generic_token) => ( + helpers::retrieve_payment_method_with_temporary_token( + state, + &generic_token.token, + payment_intent, + merchant_key_store, + card_token_data, ) - } + .await, + None, + ), - storage::PaymentTokenData::Temporary(generic_token) => { - ( - helpers::retrieve_payment_method_with_temporary_token( - state, - &generic_token.token, - payment_intent, - merchant_key_store, - card_token_data, - ) - .await, - None, + storage::PaymentTokenData::Temporary(generic_token) => ( + helpers::retrieve_payment_method_with_temporary_token( + state, + &generic_token.token, + payment_intent, + merchant_key_store, + card_token_data, ) - } + .await, + None, + ), - storage::PaymentTokenData::Permanent(card_token) => { - ( - helpers::retrieve_card_with_permanent_token( - state, - card_token.locker_id.as_ref().unwrap_or(&card_token.token), - card_token - .payment_method_id - .as_ref() - .unwrap_or(&card_token.token), - payment_intent, - card_token_data, - ) - .await - .map(|card| Some((card, enums::PaymentMethod::Card))), - Some( - card_token - .payment_method_id - .as_ref() - .unwrap_or(&card_token.token) - .to_string(), - ), + storage::PaymentTokenData::Permanent(card_token) => ( + helpers::retrieve_card_with_permanent_token( + state, + card_token.locker_id.as_ref().unwrap_or(&card_token.token), + card_token + .payment_method_id + .as_ref() + .unwrap_or(&card_token.token), + payment_intent, + card_token_data, ) - } + .await + .map(|card| Some((card, enums::PaymentMethod::Card))), + Some( + card_token + .payment_method_id + .as_ref() + .unwrap_or(&card_token.token) + .to_string(), + ), + ), - storage::PaymentTokenData::PermanentCard(card_token) => { - ( - helpers::retrieve_card_with_permanent_token( - state, - card_token.locker_id.as_ref().unwrap_or(&card_token.token), - card_token - .payment_method_id - .as_ref() - .unwrap_or(&card_token.token), - payment_intent, - card_token_data, - ) - .await - .map(|card| Some((card, enums::PaymentMethod::Card))), - Some( - card_token - .payment_method_id - .as_ref() - .unwrap_or(&card_token.token) - .to_string(), - ), + storage::PaymentTokenData::PermanentCard(card_token) => ( + helpers::retrieve_card_with_permanent_token( + state, + card_token.locker_id.as_ref().unwrap_or(&card_token.token), + card_token + .payment_method_id + .as_ref() + .unwrap_or(&card_token.token), + payment_intent, + card_token_data, ) - } + .await + .map(|card| Some((card, enums::PaymentMethod::Card))), + Some( + card_token + .payment_method_id + .as_ref() + .unwrap_or(&card_token.token) + .to_string(), + ), + ), - storage::PaymentTokenData::AuthBankDebit(auth_token) => { - ( - core_pm_auth::retrieve_payment_method_from_auth_service( - state, - merchant_key_store, - auth_token, - payment_intent, - customer, - ) - .await, - None, + storage::PaymentTokenData::AuthBankDebit(auth_token) => ( + core_pm_auth::retrieve_payment_method_from_auth_service( + state, + merchant_key_store, + auth_token, + payment_intent, + customer, ) - } + .await, + None, + ), } } } diff --git a/crates/router/src/core/payments/operations/payment_confirm.rs b/crates/router/src/core/payments/operations/payment_confirm.rs index f62ad2f9d0ea..ceb5f3a18041 100644 --- a/crates/router/src/core/payments/operations/payment_confirm.rs +++ b/crates/router/src/core/payments/operations/payment_confirm.rs @@ -733,7 +733,7 @@ impl .unwrap_or(payment_data.payment_attempt.amount); let m_payment_data_payment_attempt = payment_data.payment_attempt.clone(); - let m_payment_method_id = payment_data.payment_attempt.payment_method_id.clone(); + let m_payment_method_id = payment_data.payment_attempt.payment_method_id.clone(); let m_browser_info = browser_info.clone(); let m_connector = connector.clone(); let m_payment_token = payment_token.clone(); diff --git a/crates/storage_impl/src/payments/payment_attempt.rs b/crates/storage_impl/src/payments/payment_attempt.rs index 024cd2b12105..df0b5a13ada9 100644 --- a/crates/storage_impl/src/payments/payment_attempt.rs +++ b/crates/storage_impl/src/payments/payment_attempt.rs @@ -1680,7 +1680,7 @@ impl DataModelExt for PaymentAttemptUpdate { fingerprint_id, updated_by, merchant_connector_id: connector_id, - payment_method_id + payment_method_id, }, DieselPaymentAttemptUpdate::VoidUpdate { status, From 23c2b771a6a2aaf72e51183c64f9ec7215a72a24 Mon Sep 17 00:00:00 2001 From: prajjwalkumar17 Date: Fri, 1 Mar 2024 15:35:08 +0530 Subject: [PATCH 08/32] chore: updated openapi spec --- openapi/openapi_spec.json | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/openapi/openapi_spec.json b/openapi/openapi_spec.json index fd9471528029..7c567d39b369 100644 --- a/openapi/openapi_spec.json +++ b/openapi/openapi_spec.json @@ -13888,8 +13888,11 @@ "nullable": true }, "payment_method_status": { - "type": "string", - "description": "Payment Method Status", + "allOf": [ + { + "$ref": "#/components/schemas/common_enums.PaymentMethodStatus" + } + ], "nullable": true } } From 2bd0a614d4337e2aeb3123be2cbb6fd99844b7de Mon Sep 17 00:00:00 2001 From: prajjwalkumar17 Date: Fri, 1 Mar 2024 17:01:48 +0530 Subject: [PATCH 09/32] chore: updated openapi spec --- crates/common_enums/src/enums.rs | 6 +++--- crates/openapi/src/openapi.rs | 1 + openapi/openapi_spec.json | 8 ++++++++ 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/crates/common_enums/src/enums.rs b/crates/common_enums/src/enums.rs index 071d6992cbeb..bbd2c97a5143 100644 --- a/crates/common_enums/src/enums.rs +++ b/crates/common_enums/src/enums.rs @@ -1206,9 +1206,9 @@ pub enum PaymentMethodStatus { impl From for PaymentMethodStatus { fn from(attempt_status: AttemptStatus) -> Self { match attempt_status { - AttemptStatus::Charged => PaymentMethodStatus::Active, - AttemptStatus::Failure => PaymentMethodStatus::Inactive, - _ => PaymentMethodStatus::Processing, + AttemptStatus::Charged => Self::Active, + AttemptStatus::Failure => Self::Inactive, + _ => Self::Processing, } } } diff --git a/crates/openapi/src/openapi.rs b/crates/openapi/src/openapi.rs index e21797d2eefa..3e86726d57a3 100644 --- a/crates/openapi/src/openapi.rs +++ b/crates/openapi/src/openapi.rs @@ -225,6 +225,7 @@ Never share your secret api keys. Keep them guarded and secure. api_models::enums::ReconStatus, api_models::enums::ConnectorStatus, api_models::enums::AuthorizationStatus, + api_models::enums::PaymentMethodStatus, api_models::admin::MerchantConnectorCreate, api_models::admin::MerchantConnectorUpdate, api_models::admin::PrimaryBusinessDetails, diff --git a/openapi/openapi_spec.json b/openapi/openapi_spec.json index 7c567d39b369..ca0ac543b2a6 100644 --- a/openapi/openapi_spec.json +++ b/openapi/openapi_spec.json @@ -12013,6 +12013,14 @@ } } }, + "PaymentMethodStatus": { + "type": "string", + "enum": [ + "active", + "inactive", + "processing" + ] + }, "PaymentMethodType": { "type": "string", "description": "Indicates the sub type of payment method. Eg: 'google_pay' & 'apple_pay' for wallets.", From 0a4ea1d2425b10bc9e33f98ffc97e25775b3ddc8 Mon Sep 17 00:00:00 2001 From: prajjwalkumar17 Date: Fri, 1 Mar 2024 17:33:06 +0530 Subject: [PATCH 10/32] chore: updated openapi spec --- crates/api_models/src/payments.rs | 1 + openapi/openapi_spec.json | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/crates/api_models/src/payments.rs b/crates/api_models/src/payments.rs index 9586ddd1c157..3101ce060c45 100644 --- a/crates/api_models/src/payments.rs +++ b/crates/api_models/src/payments.rs @@ -2529,6 +2529,7 @@ pub struct PaymentsResponse { pub payment_method_id: Option, /// Payment Method Status + #[schema(value_type = Option)] pub payment_method_status: Option, } diff --git a/openapi/openapi_spec.json b/openapi/openapi_spec.json index ca0ac543b2a6..d90c0d49acd0 100644 --- a/openapi/openapi_spec.json +++ b/openapi/openapi_spec.json @@ -13898,7 +13898,7 @@ "payment_method_status": { "allOf": [ { - "$ref": "#/components/schemas/common_enums.PaymentMethodStatus" + "$ref": "#/components/schemas/PaymentMethodStatus" } ], "nullable": true From d351c1fa263a7522475331ad81a42edb2ed494ef Mon Sep 17 00:00:00 2001 From: prajjwalkumar17 Date: Mon, 4 Mar 2024 17:23:11 +0530 Subject: [PATCH 11/32] chore: addressed the comments --- crates/diesel_models/src/schema.rs | 33 ++++ crates/router/src/core/payment_methods.rs | 147 +++++++++--------- crates/router/src/core/payments/helpers.rs | 14 +- .../src/types/storage/payment_method.rs | 9 ++ 4 files changed, 123 insertions(+), 80 deletions(-) diff --git a/crates/diesel_models/src/schema.rs b/crates/diesel_models/src/schema.rs index 35239ce0268d..49ba814709ae 100644 --- a/crates/diesel_models/src/schema.rs +++ b/crates/diesel_models/src/schema.rs @@ -58,6 +58,38 @@ diesel::table! { } } +diesel::table! { + use diesel::sql_types::*; + use crate::enums::diesel_exports::*; + + authentication (authentication_id) { + #[max_length = 64] + authentication_id -> Varchar, + #[max_length = 64] + merchant_id -> Varchar, + #[max_length = 64] + authentication_connector -> Varchar, + #[max_length = 64] + connector_authentication_id -> Nullable, + authentication_data -> Nullable, + #[max_length = 64] + payment_method_id -> Varchar, + #[max_length = 64] + authentication_type -> Nullable, + #[max_length = 64] + authentication_status -> Varchar, + #[max_length = 64] + authentication_lifecycle_status -> Varchar, + created_at -> Timestamp, + modified_at -> Timestamp, + #[max_length = 64] + error_message -> Nullable, + #[max_length = 64] + error_code -> Nullable, + connector_metadata -> Nullable, + } +} + diesel::table! { use diesel::sql_types::*; use crate::enums::diesel_exports::*; @@ -1108,6 +1140,7 @@ diesel::table! { diesel::allow_tables_to_appear_in_same_query!( address, api_keys, + authentication, blocklist, blocklist_fingerprint, blocklist_lookup, diff --git a/crates/router/src/core/payment_methods.rs b/crates/router/src/core/payment_methods.rs index 96ee61aae195..343d5a987cf6 100644 --- a/crates/router/src/core/payment_methods.rs +++ b/crates/router/src/core/payment_methods.rs @@ -13,11 +13,7 @@ use data_models::payments::{payment_attempt::PaymentAttempt, PaymentIntent}; use diesel_models::enums; use crate::{ - core::{ - errors::RouterResult, - payments::helpers, - pm_auth::{self as core_pm_auth}, - }, + core::{errors::RouterResult, payments::helpers, pm_auth as core_pm_auth}, routes::AppState, types::{ api::{self, payments}, @@ -44,10 +40,7 @@ pub trait PaymentMethodRetrieve { payment_intent: &PaymentIntent, card_token_data: Option<&CardToken>, customer: &Option, - ) -> ( - RouterResult>, - Option, - ); + ) -> RouterResult; } #[async_trait::async_trait] @@ -131,37 +124,38 @@ impl PaymentMethodRetrieve for Oss { payment_intent: &PaymentIntent, card_token_data: Option<&CardToken>, customer: &Option, - ) -> ( - RouterResult>, - Option, - ) { - match token_data { - storage::PaymentTokenData::TemporaryGeneric(generic_token) => ( - helpers::retrieve_payment_method_with_temporary_token( - state, - &generic_token.token, - payment_intent, - merchant_key_store, - card_token_data, - ) - .await, - None, - ), + ) -> RouterResult { + Ok(match token_data { + storage::PaymentTokenData::TemporaryGeneric(generic_token) => { + storage::PaymentMethodDataWithId { + payment_method_data: helpers::retrieve_payment_method_with_temporary_token( + state, + &generic_token.token, + payment_intent, + merchant_key_store, + card_token_data, + ) + .await?, + payment_method_id: None, + } + } - storage::PaymentTokenData::Temporary(generic_token) => ( - helpers::retrieve_payment_method_with_temporary_token( - state, - &generic_token.token, - payment_intent, - merchant_key_store, - card_token_data, - ) - .await, - None, - ), + storage::PaymentTokenData::Temporary(generic_token) => { + storage::PaymentMethodDataWithId { + payment_method_data: helpers::retrieve_payment_method_with_temporary_token( + state, + &generic_token.token, + payment_intent, + merchant_key_store, + card_token_data, + ) + .await?, + payment_method_id: None, + } + } - storage::PaymentTokenData::Permanent(card_token) => ( - helpers::retrieve_card_with_permanent_token( + storage::PaymentTokenData::Permanent(card_token) => storage::PaymentMethodDataWithId { + payment_method_data: helpers::retrieve_card_with_permanent_token( state, card_token.locker_id.as_ref().unwrap_or(&card_token.token), card_token @@ -172,49 +166,54 @@ impl PaymentMethodRetrieve for Oss { card_token_data, ) .await - .map(|card| Some((card, enums::PaymentMethod::Card))), - Some( + .map(|card| Some((card, enums::PaymentMethod::Card)))?, + payment_method_id: Some( card_token .payment_method_id .as_ref() .unwrap_or(&card_token.token) .to_string(), ), - ), + }, - storage::PaymentTokenData::PermanentCard(card_token) => ( - helpers::retrieve_card_with_permanent_token( - state, - card_token.locker_id.as_ref().unwrap_or(&card_token.token), - card_token - .payment_method_id - .as_ref() - .unwrap_or(&card_token.token), - payment_intent, - card_token_data, - ) - .await - .map(|card| Some((card, enums::PaymentMethod::Card))), - Some( - card_token - .payment_method_id - .as_ref() - .unwrap_or(&card_token.token) - .to_string(), - ), - ), + storage::PaymentTokenData::PermanentCard(card_token) => { + storage::PaymentMethodDataWithId { + payment_method_data: helpers::retrieve_card_with_permanent_token( + state, + card_token.locker_id.as_ref().unwrap_or(&card_token.token), + card_token + .payment_method_id + .as_ref() + .unwrap_or(&card_token.token), + payment_intent, + card_token_data, + ) + .await + .map(|card| Some((card, enums::PaymentMethod::Card)))?, - storage::PaymentTokenData::AuthBankDebit(auth_token) => ( - core_pm_auth::retrieve_payment_method_from_auth_service( - state, - merchant_key_store, - auth_token, - payment_intent, - customer, - ) - .await, - None, - ), - } + payment_method_id: Some( + card_token + .payment_method_id + .as_ref() + .unwrap_or(&card_token.token) + .to_string(), + ), + } + } + + storage::PaymentTokenData::AuthBankDebit(auth_token) => { + storage::PaymentMethodDataWithId { + payment_method_data: core_pm_auth::retrieve_payment_method_from_auth_service( + state, + merchant_key_store, + auth_token, + payment_intent, + customer, + ) + .await?, + payment_method_id: None, + } + } + }) } } diff --git a/crates/router/src/core/payments/helpers.rs b/crates/router/src/core/payments/helpers.rs index a71adee1f4bc..dc702e3bad92 100644 --- a/crates/router/src/core/payments/helpers.rs +++ b/crates/router/src/core/payments/helpers.rs @@ -1690,7 +1690,7 @@ pub async fn make_pm_data<'a, F: Clone, R, Ctx: PaymentMethodRetrieve>( // TODO: Handle case where payment method and token both are present in request properly. let (payment_method, pm_id) = match (request, hyperswitch_token) { (_, Some(hyperswitch_token)) => { - let (payment_method_details, pm_id) = Ctx::retrieve_payment_method_with_token( + let pm_data = Ctx::retrieve_payment_method_with_token( state, merchant_key_store, &hyperswitch_token, @@ -1700,13 +1700,15 @@ pub async fn make_pm_data<'a, F: Clone, R, Ctx: PaymentMethodRetrieve>( ) .await; - let payment_method_details = - payment_method_details.attach_printable("in 'make_pm_data'")?; + let payment_method_details = pm_data.attach_printable("in 'make_pm_data'")?; Ok::<_, error_stack::Report>( - if let Some((payment_method_data, payment_method)) = payment_method_details { + if let (Some((payment_method_data, payment_method)), Some(pm_id)) = ( + payment_method_details.payment_method_data, + payment_method_details.payment_method_id, + ) { payment_data.payment_attempt.payment_method = Some(payment_method); - (Some(payment_method_data), pm_id) + (Some(payment_method_data), Some(pm_id)) } else { (None, None) }, @@ -2967,7 +2969,7 @@ pub async fn get_merchant_connector_account( /// # Arguments /// /// * `router_data` - original router data -/// * `request` - new requestcore/helper +/// * `request` - new request core/helper /// * `response` - new response pub fn router_data_type_conversion( router_data: RouterData, diff --git a/crates/router/src/types/storage/payment_method.rs b/crates/router/src/types/storage/payment_method.rs index a787a4d932c7..560d7dfc384b 100644 --- a/crates/router/src/types/storage/payment_method.rs +++ b/crates/router/src/types/storage/payment_method.rs @@ -1,9 +1,12 @@ use api_models::payment_methods; +use diesel_models::enums; pub use diesel_models::payment_method::{ PaymentMethod, PaymentMethodNew, PaymentMethodUpdate, PaymentMethodUpdateInternal, TokenizeCoreWorkflow, }; +use crate::types::api::payments; + #[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] #[serde(rename_all = "snake_case")] pub enum PaymentTokenKind { @@ -18,6 +21,12 @@ pub struct CardTokenData { pub token: String, } +#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] +pub struct PaymentMethodDataWithId { + pub payment_method_data: Option<(payments::PaymentMethodData, enums::PaymentMethod)>, + pub payment_method_id: Option, +} + #[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] pub struct GenericTokenData { pub token: String, From 230c058635a4896603a48117239ab589caab0f61 Mon Sep 17 00:00:00 2001 From: prajjwalkumar17 Date: Tue, 5 Mar 2024 15:53:40 +0530 Subject: [PATCH 12/32] chore: removed the status failing check --- crates/router/src/core/payments/helpers.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/crates/router/src/core/payments/helpers.rs b/crates/router/src/core/payments/helpers.rs index dc702e3bad92..d79cb99cca00 100644 --- a/crates/router/src/core/payments/helpers.rs +++ b/crates/router/src/core/payments/helpers.rs @@ -1703,14 +1703,16 @@ pub async fn make_pm_data<'a, F: Clone, R, Ctx: PaymentMethodRetrieve>( let payment_method_details = pm_data.attach_printable("in 'make_pm_data'")?; Ok::<_, error_stack::Report>( - if let (Some((payment_method_data, payment_method)), Some(pm_id)) = ( - payment_method_details.payment_method_data, - payment_method_details.payment_method_id, - ) { + if let Some((payment_method_data, payment_method)) = + payment_method_details.payment_method_data + { payment_data.payment_attempt.payment_method = Some(payment_method); - (Some(payment_method_data), Some(pm_id)) + ( + Some(payment_method_data), + payment_method_details.payment_method_id, + ) } else { - (None, None) + (None, payment_method_details.payment_method_id) }, ) } From 293be3058de636492d3b0450c03741d4712e4c06 Mon Sep 17 00:00:00 2001 From: prajjwalkumar17 Date: Wed, 6 Mar 2024 13:34:55 +0530 Subject: [PATCH 13/32] chore: restored connector file --- config/development.toml | 2 +- crates/router/src/connector/fiserv/transformers.rs | 12 ++++++------ crates/router/src/core/payments/helpers.rs | 1 + 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/config/development.toml b/config/development.toml index 8b3c036af4d1..c0716c02a5fe 100644 --- a/config/development.toml +++ b/config/development.toml @@ -3,7 +3,7 @@ enabled = false [log.console] enabled = true -level = "DEBUG" +level = "WARN" log_format = "default" [log.telemetry] diff --git a/crates/router/src/connector/fiserv/transformers.rs b/crates/router/src/connector/fiserv/transformers.rs index e2511dc8d568..b8dd3c9643fb 100644 --- a/crates/router/src/connector/fiserv/transformers.rs +++ b/crates/router/src/connector/fiserv/transformers.rs @@ -62,8 +62,8 @@ pub enum Source { }, #[allow(dead_code)] GooglePay { - data: String, - signature: String, + data: Secret, + signature: Secret, version: String, }, } @@ -80,8 +80,8 @@ pub struct CardData { #[derive(Default, Debug, Serialize)] #[serde(rename_all = "camelCase")] pub struct GooglePayToken { - signature: String, - signed_message: String, + signature: Secret, + signed_message: Secret, protocol_version: String, } @@ -104,7 +104,7 @@ pub struct TransactionDetails { #[serde(rename_all = "camelCase")] pub struct MerchantDetails { merchant_id: Secret, - terminal_id: Option, + terminal_id: Option>, } #[derive(Default, Debug, Serialize)] @@ -428,7 +428,7 @@ pub struct ReferenceTransactionDetails { #[derive(Debug, Default, Serialize, Deserialize)] pub struct FiservSessionObject { - pub terminal_id: String, + pub terminal_id: Secret, } impl TryFrom<&Option> for FiservSessionObject { diff --git a/crates/router/src/core/payments/helpers.rs b/crates/router/src/core/payments/helpers.rs index d79cb99cca00..cd315f8de8cd 100644 --- a/crates/router/src/core/payments/helpers.rs +++ b/crates/router/src/core/payments/helpers.rs @@ -1461,6 +1461,7 @@ pub async fn retrieve_payment_method_with_temporary_token( "Payment method for given token not found or there was a problem fetching it", )?; + println!(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>{:?}",pm); utils::when( supplementary_data .customer_id From 06e28b19354ae3be23d080b8cde1aaeddb1d9053 Mon Sep 17 00:00:00 2001 From: prajjwalkumar17 Date: Thu, 7 Mar 2024 18:30:23 +0530 Subject: [PATCH 14/32] chore: resolve conflicts --- crates/router/src/core/payment_methods.rs | 11 ++++++++--- .../router/src/core/payments/flows/authorize_flow.rs | 8 ++++---- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/crates/router/src/core/payment_methods.rs b/crates/router/src/core/payment_methods.rs index 3d7a2edfb769..2caf2b4caed2 100644 --- a/crates/router/src/core/payment_methods.rs +++ b/crates/router/src/core/payment_methods.rs @@ -199,7 +199,7 @@ impl PaymentMethodRetrieve for Oss { .to_string(), ), } - } + }, storage::PaymentTokenData::AuthBankDebit(auth_token) => { storage::PaymentMethodDataWithId { @@ -213,9 +213,14 @@ impl PaymentMethodRetrieve for Oss { .await?, payment_method_id: None, } - } + }, - storage::PaymentTokenData::WalletToken(_) => Ok(None), + storage::PaymentTokenData::WalletToken(_) => { + storage::PaymentMethodDataWithId { + payment_method_data: None, + payment_method_id: None, + } + }, }) } } diff --git a/crates/router/src/core/payments/flows/authorize_flow.rs b/crates/router/src/core/payments/flows/authorize_flow.rs index b36207edcd1a..4512b8c8e1c5 100644 --- a/crates/router/src/core/payments/flows/authorize_flow.rs +++ b/crates/router/src/core/payments/flows/authorize_flow.rs @@ -91,10 +91,7 @@ impl Feature for types::PaymentsAu let is_mandate = resp.request.setup_mandate_details.is_some(); if is_mandate { - resp.payment_method_id = payment_method_id.clone(); - resp.payment_method_status = payment_method_status; - - let (payment_method_id, payment_method_status) = = Box::pin(tokenization::save_payment_method( + let (payment_method_id, payment_method_status) = Box::pin(tokenization::save_payment_method( state, connector, resp.to_owned(), @@ -105,6 +102,9 @@ impl Feature for types::PaymentsAu )) .await?; + resp.payment_method_id = payment_method_id.clone(); + resp.payment_method_status = payment_method_status; + Ok(mandate::mandate_procedure( state, resp, From cb4a0253c3ac290127ee67ced7a89d1a96a7665d Mon Sep 17 00:00:00 2001 From: "hyperswitch-bot[bot]" <148525504+hyperswitch-bot[bot]@users.noreply.github.com> Date: Thu, 7 Mar 2024 13:05:20 +0000 Subject: [PATCH 15/32] chore: run formatter --- crates/router/src/core/payment_methods.rs | 12 +++++------ .../src/core/payments/flows/authorize_flow.rs | 21 ++++++++++--------- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/crates/router/src/core/payment_methods.rs b/crates/router/src/core/payment_methods.rs index 2caf2b4caed2..1754c650f1dc 100644 --- a/crates/router/src/core/payment_methods.rs +++ b/crates/router/src/core/payment_methods.rs @@ -199,7 +199,7 @@ impl PaymentMethodRetrieve for Oss { .to_string(), ), } - }, + } storage::PaymentTokenData::AuthBankDebit(auth_token) => { storage::PaymentMethodDataWithId { @@ -213,13 +213,11 @@ impl PaymentMethodRetrieve for Oss { .await?, payment_method_id: None, } - }, + } - storage::PaymentTokenData::WalletToken(_) => { - storage::PaymentMethodDataWithId { - payment_method_data: None, - payment_method_id: None, - } + storage::PaymentTokenData::WalletToken(_) => storage::PaymentMethodDataWithId { + payment_method_data: None, + payment_method_id: None, }, }) } diff --git a/crates/router/src/core/payments/flows/authorize_flow.rs b/crates/router/src/core/payments/flows/authorize_flow.rs index 4512b8c8e1c5..4f50deeb556c 100644 --- a/crates/router/src/core/payments/flows/authorize_flow.rs +++ b/crates/router/src/core/payments/flows/authorize_flow.rs @@ -91,16 +91,17 @@ impl Feature for types::PaymentsAu let is_mandate = resp.request.setup_mandate_details.is_some(); if is_mandate { - let (payment_method_id, payment_method_status) = Box::pin(tokenization::save_payment_method( - state, - connector, - resp.to_owned(), - maybe_customer, - merchant_account, - self.request.payment_method_type, - key_store, - )) - .await?; + let (payment_method_id, payment_method_status) = + Box::pin(tokenization::save_payment_method( + state, + connector, + resp.to_owned(), + maybe_customer, + merchant_account, + self.request.payment_method_type, + key_store, + )) + .await?; resp.payment_method_id = payment_method_id.clone(); resp.payment_method_status = payment_method_status; From 933db1a6e5471b20445e85d98142f1bb2b007860 Mon Sep 17 00:00:00 2001 From: prajjwalkumar17 Date: Thu, 7 Mar 2024 18:47:21 +0530 Subject: [PATCH 16/32] chore: add pm_id and pm_status froom setup mandate flow --- .../src/core/payments/flows/setup_mandate_flow.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/crates/router/src/core/payments/flows/setup_mandate_flow.rs b/crates/router/src/core/payments/flows/setup_mandate_flow.rs index cbd87155f5b1..54f86b01063d 100644 --- a/crates/router/src/core/payments/flows/setup_mandate_flow.rs +++ b/crates/router/src/core/payments/flows/setup_mandate_flow.rs @@ -89,7 +89,7 @@ impl Feature for types::Setup types::PaymentsResponseData, > = connector.connector.get_connector_integration(); - let resp = services::execute_connector_processing_step( + let mut resp = services::execute_connector_processing_step( state, connector_integration, &self, @@ -99,7 +99,7 @@ impl Feature for types::Setup .await .to_setup_mandate_failed_response()?; - let pm_id = Box::pin(tokenization::save_payment_method( + let (pm_id, payment_method_status) = Box::pin(tokenization::save_payment_method( state, connector, resp.to_owned(), @@ -108,8 +108,10 @@ impl Feature for types::Setup self.request.payment_method_type, key_store, )) - .await? - .0; + .await?; + + resp.payment_method_id = pm_id.clone(); + resp.payment_method_status = payment_method_status; mandate::mandate_procedure( state, resp, From 39c06dd936dec803cfa04f4a5d91c8b31f4c0904 Mon Sep 17 00:00:00 2001 From: "hyperswitch-bot[bot]" <148525504+hyperswitch-bot[bot]@users.noreply.github.com> Date: Thu, 7 Mar 2024 13:46:37 +0000 Subject: [PATCH 17/32] chore: run formatter --- crates/router/src/core/payments/helpers.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/router/src/core/payments/helpers.rs b/crates/router/src/core/payments/helpers.rs index a2c2fa638a7a..652005b7b7c4 100644 --- a/crates/router/src/core/payments/helpers.rs +++ b/crates/router/src/core/payments/helpers.rs @@ -1451,7 +1451,7 @@ pub async fn retrieve_payment_method_with_temporary_token( "Payment method for given token not found or there was a problem fetching it", )?; - println!(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>{:?}",pm); + println!(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>{:?}", pm); utils::when( supplementary_data .customer_id From d8e3202a6eaaf1ba27e0c4102375ec1f2b7749c8 Mon Sep 17 00:00:00 2001 From: prajjwalkumar17 Date: Thu, 7 Mar 2024 19:25:48 +0530 Subject: [PATCH 18/32] chore: debug logs --- config/development.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config/development.toml b/config/development.toml index 3442af16a679..408c60912122 100644 --- a/config/development.toml +++ b/config/development.toml @@ -3,7 +3,7 @@ enabled = false [log.console] enabled = true -level = "WARN" +level = "DEBUG" log_format = "default" [log.telemetry] @@ -579,4 +579,4 @@ enabled = true file_storage_backend = "file_system" [unmasked_headers] -keys = "user-agent" \ No newline at end of file +keys = "user-agent" From 9a8e0fb17cf22f9fa1966c018de1bf1660abee08 Mon Sep 17 00:00:00 2001 From: prajjwalkumar17 Date: Thu, 7 Mar 2024 19:28:09 +0530 Subject: [PATCH 19/32] chore: debug logs --- config/development.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/config/development.toml b/config/development.toml index 408c60912122..877aac66be75 100644 --- a/config/development.toml +++ b/config/development.toml @@ -580,3 +580,4 @@ file_storage_backend = "file_system" [unmasked_headers] keys = "user-agent" + From 56b8cc7a65f2dafe89f5927169e5cffab59b171f Mon Sep 17 00:00:00 2001 From: prajjwalkumar17 Date: Thu, 7 Mar 2024 19:28:53 +0530 Subject: [PATCH 20/32] chore: removed trailing spaces --- config/development.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/config/development.toml b/config/development.toml index 877aac66be75..408c60912122 100644 --- a/config/development.toml +++ b/config/development.toml @@ -580,4 +580,3 @@ file_storage_backend = "file_system" [unmasked_headers] keys = "user-agent" - From 112e814ed41e40fe4fe7954de9e4fcac1cf83840 Mon Sep 17 00:00:00 2001 From: prajjwalkumar17 Date: Thu, 7 Mar 2024 19:31:07 +0530 Subject: [PATCH 21/32] chore: updated development.toml --- config/development.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/development.toml b/config/development.toml index 408c60912122..c7bfefc3435d 100644 --- a/config/development.toml +++ b/config/development.toml @@ -579,4 +579,4 @@ enabled = true file_storage_backend = "file_system" [unmasked_headers] -keys = "user-agent" +keys = "user-agent" \ No newline at end of file From fe1ff879fd62a368bbb5ad045ff59b1ffd6e7b3e Mon Sep 17 00:00:00 2001 From: prajjwalkumar17 Date: Thu, 7 Mar 2024 19:43:14 +0530 Subject: [PATCH 22/32] chore: addressed the comments --- crates/common_enums/src/enums.rs | 27 +++++++++++++++++++++-- crates/router/src/core/payment_methods.rs | 5 +++-- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/crates/common_enums/src/enums.rs b/crates/common_enums/src/enums.rs index 61b5e3b88e76..2891b058791c 100644 --- a/crates/common_enums/src/enums.rs +++ b/crates/common_enums/src/enums.rs @@ -1208,9 +1208,32 @@ pub enum PaymentMethodStatus { impl From for PaymentMethodStatus { fn from(attempt_status: AttemptStatus) -> Self { match attempt_status { - AttemptStatus::Charged => Self::Active, + AttemptStatus::Charged | + AttemptStatus::Authorized + => Self::Active, AttemptStatus::Failure => Self::Inactive, - _ => Self::Processing, + AttemptStatus::Voided | + AttemptStatus::Started | + AttemptStatus::Pending | + AttemptStatus::Unresolved | + AttemptStatus::CodInitiated | + AttemptStatus::Authorizing | + AttemptStatus::VoidInitiated | + AttemptStatus::AuthorizationFailed | + AttemptStatus::RouterDeclined | + AttemptStatus::AuthenticationSuccessful | + AttemptStatus::PaymentMethodAwaited | + AttemptStatus::AuthenticationFailed | + AttemptStatus::AuthenticationPending | + AttemptStatus::CaptureInitiated | + AttemptStatus::CaptureFailed | + AttemptStatus::VoidFailed | + AttemptStatus::AutoRefunded | + AttemptStatus::PartialCharged | + AttemptStatus::PartialChargedAndChargeable | + AttemptStatus::ConfirmationAwaited | + AttemptStatus::DeviceDataCollectionPending + => Self::Processing, } } } diff --git a/crates/router/src/core/payment_methods.rs b/crates/router/src/core/payment_methods.rs index 1754c650f1dc..65fc8b7fd41f 100644 --- a/crates/router/src/core/payment_methods.rs +++ b/crates/router/src/core/payment_methods.rs @@ -125,7 +125,7 @@ impl PaymentMethodRetrieve for Oss { card_token_data: Option<&CardToken>, customer: &Option, ) -> RouterResult { - Ok(match token_data { + let token = match token_data { storage::PaymentTokenData::TemporaryGeneric(generic_token) => { storage::PaymentMethodDataWithId { payment_method_data: helpers::retrieve_payment_method_with_temporary_token( @@ -219,6 +219,7 @@ impl PaymentMethodRetrieve for Oss { payment_method_data: None, payment_method_id: None, }, - }) + }; + Ok(token) } } From eb24ecba6bc093b6e73c235884035d96f08ebd11 Mon Sep 17 00:00:00 2001 From: "hyperswitch-bot[bot]" <148525504+hyperswitch-bot[bot]@users.noreply.github.com> Date: Thu, 7 Mar 2024 14:14:16 +0000 Subject: [PATCH 23/32] chore: run formatter --- crates/common_enums/src/enums.rs | 47 +++++++++++++++----------------- 1 file changed, 22 insertions(+), 25 deletions(-) diff --git a/crates/common_enums/src/enums.rs b/crates/common_enums/src/enums.rs index 2891b058791c..ce88aee921c7 100644 --- a/crates/common_enums/src/enums.rs +++ b/crates/common_enums/src/enums.rs @@ -1208,32 +1208,29 @@ pub enum PaymentMethodStatus { impl From for PaymentMethodStatus { fn from(attempt_status: AttemptStatus) -> Self { match attempt_status { - AttemptStatus::Charged | - AttemptStatus::Authorized - => Self::Active, + AttemptStatus::Charged | AttemptStatus::Authorized => Self::Active, AttemptStatus::Failure => Self::Inactive, - AttemptStatus::Voided | - AttemptStatus::Started | - AttemptStatus::Pending | - AttemptStatus::Unresolved | - AttemptStatus::CodInitiated | - AttemptStatus::Authorizing | - AttemptStatus::VoidInitiated | - AttemptStatus::AuthorizationFailed | - AttemptStatus::RouterDeclined | - AttemptStatus::AuthenticationSuccessful | - AttemptStatus::PaymentMethodAwaited | - AttemptStatus::AuthenticationFailed | - AttemptStatus::AuthenticationPending | - AttemptStatus::CaptureInitiated | - AttemptStatus::CaptureFailed | - AttemptStatus::VoidFailed | - AttemptStatus::AutoRefunded | - AttemptStatus::PartialCharged | - AttemptStatus::PartialChargedAndChargeable | - AttemptStatus::ConfirmationAwaited | - AttemptStatus::DeviceDataCollectionPending - => Self::Processing, + AttemptStatus::Voided + | AttemptStatus::Started + | AttemptStatus::Pending + | AttemptStatus::Unresolved + | AttemptStatus::CodInitiated + | AttemptStatus::Authorizing + | AttemptStatus::VoidInitiated + | AttemptStatus::AuthorizationFailed + | AttemptStatus::RouterDeclined + | AttemptStatus::AuthenticationSuccessful + | AttemptStatus::PaymentMethodAwaited + | AttemptStatus::AuthenticationFailed + | AttemptStatus::AuthenticationPending + | AttemptStatus::CaptureInitiated + | AttemptStatus::CaptureFailed + | AttemptStatus::VoidFailed + | AttemptStatus::AutoRefunded + | AttemptStatus::PartialCharged + | AttemptStatus::PartialChargedAndChargeable + | AttemptStatus::ConfirmationAwaited + | AttemptStatus::DeviceDataCollectionPending => Self::Processing, } } } From d810874041e5684628dabfce9dc64d0b01274103 Mon Sep 17 00:00:00 2001 From: prajjwalkumar17 Date: Thu, 7 Mar 2024 20:20:55 +0530 Subject: [PATCH 24/32] chore: fixed tests --- crates/router/src/core/payments/tokenization.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/router/src/core/payments/tokenization.rs b/crates/router/src/core/payments/tokenization.rs index cf2bb86077bf..7aaaaed92aad 100644 --- a/crates/router/src/core/payments/tokenization.rs +++ b/crates/router/src/core/payments/tokenization.rs @@ -43,6 +43,7 @@ pub async fn save_payment_method( where FData: mandate::MandateBehaviour, { + let mut pm_status = None; match resp.response { Ok(responses) => { let db = &*state.store; @@ -71,14 +72,12 @@ where } else { None }; - let pm_status = common_enums::PaymentMethodStatus::from(resp.status); let mandate_data_customer_acceptance = resp .request .get_setup_mandate_details() .and_then(|mandate_data| mandate_data.customer_acceptance.clone()); - let pm_status = common_enums::PaymentMethodStatus::from(resp.status); let customer_acceptance = resp .request .get_customer_acceptance() @@ -122,6 +121,7 @@ where ) .await? } else { + pm_status = Some(common_enums::PaymentMethodStatus::from(resp.status)); Box::pin(save_in_locker( state, merchant_account, @@ -403,7 +403,7 @@ where } else { None }; - Ok((pm_id, Some(pm_status))) + Ok((pm_id, pm_status)) } Err(_) => Ok((None, None)), } From c109748f1d6e38ebd5fdbc9c1ede8b9d774253b9 Mon Sep 17 00:00:00 2001 From: prajjwalkumar17 Date: Thu, 7 Mar 2024 21:03:07 +0530 Subject: [PATCH 25/32] chore: resolved tests --- .../src/core/payments/flows/setup_mandate_flow.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/crates/router/src/core/payments/flows/setup_mandate_flow.rs b/crates/router/src/core/payments/flows/setup_mandate_flow.rs index 54f86b01063d..65342a1f06bf 100644 --- a/crates/router/src/core/payments/flows/setup_mandate_flow.rs +++ b/crates/router/src/core/payments/flows/setup_mandate_flow.rs @@ -224,7 +224,7 @@ impl types::SetupMandateRouterData { types::SetupMandateRequestData, types::PaymentsResponseData, > = connector.connector.get_connector_integration(); - let resp = services::execute_connector_processing_step( + let mut resp = services::execute_connector_processing_step( state, connector_integration, self, @@ -236,7 +236,7 @@ impl types::SetupMandateRouterData { let payment_method_type = self.request.payment_method_type; - let pm_id = Box::pin(tokenization::save_payment_method( + let (pm_id, payment_method_status) = Box::pin(tokenization::save_payment_method( state, connector, resp.to_owned(), @@ -245,8 +245,10 @@ impl types::SetupMandateRouterData { payment_method_type, key_store, )) - .await? - .0; + .await?; + + resp.payment_method_id = pm_id.clone(); + resp.payment_method_status = payment_method_status; Ok(mandate::mandate_procedure( state, From 2d84edac2786919ee3e1476ff96747c8c921d97a Mon Sep 17 00:00:00 2001 From: prajjwalkumar17 Date: Fri, 8 Mar 2024 14:37:05 +0530 Subject: [PATCH 26/32] chore: resolved comments --- crates/router/src/core/payment_methods.rs | 153 ++++++++++-------- .../src/core/payments/flows/authorize_flow.rs | 32 ++-- crates/router/src/core/payments/helpers.rs | 8 +- .../src/types/storage/payment_method.rs | 5 +- 4 files changed, 112 insertions(+), 86 deletions(-) diff --git a/crates/router/src/core/payment_methods.rs b/crates/router/src/core/payment_methods.rs index 65fc8b7fd41f..8a9235c2fb6f 100644 --- a/crates/router/src/core/payment_methods.rs +++ b/crates/router/src/core/payment_methods.rs @@ -127,35 +127,44 @@ impl PaymentMethodRetrieve for Oss { ) -> RouterResult { let token = match token_data { storage::PaymentTokenData::TemporaryGeneric(generic_token) => { - storage::PaymentMethodDataWithId { - payment_method_data: helpers::retrieve_payment_method_with_temporary_token( - state, - &generic_token.token, - payment_intent, - merchant_key_store, - card_token_data, - ) - .await?, - payment_method_id: None, - } + helpers::retrieve_payment_method_with_temporary_token( + state, + &generic_token.token, + payment_intent, + merchant_key_store, + card_token_data, + ) + .await? + .map( + |(payment_method_data, payment_method)| storage::PaymentMethodDataWithId { + payment_method_data: Some(payment_method_data), + payment_method: Some(payment_method), + payment_method_id: None, + }, + ) + .unwrap_or_default() } storage::PaymentTokenData::Temporary(generic_token) => { - storage::PaymentMethodDataWithId { - payment_method_data: helpers::retrieve_payment_method_with_temporary_token( - state, - &generic_token.token, - payment_intent, - merchant_key_store, - card_token_data, - ) - .await?, - payment_method_id: None, - } + helpers::retrieve_payment_method_with_temporary_token( + state, + &generic_token.token, + payment_intent, + merchant_key_store, + card_token_data, + ) + .await? + .map( + |(payment_method_data, payment_method)| storage::PaymentMethodDataWithId { + payment_method_data: Some(payment_method_data), + payment_method: Some(payment_method), + payment_method_id: None, + }, + ).unwrap_or_default() } - storage::PaymentTokenData::Permanent(card_token) => storage::PaymentMethodDataWithId { - payment_method_data: helpers::retrieve_card_with_permanent_token( + storage::PaymentTokenData::Permanent(card_token) => { + helpers::retrieve_card_with_permanent_token( state, card_token.locker_id.as_ref().unwrap_or(&card_token.token), card_token @@ -166,56 +175,70 @@ impl PaymentMethodRetrieve for Oss { card_token_data, ) .await - .map(|card| Some((card, enums::PaymentMethod::Card)))?, - payment_method_id: Some( + .map(|card| Some((card, enums::PaymentMethod::Card)))? + .map( + |(payment_method_data, payment_method)| storage::PaymentMethodDataWithId { + payment_method_data: Some(payment_method_data), + payment_method: Some(payment_method), + payment_method_id: Some( + card_token + .payment_method_id + .as_ref() + .unwrap_or(&card_token.token) + .to_string(), + ), + }, + ).unwrap_or_default() + } + + storage::PaymentTokenData::PermanentCard(card_token) => { + helpers::retrieve_card_with_permanent_token( + state, + card_token.locker_id.as_ref().unwrap_or(&card_token.token), card_token .payment_method_id .as_ref() - .unwrap_or(&card_token.token) - .to_string(), - ), - }, - - storage::PaymentTokenData::PermanentCard(card_token) => { - storage::PaymentMethodDataWithId { - payment_method_data: helpers::retrieve_card_with_permanent_token( - state, - card_token.locker_id.as_ref().unwrap_or(&card_token.token), - card_token - .payment_method_id - .as_ref() - .unwrap_or(&card_token.token), - payment_intent, - card_token_data, - ) - .await - .map(|card| Some((card, enums::PaymentMethod::Card)))?, - - payment_method_id: Some( - card_token - .payment_method_id - .as_ref() - .unwrap_or(&card_token.token) - .to_string(), - ), - } + .unwrap_or(&card_token.token), + payment_intent, + card_token_data, + ) + .await + .map(|card| Some((card, enums::PaymentMethod::Card)))? + .map( + |(payment_method_data, payment_method)| storage::PaymentMethodDataWithId { + payment_method_data: Some(payment_method_data), + payment_method: Some(payment_method), + payment_method_id: Some( + card_token + .payment_method_id + .as_ref() + .unwrap_or(&card_token.token) + .to_string(), + ), + }, + ).unwrap_or_default() } storage::PaymentTokenData::AuthBankDebit(auth_token) => { - storage::PaymentMethodDataWithId { - payment_method_data: core_pm_auth::retrieve_payment_method_from_auth_service( - state, - merchant_key_store, - auth_token, - payment_intent, - customer, - ) - .await?, - payment_method_id: None, - } + core_pm_auth::retrieve_payment_method_from_auth_service( + state, + merchant_key_store, + auth_token, + payment_intent, + customer, + ) + .await? + .map( + |(payment_method_data, payment_method)| storage::PaymentMethodDataWithId { + payment_method_data: Some(payment_method_data), + payment_method: Some(payment_method), + payment_method_id: None, + }, + ).unwrap_or_default() } storage::PaymentTokenData::WalletToken(_) => storage::PaymentMethodDataWithId { + payment_method: None, payment_method_data: None, payment_method_id: None, }, diff --git a/crates/router/src/core/payments/flows/authorize_flow.rs b/crates/router/src/core/payments/flows/authorize_flow.rs index 4f50deeb556c..fb83e81c1516 100644 --- a/crates/router/src/core/payments/flows/authorize_flow.rs +++ b/crates/router/src/core/payments/flows/authorize_flow.rs @@ -124,20 +124,24 @@ impl Feature for types::PaymentsAu logger::info!("Call to save_payment_method in locker"); - let (payment_method_id, payment_method_status) = - Box::pin(tokenization::save_payment_method( - &state, - &connector, - response, - &maybe_customer, - &merchant_account, - self.request.payment_method_type, - &key_store, - )) - .await?; - - resp.payment_method_id = payment_method_id.clone(); - resp.payment_method_status = payment_method_status; + let pm = Box::pin(tokenization::save_payment_method( + &state, + &connector, + response, + &maybe_customer, + &merchant_account, + self.request.payment_method_type, + &key_store, + )) + .await; + + match pm { + Ok((payment_method_id, payment_method_status)) => { + resp.payment_method_id = payment_method_id.clone(); + resp.payment_method_status = payment_method_status; + } + Err(_) => logger::error!("Save pm to locker failed"), + } Ok(resp) } diff --git a/crates/router/src/core/payments/helpers.rs b/crates/router/src/core/payments/helpers.rs index 652005b7b7c4..7c617623e2b3 100644 --- a/crates/router/src/core/payments/helpers.rs +++ b/crates/router/src/core/payments/helpers.rs @@ -1451,7 +1451,6 @@ pub async fn retrieve_payment_method_with_temporary_token( "Payment method for given token not found or there was a problem fetching it", )?; - println!(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>{:?}", pm); utils::when( supplementary_data .customer_id @@ -1694,10 +1693,9 @@ pub async fn make_pm_data<'a, F: Clone, R, Ctx: PaymentMethodRetrieve>( let payment_method_details = pm_data.attach_printable("in 'make_pm_data'")?; Ok::<_, error_stack::Report>( - if let Some((payment_method_data, payment_method)) = - payment_method_details.payment_method_data - { - payment_data.payment_attempt.payment_method = Some(payment_method); + if let Some(payment_method_data) = payment_method_details.payment_method_data { + payment_data.payment_attempt.payment_method = + payment_method_details.payment_method; ( Some(payment_method_data), payment_method_details.payment_method_id, diff --git a/crates/router/src/types/storage/payment_method.rs b/crates/router/src/types/storage/payment_method.rs index 6d7e7385ae38..8edfb8b36d8d 100644 --- a/crates/router/src/types/storage/payment_method.rs +++ b/crates/router/src/types/storage/payment_method.rs @@ -23,9 +23,10 @@ pub struct CardTokenData { pub token: String, } -#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] +#[derive(Debug, Clone, serde::Serialize, Default, serde::Deserialize)] pub struct PaymentMethodDataWithId { - pub payment_method_data: Option<(payments::PaymentMethodData, enums::PaymentMethod)>, + pub payment_method: Option, + pub payment_method_data: Option, pub payment_method_id: Option, } From ca65bc143eac90045dbd0c1ceafc0eafdfc41efa Mon Sep 17 00:00:00 2001 From: "hyperswitch-bot[bot]" <148525504+hyperswitch-bot[bot]@users.noreply.github.com> Date: Fri, 8 Mar 2024 09:07:45 +0000 Subject: [PATCH 27/32] chore: run formatter --- crates/router/src/core/payment_methods.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/crates/router/src/core/payment_methods.rs b/crates/router/src/core/payment_methods.rs index 8a9235c2fb6f..46e26cbcde55 100644 --- a/crates/router/src/core/payment_methods.rs +++ b/crates/router/src/core/payment_methods.rs @@ -160,7 +160,8 @@ impl PaymentMethodRetrieve for Oss { payment_method: Some(payment_method), payment_method_id: None, }, - ).unwrap_or_default() + ) + .unwrap_or_default() } storage::PaymentTokenData::Permanent(card_token) => { @@ -188,7 +189,8 @@ impl PaymentMethodRetrieve for Oss { .to_string(), ), }, - ).unwrap_or_default() + ) + .unwrap_or_default() } storage::PaymentTokenData::PermanentCard(card_token) => { @@ -216,7 +218,8 @@ impl PaymentMethodRetrieve for Oss { .to_string(), ), }, - ).unwrap_or_default() + ) + .unwrap_or_default() } storage::PaymentTokenData::AuthBankDebit(auth_token) => { @@ -234,7 +237,8 @@ impl PaymentMethodRetrieve for Oss { payment_method: Some(payment_method), payment_method_id: None, }, - ).unwrap_or_default() + ) + .unwrap_or_default() } storage::PaymentTokenData::WalletToken(_) => storage::PaymentMethodDataWithId { From d66a539d0f305689cb649e6e2ecaf584e77478d0 Mon Sep 17 00:00:00 2001 From: prajjwalkumar17 Date: Fri, 8 Mar 2024 15:57:10 +0530 Subject: [PATCH 28/32] chore: resolved comments --- crates/router/src/core/payments/operations/payment_response.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/router/src/core/payments/operations/payment_response.rs b/crates/router/src/core/payments/operations/payment_response.rs index 33a32c0563c5..18e568eb9b89 100644 --- a/crates/router/src/core/payments/operations/payment_response.rs +++ b/crates/router/src/core/payments/operations/payment_response.rs @@ -616,7 +616,7 @@ async fn payment_response_update_tracker( metrics::SUCCESSFUL_PAYMENT.add(&metrics::CONTEXT, 1, &[]); } - let payment_method_id = payment_data.payment_attempt.payment_method_id.clone(); + let payment_method_id = router_data.payment_method_id.clone(); utils::add_apple_pay_payment_status_metrics( router_data.status, From 7b61f63368208afc991af5a540ef244c2f53001e Mon Sep 17 00:00:00 2001 From: prajjwalkumar17 Date: Fri, 8 Mar 2024 17:35:16 +0530 Subject: [PATCH 29/32] chore: addressed comments --- crates/router/src/core/payments/flows/authorize_flow.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/crates/router/src/core/payments/flows/authorize_flow.rs b/crates/router/src/core/payments/flows/authorize_flow.rs index fb83e81c1516..4e5a25c70603 100644 --- a/crates/router/src/core/payments/flows/authorize_flow.rs +++ b/crates/router/src/core/payments/flows/authorize_flow.rs @@ -124,7 +124,7 @@ impl Feature for types::PaymentsAu logger::info!("Call to save_payment_method in locker"); - let pm = Box::pin(tokenization::save_payment_method( + let save_pm_result = Box::pin(tokenization::save_payment_method( &state, &connector, response, @@ -135,12 +135,14 @@ impl Feature for types::PaymentsAu )) .await; - match pm { + match save_pm_result { Ok((payment_method_id, payment_method_status)) => { resp.payment_method_id = payment_method_id.clone(); resp.payment_method_status = payment_method_status; } - Err(_) => logger::error!("Save pm to locker failed"), + Err(_error) => { + logger::error!(?_error) + } } Ok(resp) From 3d5075826e5e3c3e4122e193ef41f557bcd81f48 Mon Sep 17 00:00:00 2001 From: prajjwalkumar17 Date: Fri, 8 Mar 2024 17:41:57 +0530 Subject: [PATCH 30/32] chore: addressed comments --- crates/router/src/core/payments/flows/authorize_flow.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/router/src/core/payments/flows/authorize_flow.rs b/crates/router/src/core/payments/flows/authorize_flow.rs index 4e5a25c70603..058f02a9a652 100644 --- a/crates/router/src/core/payments/flows/authorize_flow.rs +++ b/crates/router/src/core/payments/flows/authorize_flow.rs @@ -140,8 +140,8 @@ impl Feature for types::PaymentsAu resp.payment_method_id = payment_method_id.clone(); resp.payment_method_status = payment_method_status; } - Err(_error) => { - logger::error!(?_error) + Err(error) => { + logger::error!("Asynchronously saving card in locker failed : {:?}", error); } } From fcb0198ba0167461fe8a3fce6d0e64955beb3d68 Mon Sep 17 00:00:00 2001 From: prajjwalkumar17 Date: Fri, 8 Mar 2024 18:01:43 +0530 Subject: [PATCH 31/32] chore: tokio is back --- .../src/core/payments/flows/authorize_flow.rs | 35 +++++++++---------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/crates/router/src/core/payments/flows/authorize_flow.rs b/crates/router/src/core/payments/flows/authorize_flow.rs index 058f02a9a652..212e694ac926 100644 --- a/crates/router/src/core/payments/flows/authorize_flow.rs +++ b/crates/router/src/core/payments/flows/authorize_flow.rs @@ -123,27 +123,24 @@ impl Feature for types::PaymentsAu let state = state.clone(); logger::info!("Call to save_payment_method in locker"); + tokio::spawn(async move { + logger::info!("Starting async call to save_payment_method in locker"); + + let result = Box::pin(tokenization::save_payment_method( + &state, + &connector, + response, + &maybe_customer, + &merchant_account, + self.request.payment_method_type, + &key_store, + )) + .await; - let save_pm_result = Box::pin(tokenization::save_payment_method( - &state, - &connector, - response, - &maybe_customer, - &merchant_account, - self.request.payment_method_type, - &key_store, - )) - .await; - - match save_pm_result { - Ok((payment_method_id, payment_method_status)) => { - resp.payment_method_id = payment_method_id.clone(); - resp.payment_method_status = payment_method_status; + if let Err(err) = result { + logger::error!("Asynchronously saving card in locker failed : {:?}", err); } - Err(error) => { - logger::error!("Asynchronously saving card in locker failed : {:?}", error); - } - } + }); Ok(resp) } From 2f633dd2634434ed7d26675e0edc90d85b3ea3ef Mon Sep 17 00:00:00 2001 From: prajjwalkumar17 Date: Sun, 10 Mar 2024 20:55:08 +0530 Subject: [PATCH 32/32] chore: fixed tests --- crates/router/src/core/authentication/transformers.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/router/src/core/authentication/transformers.rs b/crates/router/src/core/authentication/transformers.rs index 99f468b4677e..870a356b19a4 100644 --- a/crates/router/src/core/authentication/transformers.rs +++ b/crates/router/src/core/authentication/transformers.rs @@ -170,6 +170,7 @@ pub fn construct_router_data( frm_metadata: None, dispute_id: None, refund_id: None, + payment_method_status: None, }) }