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
refactor(core): make the ppt token flow to accept optional mca_id (#5744)
Prajjwal Kumarf682b570dd1f
diff --git a/api-reference-v2/openapi_spec.json b/api-reference-v2/openapi_spec.jsonindex 6882e82390..ed591af7a6 100644--- a/api-reference-v2/openapi_spec.json+++ b/api-reference-v2/openapi_spec.json@@ -16052,19 +16052,15 @@"type": "object","description": "Processor payment token for MIT payments where payment_method_data is not available","required": [- "processor_payment_token",- "connector",- "merchant_connector_id"+ "processor_payment_token"],"properties": {"processor_payment_token": {"type": "string"},- "connector": {- "$ref": "#/components/schemas/Connector"- },"merchant_connector_id": {- "type": "string"+ "type": "string",+ "nullable": true}}},diff --git a/api-reference/openapi_spec.json b/api-reference/openapi_spec.jsonindex 4a07d1179e..70bfc8c986 100644--- a/api-reference/openapi_spec.json+++ b/api-reference/openapi_spec.json@@ -20505,19 +20505,15 @@"type": "object","description": "Processor payment token for MIT payments where payment_method_data is not available","required": [- "processor_payment_token",- "connector",- "merchant_connector_id"+ "processor_payment_token"],"properties": {"processor_payment_token": {"type": "string"},- "connector": {- "$ref": "#/components/schemas/Connector"- },"merchant_connector_id": {- "type": "string"+ "type": "string",+ "nullable": true}}},diff --git a/crates/api_models/src/mandates.rs b/crates/api_models/src/mandates.rsindex 44a8331942..fe5b053b18 100644--- a/crates/api_models/src/mandates.rs+++ b/crates/api_models/src/mandates.rs@@ -127,8 +127,6 @@ pub enum RecurringDetails {#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, ToSchema, PartialEq, Eq)]pub struct ProcessorPaymentToken {pub processor_payment_token: String,- #[schema(value_type = Connector, example = "stripe")]- pub connector: api_enums::Connector,- #[schema(value_type = String)]- pub merchant_connector_id: common_utils::id_type::MerchantConnectorAccountId,+ #[schema(value_type = Option<String>)]+ pub merchant_connector_id: Option<common_utils::id_type::MerchantConnectorAccountId>,}diff --git a/crates/router/src/core/payments.rs b/crates/router/src/core/payments.rsindex 1af097114f..75fe544ae5 100644--- a/crates/router/src/core/payments.rs+++ b/crates/router/src/core/payments.rs@@ -3809,6 +3809,30 @@ pub async fn decide_multiplex_connector_for_normal_or_recurring_payment<F: CloneOk(ConnectorCallType::PreDetermined(chosen_connector_data))}+ (+ None,+ None,+ Some(RecurringDetails::ProcessorPaymentToken(_token)),+ Some(true),+ Some(api::MandateTransactionType::RecurringMandateTransaction),+ ) => {+ if let Some(connector) = connectors.first() {+ routing_data.routed_through = Some(connector.connector_name.clone().to_string());+ routing_data+ .merchant_connector_id+ .clone_from(&connector.merchant_connector_id);+ Ok(ConnectorCallType::PreDetermined(api::ConnectorData {+ connector: connector.connector.clone(),+ connector_name: connector.connector_name,+ get_token: connector.get_token.clone(),+ merchant_connector_id: connector.merchant_connector_id.clone(),+ }))+ } else {+ logger::error!("no eligible connector found for the ppt_mandate payment");+ Err(errors::ApiErrorResponse::IncorrectPaymentMethodConfiguration.into())+ }+ }+_ => {helpers::override_setup_future_usage_to_on_session(&*state.store, payment_data).await?;diff --git a/crates/router/src/core/payments/helpers.rs b/crates/router/src/core/payments/helpers.rsindex 52e439a2e4..34fb2e954b 100644--- a/crates/router/src/core/payments/helpers.rs+++ b/crates/router/src/core/payments/helpers.rs@@ -420,73 +420,108 @@ pub async fn get_token_pm_type_mandate_details(),Some(api::MandateTransactionType::RecurringMandateTransaction) => {match &request.recurring_details {- Some(recurring_details) => match recurring_details {- RecurringDetails::ProcessorPaymentToken(processor_payment_token) => (- None,- request.payment_method,- None,- None,- None,- Some(payments::MandateConnectorDetails {- connector: processor_payment_token.connector.to_string(),- merchant_connector_id: Some(- processor_payment_token.merchant_connector_id.clone(),- ),- }),- None,- ),- RecurringDetails::MandateId(mandate_id) => {- let mandate_generic_data = get_token_for_recurring_mandate(- state,- request,- merchant_account,- merchant_key_store,- mandate_id.to_owned(),- )- .await?;+ Some(recurring_details) => {+ match recurring_details {+ RecurringDetails::ProcessorPaymentToken(processor_payment_token) => {+ if let Some(mca_id) = &processor_payment_token.merchant_connector_id {+ let db = &*state.store;+ let key_manager_state = &state.into();++ #[cfg(all(+ any(feature = "v1", feature = "v2"),+ not(feature = "merchant_connector_account_v2")+ ))]+ let connector_name = db+ .find_by_merchant_connector_account_merchant_id_merchant_connector_id(+ key_manager_state,+ merchant_account.get_id(),+ mca_id,+ merchant_key_store,+ )+ .await+ .to_not_found_response(errors::ApiErrorResponse::MerchantConnectorAccountNotFound {+ id: mca_id.clone().get_string_repr().to_string(),+ })?.connector_name;- (- mandate_generic_data.token,- mandate_generic_data.payment_method,- mandate_generic_data- .payment_method_type- .or(request.payment_method_type),- None,- mandate_generic_data.recurring_mandate_payment_data,- mandate_generic_data.mandate_connector,- mandate_generic_data.payment_method_info,- )- }- RecurringDetails::PaymentMethodId(payment_method_id) => {- let payment_method_info = state- .store- .find_payment_method(payment_method_id, merchant_account.storage_scheme)- .await- .to_not_found_response(- errors::ApiErrorResponse::PaymentMethodNotFound,+ #[cfg(all(feature = "v2", feature = "merchant_connector_account_v2"))]+ let connector_name = db+ .find_merchant_connector_account_by_id(key_manager_state, &mca_id, &merchant_key_store)+ .await+ .to_not_found_response(errors::ApiErrorResponse::MerchantConnectorAccountNotFound {+ id: mca_id.clone().get_string_repr().to_string(),+ })?.connector_name;+ (+ None,+ request.payment_method,+ None,+ None,+ None,+ Some(payments::MandateConnectorDetails {+ connector: connector_name,+ merchant_connector_id: Some(mca_id.clone()),+ }),+ None,+ )+ } else {+ (None, request.payment_method, None, None, None, None, None)+ }+ }+ RecurringDetails::MandateId(mandate_id) => {+ let mandate_generic_data = get_token_for_recurring_mandate(+ state,+ request,+ merchant_account,+ merchant_key_store,+ mandate_id.to_owned(),+ )+ .await?;++ (+ mandate_generic_data.token,+ mandate_generic_data.payment_method,+ mandate_generic_data+ .payment_method_type+ .or(request.payment_method_type),+ None,+ mandate_generic_data.recurring_mandate_payment_data,+ mandate_generic_data.mandate_connector,+ mandate_generic_data.payment_method_info,+ )+ }+ RecurringDetails::PaymentMethodId(payment_method_id) => {+ let payment_method_info = state+ .store+ .find_payment_method(+ payment_method_id,+ merchant_account.storage_scheme,+ )+ .await+ .to_not_found_response(+ errors::ApiErrorResponse::PaymentMethodNotFound,+ )?;+ let customer_id = request+ .get_customer_id()+ .get_required_value("customer_id")?;++ verify_mandate_details_for_recurring_payments(+ &payment_method_info.merchant_id,+ merchant_account.get_id(),+ &payment_method_info.customer_id,+ customer_id,)?;- let customer_id = request- .get_customer_id()- .get_required_value("customer_id")?;-- verify_mandate_details_for_recurring_payments(- &payment_method_info.merchant_id,- merchant_account.get_id(),- &payment_method_info.customer_id,- customer_id,- )?;- (- None,- payment_method_info.payment_method,- payment_method_info.payment_method_type,- None,- None,- None,- Some(payment_method_info),- )+ (+ None,+ payment_method_info.payment_method,+ payment_method_info.payment_method_type,+ None,+ None,+ None,+ Some(payment_method_info),+ )+ }}- },+ }None => {if let Some(mandate_id) = request.mandate_id.clone() {let mandate_generic_data = get_token_for_recurring_mandate(