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): enable payment method and customer routes for v2 in platform (#11281)
Apoorv Dixit2b9a0a62bfbd
diff --git a/crates/router/src/core/payment_methods.rs b/crates/router/src/core/payment_methods.rsindex 3400c22895..95fcdc07cc 100644--- a/crates/router/src/core/payment_methods.rs+++ b/crates/router/src/core/payment_methods.rs@@ -4333,9 +4333,9 @@ pub async fn payment_methods_session_create(if let (Some(customer_id)) = &request.customer_id {db.find_customer_by_global_id_merchant_id(customer_id,- provider.get_account().get_id(),- provider.get_key_store(),- provider.get_account().storage_scheme,+ platform.get_provider().get_account().get_id(),+ platform.get_provider().get_key_store(),+ platform.get_provider().get_account().storage_scheme,).await.to_not_found_response(errors::ApiErrorResponse::CustomerNotFound)@@ -4348,7 +4348,7 @@ pub async fn payment_methods_session_create(.attach_printable("Unable to generate GlobalPaymentMethodSessionId")?;let encrypted_data = request- .encrypt_data(key_manager_state, provider.get_key_store())+ .encrypt_data(key_manager_state, platform.get_provider().get_key_store()).await.change_context(errors::ApiErrorResponse::InternalServerError).attach_printable("Failed to encrypt payment methods session data")?;@@ -4374,7 +4374,7 @@ pub async fn payment_methods_session_create(let client_secret = payment_helpers::create_client_secret(&state,- provider.get_account().get_id(),+ platform.get_provider().get_account().get_id(),util_types::authentication::ResourceId::PaymentMethodSession(payment_methods_session_id.clone(),),@@ -4400,7 +4400,7 @@ pub async fn payment_methods_session_create(};db.insert_payment_methods_session(- provider.get_key_store(),+ platform.get_provider().get_key_store(),payment_method_session_domain_model.clone(),expires_in,)diff --git a/crates/router/src/core/payment_methods/transformers.rs b/crates/router/src/core/payment_methods/transformers.rsindex d761e65bd7..ed62ae6069 100644--- a/crates/router/src/core/payment_methods/transformers.rs+++ b/crates/router/src/core/payment_methods/transformers.rs@@ -1142,7 +1142,7 @@ impl transformers::ForeignFrom<&payment_method_data::SingleUsePaymentMethodToken#[cfg(feature = "v1")]pub async fn call_modular_payment_method_update(state: &routes::SessionState,- merchant_id: &id_type::MerchantId,+ processor_merchant_id: &id_type::MerchantId,profile_id: &id_type::ProfileId,payment_method_id: &str,payload: UpdatePaymentMethodV1Payload,@@ -1154,7 +1154,7 @@ pub async fn call_modular_payment_method_update());parent_headers.insert((headers::X_MERCHANT_ID.to_string(),- merchant_id.get_string_repr().to_string().into(),+ processor_merchant_id.get_string_repr().to_string().into(),));parent_headers.insert((headers::X_INTERNAL_API_KEY.to_string(),@@ -1591,7 +1591,7 @@ pub async fn fetch_payment_method_from_modular_service(//Fetch modular service calllet pm_response = retrieve_pm_modular_service_call(state,- platform.get_provider().get_account().get_id(),+ platform.get_processor().get_account().get_id(),profile_id,payment_method_fetch_req,)@@ -1630,7 +1630,7 @@ pub async fn fetch_payment_method_from_modular_service(#[cfg(feature = "v1")]pub async fn retrieve_pm_modular_service_call(state: &routes::SessionState,- merchant_id: &id_type::MerchantId,+ processor_merchant_id: &id_type::MerchantId,profile_id: &id_type::ProfileId,payment_method_fetch_req: RetrievePaymentMethodV1Request,) -> CustomResult<RetrievePaymentMethodResponse, errors::ApiErrorResponse> {@@ -1649,7 +1649,10 @@ pub async fn retrieve_pm_modular_service_call());parent_headers.insert((headers::X_MERCHANT_ID.to_string(),- merchant_id.get_string_repr().to_string().into_masked(),+ processor_merchant_id+ .get_string_repr()+ .to_string()+ .into_masked(),));let trace = RequestIdentifier::new(&state.conf.trace_header.header_name)@@ -1680,7 +1683,8 @@ pub async fn retrieve_pm_modular_service_call(#[allow(clippy::too_many_arguments)]pub async fn create_payment_method_in_modular_service(state: &routes::SessionState,- merchant_id: &id_type::MerchantId,+ provider_merchant_id: &id_type::MerchantId,+ processor_merchant_id: &id_type::MerchantId,profile_id: &id_type::ProfileId,payment_method: common_enums::PaymentMethod,payment_method_type: common_enums::PaymentMethodType,@@ -1689,7 +1693,7 @@ pub async fn create_payment_method_in_modular_service(customer_id: id_type::CustomerId,) -> CustomResult<domain::PaymentMethod, errors::ApiErrorResponse> {let payment_method_request = CreatePaymentMethodV1Request {- merchant_id: merchant_id.clone(),+ merchant_id: provider_merchant_id.clone(),payment_method,payment_method_type,metadata: None,@@ -1702,9 +1706,13 @@ pub async fn create_payment_method_in_modular_service(};//Create modular service call- let pm_response =- create_pm_modular_service_call(state, merchant_id, profile_id, payment_method_request)- .await?;+ let pm_response = create_pm_modular_service_call(+ state,+ processor_merchant_id,+ profile_id,+ payment_method_request,+ )+ .await?;//Convert PMResponse to PaymentMethodWithRawDatalet payment_method_with_raw_data = DomainPaymentMethodWrapper::try_from(pm_response)?;diff --git a/crates/router/src/core/payment_methods/vault.rs b/crates/router/src/core/payment_methods/vault.rsindex 018c98c2f0..51c147110d 100644--- a/crates/router/src/core/payment_methods/vault.rs+++ b/crates/router/src/core/payment_methods/vault.rs@@ -1985,7 +1985,7 @@ pub async fn retrieve_payment_method_data_from_storage(let card_cvc = retrieve_and_delete_cvc_from_payment_token(state,&pm.id.get_string_repr().to_string(),- platform.get_processor().get_key_store(),+ platform.get_provider().get_key_store(),).await.inspect_err(|err| {diff --git a/crates/router/src/core/payments/operations/payment_confirm.rs b/crates/router/src/core/payments/operations/payment_confirm.rsindex 45418b73c5..bbfd6a27fd 100644--- a/crates/router/src/core/payments/operations/payment_confirm.rs+++ b/crates/router/src/core/payments/operations/payment_confirm.rs@@ -1117,6 +1117,7 @@ impl<F: Clone + Send + Sync> Domain<F, api::PaymentsRequest, PaymentData<F>> formatch pm_transformers::create_payment_method_in_modular_service(state,platform.get_provider().get_account().get_id(),+ platform.get_processor().get_account().get_id(),business_profile.get_id(),payment_method,payment_method_type,@@ -1186,7 +1187,7 @@ impl<F: Clone + Send + Sync> Domain<F, api::PaymentsRequest, PaymentData<F>> for.profile_id.clone().or(platform- .get_provider()+ .get_processor().get_account().get_default_profile().clone())diff --git a/crates/router/src/core/payments/operations/payment_create.rs b/crates/router/src/core/payments/operations/payment_create.rsindex 2ab4bbeccf..8b9c6bfd64 100644--- a/crates/router/src/core/payments/operations/payment_create.rs+++ b/crates/router/src/core/payments/operations/payment_create.rs@@ -846,7 +846,7 @@ impl<F: Clone + Send + Sync> Domain<F, api::PaymentsRequest, PaymentData<F>> for.profile_id.clone().or(platform- .get_provider()+ .get_processor().get_account().get_default_profile().clone())diff --git a/crates/router/src/core/payments/operations/payment_response.rs b/crates/router/src/core/payments/operations/payment_response.rsindex 3db6f4d60f..7d0f339730 100644--- a/crates/router/src/core/payments/operations/payment_response.rs+++ b/crates/router/src/core/payments/operations/payment_response.rs@@ -194,7 +194,7 @@ where{match call_modular_payment_method_update(state,- &payment_data.payment_attempt.merchant_id,+ &payment_data.payment_attempt.processor_merchant_id,&payment_data.payment_attempt.profile_id,&payment_method_id,payload,diff --git a/crates/router/src/routes/customers.rs b/crates/router/src/routes/customers.rsindex a90bedce87..8dab9ab6dc 100644--- a/crates/router/src/routes/customers.rs+++ b/crates/router/src/routes/customers.rs@@ -26,8 +26,8 @@ pub async fn customers_create(},auth::auth_type(&auth::V2ApiKeyAuth {- allow_connected_scope_operation: false,- allow_platform_self_operation: false,+ allow_connected_scope_operation: true,+ allow_platform_self_operation: true,},&auth::JWTAuth {permission: Permission::MerchantCustomerWrite,@@ -144,8 +144,8 @@ pub async fn customers_retrieve(sdk_or_api_or_client_auth(&sdk_auth,&auth::V2ApiKeyAuth {- allow_connected_scope_operation: false,- allow_platform_self_operation: false,+ allow_connected_scope_operation: true,+ allow_platform_self_operation: true,},&v2_client_auth,req.headers(),@@ -185,8 +185,8 @@ pub async fn customers_list(},auth::auth_type(&auth::V2ApiKeyAuth {- allow_connected_scope_operation: false,- allow_platform_self_operation: false,+ allow_connected_scope_operation: true,+ allow_platform_self_operation: true,},&auth::JWTAuth {permission: Permission::MerchantCustomerRead,@@ -250,8 +250,8 @@ pub async fn customers_list_with_count(},auth::auth_type(&auth::V2ApiKeyAuth {- allow_connected_scope_operation: false,- allow_platform_self_operation: false,+ allow_connected_scope_operation: true,+ allow_platform_self_operation: true,},&auth::JWTAuth {permission: Permission::MerchantCustomerRead,@@ -365,8 +365,8 @@ pub async fn customers_update(},auth::auth_type(&auth::V2ApiKeyAuth {- allow_connected_scope_operation: false,- allow_platform_self_operation: false,+ allow_connected_scope_operation: true,+ allow_platform_self_operation: true,},&auth::JWTAuth {permission: Permission::MerchantCustomerWrite,@@ -398,8 +398,8 @@ pub async fn customers_delete(},auth::auth_type(&auth::V2ApiKeyAuth {- allow_connected_scope_operation: false,- allow_platform_self_operation: false,+ allow_connected_scope_operation: true,+ allow_platform_self_operation: true,},&auth::JWTAuth {permission: Permission::MerchantCustomerWrite,diff --git a/crates/router/src/routes/payment_methods.rs b/crates/router/src/routes/payment_methods.rsindex 2a3c40c118..eb5c45d517 100644--- a/crates/router/src/routes/payment_methods.rs+++ b/crates/router/src/routes/payment_methods.rs@@ -78,8 +78,8 @@ pub async fn create_payment_method_api(let flow = Flow::PaymentMethodsCreate;let api_auth = auth::V2ApiKeyAuth {- allow_connected_scope_operation: false,- allow_platform_self_operation: false,+ allow_connected_scope_operation: true,+ allow_platform_self_operation: true,};let jwt_auth = auth::JWTAuth {permission: Permission::MerchantCustomerRead,@@ -140,8 +140,8 @@ pub async fn get_pm_nt_eligibility_api(.await},&auth::V2ApiKeyAuth {- allow_connected_scope_operation: false,- allow_platform_self_operation: false,+ allow_connected_scope_operation: true,+ allow_platform_self_operation: true,},api_locking::LockAction::NotApplicable,))@@ -171,8 +171,8 @@ pub async fn create_payment_method_intent_api(.await},&auth::V2ApiKeyAuth {- allow_connected_scope_operation: false,- allow_platform_self_operation: false,+ allow_connected_scope_operation: true,+ allow_platform_self_operation: true,},api_locking::LockAction::NotApplicable,))@@ -218,8 +218,8 @@ pub async fn payment_method_update_api(let payload = json_payload.into_inner();let api_auth = auth::V2ApiKeyAuth {- allow_connected_scope_operation: false,- allow_platform_self_operation: false,+ allow_connected_scope_operation: true,+ allow_platform_self_operation: true,};let (auth_type, api_key_type) = match auth::check_internal_api_key_auth_no_client_secret(@@ -266,8 +266,8 @@ pub async fn payment_method_retrieve_api(.into_inner();let api_auth = auth::V2ApiKeyAuth {- allow_connected_scope_operation: false,- allow_platform_self_operation: false,+ allow_connected_scope_operation: true,+ allow_platform_self_operation: true,};let (auth_type, api_key_type) = match auth::check_internal_api_key_auth_no_client_secret(@@ -314,8 +314,8 @@ pub async fn payment_method_delete_api(.into_inner();let api_auth = auth::V2ApiKeyAuth {- allow_connected_scope_operation: false,- allow_platform_self_operation: false,+ allow_connected_scope_operation: true,+ allow_platform_self_operation: true,};let (auth_type, api_key_type) = match auth::check_internal_api_key_auth_no_client_secret(@@ -848,8 +848,8 @@ pub async fn list_customer_payment_method_api(let customer_id = customer_id.into_inner();let api_auth = auth::V2ApiKeyAuth {- allow_connected_scope_operation: false,- allow_platform_self_operation: false,+ allow_connected_scope_operation: true,+ allow_platform_self_operation: true,};let (auth_type, api_key_type) = match auth::check_internal_api_key_auth_no_client_secret(@@ -907,8 +907,8 @@ pub async fn get_payment_method_token_data(},auth::auth_type(&auth::V2ApiKeyAuth {- allow_connected_scope_operation: false,- allow_platform_self_operation: false,+ allow_connected_scope_operation: true,+ allow_platform_self_operation: true,},&auth::JWTAuth {permission: Permission::MerchantCustomerRead,@@ -941,8 +941,8 @@ pub async fn get_total_payment_method_count(},auth::auth_type(&auth::V2ApiKeyAuth {- allow_connected_scope_operation: false,- allow_platform_self_operation: false,+ allow_connected_scope_operation: true,+ allow_platform_self_operation: true,},&auth::JWTAuth {permission: Permission::MerchantCustomerRead,@@ -1171,8 +1171,8 @@ pub async fn list_countries_currencies_for_connector_payment_method(#[cfg(not(feature = "release"))]auth::auth_type(&auth::V2ApiKeyAuth {- allow_connected_scope_operation: false,- allow_platform_self_operation: false,+ allow_connected_scope_operation: true,+ allow_platform_self_operation: true,},&auth::JWTAuth {permission: Permission::ProfileConnectorRead,@@ -1865,8 +1865,8 @@ pub async fn network_token_status_check_api()},&auth::V2ApiKeyAuth {- allow_connected_scope_operation: false,- allow_platform_self_operation: false,+ allow_connected_scope_operation: true,+ allow_platform_self_operation: true,},api_locking::LockAction::NotApplicable,))@@ -1884,8 +1884,8 @@ pub async fn payment_method_get_token_details_api(let temporary_token = path.into_inner();let api_auth = auth::V2ApiKeyAuth {- allow_connected_scope_operation: false,- allow_platform_self_operation: false,+ allow_connected_scope_operation: true,+ allow_platform_self_operation: true,};let (auth_type, api_key_type) = match auth::check_internal_api_key_auth_no_client_secret(diff --git a/crates/router/src/services/authentication.rs b/crates/router/src/services/authentication.rsindex f150861b25..307cf2e3a6 100644--- a/crates/router/src/services/authentication.rs+++ b/crates/router/src/services/authentication.rs@@ -2630,25 +2630,26 @@ where.await.to_not_found_response(errors::ApiErrorResponse::Unauthorized)?;- let merchant = state+ let initiator_merchant = state.store().find_merchant_account_by_merchant_id(&merchant_id, &key_store).await.to_not_found_response(errors::ApiErrorResponse::Unauthorized)?;let initiator = Some(domain::Initiator::Api {- merchant_id: merchant.get_id().clone(),- merchant_account_type: merchant.merchant_account_type,- publishable_key: merchant.publishable_key.clone(),+ merchant_id: initiator_merchant.get_id().clone(),+ merchant_account_type: initiator_merchant.merchant_account_type,+ publishable_key: initiator_merchant.publishable_key.clone(),});- let platform = domain::Platform::new(- merchant.clone(),- key_store.clone(),- merchant,+ let platform = resolve_platform(+ state,+ request_headers,+ initiator_merchant.clone(),key_store,initiator,- );+ )+ .await?;let auth = AuthenticationData::construct_authentication_data_for_internal_merchant_id_profile_id_auth(platform, profile);@@ -3012,36 +3013,42 @@ where}}- let (merchant_account, key_store) = state+ let (initiator_merchant, key_store) = state.store().find_merchant_account_by_publishable_key(publishable_key).await.to_not_found_response(errors::ApiErrorResponse::Unauthorized)?;- let merchant_id = merchant_account.get_id().clone();+ let merchant_id = initiator_merchant.get_id().clone();++ let initiator = Some(domain::Initiator::Api {+ merchant_id: initiator_merchant.get_id().clone(),+ merchant_account_type: initiator_merchant.merchant_account_type,+ publishable_key: initiator_merchant.publishable_key.clone(),+ });- if db_client_secret.merchant_id != merchant_id {+ let platform = resolve_platform(+ state,+ request_headers,+ initiator_merchant.clone(),+ key_store.clone(),+ initiator,+ )+ .await?;++ if db_client_secret.merchant_id != *platform.get_provider().get_account().get_id() {return Err(errors::ApiErrorResponse::Unauthorized.into());}+let profile = state.store()- .find_business_profile_by_merchant_id_profile_id(&key_store, &merchant_id, &profile_id)+ .find_business_profile_by_merchant_id_profile_id(+ &key_store,+ platform.get_processor().get_account().get_id(),+ &profile_id,+ ).await.to_not_found_response(errors::ApiErrorResponse::Unauthorized)?;- let initiator = Some(domain::Initiator::Api {- merchant_id: merchant_account.get_id().clone(),- merchant_account_type: merchant_account.merchant_account_type,- publishable_key: merchant_account.publishable_key.clone(),- });-- let platform = domain::Platform::new(- merchant_account.clone(),- key_store.clone(),- merchant_account.clone(),- key_store,- initiator,- );-let auth = AuthenticationData {platform,profile,@@ -3619,7 +3626,17 @@ where}};- if db_client_secret.merchant_id != *initiator_merchant.get_id() {+ let platform = check_sdk_auth_and_resolve_platform(+ state,+ &sdk_auth,+ initiator_merchant.clone(),+ initiator_merchant_key_store,+ self.allow_connected_scope_operation,+ self.allow_platform_self_operation,+ )+ .await?;++ if db_client_secret.merchant_id != *platform.get_provider().get_account().get_id() {return Err(errors::ApiErrorResponse::Unauthorized.into());}@@ -3653,16 +3670,6 @@ where}}- let platform = check_sdk_auth_and_resolve_platform(- state,- &sdk_auth,- initiator_merchant.clone(),- initiator_merchant_key_store,- self.allow_connected_scope_operation,- self.allow_platform_self_operation,- )- .await?;-let profile = state.store().find_business_profile_by_merchant_id_profile_id(