mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-11-03 05:17:02 +08:00
refactor(core): make the ppt token flow to accept optional mca_id (#5744)
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
This commit is contained in:
@ -16052,19 +16052,15 @@
|
|||||||
"type": "object",
|
"type": "object",
|
||||||
"description": "Processor payment token for MIT payments where payment_method_data is not available",
|
"description": "Processor payment token for MIT payments where payment_method_data is not available",
|
||||||
"required": [
|
"required": [
|
||||||
"processor_payment_token",
|
"processor_payment_token"
|
||||||
"connector",
|
|
||||||
"merchant_connector_id"
|
|
||||||
],
|
],
|
||||||
"properties": {
|
"properties": {
|
||||||
"processor_payment_token": {
|
"processor_payment_token": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
"connector": {
|
|
||||||
"$ref": "#/components/schemas/Connector"
|
|
||||||
},
|
|
||||||
"merchant_connector_id": {
|
"merchant_connector_id": {
|
||||||
"type": "string"
|
"type": "string",
|
||||||
|
"nullable": true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@ -20505,19 +20505,15 @@
|
|||||||
"type": "object",
|
"type": "object",
|
||||||
"description": "Processor payment token for MIT payments where payment_method_data is not available",
|
"description": "Processor payment token for MIT payments where payment_method_data is not available",
|
||||||
"required": [
|
"required": [
|
||||||
"processor_payment_token",
|
"processor_payment_token"
|
||||||
"connector",
|
|
||||||
"merchant_connector_id"
|
|
||||||
],
|
],
|
||||||
"properties": {
|
"properties": {
|
||||||
"processor_payment_token": {
|
"processor_payment_token": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
"connector": {
|
|
||||||
"$ref": "#/components/schemas/Connector"
|
|
||||||
},
|
|
||||||
"merchant_connector_id": {
|
"merchant_connector_id": {
|
||||||
"type": "string"
|
"type": "string",
|
||||||
|
"nullable": true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@ -127,8 +127,6 @@ pub enum RecurringDetails {
|
|||||||
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, ToSchema, PartialEq, Eq)]
|
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, ToSchema, PartialEq, Eq)]
|
||||||
pub struct ProcessorPaymentToken {
|
pub struct ProcessorPaymentToken {
|
||||||
pub processor_payment_token: String,
|
pub processor_payment_token: String,
|
||||||
#[schema(value_type = Connector, example = "stripe")]
|
#[schema(value_type = Option<String>)]
|
||||||
pub connector: api_enums::Connector,
|
pub merchant_connector_id: Option<common_utils::id_type::MerchantConnectorAccountId>,
|
||||||
#[schema(value_type = String)]
|
|
||||||
pub merchant_connector_id: common_utils::id_type::MerchantConnectorAccountId,
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3809,6 +3809,30 @@ pub async fn decide_multiplex_connector_for_normal_or_recurring_payment<F: Clone
|
|||||||
|
|
||||||
Ok(ConnectorCallType::PreDetermined(chosen_connector_data))
|
Ok(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?;
|
helpers::override_setup_future_usage_to_on_session(&*state.store, payment_data).await?;
|
||||||
|
|
||||||
|
|||||||
@ -420,21 +420,52 @@ pub async fn get_token_pm_type_mandate_details(
|
|||||||
),
|
),
|
||||||
Some(api::MandateTransactionType::RecurringMandateTransaction) => {
|
Some(api::MandateTransactionType::RecurringMandateTransaction) => {
|
||||||
match &request.recurring_details {
|
match &request.recurring_details {
|
||||||
Some(recurring_details) => match recurring_details {
|
Some(recurring_details) => {
|
||||||
RecurringDetails::ProcessorPaymentToken(processor_payment_token) => (
|
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;
|
||||||
|
|
||||||
|
#[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,
|
None,
|
||||||
request.payment_method,
|
request.payment_method,
|
||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
Some(payments::MandateConnectorDetails {
|
Some(payments::MandateConnectorDetails {
|
||||||
connector: processor_payment_token.connector.to_string(),
|
connector: connector_name,
|
||||||
merchant_connector_id: Some(
|
merchant_connector_id: Some(mca_id.clone()),
|
||||||
processor_payment_token.merchant_connector_id.clone(),
|
|
||||||
),
|
|
||||||
}),
|
}),
|
||||||
None,
|
None,
|
||||||
),
|
)
|
||||||
|
} else {
|
||||||
|
(None, request.payment_method, None, None, None, None, None)
|
||||||
|
}
|
||||||
|
}
|
||||||
RecurringDetails::MandateId(mandate_id) => {
|
RecurringDetails::MandateId(mandate_id) => {
|
||||||
let mandate_generic_data = get_token_for_recurring_mandate(
|
let mandate_generic_data = get_token_for_recurring_mandate(
|
||||||
state,
|
state,
|
||||||
@ -460,7 +491,10 @@ pub async fn get_token_pm_type_mandate_details(
|
|||||||
RecurringDetails::PaymentMethodId(payment_method_id) => {
|
RecurringDetails::PaymentMethodId(payment_method_id) => {
|
||||||
let payment_method_info = state
|
let payment_method_info = state
|
||||||
.store
|
.store
|
||||||
.find_payment_method(payment_method_id, merchant_account.storage_scheme)
|
.find_payment_method(
|
||||||
|
payment_method_id,
|
||||||
|
merchant_account.storage_scheme,
|
||||||
|
)
|
||||||
.await
|
.await
|
||||||
.to_not_found_response(
|
.to_not_found_response(
|
||||||
errors::ApiErrorResponse::PaymentMethodNotFound,
|
errors::ApiErrorResponse::PaymentMethodNotFound,
|
||||||
@ -486,7 +520,8 @@ pub async fn get_token_pm_type_mandate_details(
|
|||||||
Some(payment_method_info),
|
Some(payment_method_info),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
|
}
|
||||||
None => {
|
None => {
|
||||||
if let Some(mandate_id) = request.mandate_id.clone() {
|
if let Some(mandate_id) = request.mandate_id.clone() {
|
||||||
let mandate_generic_data = get_token_for_recurring_mandate(
|
let mandate_generic_data = get_token_for_recurring_mandate(
|
||||||
|
|||||||
Reference in New Issue
Block a user