From 9bb2e0c86e6b35b83b30cb740a5d396d2320b1cd Mon Sep 17 00:00:00 2001 From: "shivansh.mathur" Date: Fri, 31 Jan 2025 15:42:40 +0530 Subject: [PATCH 01/19] Update flow of Payment Method Session --- crates/api_models/src/events.rs | 3 + crates/api_models/src/payment_methods.rs | 17 +++ .../src/payment_methods_session.rs | 10 ++ .../src/payment_methods.rs | 86 ++++++++++++ crates/openapi/src/openapi_v2.rs | 1 + crates/router/src/core/payment_methods.rs | 128 ++++++++++++++++++ crates/router/src/db/kafka_store.rs | 12 ++ .../router/src/db/payment_method_session.rs | 55 +++++++- crates/router/src/routes/app.rs | 3 +- crates/router/src/routes/lock_utils.rs | 3 +- crates/router/src/routes/payment_methods.rs | 40 ++++++ crates/router_env/src/logger/types.rs | 2 + 12 files changed, 357 insertions(+), 3 deletions(-) diff --git a/crates/api_models/src/events.rs b/crates/api_models/src/events.rs index 2124ff1aff9..1a9cb260d39 100644 --- a/crates/api_models/src/events.rs +++ b/crates/api_models/src/events.rs @@ -206,6 +206,9 @@ impl ApiEventMetric for DisputeListFilters { #[cfg(feature = "v2")] impl ApiEventMetric for PaymentMethodSessionRequest {} +#[cfg(feature = "v2")] +impl ApiEventMetric for PaymentMethodsSessionUpdateRequest {} + #[cfg(feature = "v2")] impl ApiEventMetric for PaymentMethodsSessionResponse { fn get_api_event_type(&self) -> Option { diff --git a/crates/api_models/src/payment_methods.rs b/crates/api_models/src/payment_methods.rs index ba18cbba506..6d62bcf3532 100644 --- a/crates/api_models/src/payment_methods.rs +++ b/crates/api_models/src/payment_methods.rs @@ -2496,6 +2496,23 @@ pub struct PaymentMethodSessionRequest { pub expires_in: Option, } +#[cfg(feature = "v2")] +#[derive(Debug, Clone, serde::Deserialize, serde::Serialize, ToSchema)] +pub struct PaymentMethodsSessionUpdateRequest { + /// The billing address details of the customer. This will also be used for any new payment methods added during the session + #[schema(value_type = Option
)] + pub billing: Option, + + /// The tokenization type to be applied + #[schema(value_type = Option)] + pub psp_tokenization: Option, + + /// The network tokenization configuration if applicable + #[schema(value_type = Option)] + pub network_tokenization: Option, + +} + #[cfg(feature = "v2")] #[derive(Debug, Clone, serde::Deserialize, serde::Serialize, ToSchema)] pub struct PaymentMethodSessionUpdateSavedPaymentMethod { diff --git a/crates/diesel_models/src/payment_methods_session.rs b/crates/diesel_models/src/payment_methods_session.rs index dad3e995e01..c9d151d359f 100644 --- a/crates/diesel_models/src/payment_methods_session.rs +++ b/crates/diesel_models/src/payment_methods_session.rs @@ -9,3 +9,13 @@ pub struct PaymentMethodsSession { #[serde(with = "common_utils::custom_serde::iso8601")] pub expires_at: time::PrimitiveDateTime, } + + +#[cfg(feature = "v2")] +#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)] +pub struct PaymentMethodsSessionUpdate { + pub id: common_utils::id_type::GlobalPaymentMethodSessionId, + pub billing: Option, + pub psp_tokenization: Option, + pub network_tokeinzation: Option, +} \ No newline at end of file diff --git a/crates/hyperswitch_domain_models/src/payment_methods.rs b/crates/hyperswitch_domain_models/src/payment_methods.rs index c8683919f7b..6a252956a31 100644 --- a/crates/hyperswitch_domain_models/src/payment_methods.rs +++ b/crates/hyperswitch_domain_models/src/payment_methods.rs @@ -661,6 +661,92 @@ impl super::behaviour::Conversion for PaymentMethodsSession { } } +#[cfg(feature = "v2")] +#[derive(Clone, Debug, router_derive::ToEncryption)] +pub struct PaymentMethodsSessionUpdate { + pub id: common_utils::id_type::GlobalPaymentMethodSessionId, + #[encrypt(ty = Value)] + pub billing: Option>, + pub psp_tokenization: Option, + pub network_tokenization: Option, +} + +#[cfg(feature = "v2")] +#[async_trait::async_trait] +impl super::behaviour::Conversion for PaymentMethodsSessionUpdate { + type DstType = diesel_models::payment_methods_session::PaymentMethodsSessionUpdate; + type NewDstType = diesel_models::payment_methods_session::PaymentMethodsSessionUpdate; + async fn convert(self) -> CustomResult { + Ok(Self::DstType { + id: self.id, + billing: self.billing.map(|val| val.into()), + psp_tokenization: self.psp_tokenization, + network_tokeinzation: self.network_tokenization, + }) + } + + async fn convert_back( + state: &keymanager::KeyManagerState, + storage_model: Self::DstType, + key: &Secret>, + key_manager_identifier: keymanager::Identifier, + ) -> CustomResult + where + Self: Sized, + { + use common_utils::ext_traits::ValueExt; + + async { + let decrypted_data = crypto_operation( + state, + type_name!(Self::DstType), + CryptoOperation::BatchDecrypt(EncryptedPaymentMethodsSessionUpdate::to_encryptable( + EncryptedPaymentMethodsSessionUpdate { + billing: storage_model.billing, + }, + )), + key_manager_identifier, + key.peek(), + ) + .await + .and_then(|val| val.try_into_batchoperation())?; + + let data = EncryptedPaymentMethodsSessionUpdate::from_encryptable(decrypted_data) + .change_context(common_utils::errors::CryptoError::DecodingFailed) + .attach_printable("Invalid batch operation data")?; + + let billing = data + .billing + .map(|billing| { + billing.deserialize_inner_value(|value| value.parse_value("Address")) + }) + .transpose() + .change_context(common_utils::errors::CryptoError::DecodingFailed) + .attach_printable("Error while deserializing Address")?; + + Ok::>(Self { + id: storage_model.id, + billing, + psp_tokenization: storage_model.psp_tokenization, + network_tokenization: storage_model.network_tokeinzation, + }) + } + .await + .change_context(ValidationError::InvalidValue { + message: "Failed while decrypting payment method data".to_string(), + }) + } + + async fn construct_new(self) -> CustomResult { + Ok(Self::NewDstType { + id: self.id, + billing: self.billing.map(|val| val.into()), + psp_tokenization: self.psp_tokenization, + network_tokeinzation: self.network_tokenization, + }) + } +} + #[cfg(all( any(feature = "v1", feature = "v2"), not(feature = "payment_methods_v2") diff --git a/crates/openapi/src/openapi_v2.rs b/crates/openapi/src/openapi_v2.rs index cc6f1b0e411..cce56fb55d9 100644 --- a/crates/openapi/src/openapi_v2.rs +++ b/crates/openapi/src/openapi_v2.rs @@ -501,6 +501,7 @@ Never share your secret api keys. Keep them guarded and secure. api_models::payment_methods::PaymentMethodCollectLinkResponse, api_models::payment_methods::PaymentMethodSubtypeSpecificData, api_models::payment_methods::PaymentMethodSessionRequest, + api_models::payment_methods::PaymentMethodsSessionUpdateRequest, api_models::payment_methods::PaymentMethodsSessionResponse, api_models::payments::PaymentsRetrieveResponse, api_models::refunds::RefundListRequest, diff --git a/crates/router/src/core/payment_methods.rs b/crates/router/src/core/payment_methods.rs index 5bdb0f0819e..3cf2cabc3d6 100644 --- a/crates/router/src/core/payment_methods.rs +++ b/crates/router/src/core/payment_methods.rs @@ -1791,6 +1791,56 @@ impl EncryptableData for payment_methods::PaymentMethodSessionRequest { } } +#[cfg(feature = "v2")] +#[async_trait::async_trait] +impl EncryptableData for payment_methods::PaymentMethodsSessionUpdateRequest { + type Output = hyperswitch_domain_models::payment_methods::DecryptedPaymentMethodsSession; + + async fn encrypt_data( + &self, + key_manager_state: &common_utils::types::keymanager::KeyManagerState, + key_store: &domain::MerchantKeyStore, + ) -> RouterResult { + use common_utils::types::keymanager::ToEncryptable; + + let encrypted_billing_address = self + .billing + .clone() + .map(|address| address.encode_to_value()) + .transpose() + .change_context(errors::ApiErrorResponse::InternalServerError) + .attach_printable("Failed to encode billing address")? + .map(Secret::new); + + let batch_encrypted_data = domain_types::crypto_operation( + key_manager_state, + common_utils::type_name!(hyperswitch_domain_models::payment_methods::PaymentMethodsSession), + domain_types::CryptoOperation::BatchEncrypt( + hyperswitch_domain_models::payment_methods::FromRequestEncryptablePaymentMethodsSession::to_encryptable( + hyperswitch_domain_models::payment_methods::FromRequestEncryptablePaymentMethodsSession { + billing: encrypted_billing_address, + }, + ), + ), + common_utils::types::keymanager::Identifier::Merchant(key_store.merchant_id.clone()), + key_store.key.peek(), + ) + .await + .and_then(|val| val.try_into_batchoperation()) + .change_context(errors::ApiErrorResponse::InternalServerError) + .attach_printable("Failed while encrypting payment methods session details".to_string())?; + + let encrypted_data = + hyperswitch_domain_models::payment_methods::FromRequestEncryptablePaymentMethodsSession::from_encryptable( + batch_encrypted_data, + ) + .change_context(errors::ApiErrorResponse::InternalServerError) + .attach_printable("Failed while encrypting payment methods session detailss")?; + + Ok(encrypted_data) + } +} + #[cfg(feature = "v2")] pub async fn payment_methods_session_create( state: SessionState, @@ -1880,6 +1930,67 @@ pub async fn payment_methods_session_create( Ok(services::ApplicationResponse::Json(response)) } +#[cfg(feature = "v2")] +pub async fn payment_methods_session_update( + state: SessionState, + merchant_account: domain::MerchantAccount, + key_store: domain::MerchantKeyStore, + payment_method_session_id: id_type::GlobalPaymentMethodSessionId, + request: payment_methods::PaymentMethodsSessionUpdateRequest, +) -> RouterResponse { + let db = state.store.as_ref(); + let key_manager_state = &(&state).into(); + + let payment_method_session_state = db + .get_payment_methods_session(key_manager_state, &key_store, &payment_method_session_id) + .await + .to_not_found_response(errors::ApiErrorResponse::GenericNotFoundError { + message: "payment methods session does not exist or has expired".to_string(), + }) + .attach_printable("Failed to retrieve payment methods session from db")?; + + let encrypted_data = request + .encrypt_data(key_manager_state, &key_store) + .await + .change_context(errors::ApiErrorResponse::InternalServerError) + .attach_printable("Failed to encrypt payment methods session data")?; + + let billing = encrypted_data + .billing + .as_ref() + .map(|data| { + data.clone() + .deserialize_inner_value(|value| value.parse_value("Address")) + }) + .transpose() + .change_context(errors::ApiErrorResponse::InternalServerError) + .attach_printable("Unable to decode billing address")?; + + let payment_method_session_domain_model = hyperswitch_domain_models::payment_methods::PaymentMethodsSessionUpdate { + id: payment_method_session_id.clone(), + billing, + psp_tokenization: request.psp_tokenization, + network_tokenization: request.network_tokenization, + }; + + let update_state_change = payment_method_session_update_to_current_state( + payment_method_session_domain_model, + payment_method_session_state + ).await; + + db.update_payment_method_session( key_manager_state, &key_store, &payment_method_session_id, update_state_change.clone() ) + .await + .change_context(errors::ApiErrorResponse::InternalServerError) + .attach_printable("Failed to update payment methods session in db")?; + + let response = payment_methods::PaymentMethodsSessionResponse::foreign_from(( + update_state_change, + Secret::new("CLIENT_SECRET_REDACTED".to_string()), + )); + Ok(services::ApplicationResponse::Json(response)) + + +} #[cfg(feature = "v2")] pub async fn payment_methods_session_retrieve( state: SessionState, @@ -1995,3 +2106,20 @@ impl pm_types::SavedPMLPaymentsInfo { Ok(()) } } + + + +#[cfg(feature = "v2")] +pub async fn payment_method_session_update_to_current_state( + update_state: hyperswitch_domain_models::payment_methods::PaymentMethodsSessionUpdate, + current_state: hyperswitch_domain_models::payment_methods::PaymentMethodsSession +) -> hyperswitch_domain_models::payment_methods::PaymentMethodsSession { + hyperswitch_domain_models::payment_methods::PaymentMethodsSession { + id: current_state.id, + customer_id: current_state.customer_id, + billing: update_state.billing.or(current_state.billing), + psp_tokenization: update_state.psp_tokenization.or(current_state.psp_tokenization), + network_tokenization: update_state.network_tokenization.or(current_state.network_tokenization), + expires_at: current_state.expires_at, + } +} \ No newline at end of file diff --git a/crates/router/src/db/kafka_store.rs b/crates/router/src/db/kafka_store.rs index 2dc7191863a..2b5dc9cd461 100644 --- a/crates/router/src/db/kafka_store.rs +++ b/crates/router/src/db/kafka_store.rs @@ -3955,6 +3955,18 @@ impl db::payment_method_session::PaymentMethodsSessionInterface for KafkaStore { .get_payment_methods_session(state, key_store, id) .await } + + async fn update_payment_method_session( + &self, + state: &KeyManagerState, + key_store: &hyperswitch_domain_models::merchant_key_store::MerchantKeyStore, + id: &id_type::GlobalPaymentMethodSessionId, + payment_methods_session: hyperswitch_domain_models::payment_methods::PaymentMethodsSession, + ) -> CustomResult< (), errors::StorageError, > { + self.diesel_store + .update_payment_method_session(state, key_store, id, payment_methods_session) + .await + } } #[async_trait::async_trait] diff --git a/crates/router/src/db/payment_method_session.rs b/crates/router/src/db/payment_method_session.rs index a7e500ac52c..1933e49fe5f 100644 --- a/crates/router/src/db/payment_method_session.rs +++ b/crates/router/src/db/payment_method_session.rs @@ -13,6 +13,17 @@ pub trait PaymentMethodsSessionInterface { validity: i64, ) -> CustomResult<(), errors::StorageError>; + async fn update_payment_method_session( + &self, + state: &common_utils::types::keymanager::KeyManagerState, + key_store: &hyperswitch_domain_models::merchant_key_store::MerchantKeyStore, + id: &common_utils::id_type::GlobalPaymentMethodSessionId, + payment_methods_session: hyperswitch_domain_models::payment_methods::PaymentMethodsSession, + ) -> CustomResult< + (), + errors::StorageError, + >; + async fn get_payment_methods_session( &self, state: &common_utils::types::keymanager::KeyManagerState, @@ -102,9 +113,38 @@ mod storage { .change_context(errors::StorageError::DecryptionError) .attach_printable("Failed to decrypt payment methods session") } + + #[instrument(skip_all)] + async fn update_payment_method_session( + &self, + state: &common_utils::types::keymanager::KeyManagerState, + key_store: &hyperswitch_domain_models::merchant_key_store::MerchantKeyStore, + session_id: &common_utils::id_type::GlobalPaymentMethodSessionId, + update_request: hyperswitch_domain_models::payment_methods::PaymentMethodsSession, + ) -> CustomResult< + (), + errors::StorageError, + > { + let redis_key = session_id.get_redis_key(); + + let db_model = update_request + .construct_new() + .await + .change_context(errors::StorageError::EncryptionError)?; + + let redis_connection = self + .get_redis_conn() + .map_err(Into::::into)?; + + redis_connection + .serialize_and_set_key_without_modifying_ttl(&redis_key.into(), db_model) + .await + .change_context(errors::StorageError::KVError) + .attach_printable("Failed to insert payment methods session to redis") + + } } } - #[cfg(feature = "v2")] #[async_trait::async_trait] impl PaymentMethodsSessionInterface for MockDb { @@ -118,6 +158,19 @@ impl PaymentMethodsSessionInterface for MockDb { Err(errors::StorageError::MockDbError)? } + async fn update_payment_method_session( + &self, + state: &common_utils::types::keymanager::KeyManagerState, + key_store: &hyperswitch_domain_models::merchant_key_store::MerchantKeyStore, + id: &common_utils::id_type::GlobalPaymentMethodSessionId, + payment_methods_session: hyperswitch_domain_models::payment_methods::PaymentMethodsSession, + ) -> CustomResult< + (), + errors::StorageError + > { + Err(errors::StorageError::MockDbError)? + } + #[cfg(feature = "v2")] async fn get_payment_methods_session( &self, diff --git a/crates/router/src/routes/app.rs b/crates/router/src/routes/app.rs index c5e1f8a1082..59f948d7425 100644 --- a/crates/router/src/routes/app.rs +++ b/crates/router/src/routes/app.rs @@ -1270,7 +1270,8 @@ impl PaymentMethodsSession { web::scope("/{payment_method_session_id}") .service( web::resource("") - .route(web::get().to(payment_methods::payment_methods_session_retrieve)), + .route(web::get().to(payment_methods::payment_methods_session_retrieve)) + .route(web::put().to(payment_methods::payment_methods_session_update)), ) .service(web::resource("/list-payment-methods").route( web::get().to(payment_methods::payment_method_session_list_payment_methods), diff --git a/crates/router/src/routes/lock_utils.rs b/crates/router/src/routes/lock_utils.rs index ce9dda97c9f..9a3f29fbb2b 100644 --- a/crates/router/src/routes/lock_utils.rs +++ b/crates/router/src/routes/lock_utils.rs @@ -313,7 +313,8 @@ impl From for ApiIdentifier { Flow::PaymentMethodSessionCreate | Flow::PaymentMethodSessionRetrieve - | Flow::PaymentMethodSessionUpdateSavedPaymentMethod => Self::PaymentMethodsSession, + | Flow::PaymentMethodSessionUpdateSavedPaymentMethod + | Flow::PaymentMethodSessionUpdate => Self::PaymentMethodsSession, } } } diff --git a/crates/router/src/routes/payment_methods.rs b/crates/router/src/routes/payment_methods.rs index 86f1874ab09..a24cc6dbb5f 100644 --- a/crates/router/src/routes/payment_methods.rs +++ b/crates/router/src/routes/payment_methods.rs @@ -917,6 +917,46 @@ pub async fn payment_methods_session_create( .await } +#[cfg(feature = "v2")] +#[instrument(skip_all, fields(flow = ?Flow::PaymentMethodSessionUpdate))] +pub async fn payment_methods_session_update( + state: web::Data, + req: HttpRequest, + path: web::Path, + json_payload: web::Json, +) -> HttpResponse { + let flow = Flow::PaymentMethodSessionUpdate; + let payment_method_session_id = path.into_inner(); + let payload = json_payload.into_inner(); + + Box::pin(api::server_wrap( + flow, + state, + &req, + payload, + |state, auth: auth::AuthenticationData, req, _| { + let value = payment_method_session_id.clone(); + async move { + payment_methods_routes::payment_methods_session_update( + state, + auth.merchant_account, + auth.key_store, + value.clone(), + req, + ) + .await + }}, + &vec![ + auth::V2Auth::ApiKeyAuth, + auth::V2Auth::ClientAuth(diesel_models::ResourceId::PaymentMethodSession( + payment_method_session_id.clone(), + )), + ], + api_locking::LockAction::NotApplicable, + )) + .await +} + #[cfg(feature = "v2")] #[instrument(skip_all, fields(flow = ?Flow::PaymentMethodSessionRetrieve))] pub async fn payment_methods_session_retrieve( diff --git a/crates/router_env/src/logger/types.rs b/crates/router_env/src/logger/types.rs index b88effea34f..cd44cfdf4f0 100644 --- a/crates/router_env/src/logger/types.rs +++ b/crates/router_env/src/logger/types.rs @@ -547,6 +547,8 @@ pub enum Flow { PaymentMethodSessionCreate, /// Payment Method Session Retrieve PaymentMethodSessionRetrieve, + // Payment Method Session Update + PaymentMethodSessionUpdate, /// Update a saved payment method using the payment methods session PaymentMethodSessionUpdateSavedPaymentMethod, } From 09ddeff54d12d1bb9de09f98014e9e3cabb16226 Mon Sep 17 00:00:00 2001 From: "shivansh.mathur" Date: Thu, 13 Feb 2025 14:56:47 +0530 Subject: [PATCH 02/19] Changes --- crates/router/src/routes/payment_methods.rs | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/crates/router/src/routes/payment_methods.rs b/crates/router/src/routes/payment_methods.rs index a24cc6dbb5f..c03a2afb2e0 100644 --- a/crates/router/src/routes/payment_methods.rs +++ b/crates/router/src/routes/payment_methods.rs @@ -946,15 +946,18 @@ pub async fn payment_methods_session_update( ) .await }}, - &vec![ - auth::V2Auth::ApiKeyAuth, - auth::V2Auth::ClientAuth(diesel_models::ResourceId::PaymentMethodSession( - payment_method_session_id.clone(), - )), - ], - api_locking::LockAction::NotApplicable, - )) - .await + auth::api_or_client_auth( + &auth::V2ApiKeyAuth, + &auth::V2ClientAuth( + common_utils::types::authentication::ResourceId::PaymentMethodSession( + payment_method_session_id.clone(), + ), + ), + req.headers(), + ), + api_locking::LockAction::NotApplicable, + )) + .await } #[cfg(feature = "v2")] From b9907320b6b2c1233f91c20ec2591cdb1c34c091 Mon Sep 17 00:00:00 2001 From: "shivansh.mathur" Date: Mon, 3 Feb 2025 14:56:05 +0530 Subject: [PATCH 03/19] openapi changes --- api-reference-v2/openapi_spec.json | 39 ++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/api-reference-v2/openapi_spec.json b/api-reference-v2/openapi_spec.json index a5dc3a83f2d..7e0563b5273 100644 --- a/api-reference-v2/openapi_spec.json +++ b/api-reference-v2/openapi_spec.json @@ -2584,6 +2584,45 @@ "ephemeral_key": [] } ] + }, + "put": { + "tags": [ + "Payment Method Session" + ], + "summary": "Payment Method Session - Update", + "description": "Update the payment method session", + "operationId": "Update the payment method session", + "parameters": [ + { + "name": "id", + "in": "path", + "description": "The unique identifier for the Payment Method Session", + "required": true, + "schema": { + "type": "string" + } + } + ], + "responses": { + "200": { + "description": "The payment method session is updated successfully", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/PaymentMethodsSessionResponse" + } + } + } + }, + "404": { + "description": "The request is invalid" + } + }, + "security": [ + { + "ephemeral_key": [] + } + ] } }, "/v2/payment-method-session/:id/list-payment-methods": { From a8e7b3251bd1532151f022bf04098affd8f1e5b9 Mon Sep 17 00:00:00 2001 From: "hyperswitch-bot[bot]" <148525504+hyperswitch-bot[bot]@users.noreply.github.com> Date: Thu, 13 Feb 2025 10:40:55 +0000 Subject: [PATCH 04/19] chore: run formatter --- crates/api_models/src/payment_methods.rs | 1 - .../src/payment_methods_session.rs | 3 +- .../src/payment_methods.rs | 12 ++-- crates/router/src/core/payment_methods.rs | 55 +++++++++++-------- crates/router/src/db/kafka_store.rs | 2 +- .../router/src/db/payment_method_session.rs | 16 +----- crates/router/src/routes/app.rs | 29 +++++----- crates/router/src/routes/lock_utils.rs | 2 +- crates/router/src/routes/payment_methods.rs | 37 +++++++------ 9 files changed, 77 insertions(+), 80 deletions(-) diff --git a/crates/api_models/src/payment_methods.rs b/crates/api_models/src/payment_methods.rs index 6d62bcf3532..30491d7511b 100644 --- a/crates/api_models/src/payment_methods.rs +++ b/crates/api_models/src/payment_methods.rs @@ -2510,7 +2510,6 @@ pub struct PaymentMethodsSessionUpdateRequest { /// The network tokenization configuration if applicable #[schema(value_type = Option)] pub network_tokenization: Option, - } #[cfg(feature = "v2")] diff --git a/crates/diesel_models/src/payment_methods_session.rs b/crates/diesel_models/src/payment_methods_session.rs index c9d151d359f..ee16635c43c 100644 --- a/crates/diesel_models/src/payment_methods_session.rs +++ b/crates/diesel_models/src/payment_methods_session.rs @@ -10,7 +10,6 @@ pub struct PaymentMethodsSession { pub expires_at: time::PrimitiveDateTime, } - #[cfg(feature = "v2")] #[derive(Clone, Debug, serde::Serialize, serde::Deserialize)] pub struct PaymentMethodsSessionUpdate { @@ -18,4 +17,4 @@ pub struct PaymentMethodsSessionUpdate { pub billing: Option, pub psp_tokenization: Option, pub network_tokeinzation: Option, -} \ No newline at end of file +} diff --git a/crates/hyperswitch_domain_models/src/payment_methods.rs b/crates/hyperswitch_domain_models/src/payment_methods.rs index 6a252956a31..a3d02b53f28 100644 --- a/crates/hyperswitch_domain_models/src/payment_methods.rs +++ b/crates/hyperswitch_domain_models/src/payment_methods.rs @@ -700,11 +700,13 @@ impl super::behaviour::Conversion for PaymentMethodsSessionUpdate { let decrypted_data = crypto_operation( state, type_name!(Self::DstType), - CryptoOperation::BatchDecrypt(EncryptedPaymentMethodsSessionUpdate::to_encryptable( - EncryptedPaymentMethodsSessionUpdate { - billing: storage_model.billing, - }, - )), + CryptoOperation::BatchDecrypt( + EncryptedPaymentMethodsSessionUpdate::to_encryptable( + EncryptedPaymentMethodsSessionUpdate { + billing: storage_model.billing, + }, + ), + ), key_manager_identifier, key.peek(), ) diff --git a/crates/router/src/core/payment_methods.rs b/crates/router/src/core/payment_methods.rs index 3cf2cabc3d6..05320364836 100644 --- a/crates/router/src/core/payment_methods.rs +++ b/crates/router/src/core/payment_methods.rs @@ -1948,7 +1948,7 @@ pub async fn payment_methods_session_update( message: "payment methods session does not exist or has expired".to_string(), }) .attach_printable("Failed to retrieve payment methods session from db")?; - + let encrypted_data = request .encrypt_data(key_manager_state, &key_store) .await @@ -1964,32 +1964,37 @@ pub async fn payment_methods_session_update( }) .transpose() .change_context(errors::ApiErrorResponse::InternalServerError) - .attach_printable("Unable to decode billing address")?; + .attach_printable("Unable to decode billing address")?; - let payment_method_session_domain_model = hyperswitch_domain_models::payment_methods::PaymentMethodsSessionUpdate { - id: payment_method_session_id.clone(), - billing, - psp_tokenization: request.psp_tokenization, - network_tokenization: request.network_tokenization, - }; + let payment_method_session_domain_model = + hyperswitch_domain_models::payment_methods::PaymentMethodsSessionUpdate { + id: payment_method_session_id.clone(), + billing, + psp_tokenization: request.psp_tokenization, + network_tokenization: request.network_tokenization, + }; - let update_state_change = payment_method_session_update_to_current_state( - payment_method_session_domain_model, - payment_method_session_state - ).await; + let update_state_change = payment_method_session_update_to_current_state( + payment_method_session_domain_model, + payment_method_session_state, + ) + .await; - db.update_payment_method_session( key_manager_state, &key_store, &payment_method_session_id, update_state_change.clone() ) - .await - .change_context(errors::ApiErrorResponse::InternalServerError) - .attach_printable("Failed to update payment methods session in db")?; + db.update_payment_method_session( + key_manager_state, + &key_store, + &payment_method_session_id, + update_state_change.clone(), + ) + .await + .change_context(errors::ApiErrorResponse::InternalServerError) + .attach_printable("Failed to update payment methods session in db")?; let response = payment_methods::PaymentMethodsSessionResponse::foreign_from(( update_state_change, Secret::new("CLIENT_SECRET_REDACTED".to_string()), )); Ok(services::ApplicationResponse::Json(response)) - - } #[cfg(feature = "v2")] pub async fn payment_methods_session_retrieve( @@ -2107,19 +2112,21 @@ impl pm_types::SavedPMLPaymentsInfo { } } - - #[cfg(feature = "v2")] pub async fn payment_method_session_update_to_current_state( update_state: hyperswitch_domain_models::payment_methods::PaymentMethodsSessionUpdate, - current_state: hyperswitch_domain_models::payment_methods::PaymentMethodsSession + current_state: hyperswitch_domain_models::payment_methods::PaymentMethodsSession, ) -> hyperswitch_domain_models::payment_methods::PaymentMethodsSession { hyperswitch_domain_models::payment_methods::PaymentMethodsSession { id: current_state.id, customer_id: current_state.customer_id, billing: update_state.billing.or(current_state.billing), - psp_tokenization: update_state.psp_tokenization.or(current_state.psp_tokenization), - network_tokenization: update_state.network_tokenization.or(current_state.network_tokenization), + psp_tokenization: update_state + .psp_tokenization + .or(current_state.psp_tokenization), + network_tokenization: update_state + .network_tokenization + .or(current_state.network_tokenization), expires_at: current_state.expires_at, } -} \ No newline at end of file +} diff --git a/crates/router/src/db/kafka_store.rs b/crates/router/src/db/kafka_store.rs index 2b5dc9cd461..213aa23f2bf 100644 --- a/crates/router/src/db/kafka_store.rs +++ b/crates/router/src/db/kafka_store.rs @@ -3962,7 +3962,7 @@ impl db::payment_method_session::PaymentMethodsSessionInterface for KafkaStore { key_store: &hyperswitch_domain_models::merchant_key_store::MerchantKeyStore, id: &id_type::GlobalPaymentMethodSessionId, payment_methods_session: hyperswitch_domain_models::payment_methods::PaymentMethodsSession, - ) -> CustomResult< (), errors::StorageError, > { + ) -> CustomResult<(), errors::StorageError> { self.diesel_store .update_payment_method_session(state, key_store, id, payment_methods_session) .await diff --git a/crates/router/src/db/payment_method_session.rs b/crates/router/src/db/payment_method_session.rs index 1933e49fe5f..e45ff010f8d 100644 --- a/crates/router/src/db/payment_method_session.rs +++ b/crates/router/src/db/payment_method_session.rs @@ -19,10 +19,7 @@ pub trait PaymentMethodsSessionInterface { key_store: &hyperswitch_domain_models::merchant_key_store::MerchantKeyStore, id: &common_utils::id_type::GlobalPaymentMethodSessionId, payment_methods_session: hyperswitch_domain_models::payment_methods::PaymentMethodsSession, - ) -> CustomResult< - (), - errors::StorageError, - >; + ) -> CustomResult<(), errors::StorageError>; async fn get_payment_methods_session( &self, @@ -121,10 +118,7 @@ mod storage { key_store: &hyperswitch_domain_models::merchant_key_store::MerchantKeyStore, session_id: &common_utils::id_type::GlobalPaymentMethodSessionId, update_request: hyperswitch_domain_models::payment_methods::PaymentMethodsSession, - ) -> CustomResult< - (), - errors::StorageError, - > { + ) -> CustomResult<(), errors::StorageError> { let redis_key = session_id.get_redis_key(); let db_model = update_request @@ -141,7 +135,6 @@ mod storage { .await .change_context(errors::StorageError::KVError) .attach_printable("Failed to insert payment methods session to redis") - } } } @@ -164,10 +157,7 @@ impl PaymentMethodsSessionInterface for MockDb { key_store: &hyperswitch_domain_models::merchant_key_store::MerchantKeyStore, id: &common_utils::id_type::GlobalPaymentMethodSessionId, payment_methods_session: hyperswitch_domain_models::payment_methods::PaymentMethodsSession, - ) -> CustomResult< - (), - errors::StorageError - > { + ) -> CustomResult<(), errors::StorageError> { Err(errors::StorageError::MockDbError)? } diff --git a/crates/router/src/routes/app.rs b/crates/router/src/routes/app.rs index 59f948d7425..2319d32db4c 100644 --- a/crates/router/src/routes/app.rs +++ b/crates/router/src/routes/app.rs @@ -1266,24 +1266,23 @@ impl PaymentMethodsSession { .route(web::post().to(payment_methods::payment_methods_session_create)), ); - route = route.service( - web::scope("/{payment_method_session_id}") - .service( - web::resource("") - .route(web::get().to(payment_methods::payment_methods_session_retrieve)) - .route(web::put().to(payment_methods::payment_methods_session_update)), - ) - .service(web::resource("/list-payment-methods").route( - web::get().to(payment_methods::payment_method_session_list_payment_methods), - )) - .service( - web::resource("/update-saved-payment-method").route( + route = + route.service( + web::scope("/{payment_method_session_id}") + .service( + web::resource("") + .route(web::get().to(payment_methods::payment_methods_session_retrieve)) + .route(web::put().to(payment_methods::payment_methods_session_update)), + ) + .service(web::resource("/list-payment-methods").route( + web::get().to(payment_methods::payment_method_session_list_payment_methods), + )) + .service(web::resource("/update-saved-payment-method").route( web::put().to( payment_methods::payment_method_session_update_saved_payment_method, ), - ), - ), - ); + )), + ); route } diff --git a/crates/router/src/routes/lock_utils.rs b/crates/router/src/routes/lock_utils.rs index 9a3f29fbb2b..48f54f12502 100644 --- a/crates/router/src/routes/lock_utils.rs +++ b/crates/router/src/routes/lock_utils.rs @@ -313,7 +313,7 @@ impl From for ApiIdentifier { Flow::PaymentMethodSessionCreate | Flow::PaymentMethodSessionRetrieve - | Flow::PaymentMethodSessionUpdateSavedPaymentMethod + | Flow::PaymentMethodSessionUpdateSavedPaymentMethod | Flow::PaymentMethodSessionUpdate => Self::PaymentMethodsSession, } } diff --git a/crates/router/src/routes/payment_methods.rs b/crates/router/src/routes/payment_methods.rs index c03a2afb2e0..7cea0c86daf 100644 --- a/crates/router/src/routes/payment_methods.rs +++ b/crates/router/src/routes/payment_methods.rs @@ -937,27 +937,28 @@ pub async fn payment_methods_session_update( |state, auth: auth::AuthenticationData, req, _| { let value = payment_method_session_id.clone(); async move { - payment_methods_routes::payment_methods_session_update( - state, - auth.merchant_account, - auth.key_store, - value.clone(), - req, - ) - .await - }}, - auth::api_or_client_auth( + payment_methods_routes::payment_methods_session_update( + state, + auth.merchant_account, + auth.key_store, + value.clone(), + req, + ) + .await + } + }, + auth::api_or_client_auth( &auth::V2ApiKeyAuth, &auth::V2ClientAuth( - common_utils::types::authentication::ResourceId::PaymentMethodSession( - payment_method_session_id.clone(), - ), - ), - req.headers(), + common_utils::types::authentication::ResourceId::PaymentMethodSession( + payment_method_session_id.clone(), ), - api_locking::LockAction::NotApplicable, - )) - .await + ), + req.headers(), + ), + api_locking::LockAction::NotApplicable, + )) + .await } #[cfg(feature = "v2")] From 48cfcfdf3e1a9e23a1f44907c59b67c13d4eadfe Mon Sep 17 00:00:00 2001 From: "hyperswitch-bot[bot]" <148525504+hyperswitch-bot[bot]@users.noreply.github.com> Date: Thu, 13 Feb 2025 11:21:03 +0000 Subject: [PATCH 05/19] docs(openapi): re-generate OpenAPI specification --- api-reference-v2/openapi_spec.json | 68 +++++++++++++----------------- 1 file changed, 29 insertions(+), 39 deletions(-) diff --git a/api-reference-v2/openapi_spec.json b/api-reference-v2/openapi_spec.json index 7e0563b5273..929f303cfea 100644 --- a/api-reference-v2/openapi_spec.json +++ b/api-reference-v2/openapi_spec.json @@ -2584,45 +2584,6 @@ "ephemeral_key": [] } ] - }, - "put": { - "tags": [ - "Payment Method Session" - ], - "summary": "Payment Method Session - Update", - "description": "Update the payment method session", - "operationId": "Update the payment method session", - "parameters": [ - { - "name": "id", - "in": "path", - "description": "The unique identifier for the Payment Method Session", - "required": true, - "schema": { - "type": "string" - } - } - ], - "responses": { - "200": { - "description": "The payment method session is updated successfully", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/PaymentMethodsSessionResponse" - } - } - } - }, - "404": { - "description": "The request is invalid" - } - }, - "security": [ - { - "ephemeral_key": [] - } - ] } }, "/v2/payment-method-session/:id/list-payment-methods": { @@ -14870,6 +14831,35 @@ } } }, + "PaymentMethodsSessionUpdateRequest": { + "type": "object", + "properties": { + "billing": { + "allOf": [ + { + "$ref": "#/components/schemas/Address" + } + ], + "nullable": true + }, + "psp_tokenization": { + "allOf": [ + { + "$ref": "#/components/schemas/PspTokenization" + } + ], + "nullable": true + }, + "network_tokenization": { + "allOf": [ + { + "$ref": "#/components/schemas/NetworkTokenization" + } + ], + "nullable": true + } + } + }, "PaymentProcessingDetails": { "type": "object", "required": [ From 4378976deb5be1a6433d184c0e14e562d16e0ba4 Mon Sep 17 00:00:00 2001 From: "shivansh.mathur" Date: Thu, 20 Feb 2025 19:48:28 +0530 Subject: [PATCH 06/19] Changes for better structure --- .../src/payment_methods_session.rs | 37 ++++++++- .../src/payment_methods.rs | 75 ++++++++++++++++--- crates/router/src/core/payment_methods.rs | 60 ++++++++------- crates/router/src/db/kafka_store.rs | 5 +- .../router/src/db/payment_method_session.rs | 17 ++++- 5 files changed, 147 insertions(+), 47 deletions(-) diff --git a/crates/diesel_models/src/payment_methods_session.rs b/crates/diesel_models/src/payment_methods_session.rs index ee16635c43c..681a4f97af8 100644 --- a/crates/diesel_models/src/payment_methods_session.rs +++ b/crates/diesel_models/src/payment_methods_session.rs @@ -5,16 +5,47 @@ pub struct PaymentMethodsSession { pub customer_id: common_utils::id_type::GlobalCustomerId, pub billing: Option, pub psp_tokenization: Option, - pub network_tokeinzation: Option, + pub network_tokenization: Option, #[serde(with = "common_utils::custom_serde::iso8601")] pub expires_at: time::PrimitiveDateTime, } +#[cfg(feature = "v2")] +impl PaymentMethodsSession { + pub fn apply_changeset(self , update_session: PaymentMethodsSessionUpdateInternal) -> PaymentMethodsSession { + let Self { + id, + customer_id, + billing, + psp_tokenization, + network_tokenization, + expires_at, + } = self; + PaymentMethodsSession { + id, + customer_id, + billing: update_session.billing + .or(billing), + psp_tokenization: update_session.psp_tokenization + .or(psp_tokenization), + network_tokenization: update_session.network_tokenization + .or(network_tokenization), + expires_at, + } + } +} + +#[cfg(feature = "v2")] +pub struct PaymentMethodsSessionUpdateInternal { + pub billing: Option, + pub psp_tokenization: Option, + pub network_tokenization: Option, +} + #[cfg(feature = "v2")] #[derive(Clone, Debug, serde::Serialize, serde::Deserialize)] pub struct PaymentMethodsSessionUpdate { - pub id: common_utils::id_type::GlobalPaymentMethodSessionId, pub billing: Option, pub psp_tokenization: Option, - pub network_tokeinzation: Option, + pub network_tokenization: Option, } diff --git a/crates/hyperswitch_domain_models/src/payment_methods.rs b/crates/hyperswitch_domain_models/src/payment_methods.rs index a3d02b53f28..ba2f932b5b2 100644 --- a/crates/hyperswitch_domain_models/src/payment_methods.rs +++ b/crates/hyperswitch_domain_models/src/payment_methods.rs @@ -590,7 +590,7 @@ impl super::behaviour::Conversion for PaymentMethodsSession { customer_id: self.customer_id, billing: self.billing.map(|val| val.into()), psp_tokenization: self.psp_tokenization, - network_tokeinzation: self.network_tokenization, + network_tokenization: self.network_tokenization, expires_at: self.expires_at, }) } @@ -639,7 +639,7 @@ impl super::behaviour::Conversion for PaymentMethodsSession { customer_id: storage_model.customer_id, billing, psp_tokenization: storage_model.psp_tokenization, - network_tokenization: storage_model.network_tokeinzation, + network_tokenization: storage_model.network_tokenization, expires_at: storage_model.expires_at, }) } @@ -655,7 +655,7 @@ impl super::behaviour::Conversion for PaymentMethodsSession { customer_id: self.customer_id, billing: self.billing.map(|val| val.into()), psp_tokenization: self.psp_tokenization, - network_tokeinzation: self.network_tokenization, + network_tokenization: self.network_tokenization, expires_at: self.expires_at, }) } @@ -664,13 +664,71 @@ impl super::behaviour::Conversion for PaymentMethodsSession { #[cfg(feature = "v2")] #[derive(Clone, Debug, router_derive::ToEncryption)] pub struct PaymentMethodsSessionUpdate { - pub id: common_utils::id_type::GlobalPaymentMethodSessionId, #[encrypt(ty = Value)] pub billing: Option>, pub psp_tokenization: Option, pub network_tokenization: Option, } +#[cfg(feature = "v2")] +pub enum PaymentMethodsSessionUpdateEnum { + GeneralUpdate + { + billing: Option>, + psp_tokenization: Option, + network_tokenization: Option, + } +} + +#[cfg(feature = "v2")] +impl From for PaymentMethodsSessionUpdateInternal { + fn from(update: PaymentMethodsSessionUpdateEnum) -> Self { + match update { + PaymentMethodsSessionUpdateEnum::GeneralUpdate { + billing, + psp_tokenization, + network_tokenization, + } => Self { + billing: billing.map(|val| val.into()), + psp_tokenization: psp_tokenization, + network_tokenization: network_tokenization, + }, + } + } +} + +#[cfg(feature = "v2")] +impl PaymentMethodsSession { + pub fn apply_changeset(self , update_session: PaymentMethodsSessionUpdateInternal) -> PaymentMethodsSession { + let Self { + id, + customer_id, + billing, + psp_tokenization, + network_tokenization, + expires_at, + } = self; + PaymentMethodsSession { + id, + customer_id, + billing: update_session.billing + .or(billing), + psp_tokenization: update_session.psp_tokenization + .or(psp_tokenization), + network_tokenization: update_session.network_tokenization + .or(network_tokenization), + expires_at, + } + } +} + +#[cfg(feature = "v2")] +pub struct PaymentMethodsSessionUpdateInternal { + pub billing: Option>, + pub psp_tokenization: Option, + pub network_tokenization: Option, +} + #[cfg(feature = "v2")] #[async_trait::async_trait] impl super::behaviour::Conversion for PaymentMethodsSessionUpdate { @@ -678,10 +736,9 @@ impl super::behaviour::Conversion for PaymentMethodsSessionUpdate { type NewDstType = diesel_models::payment_methods_session::PaymentMethodsSessionUpdate; async fn convert(self) -> CustomResult { Ok(Self::DstType { - id: self.id, billing: self.billing.map(|val| val.into()), psp_tokenization: self.psp_tokenization, - network_tokeinzation: self.network_tokenization, + network_tokenization: self.network_tokenization }) } @@ -727,10 +784,9 @@ impl super::behaviour::Conversion for PaymentMethodsSessionUpdate { .attach_printable("Error while deserializing Address")?; Ok::>(Self { - id: storage_model.id, billing, psp_tokenization: storage_model.psp_tokenization, - network_tokenization: storage_model.network_tokeinzation, + network_tokenization: storage_model.network_tokenization, }) } .await @@ -741,10 +797,9 @@ impl super::behaviour::Conversion for PaymentMethodsSessionUpdate { async fn construct_new(self) -> CustomResult { Ok(Self::NewDstType { - id: self.id, billing: self.billing.map(|val| val.into()), psp_tokenization: self.psp_tokenization, - network_tokeinzation: self.network_tokenization, + network_tokenization: self.network_tokenization, }) } } diff --git a/crates/router/src/core/payment_methods.rs b/crates/router/src/core/payment_methods.rs index 05320364836..fce7144a3dc 100644 --- a/crates/router/src/core/payment_methods.rs +++ b/crates/router/src/core/payment_methods.rs @@ -1941,7 +1941,7 @@ pub async fn payment_methods_session_update( let db = state.store.as_ref(); let key_manager_state = &(&state).into(); - let payment_method_session_state = db + let existing_payment_method_session_state = db .get_payment_methods_session(key_manager_state, &key_store, &payment_method_session_id) .await .to_not_found_response(errors::ApiErrorResponse::GenericNotFoundError { @@ -1967,33 +1967,36 @@ pub async fn payment_methods_session_update( .attach_printable("Unable to decode billing address")?; let payment_method_session_domain_model = - hyperswitch_domain_models::payment_methods::PaymentMethodsSessionUpdate { - id: payment_method_session_id.clone(), + hyperswitch_domain_models::payment_methods::PaymentMethodsSessionUpdateEnum::GeneralUpdate{ billing, psp_tokenization: request.psp_tokenization, network_tokenization: request.network_tokenization, }; - let update_state_change = payment_method_session_update_to_current_state( - payment_method_session_domain_model, - payment_method_session_state, - ) - .await; - db.update_payment_method_session( key_manager_state, &key_store, &payment_method_session_id, - update_state_change.clone(), + payment_method_session_domain_model, + existing_payment_method_session_state.clone() ) .await .change_context(errors::ApiErrorResponse::InternalServerError) .attach_printable("Failed to update payment methods session in db")?; + + let update_state_change = db + .get_payment_methods_session(key_manager_state, &key_store, &payment_method_session_id) + .await + .to_not_found_response(errors::ApiErrorResponse::GenericNotFoundError { + message: "payment methods session does not exist or has expired".to_string(), + }) + .attach_printable("Failed to retrieve payment methods session from db")?; let response = payment_methods::PaymentMethodsSessionResponse::foreign_from(( update_state_change, Secret::new("CLIENT_SECRET_REDACTED".to_string()), )); + Ok(services::ApplicationResponse::Json(response)) } #[cfg(feature = "v2")] @@ -2022,6 +2025,7 @@ pub async fn payment_methods_session_retrieve( Ok(services::ApplicationResponse::Json(response)) } + #[cfg(feature = "v2")] pub async fn payment_methods_session_update_payment_method( state: SessionState, @@ -2112,21 +2116,21 @@ impl pm_types::SavedPMLPaymentsInfo { } } -#[cfg(feature = "v2")] -pub async fn payment_method_session_update_to_current_state( - update_state: hyperswitch_domain_models::payment_methods::PaymentMethodsSessionUpdate, - current_state: hyperswitch_domain_models::payment_methods::PaymentMethodsSession, -) -> hyperswitch_domain_models::payment_methods::PaymentMethodsSession { - hyperswitch_domain_models::payment_methods::PaymentMethodsSession { - id: current_state.id, - customer_id: current_state.customer_id, - billing: update_state.billing.or(current_state.billing), - psp_tokenization: update_state - .psp_tokenization - .or(current_state.psp_tokenization), - network_tokenization: update_state - .network_tokenization - .or(current_state.network_tokenization), - expires_at: current_state.expires_at, - } -} +// #[cfg(feature = "v2")] +// pub async fn payment_method_session_update_to_current_state( +// update_state: hyperswitch_domain_models::payment_methods::PaymentMethodsSessionUpdate, +// current_state: hyperswitch_domain_models::payment_methods::PaymentMethodsSession, +// ) -> hyperswitch_domain_models::payment_methods::PaymentMethodsSession { +// hyperswitch_domain_models::payment_methods::PaymentMethodsSession { +// id: current_state.id, +// customer_id: current_state.customer_id, +// billing: update_state.billing.or(current_state.billing), +// psp_tokenization: update_state +// .psp_tokenization +// .or(current_state.psp_tokenization), +// network_tokenization: update_state +// .network_tokenization +// .or(current_state.network_tokenization), +// expires_at: current_state.expires_at, +// } +// } diff --git a/crates/router/src/db/kafka_store.rs b/crates/router/src/db/kafka_store.rs index 213aa23f2bf..0cf235a3cab 100644 --- a/crates/router/src/db/kafka_store.rs +++ b/crates/router/src/db/kafka_store.rs @@ -3961,10 +3961,11 @@ impl db::payment_method_session::PaymentMethodsSessionInterface for KafkaStore { state: &KeyManagerState, key_store: &hyperswitch_domain_models::merchant_key_store::MerchantKeyStore, id: &id_type::GlobalPaymentMethodSessionId, - payment_methods_session: hyperswitch_domain_models::payment_methods::PaymentMethodsSession, + payment_methods_session: hyperswitch_domain_models::payment_methods::PaymentMethodsSessionUpdateEnum, + current_session: hyperswitch_domain_models::payment_methods::PaymentMethodsSession, ) -> CustomResult<(), errors::StorageError> { self.diesel_store - .update_payment_method_session(state, key_store, id, payment_methods_session) + .update_payment_method_session(state, key_store, id, payment_methods_session, current_session) .await } } diff --git a/crates/router/src/db/payment_method_session.rs b/crates/router/src/db/payment_method_session.rs index e45ff010f8d..50942f0585a 100644 --- a/crates/router/src/db/payment_method_session.rs +++ b/crates/router/src/db/payment_method_session.rs @@ -18,7 +18,8 @@ pub trait PaymentMethodsSessionInterface { state: &common_utils::types::keymanager::KeyManagerState, key_store: &hyperswitch_domain_models::merchant_key_store::MerchantKeyStore, id: &common_utils::id_type::GlobalPaymentMethodSessionId, - payment_methods_session: hyperswitch_domain_models::payment_methods::PaymentMethodsSession, + payment_methods_session: hyperswitch_domain_models::payment_methods::PaymentMethodsSessionUpdateEnum, + current_session: hyperswitch_domain_models::payment_methods::PaymentMethodsSession, ) -> CustomResult<(), errors::StorageError>; async fn get_payment_methods_session( @@ -117,11 +118,18 @@ mod storage { state: &common_utils::types::keymanager::KeyManagerState, key_store: &hyperswitch_domain_models::merchant_key_store::MerchantKeyStore, session_id: &common_utils::id_type::GlobalPaymentMethodSessionId, - update_request: hyperswitch_domain_models::payment_methods::PaymentMethodsSession, + update_request: hyperswitch_domain_models::payment_methods::PaymentMethodsSessionUpdateEnum, + current_session: hyperswitch_domain_models::payment_methods::PaymentMethodsSession, ) -> CustomResult<(), errors::StorageError> { let redis_key = session_id.get_redis_key(); - let db_model = update_request + let internal_obj = hyperswitch_domain_models::payment_methods::PaymentMethodsSessionUpdateInternal::from(update_request); + + let update_state = current_session.apply_changeset(internal_obj); + + // let update_session = diesel_models::payment_methods_session::PaymentMethodsSession::apply_changeset(current_session, internal_obj); + + let db_model = update_state .construct_new() .await .change_context(errors::StorageError::EncryptionError)?; @@ -156,7 +164,8 @@ impl PaymentMethodsSessionInterface for MockDb { state: &common_utils::types::keymanager::KeyManagerState, key_store: &hyperswitch_domain_models::merchant_key_store::MerchantKeyStore, id: &common_utils::id_type::GlobalPaymentMethodSessionId, - payment_methods_session: hyperswitch_domain_models::payment_methods::PaymentMethodsSession, + payment_methods_session: hyperswitch_domain_models::payment_methods::PaymentMethodsSessionUpdateEnum, + current_session: hyperswitch_domain_models::payment_methods::PaymentMethodsSession, ) -> CustomResult<(), errors::StorageError> { Err(errors::StorageError::MockDbError)? } From 5c1a0be6b1318a623a3e51849e37aed07adedb21 Mon Sep 17 00:00:00 2001 From: "hyperswitch-bot[bot]" <148525504+hyperswitch-bot[bot]@users.noreply.github.com> Date: Thu, 20 Feb 2025 15:16:15 +0000 Subject: [PATCH 07/19] chore: run formatter --- .../src/payment_methods_session.rs | 14 ++++++------- .../src/payment_methods.rs | 21 +++++++++---------- crates/router/src/core/payment_methods.rs | 17 +++++++-------- crates/router/src/db/kafka_store.rs | 8 ++++++- .../router/src/db/payment_method_session.rs | 4 ++-- 5 files changed, 34 insertions(+), 30 deletions(-) diff --git a/crates/diesel_models/src/payment_methods_session.rs b/crates/diesel_models/src/payment_methods_session.rs index 681a4f97af8..935e0d5e261 100644 --- a/crates/diesel_models/src/payment_methods_session.rs +++ b/crates/diesel_models/src/payment_methods_session.rs @@ -12,7 +12,10 @@ pub struct PaymentMethodsSession { #[cfg(feature = "v2")] impl PaymentMethodsSession { - pub fn apply_changeset(self , update_session: PaymentMethodsSessionUpdateInternal) -> PaymentMethodsSession { + pub fn apply_changeset( + self, + update_session: PaymentMethodsSessionUpdateInternal, + ) -> PaymentMethodsSession { let Self { id, customer_id, @@ -24,12 +27,9 @@ impl PaymentMethodsSession { PaymentMethodsSession { id, customer_id, - billing: update_session.billing - .or(billing), - psp_tokenization: update_session.psp_tokenization - .or(psp_tokenization), - network_tokenization: update_session.network_tokenization - .or(network_tokenization), + billing: update_session.billing.or(billing), + psp_tokenization: update_session.psp_tokenization.or(psp_tokenization), + network_tokenization: update_session.network_tokenization.or(network_tokenization), expires_at, } } diff --git a/crates/hyperswitch_domain_models/src/payment_methods.rs b/crates/hyperswitch_domain_models/src/payment_methods.rs index ba2f932b5b2..2ff7329f937 100644 --- a/crates/hyperswitch_domain_models/src/payment_methods.rs +++ b/crates/hyperswitch_domain_models/src/payment_methods.rs @@ -672,12 +672,11 @@ pub struct PaymentMethodsSessionUpdate { #[cfg(feature = "v2")] pub enum PaymentMethodsSessionUpdateEnum { - GeneralUpdate - { + GeneralUpdate { billing: Option>, psp_tokenization: Option, network_tokenization: Option, - } + }, } #[cfg(feature = "v2")] @@ -699,7 +698,10 @@ impl From for PaymentMethodsSessionUpdateIntern #[cfg(feature = "v2")] impl PaymentMethodsSession { - pub fn apply_changeset(self , update_session: PaymentMethodsSessionUpdateInternal) -> PaymentMethodsSession { + pub fn apply_changeset( + self, + update_session: PaymentMethodsSessionUpdateInternal, + ) -> PaymentMethodsSession { let Self { id, customer_id, @@ -711,12 +713,9 @@ impl PaymentMethodsSession { PaymentMethodsSession { id, customer_id, - billing: update_session.billing - .or(billing), - psp_tokenization: update_session.psp_tokenization - .or(psp_tokenization), - network_tokenization: update_session.network_tokenization - .or(network_tokenization), + billing: update_session.billing.or(billing), + psp_tokenization: update_session.psp_tokenization.or(psp_tokenization), + network_tokenization: update_session.network_tokenization.or(network_tokenization), expires_at, } } @@ -738,7 +737,7 @@ impl super::behaviour::Conversion for PaymentMethodsSessionUpdate { Ok(Self::DstType { billing: self.billing.map(|val| val.into()), psp_tokenization: self.psp_tokenization, - network_tokenization: self.network_tokenization + network_tokenization: self.network_tokenization, }) } diff --git a/crates/router/src/core/payment_methods.rs b/crates/router/src/core/payment_methods.rs index fce7144a3dc..767a0edaa06 100644 --- a/crates/router/src/core/payment_methods.rs +++ b/crates/router/src/core/payment_methods.rs @@ -1978,19 +1978,19 @@ pub async fn payment_methods_session_update( &key_store, &payment_method_session_id, payment_method_session_domain_model, - existing_payment_method_session_state.clone() + existing_payment_method_session_state.clone(), ) .await .change_context(errors::ApiErrorResponse::InternalServerError) .attach_printable("Failed to update payment methods session in db")?; - + let update_state_change = db - .get_payment_methods_session(key_manager_state, &key_store, &payment_method_session_id) - .await - .to_not_found_response(errors::ApiErrorResponse::GenericNotFoundError { - message: "payment methods session does not exist or has expired".to_string(), - }) - .attach_printable("Failed to retrieve payment methods session from db")?; + .get_payment_methods_session(key_manager_state, &key_store, &payment_method_session_id) + .await + .to_not_found_response(errors::ApiErrorResponse::GenericNotFoundError { + message: "payment methods session does not exist or has expired".to_string(), + }) + .attach_printable("Failed to retrieve payment methods session from db")?; let response = payment_methods::PaymentMethodsSessionResponse::foreign_from(( update_state_change, @@ -2025,7 +2025,6 @@ pub async fn payment_methods_session_retrieve( Ok(services::ApplicationResponse::Json(response)) } - #[cfg(feature = "v2")] pub async fn payment_methods_session_update_payment_method( state: SessionState, diff --git a/crates/router/src/db/kafka_store.rs b/crates/router/src/db/kafka_store.rs index 0cf235a3cab..0fb84aa3606 100644 --- a/crates/router/src/db/kafka_store.rs +++ b/crates/router/src/db/kafka_store.rs @@ -3965,7 +3965,13 @@ impl db::payment_method_session::PaymentMethodsSessionInterface for KafkaStore { current_session: hyperswitch_domain_models::payment_methods::PaymentMethodsSession, ) -> CustomResult<(), errors::StorageError> { self.diesel_store - .update_payment_method_session(state, key_store, id, payment_methods_session, current_session) + .update_payment_method_session( + state, + key_store, + id, + payment_methods_session, + current_session, + ) .await } } diff --git a/crates/router/src/db/payment_method_session.rs b/crates/router/src/db/payment_method_session.rs index 50942f0585a..0bc0622b607 100644 --- a/crates/router/src/db/payment_method_session.rs +++ b/crates/router/src/db/payment_method_session.rs @@ -128,8 +128,8 @@ mod storage { let update_state = current_session.apply_changeset(internal_obj); // let update_session = diesel_models::payment_methods_session::PaymentMethodsSession::apply_changeset(current_session, internal_obj); - - let db_model = update_state + + let db_model = update_state .construct_new() .await .change_context(errors::StorageError::EncryptionError)?; From ebfba330e3947918d435fab9ba2c72070920ef44 Mon Sep 17 00:00:00 2001 From: "shivansh.mathur" Date: Thu, 20 Feb 2025 23:40:57 +0530 Subject: [PATCH 08/19] Return value changes --- crates/router/src/core/payment_methods.rs | 10 +----- crates/router/src/db/kafka_store.rs | 5 ++- .../router/src/db/payment_method_session.rs | 35 ++++++++++++++----- crates/router/src/routes/payment_methods.rs | 11 +----- 4 files changed, 32 insertions(+), 29 deletions(-) diff --git a/crates/router/src/core/payment_methods.rs b/crates/router/src/core/payment_methods.rs index fce7144a3dc..ee30554e89a 100644 --- a/crates/router/src/core/payment_methods.rs +++ b/crates/router/src/core/payment_methods.rs @@ -1973,7 +1973,7 @@ pub async fn payment_methods_session_update( network_tokenization: request.network_tokenization, }; - db.update_payment_method_session( + let update_state_change = db.update_payment_method_session( key_manager_state, &key_store, &payment_method_session_id, @@ -1983,14 +1983,6 @@ pub async fn payment_methods_session_update( .await .change_context(errors::ApiErrorResponse::InternalServerError) .attach_printable("Failed to update payment methods session in db")?; - - let update_state_change = db - .get_payment_methods_session(key_manager_state, &key_store, &payment_method_session_id) - .await - .to_not_found_response(errors::ApiErrorResponse::GenericNotFoundError { - message: "payment methods session does not exist or has expired".to_string(), - }) - .attach_printable("Failed to retrieve payment methods session from db")?; let response = payment_methods::PaymentMethodsSessionResponse::foreign_from(( update_state_change, diff --git a/crates/router/src/db/kafka_store.rs b/crates/router/src/db/kafka_store.rs index 0cf235a3cab..3d5a65e0208 100644 --- a/crates/router/src/db/kafka_store.rs +++ b/crates/router/src/db/kafka_store.rs @@ -3963,7 +3963,10 @@ impl db::payment_method_session::PaymentMethodsSessionInterface for KafkaStore { id: &id_type::GlobalPaymentMethodSessionId, payment_methods_session: hyperswitch_domain_models::payment_methods::PaymentMethodsSessionUpdateEnum, current_session: hyperswitch_domain_models::payment_methods::PaymentMethodsSession, - ) -> CustomResult<(), errors::StorageError> { + ) -> CustomResult< + hyperswitch_domain_models::payment_methods::PaymentMethodsSession, + errors::StorageError, + > { self.diesel_store .update_payment_method_session(state, key_store, id, payment_methods_session, current_session) .await diff --git a/crates/router/src/db/payment_method_session.rs b/crates/router/src/db/payment_method_session.rs index 50942f0585a..0380e33c5f8 100644 --- a/crates/router/src/db/payment_method_session.rs +++ b/crates/router/src/db/payment_method_session.rs @@ -20,7 +20,10 @@ pub trait PaymentMethodsSessionInterface { id: &common_utils::id_type::GlobalPaymentMethodSessionId, payment_methods_session: hyperswitch_domain_models::payment_methods::PaymentMethodsSessionUpdateEnum, current_session: hyperswitch_domain_models::payment_methods::PaymentMethodsSession, - ) -> CustomResult<(), errors::StorageError>; + ) -> CustomResult< + hyperswitch_domain_models::payment_methods::PaymentMethodsSession, + errors::StorageError, + >; async fn get_payment_methods_session( &self, @@ -120,14 +123,15 @@ mod storage { session_id: &common_utils::id_type::GlobalPaymentMethodSessionId, update_request: hyperswitch_domain_models::payment_methods::PaymentMethodsSessionUpdateEnum, current_session: hyperswitch_domain_models::payment_methods::PaymentMethodsSession, - ) -> CustomResult<(), errors::StorageError> { + ) -> CustomResult< + hyperswitch_domain_models::payment_methods::PaymentMethodsSession, + errors::StorageError, + > { let redis_key = session_id.get_redis_key(); let internal_obj = hyperswitch_domain_models::payment_methods::PaymentMethodsSessionUpdateInternal::from(update_request); let update_state = current_session.apply_changeset(internal_obj); - - // let update_session = diesel_models::payment_methods_session::PaymentMethodsSession::apply_changeset(current_session, internal_obj); let db_model = update_state .construct_new() @@ -139,10 +143,20 @@ mod storage { .map_err(Into::::into)?; redis_connection - .serialize_and_set_key_without_modifying_ttl(&redis_key.into(), db_model) + .serialize_and_set_key_without_modifying_ttl(&redis_key.into(), db_model.clone()) .await .change_context(errors::StorageError::KVError) - .attach_printable("Failed to insert payment methods session to redis") + .attach_printable("Failed to insert payment methods session to redis"); + + let key_manager_identifier = common_utils::types::keymanager::Identifier::Merchant( + key_store.merchant_id.clone(), + ); + + db_model + .convert(state, &key_store.key, key_manager_identifier) + .await + .change_context(errors::StorageError::DecryptionError) + .attach_printable("Failed to decrypt payment methods session") } } } @@ -166,9 +180,12 @@ impl PaymentMethodsSessionInterface for MockDb { id: &common_utils::id_type::GlobalPaymentMethodSessionId, payment_methods_session: hyperswitch_domain_models::payment_methods::PaymentMethodsSessionUpdateEnum, current_session: hyperswitch_domain_models::payment_methods::PaymentMethodsSession, - ) -> CustomResult<(), errors::StorageError> { - Err(errors::StorageError::MockDbError)? - } + ) -> CustomResult< + hyperswitch_domain_models::payment_methods::PaymentMethodsSession, + errors::StorageError, + > { + Err(errors::StorageError::MockDbError)? + } #[cfg(feature = "v2")] async fn get_payment_methods_session( diff --git a/crates/router/src/routes/payment_methods.rs b/crates/router/src/routes/payment_methods.rs index 7cea0c86daf..38643017cee 100644 --- a/crates/router/src/routes/payment_methods.rs +++ b/crates/router/src/routes/payment_methods.rs @@ -928,7 +928,6 @@ pub async fn payment_methods_session_update( let flow = Flow::PaymentMethodSessionUpdate; let payment_method_session_id = path.into_inner(); let payload = json_payload.into_inner(); - Box::pin(api::server_wrap( flow, state, @@ -947,15 +946,7 @@ pub async fn payment_methods_session_update( .await } }, - auth::api_or_client_auth( - &auth::V2ApiKeyAuth, - &auth::V2ClientAuth( - common_utils::types::authentication::ResourceId::PaymentMethodSession( - payment_method_session_id.clone(), - ), - ), - req.headers(), - ), + &auth::V2ApiKeyAuth, api_locking::LockAction::NotApplicable, )) .await From a8a7c6210e8142ece2b865aa9ea40177ec8dfcf3 Mon Sep 17 00:00:00 2001 From: "hyperswitch-bot[bot]" <148525504+hyperswitch-bot[bot]@users.noreply.github.com> Date: Thu, 20 Feb 2025 18:28:56 +0000 Subject: [PATCH 09/19] chore: run formatter --- crates/router/src/core/payment_methods.rs | 21 ++++++++++--------- crates/router/src/db/kafka_store.rs | 6 +++--- .../router/src/db/payment_method_session.rs | 20 +++++++++--------- 3 files changed, 24 insertions(+), 23 deletions(-) diff --git a/crates/router/src/core/payment_methods.rs b/crates/router/src/core/payment_methods.rs index 8e323f4dec2..b4bde66431c 100644 --- a/crates/router/src/core/payment_methods.rs +++ b/crates/router/src/core/payment_methods.rs @@ -1973,16 +1973,17 @@ pub async fn payment_methods_session_update( network_tokenization: request.network_tokenization, }; - let update_state_change = db.update_payment_method_session( - key_manager_state, - &key_store, - &payment_method_session_id, - payment_method_session_domain_model, - existing_payment_method_session_state.clone(), - ) - .await - .change_context(errors::ApiErrorResponse::InternalServerError) - .attach_printable("Failed to update payment methods session in db")?; + let update_state_change = db + .update_payment_method_session( + key_manager_state, + &key_store, + &payment_method_session_id, + payment_method_session_domain_model, + existing_payment_method_session_state.clone(), + ) + .await + .change_context(errors::ApiErrorResponse::InternalServerError) + .attach_printable("Failed to update payment methods session in db")?; let response = payment_methods::PaymentMethodsSessionResponse::foreign_from(( update_state_change, diff --git a/crates/router/src/db/kafka_store.rs b/crates/router/src/db/kafka_store.rs index 78dbcfdde7e..d1b20edb4e6 100644 --- a/crates/router/src/db/kafka_store.rs +++ b/crates/router/src/db/kafka_store.rs @@ -3964,9 +3964,9 @@ impl db::payment_method_session::PaymentMethodsSessionInterface for KafkaStore { payment_methods_session: hyperswitch_domain_models::payment_methods::PaymentMethodsSessionUpdateEnum, current_session: hyperswitch_domain_models::payment_methods::PaymentMethodsSession, ) -> CustomResult< - hyperswitch_domain_models::payment_methods::PaymentMethodsSession, - errors::StorageError, - > { + hyperswitch_domain_models::payment_methods::PaymentMethodsSession, + errors::StorageError, + > { self.diesel_store .update_payment_method_session( state, diff --git a/crates/router/src/db/payment_method_session.rs b/crates/router/src/db/payment_method_session.rs index 0380e33c5f8..375273f15b1 100644 --- a/crates/router/src/db/payment_method_session.rs +++ b/crates/router/src/db/payment_method_session.rs @@ -124,16 +124,16 @@ mod storage { update_request: hyperswitch_domain_models::payment_methods::PaymentMethodsSessionUpdateEnum, current_session: hyperswitch_domain_models::payment_methods::PaymentMethodsSession, ) -> CustomResult< - hyperswitch_domain_models::payment_methods::PaymentMethodsSession, - errors::StorageError, + hyperswitch_domain_models::payment_methods::PaymentMethodsSession, + errors::StorageError, > { let redis_key = session_id.get_redis_key(); let internal_obj = hyperswitch_domain_models::payment_methods::PaymentMethodsSessionUpdateInternal::from(update_request); let update_state = current_session.apply_changeset(internal_obj); - - let db_model = update_state + + let db_model = update_state .construct_new() .await .change_context(errors::StorageError::EncryptionError)?; @@ -147,7 +147,7 @@ mod storage { .await .change_context(errors::StorageError::KVError) .attach_printable("Failed to insert payment methods session to redis"); - + let key_manager_identifier = common_utils::types::keymanager::Identifier::Merchant( key_store.merchant_id.clone(), ); @@ -181,11 +181,11 @@ impl PaymentMethodsSessionInterface for MockDb { payment_methods_session: hyperswitch_domain_models::payment_methods::PaymentMethodsSessionUpdateEnum, current_session: hyperswitch_domain_models::payment_methods::PaymentMethodsSession, ) -> CustomResult< - hyperswitch_domain_models::payment_methods::PaymentMethodsSession, - errors::StorageError, - > { - Err(errors::StorageError::MockDbError)? - } + hyperswitch_domain_models::payment_methods::PaymentMethodsSession, + errors::StorageError, + > { + Err(errors::StorageError::MockDbError)? + } #[cfg(feature = "v2")] async fn get_payment_methods_session( From 6ec0ac186d3f2d5baa2d5a34b440c9f0d3a646f3 Mon Sep 17 00:00:00 2001 From: "shivansh.mathur" Date: Fri, 21 Feb 2025 10:55:31 +0530 Subject: [PATCH 10/19] Removing unwanted Structs --- .../src/payment_methods_session.rs | 10 +-- .../src/payment_methods.rs | 74 ------------------- 2 files changed, 1 insertion(+), 83 deletions(-) diff --git a/crates/diesel_models/src/payment_methods_session.rs b/crates/diesel_models/src/payment_methods_session.rs index 935e0d5e261..18de13ed01c 100644 --- a/crates/diesel_models/src/payment_methods_session.rs +++ b/crates/diesel_models/src/payment_methods_session.rs @@ -40,12 +40,4 @@ pub struct PaymentMethodsSessionUpdateInternal { pub billing: Option, pub psp_tokenization: Option, pub network_tokenization: Option, -} - -#[cfg(feature = "v2")] -#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)] -pub struct PaymentMethodsSessionUpdate { - pub billing: Option, - pub psp_tokenization: Option, - pub network_tokenization: Option, -} +} \ No newline at end of file diff --git a/crates/hyperswitch_domain_models/src/payment_methods.rs b/crates/hyperswitch_domain_models/src/payment_methods.rs index 2ff7329f937..dd3a2ca8590 100644 --- a/crates/hyperswitch_domain_models/src/payment_methods.rs +++ b/crates/hyperswitch_domain_models/src/payment_methods.rs @@ -728,80 +728,6 @@ pub struct PaymentMethodsSessionUpdateInternal { pub network_tokenization: Option, } -#[cfg(feature = "v2")] -#[async_trait::async_trait] -impl super::behaviour::Conversion for PaymentMethodsSessionUpdate { - type DstType = diesel_models::payment_methods_session::PaymentMethodsSessionUpdate; - type NewDstType = diesel_models::payment_methods_session::PaymentMethodsSessionUpdate; - async fn convert(self) -> CustomResult { - Ok(Self::DstType { - billing: self.billing.map(|val| val.into()), - psp_tokenization: self.psp_tokenization, - network_tokenization: self.network_tokenization, - }) - } - - async fn convert_back( - state: &keymanager::KeyManagerState, - storage_model: Self::DstType, - key: &Secret>, - key_manager_identifier: keymanager::Identifier, - ) -> CustomResult - where - Self: Sized, - { - use common_utils::ext_traits::ValueExt; - - async { - let decrypted_data = crypto_operation( - state, - type_name!(Self::DstType), - CryptoOperation::BatchDecrypt( - EncryptedPaymentMethodsSessionUpdate::to_encryptable( - EncryptedPaymentMethodsSessionUpdate { - billing: storage_model.billing, - }, - ), - ), - key_manager_identifier, - key.peek(), - ) - .await - .and_then(|val| val.try_into_batchoperation())?; - - let data = EncryptedPaymentMethodsSessionUpdate::from_encryptable(decrypted_data) - .change_context(common_utils::errors::CryptoError::DecodingFailed) - .attach_printable("Invalid batch operation data")?; - - let billing = data - .billing - .map(|billing| { - billing.deserialize_inner_value(|value| value.parse_value("Address")) - }) - .transpose() - .change_context(common_utils::errors::CryptoError::DecodingFailed) - .attach_printable("Error while deserializing Address")?; - - Ok::>(Self { - billing, - psp_tokenization: storage_model.psp_tokenization, - network_tokenization: storage_model.network_tokenization, - }) - } - .await - .change_context(ValidationError::InvalidValue { - message: "Failed while decrypting payment method data".to_string(), - }) - } - - async fn construct_new(self) -> CustomResult { - Ok(Self::NewDstType { - billing: self.billing.map(|val| val.into()), - psp_tokenization: self.psp_tokenization, - network_tokenization: self.network_tokenization, - }) - } -} #[cfg(all( any(feature = "v1", feature = "v2"), From 7e6a18719de808c3694f368d6a14f8e63c026ee0 Mon Sep 17 00:00:00 2001 From: "hyperswitch-bot[bot]" <148525504+hyperswitch-bot[bot]@users.noreply.github.com> Date: Fri, 21 Feb 2025 05:26:36 +0000 Subject: [PATCH 11/19] chore: run formatter --- crates/diesel_models/src/payment_methods_session.rs | 2 +- crates/hyperswitch_domain_models/src/payment_methods.rs | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/crates/diesel_models/src/payment_methods_session.rs b/crates/diesel_models/src/payment_methods_session.rs index 18de13ed01c..773a356634f 100644 --- a/crates/diesel_models/src/payment_methods_session.rs +++ b/crates/diesel_models/src/payment_methods_session.rs @@ -40,4 +40,4 @@ pub struct PaymentMethodsSessionUpdateInternal { pub billing: Option, pub psp_tokenization: Option, pub network_tokenization: Option, -} \ No newline at end of file +} diff --git a/crates/hyperswitch_domain_models/src/payment_methods.rs b/crates/hyperswitch_domain_models/src/payment_methods.rs index dd3a2ca8590..b9b1873649d 100644 --- a/crates/hyperswitch_domain_models/src/payment_methods.rs +++ b/crates/hyperswitch_domain_models/src/payment_methods.rs @@ -728,7 +728,6 @@ pub struct PaymentMethodsSessionUpdateInternal { pub network_tokenization: Option, } - #[cfg(all( any(feature = "v1", feature = "v2"), not(feature = "payment_methods_v2") From d81c8361e0d700a8fb7fd7b119151bc63851422c Mon Sep 17 00:00:00 2001 From: "shivansh.mathur" Date: Fri, 21 Feb 2025 11:06:55 +0530 Subject: [PATCH 12/19] Removing unwanted structs --- crates/hyperswitch_domain_models/src/payment_methods.rs | 9 --------- 1 file changed, 9 deletions(-) diff --git a/crates/hyperswitch_domain_models/src/payment_methods.rs b/crates/hyperswitch_domain_models/src/payment_methods.rs index dd3a2ca8590..d3739020805 100644 --- a/crates/hyperswitch_domain_models/src/payment_methods.rs +++ b/crates/hyperswitch_domain_models/src/payment_methods.rs @@ -661,15 +661,6 @@ impl super::behaviour::Conversion for PaymentMethodsSession { } } -#[cfg(feature = "v2")] -#[derive(Clone, Debug, router_derive::ToEncryption)] -pub struct PaymentMethodsSessionUpdate { - #[encrypt(ty = Value)] - pub billing: Option>, - pub psp_tokenization: Option, - pub network_tokenization: Option, -} - #[cfg(feature = "v2")] pub enum PaymentMethodsSessionUpdateEnum { GeneralUpdate { From eeb398d0bd7d2327f8acd5ad55191767cbc50a04 Mon Sep 17 00:00:00 2001 From: "shivansh.mathur" Date: Fri, 21 Feb 2025 11:22:21 +0530 Subject: [PATCH 13/19] Removing comments --- crates/router/src/core/payment_methods.rs | 21 +-------------------- 1 file changed, 1 insertion(+), 20 deletions(-) diff --git a/crates/router/src/core/payment_methods.rs b/crates/router/src/core/payment_methods.rs index b4bde66431c..aff96e10f7c 100644 --- a/crates/router/src/core/payment_methods.rs +++ b/crates/router/src/core/payment_methods.rs @@ -2106,23 +2106,4 @@ impl pm_types::SavedPMLPaymentsInfo { Ok(()) } -} - -// #[cfg(feature = "v2")] -// pub async fn payment_method_session_update_to_current_state( -// update_state: hyperswitch_domain_models::payment_methods::PaymentMethodsSessionUpdate, -// current_state: hyperswitch_domain_models::payment_methods::PaymentMethodsSession, -// ) -> hyperswitch_domain_models::payment_methods::PaymentMethodsSession { -// hyperswitch_domain_models::payment_methods::PaymentMethodsSession { -// id: current_state.id, -// customer_id: current_state.customer_id, -// billing: update_state.billing.or(current_state.billing), -// psp_tokenization: update_state -// .psp_tokenization -// .or(current_state.psp_tokenization), -// network_tokenization: update_state -// .network_tokenization -// .or(current_state.network_tokenization), -// expires_at: current_state.expires_at, -// } -// } +} \ No newline at end of file From 68293f099841b48387f0a0333e3f5a5c79628f6b Mon Sep 17 00:00:00 2001 From: "hyperswitch-bot[bot]" <148525504+hyperswitch-bot[bot]@users.noreply.github.com> Date: Fri, 21 Feb 2025 05:53:35 +0000 Subject: [PATCH 14/19] chore: run formatter --- crates/router/src/core/payment_methods.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/router/src/core/payment_methods.rs b/crates/router/src/core/payment_methods.rs index aff96e10f7c..0859c139b27 100644 --- a/crates/router/src/core/payment_methods.rs +++ b/crates/router/src/core/payment_methods.rs @@ -2106,4 +2106,4 @@ impl pm_types::SavedPMLPaymentsInfo { Ok(()) } -} \ No newline at end of file +} From 798605db09ecbbe4af5b226ed32b0c5763188a8a Mon Sep 17 00:00:00 2001 From: "shivansh.mathur" Date: Fri, 21 Feb 2025 16:21:18 +0530 Subject: [PATCH 15/19] correcting workflow errors --- crates/diesel_models/src/payment_methods_session.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/diesel_models/src/payment_methods_session.rs b/crates/diesel_models/src/payment_methods_session.rs index 773a356634f..e6e1384ad50 100644 --- a/crates/diesel_models/src/payment_methods_session.rs +++ b/crates/diesel_models/src/payment_methods_session.rs @@ -15,7 +15,7 @@ impl PaymentMethodsSession { pub fn apply_changeset( self, update_session: PaymentMethodsSessionUpdateInternal, - ) -> PaymentMethodsSession { + ) -> Self { let Self { id, customer_id, @@ -24,7 +24,7 @@ impl PaymentMethodsSession { network_tokenization, expires_at, } = self; - PaymentMethodsSession { + Self { id, customer_id, billing: update_session.billing.or(billing), From 9166f48986a9d416a173abe31e86aab07971e92e Mon Sep 17 00:00:00 2001 From: "hyperswitch-bot[bot]" <148525504+hyperswitch-bot[bot]@users.noreply.github.com> Date: Fri, 21 Feb 2025 13:41:18 +0000 Subject: [PATCH 16/19] chore: run formatter --- crates/diesel_models/src/payment_methods_session.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/crates/diesel_models/src/payment_methods_session.rs b/crates/diesel_models/src/payment_methods_session.rs index e6e1384ad50..3dcdd8f684d 100644 --- a/crates/diesel_models/src/payment_methods_session.rs +++ b/crates/diesel_models/src/payment_methods_session.rs @@ -12,10 +12,7 @@ pub struct PaymentMethodsSession { #[cfg(feature = "v2")] impl PaymentMethodsSession { - pub fn apply_changeset( - self, - update_session: PaymentMethodsSessionUpdateInternal, - ) -> Self { + pub fn apply_changeset(self, update_session: PaymentMethodsSessionUpdateInternal) -> Self { let Self { id, customer_id, From d223a53387411cf1450d688b062f1fa087d93ed9 Mon Sep 17 00:00:00 2001 From: "shivansh.mathur" Date: Mon, 24 Feb 2025 12:15:15 +0530 Subject: [PATCH 17/19] Runner changes --- crates/hyperswitch_domain_models/src/payment_methods.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/hyperswitch_domain_models/src/payment_methods.rs b/crates/hyperswitch_domain_models/src/payment_methods.rs index fb4a0ea9f71..acf6fba9c70 100644 --- a/crates/hyperswitch_domain_models/src/payment_methods.rs +++ b/crates/hyperswitch_domain_models/src/payment_methods.rs @@ -681,7 +681,7 @@ impl From for PaymentMethodsSessionUpdateIntern } => Self { billing: billing.map(|val| val.into()), psp_tokenization: psp_tokenization, - network_tokenization: network_tokenization, + network_tokenization, }, } } @@ -692,7 +692,7 @@ impl PaymentMethodsSession { pub fn apply_changeset( self, update_session: PaymentMethodsSessionUpdateInternal, - ) -> PaymentMethodsSession { + ) -> Self { let Self { id, customer_id, @@ -701,7 +701,7 @@ impl PaymentMethodsSession { network_tokenization, expires_at, } = self; - PaymentMethodsSession { + Self { id, customer_id, billing: update_session.billing.or(billing), From c79738381c28f19152bfecab06107a7e195911f1 Mon Sep 17 00:00:00 2001 From: "hyperswitch-bot[bot]" <148525504+hyperswitch-bot[bot]@users.noreply.github.com> Date: Mon, 24 Feb 2025 07:05:10 +0000 Subject: [PATCH 18/19] chore: run formatter --- crates/hyperswitch_domain_models/src/payment_methods.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/crates/hyperswitch_domain_models/src/payment_methods.rs b/crates/hyperswitch_domain_models/src/payment_methods.rs index acf6fba9c70..7acffca9102 100644 --- a/crates/hyperswitch_domain_models/src/payment_methods.rs +++ b/crates/hyperswitch_domain_models/src/payment_methods.rs @@ -689,10 +689,7 @@ impl From for PaymentMethodsSessionUpdateIntern #[cfg(feature = "v2")] impl PaymentMethodsSession { - pub fn apply_changeset( - self, - update_session: PaymentMethodsSessionUpdateInternal, - ) -> Self { + pub fn apply_changeset(self, update_session: PaymentMethodsSessionUpdateInternal) -> Self { let Self { id, customer_id, From bf84e2c6568318397bb9a0b3849b5a1ea9e8fa65 Mon Sep 17 00:00:00 2001 From: Shivansh Mathur <104988143+ShivanshMathurJuspay@users.noreply.github.com> Date: Mon, 24 Feb 2025 15:27:27 +0530 Subject: [PATCH 19/19] clippy error --- crates/hyperswitch_domain_models/src/payment_methods.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/hyperswitch_domain_models/src/payment_methods.rs b/crates/hyperswitch_domain_models/src/payment_methods.rs index 7acffca9102..30cc15029e1 100644 --- a/crates/hyperswitch_domain_models/src/payment_methods.rs +++ b/crates/hyperswitch_domain_models/src/payment_methods.rs @@ -679,8 +679,8 @@ impl From for PaymentMethodsSessionUpdateIntern psp_tokenization, network_tokenization, } => Self { - billing: billing.map(|val| val.into()), - psp_tokenization: psp_tokenization, + billing, + psp_tokenization, network_tokenization, }, }