Open source, composable payments platform | PCI compliant | SaaS and Self-host options | Enables connectivity to multiple payment, payout, fraud, vault and tokenization providers | Uplifts authorization with intelligent routing and revenue recovery | Reduce payment processing costs with cost observability | Reduces payment ops with reconciliation
Rust adyenbeginner-friendlyfeaturedfinancefintechhacktoberfesthigh-performanceopen-sourceorchestrationpaymentpayment-gatewaypayment-integrationpayment-processingpaymentspayments-platformrestful-apirustsdkstripeworks-with-react
feat(platform): support get customer for platform in payments (#10684)
Apoorv Dixiteb130743afce
diff --git a/crates/router/src/core/payments.rs b/crates/router/src/core/payments.rsindex 38d2dd4b26..a110ad4387 100644--- a/crates/router/src/core/payments.rs+++ b/crates/router/src/core/payments.rs@@ -614,6 +614,18 @@ where&payment_data.get_payment_intent().clone(),)?;+ operation+ .to_domain()?+ .populate_raw_customer_details(+ state,+ &mut payment_data,+ customer_details.as_ref(),+ platform.get_processor(),+ )+ .await+ .to_not_found_response(errors::ApiErrorResponse::InternalServerError)+ .attach_printable("Failed while populating raw customer details")?;+let (operation, customer) = operation.to_domain()?// get_customer_details@@ -621,8 +633,7 @@ wherestate,&mut payment_data,customer_details,- platform.get_processor().get_key_store(),- platform.get_processor().get_account().storage_scheme,+ platform.get_provider(),).await.to_not_found_response(errors::ApiErrorResponse::CustomerNotFound)@@ -1356,14 +1367,25 @@ whereNone};+ operation+ .to_domain()?+ .populate_raw_customer_details(+ state,+ &mut payment_data,+ customer_details.as_ref(),+ platform.get_processor(),+ )+ .await+ .to_not_found_response(errors::ApiErrorResponse::InternalServerError)+ .attach_printable("Failed while populating raw customer details")?;+let (operation, customer) = operation.to_domain()?.get_or_create_customer_details(state,&mut payment_data,customer_details,- platform.get_processor().get_key_store(),- platform.get_processor().get_account().storage_scheme,+ platform.get_provider(),).await.to_not_found_response(errors::ApiErrorResponse::CustomerNotFound)diff --git a/crates/router/src/core/payments/helpers.rs b/crates/router/src/core/payments/helpers.rsindex 49a13468e3..c5e43a1062 100644--- a/crates/router/src/core/payments/helpers.rs+++ b/crates/router/src/core/payments/helpers.rs@@ -1678,37 +1678,20 @@ pub async fn get_connector_data_from_request(Ok(connector_data)}-#[cfg(feature = "v2")]-#[instrument(skip_all)]-#[allow(clippy::type_complexity)]-pub async fn create_customer_if_not_exist<'a, F: Clone, R, D>(- _state: &SessionState,- _operation: BoxedOperation<'a, F, R, D>,- _payment_data: &mut PaymentData<F>,- _req: Option<CustomerDetails>,- _merchant_id: &id_type::MerchantId,- _key_store: &domain::MerchantKeyStore,- _storage_scheme: common_enums::enums::MerchantStorageScheme,-) -> CustomResult<(BoxedOperation<'a, F, R, D>, Option<domain::Customer>), errors::StorageError> {- todo!()-}-#[cfg(feature = "v1")]#[instrument(skip_all)]-#[allow(clippy::type_complexity)]-pub async fn create_customer_if_not_exist<'a, F: Clone, R, D>(+pub async fn populate_raw_customer_details<F: Clone>(state: &SessionState,- operation: BoxedOperation<'a, F, R, D>,payment_data: &mut PaymentData<F>,- req: Option<CustomerDetails>,- merchant_id: &id_type::MerchantId,- key_store: &domain::MerchantKeyStore,- storage_scheme: common_enums::enums::MerchantStorageScheme,-) -> CustomResult<(BoxedOperation<'a, F, R, D>, Option<domain::Customer>), errors::StorageError> {+ req: Option<&CustomerDetails>,+ processor: &domain::Processor,+) -> CustomResult<(), errors::StorageError> {let request_customer_details = req.get_required_value("customer").change_context(errors::StorageError::ValueNotFound("customer".to_owned()))?;+ let key_store = processor.get_key_store();+let temp_customer_data = if request_customer_details.name.is_some()|| request_customer_details.email.is_some()|| request_customer_details.phone.is_some()@@ -1764,9 +1747,9 @@ pub async fn create_customer_if_not_exist<'a, F: Clone, R, D>(.or(parsed_customer_data.tax_registration_id.clone()),}).or(temp_customer_data);+let key_manager_state = state.into();payment_data.payment_intent.customer_details = raw_customer_details- .clone().async_map(|customer_details| {create_encrypted_data(&key_manager_state, key_store, customer_details)})@@ -1775,6 +1758,39 @@ pub async fn create_customer_if_not_exist<'a, F: Clone, R, D>(.change_context(errors::StorageError::EncryptionError).attach_printable("Unable to encrypt customer details")?;+ Ok(())+}++#[cfg(feature = "v2")]+#[instrument(skip_all)]+#[allow(clippy::type_complexity)]+pub async fn create_customer_if_not_exist<'a, F: Clone, R, D>(+ _state: &SessionState,+ _operation: BoxedOperation<'a, F, R, D>,+ _payment_data: &mut PaymentData<F>,+ _req: Option<CustomerDetails>,+ _provider: &domain::Provider,+) -> CustomResult<(BoxedOperation<'a, F, R, D>, Option<domain::Customer>), errors::StorageError> {+ todo!()+}++#[cfg(feature = "v1")]+#[instrument(skip_all)]+#[allow(clippy::type_complexity)]+pub async fn create_customer_if_not_exist<'a, F: Clone, R, D>(+ state: &SessionState,+ operation: BoxedOperation<'a, F, R, D>,+ payment_data: &mut PaymentData<F>,+ req: Option<CustomerDetails>,+ provider: &domain::Provider,+) -> CustomResult<(BoxedOperation<'a, F, R, D>, Option<domain::Customer>), errors::StorageError> {+ let merchant_id = provider.get_account().get_id();+ let storage_scheme = provider.get_account().storage_scheme;+ let key_store = provider.get_key_store();+ let request_customer_details = req+ .get_required_value("customer")+ .change_context(errors::StorageError::ValueNotFound("customer".to_owned()))?;+let customer_id = request_customer_details.customer_id.or(payment_data.payment_intent.customer_id.clone());@@ -1931,6 +1947,34 @@ pub async fn create_customer_if_not_exist<'a, F: Clone, R, D>())}+#[cfg(feature = "v1")]+#[instrument(skip_all)]+pub async fn get_customer_if_exists(+ state: &SessionState,+ customer_id_from_request: Option<&id_type::CustomerId>,+ customer_id_from_intent: Option<&id_type::CustomerId>,+ provider: &domain::Provider,+) -> CustomResult<Option<domain::Customer>, errors::StorageError> {+ let db = &*state.store;++ let customer_id = customer_id_from_request.or(customer_id_from_intent);++ match customer_id {+ Some(customer_id) => {+ let customer = db+ .find_customer_by_customer_id_merchant_id(+ customer_id,+ provider.get_account().get_id(),+ provider.get_key_store(),+ provider.get_account().storage_scheme,+ )+ .await?;+ Ok(Some(customer))+ }+ None => Ok(None),+ }+}+#[cfg(feature = "v1")]pub async fn retrieve_payment_method_with_temporary_token(state: &SessionState,diff --git a/crates/router/src/core/payments/operations.rs b/crates/router/src/core/payments/operations.rsindex 984e2ff914..4dcbddd5fa 100644--- a/crates/router/src/core/payments/operations.rs+++ b/crates/router/src/core/payments/operations.rs@@ -258,6 +258,16 @@ pub trait GetTracker<F: Clone, D, R>: Send {#[async_trait]pub trait Domain<F: Clone, R, D>: Send + Sync {+ #[cfg(feature = "v1")]+ /// This will populate raw customer details in payment intent (processor context)+ async fn populate_raw_customer_details<'a>(+ &'a self,+ state: &SessionState,+ payment_data: &mut D,+ request: Option<&CustomerDetails>,+ processor: &domain::Processor,+ ) -> CustomResult<(), errors::StorageError>;+#[cfg(feature = "v1")]/// This will fetch customer details, (this operation is flow specific)async fn get_or_create_customer_details<'a>(@@ -265,8 +275,7 @@ pub trait Domain<F: Clone, R, D>: Send + Sync {state: &SessionState,payment_data: &mut D,request: Option<CustomerDetails>,- merchant_key_store: &domain::MerchantKeyStore,- storage_scheme: enums::MerchantStorageScheme,+ provider: &domain::Provider,) -> CustomResult<(BoxedOperation<'a, F, R, D>, Option<domain::Customer>), errors::StorageError>;#[cfg(feature = "v2")]@@ -593,6 +602,17 @@ wherefor<'a> &'a Op: Operation<F, api::PaymentsRetrieveRequest, Data = D>,D: OperationSessionGetters<F> + OperationSessionSetters<F> + Send,{+ #[instrument(skip_all)]+ async fn populate_raw_customer_details<'a>(+ &'a self,+ _state: &SessionState,+ _payment_data: &mut D,+ _request: Option<&CustomerDetails>,+ _processor: &domain::Processor,+ ) -> CustomResult<(), errors::StorageError> {+ Ok(())+ }+#[instrument(skip_all)]#[cfg(feature = "v1")]async fn get_or_create_customer_details<'a>(@@ -600,8 +620,7 @@ wherestate: &SessionState,payment_data: &mut D,_request: Option<CustomerDetails>,- merchant_key_store: &domain::MerchantKeyStore,- storage_scheme: enums::MerchantStorageScheme,+ provider: &domain::Provider,) -> CustomResult<(BoxedOperation<'a, F, api::PaymentsRetrieveRequest, D>,@@ -610,6 +629,8 @@ whereerrors::StorageError,> {let db = &*state.store;+ let merchant_key_store = provider.get_key_store();+ let storage_scheme = provider.get_account().storage_scheme;let customer = match payment_data.get_payment_intent().customer_id.as_ref() {None => None,Some(customer_id) => {@@ -679,6 +700,17 @@ wherefor<'a> &'a Op: Operation<F, api::PaymentsCaptureRequest, Data = D>,D: OperationSessionGetters<F> + OperationSessionSetters<F> + Send,{+ #[instrument(skip_all)]+ async fn populate_raw_customer_details<'a>(+ &'a self,+ _state: &SessionState,+ _payment_data: &mut D,+ _request: Option<&CustomerDetails>,+ _processor: &domain::Processor,+ ) -> CustomResult<(), errors::StorageError> {+ Ok(())+ }+#[instrument(skip_all)]#[cfg(feature = "v1")]async fn get_or_create_customer_details<'a>(@@ -686,8 +718,7 @@ wherestate: &SessionState,payment_data: &mut D,_request: Option<CustomerDetails>,- merchant_key_store: &domain::MerchantKeyStore,- storage_scheme: enums::MerchantStorageScheme,+ provider: &domain::Provider,) -> CustomResult<(BoxedOperation<'a, F, api::PaymentsCaptureRequest, D>,@@ -696,6 +727,8 @@ whereerrors::StorageError,> {let db = &*state.store;+ let merchant_key_store = provider.get_key_store();+ let storage_scheme = provider.get_account().storage_scheme;let customer = match payment_data.get_payment_intent().customer_id.as_ref() {None => None,@@ -782,6 +815,17 @@ wherefor<'a> &'a Op: Operation<F, api::PaymentsCancelRequest, Data = D>,D: OperationSessionGetters<F> + OperationSessionSetters<F> + Send,{+ #[instrument(skip_all)]+ async fn populate_raw_customer_details<'a>(+ &'a self,+ _state: &SessionState,+ _payment_data: &mut D,+ _request: Option<&CustomerDetails>,+ _processor: &domain::Processor,+ ) -> CustomResult<(), errors::StorageError> {+ Ok(())+ }+#[instrument(skip_all)]#[cfg(feature = "v1")]async fn get_or_create_customer_details<'a>(@@ -789,8 +833,7 @@ wherestate: &SessionState,payment_data: &mut D,_request: Option<CustomerDetails>,- merchant_key_store: &domain::MerchantKeyStore,- storage_scheme: enums::MerchantStorageScheme,+ provider: &domain::Provider,) -> CustomResult<(BoxedOperation<'a, F, api::PaymentsCancelRequest, D>,@@ -799,6 +842,8 @@ whereerrors::StorageError,> {let db = &*state.store;+ let merchant_key_store = provider.get_key_store();+ let storage_scheme = provider.get_account().storage_scheme;let customer = match payment_data.get_payment_intent().customer_id.as_ref() {None => None,@@ -884,6 +929,17 @@ impl<D, F: Clone + Send, Op: Send + Sync + Operation<F, api::PaymentsRejectRequewherefor<'a> &'a Op: Operation<F, api::PaymentsRejectRequest, Data = D>,{+ #[instrument(skip_all)]+ async fn populate_raw_customer_details<'a>(+ &'a self,+ _state: &SessionState,+ _payment_data: &mut D,+ _request: Option<&CustomerDetails>,+ _processor: &domain::Processor,+ ) -> CustomResult<(), errors::StorageError> {+ Ok(())+ }+#[cfg(feature = "v1")]#[instrument(skip_all)]async fn get_or_create_customer_details<'a>(@@ -891,8 +947,7 @@ where_state: &SessionState,_payment_data: &mut D,_request: Option<CustomerDetails>,- _merchant_key_store: &domain::MerchantKeyStore,- _storage_scheme: enums::MerchantStorageScheme,+ _provider: &domain::Provider,) -> CustomResult<(BoxedOperation<'a, F, api::PaymentsRejectRequest, D>,diff --git a/crates/router/src/core/payments/operations/payment_cancel_post_capture.rs b/crates/router/src/core/payments/operations/payment_cancel_post_capture.rsindex 40f6a0f0cb..14d2716032 100644--- a/crates/router/src/core/payments/operations/payment_cancel_post_capture.rs+++ b/crates/router/src/core/payments/operations/payment_cancel_post_capture.rs@@ -215,14 +215,24 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, api::PaymentsCancelPoimpl<F: Clone + Send + Sync> Domain<F, api::PaymentsCancelPostCaptureRequest, PaymentData<F>>for PaymentCancelPostCapture{+ #[instrument(skip_all)]+ async fn populate_raw_customer_details<'a>(+ &'a self,+ _state: &SessionState,+ _payment_data: &mut PaymentData<F>,+ _request: Option<&payments::CustomerDetails>,+ _processor: &domain::Processor,+ ) -> errors::CustomResult<(), errors::StorageError> {+ Ok(())+ }+#[instrument(skip_all)]async fn get_or_create_customer_details<'a>(&'a self,_state: &SessionState,_payment_data: &mut PaymentData<F>,_request: Option<payments::CustomerDetails>,- _merchant_key_store: &domain::MerchantKeyStore,- _storage_scheme: enums::MerchantStorageScheme,+ _provider: &domain::Provider,) -> errors::CustomResult<(PaymentCancelPostCaptureOperation<'a, F>,diff --git a/crates/router/src/core/payments/operations/payment_complete_authorize.rs b/crates/router/src/core/payments/operations/payment_complete_authorize.rsindex 9edb216dda..5d03094fff 100644--- a/crates/router/src/core/payments/operations/payment_complete_authorize.rs+++ b/crates/router/src/core/payments/operations/payment_complete_authorize.rs@@ -388,28 +388,63 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, api::PaymentsRequest>#[async_trait]impl<F: Clone + Send + Sync> Domain<F, api::PaymentsRequest, PaymentData<F>> for CompleteAuthorize {+ #[instrument(skip_all)]+ async fn populate_raw_customer_details<'a>(+ &'a self,+ state: &SessionState,+ payment_data: &mut PaymentData<F>,+ request: Option<&CustomerDetails>,+ processor: &domain::Processor,+ ) -> CustomResult<(), errors::StorageError> {+ helpers::populate_raw_customer_details(state, payment_data, request, processor).await+ }+#[instrument(skip_all)]async fn get_or_create_customer_details<'a>(&'a self,state: &SessionState,payment_data: &mut PaymentData<F>,request: Option<CustomerDetails>,- key_store: &domain::MerchantKeyStore,- storage_scheme: common_enums::enums::MerchantStorageScheme,+ provider: &domain::Provider,) -> CustomResult<(CompleteAuthorizeOperation<'a, F>, Option<domain::Customer>),errors::StorageError,> {- helpers::create_customer_if_not_exist(- state,- Box::new(self),- payment_data,- request,- &key_store.merchant_id,- key_store,- storage_scheme,- )- .await+ match provider.get_account().merchant_account_type {+ common_enums::MerchantAccountType::Standard => {+ helpers::create_customer_if_not_exist(+ state,+ Box::new(self),+ payment_data,+ request,+ provider,+ )+ .await+ }+ common_enums::MerchantAccountType::Platform => {+ let customer = helpers::get_customer_if_exists(+ state,+ request.as_ref().and_then(|r| r.customer_id.as_ref()),+ payment_data.payment_intent.customer_id.as_ref(),+ provider,+ )+ .await?+ .inspect(|cust| {+ payment_data.email = payment_data+ .clone()+ .or_else(|| cust.email.clone().map(Into::into));+ });++ Ok((Box::new(self), customer))+ }+ common_enums::MerchantAccountType::Connected => {+ Err(errors::StorageError::ValueNotFound(+ "Connected merchant cannot be a provider".to_string(),+ )+ .into())+ }+ }}#[instrument(skip_all)]diff --git a/crates/router/src/core/payments/operations/payment_confirm.rs b/crates/router/src/core/payments/operations/payment_confirm.rsindex cd2204fe20..0bc1e37cee 100644--- a/crates/router/src/core/payments/operations/payment_confirm.rs+++ b/crates/router/src/core/payments/operations/payment_confirm.rs@@ -880,28 +880,75 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, api::PaymentsRequest>#[async_trait]impl<F: Clone + Send + Sync> Domain<F, api::PaymentsRequest, PaymentData<F>> for PaymentConfirm {+ #[instrument(skip_all)]+ async fn populate_raw_customer_details<'a>(+ &'a self,+ state: &SessionState,+ payment_data: &mut PaymentData<F>,+ request: Option<&CustomerDetails>,+ processor: &domain::Processor,+ ) -> CustomResult<(), errors::StorageError> {+ helpers::populate_raw_customer_details(state, payment_data, request, processor).await+ }+#[instrument(skip_all)]async fn get_or_create_customer_details<'a>(&'a self,state: &SessionState,payment_data: &mut PaymentData<F>,request: Option<CustomerDetails>,- key_store: &domain::MerchantKeyStore,- storage_scheme: common_enums::enums::MerchantStorageScheme,+ provider: &domain::Provider,) -> CustomResult<(PaymentConfirmOperation<'a, F>, Option<domain::Customer>),errors::StorageError,> {- helpers::create_customer_if_not_exist(- state,- Box::new(self),- payment_data,- request,- &key_store.merchant_id,- key_store,- storage_scheme,- )- .await+ match provider.get_account().merchant_account_type {+ common_enums::MerchantAccountType::Standard => {+ helpers::create_customer_if_not_exist(+ state,+ Box::new(self),+ payment_data,+ request,+ provider,+ )+ .await+ }+ common_enums::MerchantAccountType::Platform => {+ let customer = helpers::get_customer_if_exists(+ state,+ request.as_ref().and_then(|r| r.customer_id.as_ref()),+ payment_data.payment_intent.customer_id.as_ref(),+ provider,+ )+ .await?+ .map(|cust| {+ payment_data+ .payment_intent+ .customer_id+ .as_ref()+ .is_some_and(|existing_id| existing_id != &cust.customer_id)+ .then_some(errors::StorageError::ValueNotFound(+ "Customer id mismatch between payment intent and request".to_string(),+ ))+ .map_or(Ok(()), Err)?;+ payment_data.email = payment_data+ .clone()+ .or_else(|| cust.email.clone().map(Into::into));+ Ok(cust)+ })+ .transpose()+ .map_err(|e: errors::StorageError| report!(e))?;++ Ok((Box::new(self), customer))+ }+ common_enums::MerchantAccountType::Connected => {+ Err(errors::StorageError::ValueNotFound(+ "Connected merchant cannot be a provider".to_string(),+ )+ .into())+ }+ }}#[cfg(feature = "v1")]diff --git a/crates/router/src/core/payments/operations/payment_create.rs b/crates/router/src/core/payments/operations/payment_create.rsindex 9d2795ddc3..88e0713cca 100644--- a/crates/router/src/core/payments/operations/payment_create.rs+++ b/crates/router/src/core/payments/operations/payment_create.rs@@ -629,26 +629,62 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, api::PaymentsRequest>#[async_trait]impl<F: Clone + Send + Sync> Domain<F, api::PaymentsRequest, PaymentData<F>> for PaymentCreate {+ #[instrument(skip_all)]+ async fn populate_raw_customer_details<'a>(+ &'a self,+ state: &SessionState,+ payment_data: &mut PaymentData<F>,+ request: Option<&CustomerDetails>,+ processor: &domain::Processor,+ ) -> CustomResult<(), errors::StorageError> {+ helpers::populate_raw_customer_details(state, payment_data, request, processor).await+ }+#[instrument(skip_all)]async fn get_or_create_customer_details<'a>(&'a self,state: &SessionState,payment_data: &mut PaymentData<F>,request: Option<CustomerDetails>,- key_store: &domain::MerchantKeyStore,- storage_scheme: enums::MerchantStorageScheme,+ provider: &domain::Provider,) -> CustomResult<(PaymentCreateOperation<'a, F>, Option<domain::Customer>), errors::StorageError>{- helpers::create_customer_if_not_exist(- state,- Box::new(self),- payment_data,- request,- &key_store.merchant_id,- key_store,- storage_scheme,- )- .await+ match provider.get_account().merchant_account_type {+ common_enums::MerchantAccountType::Standard => {+ helpers::create_customer_if_not_exist(+ state,+ Box::new(self),+ payment_data,+ request,+ provider,+ )+ .await+ }+ common_enums::MerchantAccountType::Platform => {+ let customer = helpers::get_customer_if_exists(+ state,+ request.as_ref().and_then(|r| r.customer_id.as_ref()),+ payment_data.payment_intent.customer_id.as_ref(),+ provider,+ )+ .await?+ .inspect(|cust| {+ payment_data.payment_intent.customer_id = Some(cust.customer_id.clone());+ payment_data.email = payment_data+ .clone()+ .or_else(|| cust.email.clone().map(Into::into));+ });++ Ok((Box::new(self), customer))+ }+ common_enums::MerchantAccountType::Connected => {+ Err(errors::StorageError::ValueNotFound(+ "Connected merchant cannot be a provider".to_string(),+ )+ .into())+ }+ }}async fn payments_dynamic_tax_calculation<'a>(diff --git a/crates/router/src/core/payments/operations/payment_post_session_tokens.rs b/crates/router/src/core/payments/operations/payment_post_session_tokens.rsindex fc03d34b70..633bf03c53 100644--- a/crates/router/src/core/payments/operations/payment_post_session_tokens.rs+++ b/crates/router/src/core/payments/operations/payment_post_session_tokens.rs@@ -192,14 +192,24 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, api::PaymentsPostSessimpl<F: Clone + Send + Sync> Domain<F, api::PaymentsPostSessionTokensRequest, PaymentData<F>>for PaymentPostSessionTokens{+ #[instrument(skip_all)]+ async fn populate_raw_customer_details<'a>(+ &'a self,+ _state: &SessionState,+ _payment_data: &mut PaymentData<F>,+ _request: Option<&payments::CustomerDetails>,+ _processor: &domain::Processor,+ ) -> errors::CustomResult<(), errors::StorageError> {+ Ok(())+ }+#[instrument(skip_all)]async fn get_or_create_customer_details<'a>(&'a self,_state: &SessionState,_payment_data: &mut PaymentData<F>,_request: Option<payments::CustomerDetails>,- _merchant_key_store: &domain::MerchantKeyStore,- _storage_scheme: storage_enums::MerchantStorageScheme,+ _provider: &domain::Provider,) -> errors::CustomResult<(PaymentPostSessionTokensOperation<'a, F>,diff --git a/crates/router/src/core/payments/operations/payment_session.rs b/crates/router/src/core/payments/operations/payment_session.rsindex 25ea316e21..b6aadbb1dd 100644--- a/crates/router/src/core/payments/operations/payment_session.rs+++ b/crates/router/src/core/payments/operations/payment_session.rs@@ -314,28 +314,63 @@ impl<wherefor<'a> &'a Op: Operation<F, api::PaymentsSessionRequest, Data = PaymentData<F>>,{+ #[instrument(skip_all)]+ async fn populate_raw_customer_details<'a>(+ &'a self,+ state: &SessionState,+ payment_data: &mut PaymentData<F>,+ request: Option<&payments::CustomerDetails>,+ processor: &domain::Processor,+ ) -> errors::CustomResult<(), errors::StorageError> {+ helpers::populate_raw_customer_details(state, payment_data, request, processor).await+ }+#[instrument(skip_all)]async fn get_or_create_customer_details<'a>(&'a self,state: &SessionState,payment_data: &mut PaymentData<F>,request: Option<payments::CustomerDetails>,- key_store: &domain::MerchantKeyStore,- storage_scheme: common_enums::enums::MerchantStorageScheme,+ provider: &domain::Provider,) -> errors::CustomResult<(PaymentSessionOperation<'a, F>, Option<domain::Customer>),errors::StorageError,> {- helpers::create_customer_if_not_exist(- state,- Box::new(self),- payment_data,- request,- &key_store.merchant_id,- key_store,- storage_scheme,- )- .await+ match provider.get_account().merchant_account_type {+ common_enums::MerchantAccountType::Standard => {+ helpers::create_customer_if_not_exist(+ state,+ Box::new(self),+ payment_data,+ request,+ provider,+ )+ .await+ }+ common_enums::MerchantAccountType::Platform => {+ let customer = helpers::get_customer_if_exists(+ state,+ request.as_ref().and_then(|r| r.customer_id.as_ref()),+ payment_data.payment_intent.customer_id.as_ref(),+ provider,+ )+ .await?+ .inspect(|cust| {+ payment_data.email = payment_data+ .clone()+ .or_else(|| cust.email.clone().map(Into::into));+ });++ Ok((Box::new(self), customer))+ }+ common_enums::MerchantAccountType::Connected => {+ Err(errors::StorageError::ValueNotFound(+ "Connected merchant cannot be a provider".to_string(),+ )+ .into())+ }+ }}#[instrument(skip_all)]diff --git a/crates/router/src/core/payments/operations/payment_start.rs b/crates/router/src/core/payments/operations/payment_start.rsindex 4029c5edce..a0205a3ea4 100644--- a/crates/router/src/core/payments/operations/payment_start.rs+++ b/crates/router/src/core/payments/operations/payment_start.rs@@ -284,28 +284,63 @@ impl<wherefor<'a> &'a Op: Operation<F, api::PaymentsStartRequest, Data = PaymentData<F>>,{+ #[instrument(skip_all)]+ async fn populate_raw_customer_details<'a>(+ &'a self,+ state: &SessionState,+ payment_data: &mut PaymentData<F>,+ request: Option<&CustomerDetails>,+ processor: &domain::Processor,+ ) -> CustomResult<(), errors::StorageError> {+ helpers::populate_raw_customer_details(state, payment_data, request, processor).await+ }+#[instrument(skip_all)]async fn get_or_create_customer_details<'a>(&'a self,state: &SessionState,payment_data: &mut PaymentData<F>,request: Option<CustomerDetails>,- key_store: &domain::MerchantKeyStore,- storage_scheme: common_enums::enums::MerchantStorageScheme,+ provider: &domain::Provider,) -> CustomResult<(PaymentSessionOperation<'a, F>, Option<domain::Customer>),errors::StorageError,> {- helpers::create_customer_if_not_exist(- state,- Box::new(self),- payment_data,- request,- &key_store.merchant_id,- key_store,- storage_scheme,- )- .await+ match provider.get_account().merchant_account_type {+ common_enums::MerchantAccountType::Standard => {+ helpers::create_customer_if_not_exist(+ state,+ Box::new(self),+ payment_data,+ request,+ provider,+ )+ .await+ }+ common_enums::MerchantAccountType::Platform => {+ let customer = helpers::get_customer_if_exists(+ state,+ request.as_ref().and_then(|r| r.customer_id.as_ref()),+ payment_data.payment_intent.customer_id.as_ref(),+ provider,+ )+ .await?+ .inspect(|cust| {+ payment_data.email = payment_data+ .clone()+ .or_else(|| cust.email.clone().map(Into::into));+ });++ Ok((Box::new(self), customer))+ }+ common_enums::MerchantAccountType::Connected => {+ Err(errors::StorageError::ValueNotFound(+ "Connected merchant cannot be a provider".to_string(),+ )+ .into())+ }+ }}#[instrument(skip_all)]diff --git a/crates/router/src/core/payments/operations/payment_status.rs b/crates/router/src/core/payments/operations/payment_status.rsindex bdffb110fc..e91964901d 100644--- a/crates/router/src/core/payments/operations/payment_status.rs+++ b/crates/router/src/core/payments/operations/payment_status.rs@@ -59,14 +59,24 @@ impl<F: Send + Clone + Sync> Operation<F, api::PaymentsRequest> for &PaymentStat#[async_trait]impl<F: Clone + Send + Sync> Domain<F, api::PaymentsRequest, PaymentData<F>> for PaymentStatus {+ #[instrument(skip_all)]+ async fn populate_raw_customer_details<'a>(+ &'a self,+ state: &SessionState,+ payment_data: &mut PaymentData<F>,+ request: Option<&CustomerDetails>,+ processor: &domain::Processor,+ ) -> CustomResult<(), errors::StorageError> {+ helpers::populate_raw_customer_details(state, payment_data, request, processor).await+ }+#[instrument(skip_all)]async fn get_or_create_customer_details<'a>(&'a self,state: &SessionState,payment_data: &mut PaymentData<F>,request: Option<CustomerDetails>,- key_store: &domain::MerchantKeyStore,- storage_scheme: enums::MerchantStorageScheme,+ provider: &domain::Provider,) -> CustomResult<(PaymentStatusOperation<'a, F, api::PaymentsRequest>,@@ -74,16 +84,41 @@ impl<F: Clone + Send + Sync> Domain<F, api::PaymentsRequest, PaymentData<F>> for),errors::StorageError,> {- helpers::create_customer_if_not_exist(- state,- Box::new(self),- payment_data,- request,- &key_store.merchant_id,- key_store,- storage_scheme,- )- .await+ match provider.get_account().merchant_account_type {+ common_enums::MerchantAccountType::Standard => {+ helpers::create_customer_if_not_exist(+ state,+ Box::new(self),+ payment_data,+ request,+ provider,+ )+ .await+ }+ common_enums::MerchantAccountType::Platform => {+ let customer = helpers::get_customer_if_exists(+ state,+ request.as_ref().and_then(|r| r.customer_id.as_ref()),+ payment_data.payment_intent.customer_id.as_ref(),+ provider,+ )+ .await?+ .inspect(|cust| {+ payment_data.email = payment_data+ .clone()+ .or_else(|| cust.email.clone().map(Into::into));+ });++ Ok((Box::new(self), customer))+ }+ common_enums::MerchantAccountType::Connected => {+ Err(errors::StorageError::ValueNotFound(+ "Connected merchant cannot be a provider".to_string(),+ )+ .into())+ }+ }}#[instrument(skip_all)]diff --git a/crates/router/src/core/payments/operations/payment_update.rs b/crates/router/src/core/payments/operations/payment_update.rsindex fca94cf250..15935bbddd 100644--- a/crates/router/src/core/payments/operations/payment_update.rs+++ b/crates/router/src/core/payments/operations/payment_update.rs@@ -537,26 +537,73 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, api::PaymentsRequest>#[async_trait]impl<F: Clone + Send + Sync> Domain<F, api::PaymentsRequest, PaymentData<F>> for PaymentUpdate {+ #[instrument(skip_all)]+ async fn populate_raw_customer_details<'a>(+ &'a self,+ state: &SessionState,+ payment_data: &mut PaymentData<F>,+ request: Option<&CustomerDetails>,+ processor: &domain::Processor,+ ) -> CustomResult<(), errors::StorageError> {+ helpers::populate_raw_customer_details(state, payment_data, request, processor).await+ }+#[instrument(skip_all)]async fn get_or_create_customer_details<'a>(&'a self,state: &SessionState,payment_data: &mut PaymentData<F>,request: Option<CustomerDetails>,- key_store: &domain::MerchantKeyStore,- storage_scheme: common_enums::enums::MerchantStorageScheme,+ provider: &domain::Provider,) -> CustomResult<(PaymentUpdateOperation<'a, F>, Option<domain::Customer>), errors::StorageError>{- helpers::create_customer_if_not_exist(- state,- Box::new(self),- payment_data,- request,- &key_store.merchant_id,- key_store,- storage_scheme,- )- .await+ match provider.get_account().merchant_account_type {+ common_enums::MerchantAccountType::Standard => {+ helpers::create_customer_if_not_exist(+ state,+ Box::new(self),+ payment_data,+ request,+ provider,+ )+ .await+ }+ common_enums::MerchantAccountType::Platform => {+ let customer = helpers::get_customer_if_exists(+ state,+ request.as_ref().and_then(|r| r.customer_id.as_ref()),+ payment_data.payment_intent.customer_id.as_ref(),+ provider,+ )+ .await?+ .map(|cust| {+ payment_data+ .payment_intent+ .customer_id+ .as_ref()+ .is_some_and(|existing_id| existing_id != &cust.customer_id)+ .then_some(errors::StorageError::ValueNotFound(+ "Customer id mismatch between payment intent and request".to_string(),+ ))+ .map_or(Ok(()), Err)?;+ payment_data.email = payment_data+ .clone()+ .or_else(|| cust.email.clone().map(Into::into));+ Ok(cust)+ })+ .transpose()+ .map_err(|e: errors::StorageError| report!(e))?;++ Ok((Box::new(self), customer))+ }+ common_enums::MerchantAccountType::Connected => {+ Err(errors::StorageError::ValueNotFound(+ "Connected merchant cannot be a provider".to_string(),+ )+ .into())+ }+ }}async fn payments_dynamic_tax_calculation<'a>(diff --git a/crates/router/src/core/payments/operations/payment_update_metadata.rs b/crates/router/src/core/payments/operations/payment_update_metadata.rsindex 2d0ff1d727..7c57f2529a 100644--- a/crates/router/src/core/payments/operations/payment_update_metadata.rs+++ b/crates/router/src/core/payments/operations/payment_update_metadata.rs@@ -178,14 +178,24 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, api::PaymentsUpdateMeimpl<F: Clone + Send + Sync> Domain<F, api::PaymentsUpdateMetadataRequest, PaymentData<F>>for PaymentUpdateMetadata{+ #[instrument(skip_all)]+ async fn populate_raw_customer_details<'a>(+ &'a self,+ _state: &SessionState,+ _payment_data: &mut PaymentData<F>,+ _request: Option<&payments::CustomerDetails>,+ _processor: &domain::Processor,+ ) -> errors::CustomResult<(), errors::StorageError> {+ Ok(())+ }+#[instrument(skip_all)]async fn get_or_create_customer_details<'a>(&'a self,_state: &SessionState,_payment_data: &mut PaymentData<F>,_request: Option<payments::CustomerDetails>,- _merchant_key_store: &domain::MerchantKeyStore,- _storage_scheme: storage_enums::MerchantStorageScheme,+ _provider: &domain::Provider,) -> errors::CustomResult<(PaymentUpdateMetadataOperation<'a, F>,diff --git a/crates/router/src/core/payments/operations/payments_extend_authorization.rs b/crates/router/src/core/payments/operations/payments_extend_authorization.rsindex 4815c09630..37e025fc4b 100644--- a/crates/router/src/core/payments/operations/payments_extend_authorization.rs+++ b/crates/router/src/core/payments/operations/payments_extend_authorization.rs@@ -220,14 +220,24 @@ impl<F: Send + Clone + Sync> GetTracker<F, PaymentData<F>, api::PaymentsExtendAuimpl<F: Clone + Send + Sync> Domain<F, api::PaymentsExtendAuthorizationRequest, PaymentData<F>>for PaymentExtendAuthorization{+ #[instrument(skip_all)]+ async fn populate_raw_customer_details<'a>(+ &'a self,+ _state: &SessionState,+ _payment_data: &mut PaymentData<F>,+ _request: Option<&payments::CustomerDetails>,+ _processor: &domain::Processor,+ ) -> errors::CustomResult<(), errors::StorageError> {+ Ok(())+ }+#[instrument(skip_all)]async fn get_or_create_customer_details<'a>(&'a self,_state: &SessionState,_payment_data: &mut PaymentData<F>,_request: Option<payments::CustomerDetails>,- _merchant_key_store: &domain::MerchantKeyStore,- _storage_scheme: enums::MerchantStorageScheme,+ _provider: &domain::Provider,) -> errors::CustomResult<(PaymentExtendAuthorizationOperation<'a, F>,diff --git a/crates/router/src/core/payments/operations/payments_incremental_authorization.rs b/crates/router/src/core/payments/operations/payments_incremental_authorization.rsindex 3f69907dfa..fa9031d6db 100644--- a/crates/router/src/core/payments/operations/payments_incremental_authorization.rs+++ b/crates/router/src/core/payments/operations/payments_incremental_authorization.rs@@ -318,14 +318,24 @@ impl<F: Clone + Send + Sync>Domain<F, PaymentsIncrementalAuthorizationRequest, payments::PaymentData<F>>for PaymentIncrementalAuthorization{+ #[instrument(skip_all)]+ async fn populate_raw_customer_details<'a>(+ &'a self,+ _state: &SessionState,+ _payment_data: &mut payments::PaymentData<F>,+ _request: Option<&CustomerDetails>,+ _processor: &domain::Processor,+ ) -> CustomResult<(), errors::StorageError> {+ Ok(())+ }+#[instrument(skip_all)]async fn get_or_create_customer_details<'a>(&'a self,_state: &SessionState,_payment_data: &mut payments::PaymentData<F>,_request: Option<CustomerDetails>,- _merchant_key_store: &domain::MerchantKeyStore,- _storage_scheme: enums::MerchantStorageScheme,+ _provider: &domain::Provider,) -> CustomResult<(BoxedOperation<diff --git a/crates/router/src/core/payments/operations/tax_calculation.rs b/crates/router/src/core/payments/operations/tax_calculation.rsindex c774e68d77..fb3936118d 100644--- a/crates/router/src/core/payments/operations/tax_calculation.rs+++ b/crates/router/src/core/payments/operations/tax_calculation.rs@@ -208,14 +208,24 @@ impl<F: Send + Clone + Sync>impl<F: Clone + Send + Sync> Domain<F, api::PaymentsDynamicTaxCalculationRequest, PaymentData<F>>for PaymentSessionUpdate{+ #[instrument(skip_all)]+ async fn populate_raw_customer_details<'a>(+ &'a self,+ _state: &SessionState,+ _payment_data: &mut PaymentData<F>,+ _request: Option<&payments::CustomerDetails>,+ _processor: &domain::Processor,+ ) -> errors::CustomResult<(), errors::StorageError> {+ Ok(())+ }+#[instrument(skip_all)]async fn get_or_create_customer_details<'a>(&'a self,_state: &SessionState,_payment_data: &mut PaymentData<F>,_request: Option<payments::CustomerDetails>,- _merchant_key_store: &domain::MerchantKeyStore,- _storage_scheme: storage_enums::MerchantStorageScheme,+ _provider: &domain::Provider,) -> errors::CustomResult<(PaymentSessionUpdateOperation<'a, F>,