Skip to content

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

feat: payment processor token for recurring payments (#5508)

Prajjwal Kumar0cbbc92a4319
diff --git a/api-reference/openapi_spec.json b/api-reference/openapi_spec.json
index 1e62053dde..456fcea7fd 100644
--- a/api-reference/openapi_spec.json
+++ b/api-reference/openapi_spec.json
@@ -19249,6 +19249,26 @@
},
"additionalProperties": false
},
+ "ProcessorPaymentToken": {
+ "type": "object",
+ "description": "Processor payment token for MIT payments where payment_method_data is not available",
+ "required": [
+ "processor_payment_token",
+ "connector",
+ "merchant_connector_id"
+ ],
+ "properties": {
+ "processor_payment_token": {
+ "type": "string"
+ },
+ "connector": {
+ "$ref": "#/components/schemas/Connector"
+ },
+ "merchant_connector_id": {
+ "type": "string"
+ }
+ }
+ },
"ProductType": {
"type": "string",
"enum": [
@@ -19418,6 +19438,24 @@
"type": "string"
}
}
+ },
+ {
+ "type": "object",
+ "required": [
+ "type",
+ "data"
+ ],
+ "properties": {
+ "type": {
+ "type": "string",
+ "enum": [
+ "processor_payment_token"
+ ]
+ },
+ "data": {
+ "$ref": "#/components/schemas/ProcessorPaymentToken"
+ }
+ }
}
],
"description": "Details required for recurring payment",
diff --git a/crates/api_models/src/mandates.rs b/crates/api_models/src/mandates.rs
index f4089a16c2..dc61aa08b0 100644
--- a/crates/api_models/src/mandates.rs
+++ b/crates/api_models/src/mandates.rs
@@ -120,4 +120,14 @@ pub struct MandateListConstraints {
pub enum RecurringDetails {
MandateId(String),
PaymentMethodId(String),
+ ProcessorPaymentToken(ProcessorPaymentToken),
+}
+
+/// Processor payment token for MIT payments where payment_method_data is not available
+#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, ToSchema)]
+pub struct ProcessorPaymentToken {
+ pub processor_payment_token: String,
+ #[schema(value_type = Connector, example = "stripe")]
+ pub connector: api_enums::Connector,
+ pub merchant_connector_id: String,
}
diff --git a/crates/diesel_models/src/payment_intent.rs b/crates/diesel_models/src/payment_intent.rs
index 2d390b0b34..bdea1fe52a 100644
--- a/crates/diesel_models/src/payment_intent.rs
+++ b/crates/diesel_models/src/payment_intent.rs
@@ -68,6 +68,7 @@ pub struct PaymentIntent {
pub billing_details: Option<Encryption>,
pub merchant_order_reference_id: Option<String>,
pub shipping_details: Option<Encryption>,
+ pub is_payment_processor_token_flow: Option<bool>,
}
#[cfg(all(any(feature = "v1", feature = "v2"), not(feature = "payment_v2")))]
@@ -128,6 +129,7 @@ pub struct PaymentIntent {
pub billing_details: Option<Encryption>,
pub merchant_order_reference_id: Option<String>,
pub shipping_details: Option<Encryption>,
+ pub is_payment_processor_token_flow: Option<bool>,
}
#[derive(
@@ -187,6 +189,7 @@ pub struct PaymentIntentNew {
pub billing_details: Option<Encryption>,
pub merchant_order_reference_id: Option<String>,
pub shipping_details: Option<Encryption>,
+ pub is_payment_processor_token_flow: Option<bool>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
@@ -291,6 +294,7 @@ pub struct PaymentIntentUpdateFields {
pub billing_details: Option<Encryption>,
pub merchant_order_reference_id: Option<String>,
pub shipping_details: Option<Encryption>,
+ pub is_payment_processor_token_flow: Option<bool>,
}
#[derive(Clone, Debug, AsChangeset, router_derive::DebugAsDisplay)]
@@ -331,6 +335,7 @@ pub struct PaymentIntentUpdateInternal {
pub billing_details: Option<Encryption>,
pub merchant_order_reference_id: Option<String>,
pub shipping_details: Option<Encryption>,
+ pub is_payment_processor_token_flow: Option<bool>,
}
impl PaymentIntentUpdate {
@@ -370,6 +375,7 @@ impl PaymentIntentUpdate {
billing_details,
merchant_order_reference_id,
shipping_details,
+ is_payment_processor_token_flow,
} = self.into();
PaymentIntent {
amount: amount.unwrap_or(source.amount),
@@ -412,6 +418,8 @@ impl PaymentIntentUpdate {
merchant_order_reference_id: merchant_order_reference_id
.or(source.merchant_order_reference_id),
shipping_details: shipping_details.or(source.shipping_details),
+ is_payment_processor_token_flow: is_payment_processor_token_flow
+ .or(source.is_payment_processor_token_flow),
..source
}
}
@@ -458,6 +466,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
billing_details: None,
merchant_order_reference_id: None,
shipping_details: None,
+ is_payment_processor_token_flow: None,
},
PaymentIntentUpdate::Update(value) => Self {
amount: Some(value.amount),
@@ -495,6 +504,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
surcharge_applicable: None,
incremental_authorization_allowed: None,
authorization_count: None,
+ is_payment_processor_token_flow: value.is_payment_processor_token_flow,
},
PaymentIntentUpdate::PaymentCreateUpdate {
return_url,
@@ -539,6 +549,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
billing_details: None,
merchant_order_reference_id: None,
shipping_details: None,
+ is_payment_processor_token_flow: None,
},
PaymentIntentUpdate::PGStatusUpdate {
status,
@@ -579,6 +590,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
billing_details: None,
merchant_order_reference_id: None,
shipping_details: None,
+ is_payment_processor_token_flow: None,
},
PaymentIntentUpdate::MerchantStatusUpdate {
status,
@@ -620,6 +632,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
billing_details: None,
merchant_order_reference_id: None,
shipping_details: None,
+ is_payment_processor_token_flow: None,
},
PaymentIntentUpdate::ResponseUpdate {
// amount,
@@ -669,6 +682,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
billing_details: None,
merchant_order_reference_id: None,
shipping_details: None,
+ is_payment_processor_token_flow: None,
},
PaymentIntentUpdate::PaymentAttemptAndAttemptCountUpdate {
active_attempt_id,
@@ -709,6 +723,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
billing_details: None,
merchant_order_reference_id: None,
shipping_details: None,
+ is_payment_processor_token_flow: None,
},
PaymentIntentUpdate::StatusAndAttemptUpdate {
status,
@@ -750,6 +765,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
billing_details: None,
merchant_order_reference_id: None,
shipping_details: None,
+ is_payment_processor_token_flow: None,
},
PaymentIntentUpdate::ApproveUpdate {
status,
@@ -790,6 +806,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
billing_details: None,
merchant_order_reference_id: None,
shipping_details: None,
+ is_payment_processor_token_flow: None,
},
PaymentIntentUpdate::RejectUpdate {
status,
@@ -830,6 +847,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
billing_details: None,
merchant_order_reference_id: None,
shipping_details: None,
+ is_payment_processor_token_flow: None,
},
PaymentIntentUpdate::SurchargeApplicableUpdate {
surcharge_applicable,
@@ -869,6 +887,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
billing_details: None,
merchant_order_reference_id: None,
shipping_details: None,
+ is_payment_processor_token_flow: None,
},
PaymentIntentUpdate::IncrementalAuthorizationAmountUpdate { amount } => Self {
amount: Some(amount),
@@ -905,6 +924,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
billing_details: None,
merchant_order_reference_id: None,
shipping_details: None,
+ is_payment_processor_token_flow: None,
},
PaymentIntentUpdate::AuthorizationCountUpdate {
authorization_count,
@@ -943,6 +963,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
billing_details: None,
merchant_order_reference_id: None,
shipping_details: None,
+ is_payment_processor_token_flow: None,
},
PaymentIntentUpdate::CompleteAuthorizeUpdate {
shipping_address_id,
@@ -981,6 +1002,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
billing_details: None,
merchant_order_reference_id: None,
shipping_details: None,
+ is_payment_processor_token_flow: None,
},
PaymentIntentUpdate::ManualUpdate { status, updated_by } => Self {
status,
@@ -1017,6 +1039,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
billing_details: None,
merchant_order_reference_id: None,
shipping_details: None,
+ is_payment_processor_token_flow: None,
},
}
}
diff --git a/crates/diesel_models/src/schema.rs b/crates/diesel_models/src/schema.rs
index 3aef9d271c..ebeff9c97f 100644
--- a/crates/diesel_models/src/schema.rs
+++ b/crates/diesel_models/src/schema.rs
@@ -898,6 +898,7 @@ diesel::table! {
#[max_length = 255]
merchant_order_reference_id -> Nullable<Varchar>,
shipping_details -> Nullable<Bytea>,
+ is_payment_processor_token_flow -> Nullable<Bool>,
}
}
diff --git a/crates/diesel_models/src/schema_v2.rs b/crates/diesel_models/src/schema_v2.rs
index b8bef4e2a6..68c066288f 100644
--- a/crates/diesel_models/src/schema_v2.rs
+++ b/crates/diesel_models/src/schema_v2.rs
@@ -880,6 +880,7 @@ diesel::table! {
#[max_length = 255]
merchant_order_reference_id -> Nullable<Varchar>,
shipping_details -> Nullable<Bytea>,
+ is_payment_processor_token_flow -> Nullable<Bool>,
}
}
diff --git a/crates/hyperswitch_domain_models/src/payments.rs b/crates/hyperswitch_domain_models/src/payments.rs
index ac79bc1a94..3f7cfde2f7 100644
--- a/crates/hyperswitch_domain_models/src/payments.rs
+++ b/crates/hyperswitch_domain_models/src/payments.rs
@@ -66,4 +66,5 @@ pub struct PaymentIntent {
pub billing_details: Option<Encryptable<Secret<serde_json::Value>>>,
pub merchant_order_reference_id: Option<String>,
pub shipping_details: Option<Encryptable<Secret<serde_json::Value>>>,
+ pub is_payment_processor_token_flow: Option<bool>,
}
diff --git a/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs b/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs
index 79818d5b15..54c86f3a4e 100644
--- a/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs
+++ b/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs
@@ -541,6 +541,7 @@ impl behaviour::Conversion for PaymentIntent {
billing_details: self.billing_details.map(Encryption::from),
merchant_order_reference_id: self.merchant_order_reference_id,
shipping_details: self.shipping_details.map(Encryption::from),
+ is_payment_processor_token_flow: self.is_payment_processor_token_flow,
})
}
async fn convert_back(
@@ -622,6 +623,7 @@ impl behaviour::Conversion for PaymentIntent {
.shipping_details
.async_lift(inner_decrypt)
.await?,
+ is_payment_processor_token_flow: storage_model.is_payment_processor_token_flow,
})
}
.await
@@ -679,6 +681,7 @@ impl behaviour::Conversion for PaymentIntent {
billing_details: self.billing_details.map(Encryption::from),
merchant_order_reference_id: self.merchant_order_reference_id,
shipping_details: self.shipping_details.map(Encryption::from),
+ is_payment_processor_token_flow: self.is_payment_processor_token_flow,
})
}
}
@@ -738,6 +741,7 @@ impl behaviour::Conversion for PaymentIntent {
billing_details: self.billing_details.map(Encryption::from),
merchant_order_reference_id: self.merchant_order_reference_id,
shipping_details: self.shipping_details.map(Encryption::from),
+ is_payment_processor_token_flow: self.is_payment_processor_token_flow,
})
}
@@ -820,6 +824,7 @@ impl behaviour::Conversion for PaymentIntent {
.shipping_details
.async_lift(inner_decrypt)
.await?,
+ is_payment_processor_token_flow: storage_model.is_payment_processor_token_flow,
})
}
.await
@@ -877,6 +882,7 @@ impl behaviour::Conversion for PaymentIntent {
billing_details: self.billing_details.map(Encryption::from),
merchant_order_reference_id: self.merchant_order_reference_id,
shipping_details: self.shipping_details.map(Encryption::from),
+ is_payment_processor_token_flow: self.is_payment_processor_token_flow,
})
}
}
diff --git a/crates/hyperswitch_domain_models/src/payments/payment_intent.rs b/crates/hyperswitch_domain_models/src/payments/payment_intent.rs
index 8033ec7706..90e3619f02 100644
--- a/crates/hyperswitch_domain_models/src/payments/payment_intent.rs
+++ b/crates/hyperswitch_domain_models/src/payments/payment_intent.rs
@@ -143,6 +143,7 @@ pub struct PaymentIntentNew {
pub customer_details: Option<Encryptable<Secret<serde_json::Value>>>,
pub billing_details: Option<Encryptable<Secret<serde_json::Value>>>,
pub shipping_details: Option<Encryptable<Secret<serde_json::Value>>>,
+ pub is_payment_processor_token_flow: Option<bool>,
}
#[derive(Debug, Clone, Serialize)]
@@ -172,6 +173,7 @@ pub struct PaymentIntentUpdateFields {
pub billing_details: Option<Encryptable<Secret<serde_json::Value>>>,
pub merchant_order_reference_id: Option<String>,
pub shipping_details: Option<Encryptable<Secret<serde_json::Value>>>,
+ pub is_payment_processor_token_flow: Option<bool>,
}
#[derive(Debug, Clone, Serialize)]
@@ -288,6 +290,7 @@ pub struct PaymentIntentUpdateInternal {
pub billing_details: Option<Encryptable<Secret<serde_json::Value>>>,
pub merchant_order_reference_id: Option<String>,
pub shipping_details: Option<Encryptable<Secret<serde_json::Value>>>,
+ pub is_payment_processor_token_flow: Option<bool>,
}
impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
@@ -329,6 +332,7 @@ impl From<PaymentIntentUpdate> for PaymentIntentUpdateInternal {
billing_details: value.billing_details,
merchant_order_reference_id: value.merchant_order_reference_id,
shipping_details: value.shipping_details,
+ is_payment_processor_token_flow: value.is_payment_processor_token_flow,
..Default::default()
},
PaymentIntentUpdate::PaymentCreateUpdate {
@@ -531,6 +535,7 @@ impl From<PaymentIntentUpdate> for DieselPaymentIntentUpdate {
billing_details: value.billing_details.map(Encryption::from),
merchant_order_reference_id: value.merchant_order_reference_id,
shipping_details: value.shipping_details.map(Encryption::from),
+ is_payment_processor_token_flow: value.is_payment_processor_token_flow,
}))
}
PaymentIntentUpdate::PaymentCreateUpdate {
@@ -674,6 +679,7 @@ impl From<PaymentIntentUpdateInternal> for diesel_models::PaymentIntentUpdateInt
billing_details,
merchant_order_reference_id,
shipping_details,
+ is_payment_processor_token_flow,
} = value;
Self {
@@ -711,6 +717,7 @@ impl From<PaymentIntentUpdateInternal> for diesel_models::PaymentIntentUpdateInt
billing_details: billing_details.map(Encryption::from),
merchant_order_reference_id,
shipping_details: shipping_details.map(Encryption::from),
+ is_payment_processor_token_flow,
}
}
}
diff --git a/crates/openapi/src/openapi.rs b/crates/openapi/src/openapi.rs
index 1e539462d4..50bbd79705 100644
--- a/crates/openapi/src/openapi.rs
+++ b/crates/openapi/src/openapi.rs
@@ -465,6 +465,7 @@ Never share your secret api keys. Keep them guarded and secure.
api_models::mandates::MandateResponse,
api_models::mandates::MandateCardDetails,
api_models::mandates::RecurringDetails,
+ api_models::mandates::ProcessorPaymentToken,
api_models::ephemeral_key::EphemeralKeyCreateResponse,
api_models::payments::CustomerDetails,
api_models::payments::GiftCardData,
diff --git a/crates/router/src/core/payments.rs b/crates/router/src/core/payments.rs
index 2b92cc3c7e..b4f369f71b 100644
--- a/crates/router/src/core/payments.rs
+++ b/crates/router/src/core/payments.rs
@@ -1516,15 +1516,20 @@ where
)
.await?;
- let merchant_recipient_data = payment_data
- .get_merchant_recipient_data(
- state,
- merchant_account,
- key_store,
- &merchant_connector_account,
- &connector,
- )
- .await?;
+ let merchant_recipient_data =
+ if let Some(true) = payment_data.payment_intent.is_payment_processor_token_flow {
+ None
+ } else {
+ payment_data
+ .get_merchant_recipient_data(
+ state,
+ merchant_account,
+ key_store,
+ &merchant_connector_account,
+ &connector,
+ )
+ .await?
+ };
let mut router_data = payment_data
.construct_router_data(
diff --git a/crates/router/src/core/payments/helpers.rs b/crates/router/src/core/payments/helpers.rs
index 91b7a5fc3f..d3ca7d0428 100644
--- a/crates/router/src/core/payments/helpers.rs
+++ b/crates/router/src/core/payments/helpers.rs
@@ -446,6 +446,20 @@ 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,
@@ -1168,26 +1182,31 @@ pub fn create_complete_authorize_url(
}
fn validate_recurring_mandate(req: api::MandateValidationFields) -> RouterResult<()> {
- req.recurring_details
- .check_value_present("recurring_details")?;
+ let recurring_details = req
+ .recurring_details
+ .get_required_value("recurring_details")?;
- req.customer_id.check_value_present("customer_id")?;
+ match recurring_details {
+ RecurringDetails::ProcessorPaymentToken(_) => Ok(()),
+ _ => {
+ req.customer_id.check_value_present("customer_id")?;
- let confirm = req.confirm.get_required_value("confirm")?;
- if !confirm {
- Err(report!(errors::ApiErrorResponse::PreconditionFailed {
- message: "`confirm` must be `true` for mandates".into()
- }))?
- }
+ let confirm = req.confirm.get_required_value("confirm")?;
+ if !confirm {
+ Err(report!(errors::ApiErrorResponse::PreconditionFailed {
+ message: "`confirm` must be `true` for mandates".into()
+ }))?
+ }
- let off_session = req.off_session.get_required_value("off_session")?;
- if !off_session {
- Err(report!(errors::ApiErrorResponse::PreconditionFailed {
- message: "`off_session` should be `true` for mandates".into()
- }))?
+ let off_session = req.off_session.get_required_value("off_session")?;
+ if !off_session {
+ Err(report!(errors::ApiErrorResponse::PreconditionFailed {
+ message: "`off_session` should be `true` for mandates".into()
+ }))?
+ }
+ Ok(())
+ }
}
-
- Ok(())
}
pub fn verify_mandate_details(
@@ -3069,6 +3088,7 @@ mod tests {
billing_details: None,
merchant_order_reference_id: None,
shipping_details: None,
+ is_payment_processor_token_flow: None,
};
let req_cs = Some("1".to_string());
assert!(authenticate_client_secret(req_cs.as_ref(), &payment_intent).is_ok());
@@ -3133,6 +3153,7 @@ mod tests {
billing_details: None,
merchant_order_reference_id: None,
shipping_details: None,
+ is_payment_processor_token_flow: None,
};
let req_cs = Some("1".to_string());
assert!(authenticate_client_secret(req_cs.as_ref(), &payment_intent,).is_err())
@@ -3195,6 +3216,7 @@ mod tests {
billing_details: None,
merchant_order_reference_id: None,
shipping_details: None,
+ is_payment_processor_token_flow: None,
};
let req_cs = Some("1".to_string());
assert!(authenticate_client_secret(req_cs.as_ref(), &payment_intent).is_err())
diff --git a/crates/router/src/core/payments/operations/payment_confirm.rs b/crates/router/src/core/payments/operations/payment_confirm.rs
index 747be6a5ca..2853304721 100644
--- a/crates/router/src/core/payments/operations/payment_confirm.rs
+++ b/crates/router/src/core/payments/operations/payment_confirm.rs
@@ -640,6 +640,31 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsRequest> for Pa
.as_ref()
.map(|payment_method_billing| payment_method_billing.address_id.clone());
+ // If processor_payment_token is passed in request then populating the same in PaymentData
+ let mandate_id = request
+ .recurring_details
+ .as_ref()
+ .and_then(|recurring_details| match recurring_details {
+ api_models::mandates::RecurringDetails::ProcessorPaymentToken(token) => {
+ payment_intent.is_payment_processor_token_flow = Some(true);
+ Some(api_models::payments::MandateIds {
+ mandate_id: None,
+ mandate_reference_id: Some(
+ api_models::payments::MandateReferenceId::ConnectorMandateId(
+ api_models::payments::ConnectorMandateReferenceId {
+ connector_mandate_id: Some(
+ token.processor_payment_token.clone(),
+ ),
+ payment_method_id: None,
+ update_history: None,
+ },
+ ),
+ ),
+ })
+ }
+ _ => None,
+ });
+
let payment_data = PaymentData {
flow: PhantomData,
payment_intent,
@@ -647,7 +672,7 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsRequest> for Pa
currency,
amount,
email: request.email.clone(),
- mandate_id: None,
+ mandate_id: mandate_id.clone(),
mandate_connector,
setup_mandate,
customer_acceptance: customer_acceptance.map(From::from),
@@ -1293,6 +1318,8 @@ impl<F: Clone> UpdateTracker<F, PaymentData<F>, api::PaymentsRequest> for Paymen
let session_expiry = m_payment_data_payment_intent.session_expiry;
let m_key_store = key_store.clone();
let key_manager_state = state.into();
+ let is_payment_processor_token_flow =
+ payment_data.payment_intent.is_payment_processor_token_flow;
let payment_intent_fut = tokio::spawn(
async move {
@@ -1325,6 +1352,7 @@ impl<F: Clone> UpdateTracker<F, PaymentData<F>, api::PaymentsRequest> for Paymen
merchant_order_reference_id: None,
billing_details,
shipping_details,
+ is_payment_processor_token_flow,
})),
&m_key_store,
storage_scheme,
diff --git a/crates/router/src/core/payments/operations/payment_create.rs b/crates/router/src/core/payments/operations/payment_create.rs
index 160e3d080f..72266e647e 100644
--- a/crates/router/src/core/payments/operations/payment_create.rs
+++ b/crates/router/src/core/payments/operations/payment_create.rs
@@ -410,6 +410,32 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsRequest> for Pa
.await
.transpose()?;
+ let mandate_id = if mandate_id.is_none() {
+ request
+ .recurring_details
+ .as_ref()
+ .and_then(|recurring_details| match recurring_details {
+ RecurringDetails::ProcessorPaymentToken(token) => {
+ Some(api_models::payments::MandateIds {
+ mandate_id: None,
+ mandate_reference_id: Some(
+ api_models::payments::MandateReferenceId::ConnectorMandateId(
+ api_models::payments::ConnectorMandateReferenceId {
+ connector_mandate_id: Some(
+ token.processor_payment_token.clone(),
+ ),
+ payment_method_id: None,
+ update_history: None,
+ },
+ ),
+ ),
+ })
+ }
+ _ => None,
+ })
+ } else {
+ mandate_id
+ };
let operation = payments::if_not_create_change_operation::<_, F>(
payment_intent.status,
request.confirm,
@@ -463,7 +489,7 @@ impl<F: Send + Clone> GetTracker<F, PaymentData<F>, api::PaymentsRequest> for Pa
currency,
amount,
email: request.email.clone(),
- mandate_id,
+ mandate_id: mandate_id.clone(),
mandate_connector,
setup_mandate,
customer_acceptance,
@@ -1141,6 +1167,12 @@ impl PaymentCreate {
} else {
None
};
+ let is_payment_processor_token_flow = request.recurring_details.as_ref().and_then(
+ |recurring_details| match recurring_details {
+ RecurringDetails::ProcessorPaymentToken(_) => Some(true),
+ _ => None,
+ },
+ );
// Encrypting our Customer Details to be stored in Payment Intent
let customer_details = raw_customer_details
@@ -1201,6 +1233,7 @@ impl PaymentCreate {
customer_details,
merchant_order_reference_id: request.merchant_order_reference_id.clone(),
shipping_details,
+ is_payment_processor_token_flow,
})
}
diff --git a/crates/router/src/core/payments/operations/payment_update.rs b/crates/router/src/core/payments/operations/payment_update.rs
index 8ead378362..104c43f79f 100644
--- a/crates/router/src/core/payments/operations/payment_update.rs
+++ b/crates/router/src/core/payments/operations/payment_update.rs
@@ -773,6 +773,7 @@ impl<F: Clone> UpdateTracker<F, PaymentData<F>, api::PaymentsRequest> for Paymen
merchant_order_reference_id,
billing_details,
shipping_details,
+ is_payment_processor_token_flow: None,
})),
key_store,
storage_scheme,
diff --git a/crates/router/src/utils/user/sample_data.rs b/crates/router/src/utils/user/sample_data.rs
index 628e4d573e..ac9272c86d 100644
--- a/crates/router/src/utils/user/sample_data.rs
+++ b/crates/router/src/utils/user/sample_data.rs
@@ -251,6 +251,7 @@ pub async fn generate_sample_data(
billing_details: None,
merchant_order_reference_id: Default::default(),
shipping_details: None,
+ is_payment_processor_token_flow: None,
};
let payment_attempt = PaymentAttemptBatchNew {
attempt_id: attempt_id.clone(),
diff --git a/migrations/2024-08-01-172628_add_is_payment_processor_token_flow_in_payment_intent_table/down.sql b/migrations/2024-08-01-172628_add_is_payment_processor_token_flow_in_payment_intent_table/down.sql
new file mode 100644
index 0000000000..02ff48e6b6
--- /dev/null
+++ b/migrations/2024-08-01-172628_add_is_payment_processor_token_flow_in_payment_intent_table/down.sql
@@ -0,0 +1,2 @@
+-- This file should undo anything in `up.sql`
+ALTER TABLE payment_intent DROP COLUMN IF EXISTS is_payment_processor_token_flow;
diff --git a/migrations/2024-08-01-172628_add_is_payment_processor_token_flow_in_payment_intent_table/up.sql b/migrations/2024-08-01-172628_add_is_payment_processor_token_flow_in_payment_intent_table/up.sql
new file mode 100644
index 0000000000..785806d09e
--- /dev/null
+++ b/migrations/2024-08-01-172628_add_is_payment_processor_token_flow_in_payment_intent_table/up.sql
@@ -0,0 +1,3 @@
+-- Your SQL goes here
+ALTER TABLE payment_intent
+ADD COLUMN IF NOT EXISTS is_payment_processor_token_flow BOOLEAN;