diff --git a/crates/router/src/connector/stripe.rs b/crates/router/src/connector/stripe.rs index 60d280b04d..8bb24aa6bb 100644 --- a/crates/router/src/connector/stripe.rs +++ b/crates/router/src/connector/stripe.rs @@ -349,11 +349,12 @@ impl data: &types::PaymentsAuthorizeRouterData, res: Response, ) -> CustomResult { + logger::debug!(stripe_payments_create_response=?res); let response: stripe::PaymentIntentResponse = res .response .parse_struct("PaymentIntentResponse") .change_context(errors::ConnectorError::ResponseDeserializationFailed)?; - logger::debug!(payments_create_response=?response); + types::RouterData::try_from(types::ResponseRouterData { response, data: data.clone(), diff --git a/crates/router/src/connector/stripe/transformers.rs b/crates/router/src/connector/stripe/transformers.rs index b43a2eedba..7349787deb 100644 --- a/crates/router/src/connector/stripe/transformers.rs +++ b/crates/router/src/connector/stripe/transformers.rs @@ -373,6 +373,7 @@ impl StripePaymentMethodOptions::Card { mandate_options, .. } => mandate_options.map(|mandate_options| mandate_options.reference), + StripePaymentMethodOptions::Klarna {} => None, }); Ok(types::RouterData { @@ -424,6 +425,7 @@ impl StripePaymentMethodOptions::Card { mandate_options, .. } => mandate_options.map(|mandate_option| mandate_option.reference), + StripePaymentMethodOptions::Klarna {} => None, }); Ok(types::RouterData { @@ -662,6 +664,7 @@ pub enum StripePaymentMethodOptions { Card { mandate_options: Option, }, + Klarna {}, } // #[derive(Deserialize, Debug, Clone, Eq, PartialEq)] // pub struct Card diff --git a/crates/router/src/core/payments.rs b/crates/router/src/core/payments.rs index 91e41497b2..2cb971531d 100644 --- a/crates/router/src/core/payments.rs +++ b/crates/router/src/core/payments.rs @@ -356,7 +356,6 @@ where Ok(response) } -#[allow(dead_code)] async fn call_multiple_connectors_service( state: &AppState, merchant_account: &storage::MerchantAccount, @@ -521,15 +520,7 @@ pub fn should_call_connector( payment_data: &PaymentData, ) -> bool { match format!("{:?}", operation).as_str() { - "PaymentConfirm" => { - payment_data - .payment_attempt - .authentication_type - .unwrap_or_default() - == enums::AuthenticationType::NoThreeDs - || payment_data.payment_attempt.payment_method - == Some(enums::PaymentMethodType::PayLater) - } + "PaymentConfirm" => true, "PaymentStart" => { !matches!( payment_data.payment_intent.status, diff --git a/crates/router/src/core/payments/operations/payment_confirm.rs b/crates/router/src/core/payments/operations/payment_confirm.rs index 000d56e636..ee3f8669d1 100644 --- a/crates/router/src/core/payments/operations/payment_confirm.rs +++ b/crates/router/src/core/payments/operations/payment_confirm.rs @@ -197,6 +197,7 @@ impl UpdateTracker, api::PaymentsRequest> for Paymen }; let connector = payment_data.payment_attempt.connector.clone(); + let payment_token = payment_data.token.clone(); payment_data.payment_attempt = db .update_payment_attempt( @@ -206,6 +207,7 @@ impl UpdateTracker, api::PaymentsRequest> for Paymen payment_method, browser_info, connector, + payment_token, }, 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 73ce3d6941..1f636cab59 100644 --- a/crates/router/src/core/payments/operations/payment_create.rs +++ b/crates/router/src/core/payments/operations/payment_create.rs @@ -250,6 +250,23 @@ impl UpdateTracker, api::PaymentsRequest> for Paymen _ => None, }; + let payment_token = payment_data.token.clone(); + let connector = payment_data.payment_attempt.connector.clone(); + + payment_data.payment_attempt = db + .update_payment_attempt( + payment_data.payment_attempt, + storage::PaymentAttemptUpdate::UpdateTrackers { + payment_token, + connector, + }, + storage_scheme, + ) + .await + .map_err(|error| { + error.to_not_found_response(errors::ApiErrorResponse::PaymentNotFound) + })?; + let customer_id = payment_data.payment_intent.customer_id.clone(); payment_data.payment_intent = db .update_payment_intent( diff --git a/crates/router/src/db/payment_attempt.rs b/crates/router/src/db/payment_attempt.rs index 67bb2f9a04..edf1c6ccac 100644 --- a/crates/router/src/db/payment_attempt.rs +++ b/crates/router/src/db/payment_attempt.rs @@ -240,6 +240,7 @@ impl PaymentAttemptInterface for MockDb { amount_to_capture: payment_attempt.amount_to_capture, mandate_id: None, browser_info: None, + payment_token: None, error_code: payment_attempt.error_code, }; payment_attempts.push(payment_attempt.clone()); @@ -371,6 +372,7 @@ mod storage { cancellation_reason: payment_attempt.cancellation_reason.clone(), mandate_id: payment_attempt.mandate_id.clone(), browser_info: payment_attempt.browser_info.clone(), + payment_token: payment_attempt.payment_token.clone(), error_code: payment_attempt.error_code.clone(), }; diff --git a/crates/storage_models/src/payment_attempt.rs b/crates/storage_models/src/payment_attempt.rs index acceb61748..7cd6ca9eb6 100644 --- a/crates/storage_models/src/payment_attempt.rs +++ b/crates/storage_models/src/payment_attempt.rs @@ -36,6 +36,7 @@ pub struct PaymentAttempt { pub amount_to_capture: Option, pub mandate_id: Option, pub browser_info: Option, + pub payment_token: Option, pub error_code: Option, } @@ -71,6 +72,7 @@ pub struct PaymentAttemptNew { pub amount_to_capture: Option, pub mandate_id: Option, pub browser_info: Option, + pub payment_token: Option, pub error_code: Option, } @@ -83,6 +85,10 @@ pub enum PaymentAttemptUpdate { authentication_type: Option, payment_method: Option, }, + UpdateTrackers { + payment_token: Option, + connector: Option, + }, AuthenticationTypeUpdate { authentication_type: storage_enums::AuthenticationType, }, @@ -91,6 +97,7 @@ pub enum PaymentAttemptUpdate { payment_method: Option, browser_info: Option, connector: Option, + payment_token: Option, }, VoidUpdate { status: storage_enums::AttemptStatus, @@ -133,6 +140,7 @@ pub struct PaymentAttemptUpdateInternal { redirect: Option, mandate_id: Option, browser_info: Option, + payment_token: Option, error_code: Option, } @@ -155,6 +163,7 @@ impl PaymentAttemptUpdate { .unwrap_or(source.payment_method_id), browser_info: pa_update.browser_info, modified_at: common_utils::date_time::now(), + payment_token: pa_update.payment_token, ..source } } @@ -192,12 +201,14 @@ impl From for PaymentAttemptUpdateInternal { payment_method, browser_info, connector, + payment_token, } => Self { status: Some(status), payment_method, modified_at: Some(common_utils::date_time::now()), browser_info, connector, + payment_token, ..Default::default() }, PaymentAttemptUpdate::VoidUpdate { @@ -244,6 +255,14 @@ impl From for PaymentAttemptUpdateInternal { status: Some(status), ..Default::default() }, + PaymentAttemptUpdate::UpdateTrackers { + payment_token, + connector, + } => Self { + payment_token, + connector, + ..Default::default() + }, } } } diff --git a/crates/storage_models/src/schema.rs b/crates/storage_models/src/schema.rs index 27754153c5..0408af243f 100644 --- a/crates/storage_models/src/schema.rs +++ b/crates/storage_models/src/schema.rs @@ -214,6 +214,7 @@ diesel::table! { mandate_id -> Nullable, browser_info -> Nullable, error_code -> Nullable, + payment_token -> Nullable, } } diff --git a/migrations/2022-12-14-090419_add_payment_token_in_payment_attempt/down.sql b/migrations/2022-12-14-090419_add_payment_token_in_payment_attempt/down.sql new file mode 100644 index 0000000000..18cba5b4b5 --- /dev/null +++ b/migrations/2022-12-14-090419_add_payment_token_in_payment_attempt/down.sql @@ -0,0 +1 @@ +ALTER TABLE payment_attempt DROP COLUMN payment_token; diff --git a/migrations/2022-12-14-090419_add_payment_token_in_payment_attempt/up.sql b/migrations/2022-12-14-090419_add_payment_token_in_payment_attempt/up.sql new file mode 100644 index 0000000000..a54f2cf2ef --- /dev/null +++ b/migrations/2022-12-14-090419_add_payment_token_in_payment_attempt/up.sql @@ -0,0 +1 @@ +ALTER TABLE payment_attempt ADD COLUMN payment_token VARCHAR(255); \ No newline at end of file