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(returning_customer): Paypal returning customer flow (#11603)

Nithin N0b6f8ce8a380
diff --git a/api-reference/v1/openapi_spec_v1.json b/api-reference/v1/openapi_spec_v1.json
index 6b7fc33b1e..d851b8c399 100644
--- a/api-reference/v1/openapi_spec_v1.json
+++ b/api-reference/v1/openapi_spec_v1.json
@@ -35288,6 +35288,11 @@
}
],
"nullable": true
+ },
+ "data_user_id_token": {
+ "type": "string",
+ "description": "User token required for returning customer flow, used by client to initiate sdk",
+ "nullable": true
}
}
},
diff --git a/api-reference/v2/openapi_spec_v2.json b/api-reference/v2/openapi_spec_v2.json
index ebd1d8a455..f2619b6fd5 100644
--- a/api-reference/v2/openapi_spec_v2.json
+++ b/api-reference/v2/openapi_spec_v2.json
@@ -25509,6 +25509,11 @@
}
],
"nullable": true
+ },
+ "data_user_id_token": {
+ "type": "string",
+ "description": "User token required for returning customer flow, used by client to initiate sdk",
+ "nullable": true
}
}
},
diff --git a/crates/api_models/src/payments.rs b/crates/api_models/src/payments.rs
index f1383ae11e..f46d658df5 100644
--- a/crates/api_models/src/payments.rs
+++ b/crates/api_models/src/payments.rs
@@ -10562,6 +10562,8 @@ pub struct PaypalSessionTokenResponse {
pub client_token: Option<String>,
/// The transaction info Paypal requires
pub transaction_info: Option<PaypalTransactionInfo>,
+ /// User token required for returning customer flow, used by client to initiate sdk
+ pub data_user_id_token: Option<String>,
}
#[derive(
diff --git a/crates/diesel_models/src/query/payment_method.rs b/crates/diesel_models/src/query/payment_method.rs
index c26ad5df41..0ada35b580 100644
--- a/crates/diesel_models/src/query/payment_method.rs
+++ b/crates/diesel_models/src/query/payment_method.rs
@@ -196,6 +196,28 @@ impl PaymentMethod {
.await
}
+ pub async fn find_by_customer_id_merchant_id_status_pm_type(
+ conn: &PgPooledConn,
+ customer_id: &common_utils::id_type::CustomerId,
+ merchant_id: &common_utils::id_type::MerchantId,
+ status: storage_enums::PaymentMethodStatus,
+ payment_method_type: storage_enums::PaymentMethodType,
+ limit: Option<i64>,
+ ) -> StorageResult<Vec<Self>> {
+ generics::generic_filter::<<Self as HasTable>::Table, _, _, _>(
+ conn,
+ dsl::customer_id
+ .eq(customer_id.to_owned())
+ .and(dsl::merchant_id.eq(merchant_id.to_owned()))
+ .and(dsl::status.eq(status))
+ .and(dsl::payment_method_type.eq(payment_method_type)),
+ limit,
+ None,
+ Some(dsl::last_used_at.desc()),
+ )
+ .await
+ }
+
pub async fn update_with_payment_method_id(
self,
conn: &PgPooledConn,
diff --git a/crates/hyperswitch_connectors/src/connectors/braintree/transformers.rs b/crates/hyperswitch_connectors/src/connectors/braintree/transformers.rs
index 09fedfbfea..f531122421 100644
--- a/crates/hyperswitch_connectors/src/connectors/braintree/transformers.rs
+++ b/crates/hyperswitch_connectors/src/connectors/braintree/transformers.rs
@@ -1981,6 +1981,7 @@ impl
client_token: Some(
res.data.create_client_token.client_token.clone().expose(),
),
+ data_user_id_token: None,
transaction_info: Some(
api_models::payments::PaypalTransactionInfo {
flow: PaypalFlow::Checkout.into(),
diff --git a/crates/hyperswitch_connectors/src/connectors/paypal.rs b/crates/hyperswitch_connectors/src/connectors/paypal.rs
index 8e3b475576..e3b62ff103 100644
--- a/crates/hyperswitch_connectors/src/connectors/paypal.rs
+++ b/crates/hyperswitch_connectors/src/connectors/paypal.rs
@@ -45,8 +45,9 @@ use hyperswitch_domain_models::{
PaymentsCompleteAuthorizeRouterData, PaymentsExtendAuthorizationRouterData,
PaymentsIncrementalAuthorizationRouterData, PaymentsPostAuthenticateRouterData,
PaymentsPostSessionTokensRouterData, PaymentsPreProcessingRouterData,
- PaymentsSyncRouterData, RefreshTokenRouterData, RefundSyncRouterData, RefundsRouterData,
- SdkSessionUpdateRouterData, SetupMandateRouterData, VerifyWebhookSourceRouterData,
+ PaymentsSessionRouterData, PaymentsSyncRouterData, RefreshTokenRouterData,
+ RefundSyncRouterData, RefundsRouterData, SdkSessionUpdateRouterData,
+ SetupMandateRouterData, VerifyWebhookSourceRouterData,
},
};
#[cfg(feature = "payouts")]
@@ -69,9 +70,9 @@ use hyperswitch_interfaces::{
types::{
ExtendedAuthorizationType, IncrementalAuthorizationType, PaymentsAuthorizeType,
PaymentsCaptureType, PaymentsCompleteAuthorizeType, PaymentsPostAuthenticateType,
- PaymentsPostSessionTokensType, PaymentsPreProcessingType, PaymentsSyncType,
- PaymentsVoidType, RefreshTokenType, RefundExecuteType, RefundSyncType, Response,
- SdkSessionUpdateType, SetupMandateType, VerifyWebhookSourceType,
+ PaymentsPostSessionTokensType, PaymentsPreProcessingType, PaymentsSessionType,
+ PaymentsSyncType, PaymentsVoidType, RefreshTokenType, RefundExecuteType, RefundSyncType,
+ Response, SdkSessionUpdateType, SetupMandateType, VerifyWebhookSourceType,
},
webhooks::{IncomingWebhook, IncomingWebhookRequestDetails, WebhookContext},
};
@@ -397,7 +398,122 @@ impl ConnectorIntegration<PaymentMethodToken, PaymentMethodTokenizationData, Pay
{
}
-impl ConnectorIntegration<Session, PaymentsSessionData, PaymentsResponseData> for Paypal {}
+impl ConnectorIntegration<Session, PaymentsSessionData, PaymentsResponseData> for Paypal {
+ fn get_url(
+ &self,
+ _req: &PaymentsSessionRouterData,
+ connectors: &Connectors,
+ ) -> CustomResult<String, errors::ConnectorError> {
+ Ok(format!("{}v1/oauth2/token", self.base_url(connectors)))
+ }
+
+ fn get_content_type(&self) -> &'static str {
+ "application/x-www-form-urlencoded"
+ }
+
+ fn get_headers(
+ &self,
+ req: &PaymentsSessionRouterData,
+ _connectors: &Connectors,
+ ) -> CustomResult<Vec<(String, Maskable<String>)>, errors::ConnectorError> {
+ let auth = paypal::PaypalAuthType::try_from(&req.connector_auth_type)?;
+ let credentials = auth.get_credentials()?;
+ let auth_val = credentials.generate_authorization_value();
+
+ Ok(vec![
+ (
+ headers::CONTENT_TYPE.to_string(),
+ PaymentsSessionType::get_content_type(self)
+ .to_string()
+ .into(),
+ ),
+ (headers::AUTHORIZATION.to_string(), auth_val.into_masked()),
+ ])
+ }
+
+ fn get_request_body(
+ &self,
+ req: &PaymentsSessionRouterData,
+ _connectors: &Connectors,
+ ) -> CustomResult<RequestContent, errors::ConnectorError> {
+ let connector_req = paypal::PaypalAuthUpdateRequest::try_from(req)?;
+
+ Ok(RequestContent::FormUrlEncoded(Box::new(connector_req)))
+ }
+
+ fn build_request(
+ &self,
+ req: &PaymentsSessionRouterData,
+ connectors: &Connectors,
+ ) -> CustomResult<Option<Request>, errors::ConnectorError> {
+ let req = Some(
+ RequestBuilder::new()
+ .method(Method::Post)
+ .headers(PaymentsSessionType::get_headers(self, req, connectors)?)
+ .url(&PaymentsSessionType::get_url(self, req, connectors)?)
+ .set_body(PaymentsSessionType::get_request_body(
+ self, req, connectors,
+ )?)
+ .build(),
+ );
+
+ Ok(req)
+ }
+
+ fn handle_response(
+ &self,
+ data: &PaymentsSessionRouterData,
+ event_builder: Option<&mut ConnectorEvent>,
+ res: Response,
+ ) -> CustomResult<PaymentsSessionRouterData, errors::ConnectorError>
+ where
+ PaymentsResponseData: Clone,
+ {
+ let response: paypal::PaypalAuthUpdateResponse = res
+ .response
+ .parse_struct("Paypal PaypalAuthUpdateResponse")
+ .change_context(errors::ConnectorError::ResponseDeserializationFailed)?;
+ event_builder.map(|i| i.set_response_body(&response));
+ router_env::logger::info!(connector_response=?response);
+
+ ForeignTryFrom::foreign_try_from((
+ crate::types::PaymentsSessionResponseRouterData {
+ response,
+ data: data.clone(),
+ http_code: res.status_code,
+ },
+ data.clone(),
+ ))
+ }
+
+ fn get_error_response(
+ &self,
+ res: Response,
+ event_builder: Option<&mut ConnectorEvent>,
+ ) -> CustomResult<ErrorResponse, errors::ConnectorError> {
+ let response: paypal::PaypalAccessTokenErrorResponse = res
+ .response
+ .parse_struct("Paypal AccessTokenErrorResponse")
+ .change_context(errors::ConnectorError::ResponseDeserializationFailed)?;
+
+ event_builder.map(|i| i.set_error_response_body(&response));
+ router_env::logger::info!(connector_response=?response);
+
+ Ok(ErrorResponse {
+ status_code: res.status_code,
+ code: response.error.clone(),
+ message: response.error.clone(),
+ reason: Some(response.error_description),
+ attempt_status: None,
+ connector_transaction_id: None,
+ connector_response_reference_id: None,
+ network_advice_code: None,
+ network_decline_code: None,
+ network_error_message: None,
+ connector_metadata: None,
+ })
+ }
+}
impl ConnectorIntegration<AccessTokenAuth, AccessTokenRequestData, AccessToken> for Paypal {
fn get_url(
@@ -2597,4 +2713,12 @@ impl ConnectorSpecifications for Paypal {
fn get_supported_webhook_flows(&self) -> Option<&'static [enums::EventClass]> {
Some(&PAYPAL_SUPPORTED_WEBHOOK_FLOWS)
}
+ fn is_sdk_client_token_generation_enabled(&self) -> bool {
+ true
+ }
+ fn supported_payment_method_types_for_sdk_client_token_generation(
+ &self,
+ ) -> Vec<enums::PaymentMethodType> {
+ vec![enums::PaymentMethodType::Paypal]
+ }
}
diff --git a/crates/hyperswitch_connectors/src/connectors/paypal/transformers.rs b/crates/hyperswitch_connectors/src/connectors/paypal/transformers.rs
index 470bba21b3..974cc7867a 100644
--- a/crates/hyperswitch_connectors/src/connectors/paypal/transformers.rs
+++ b/crates/hyperswitch_connectors/src/connectors/paypal/transformers.rs
@@ -1,6 +1,10 @@
#[cfg(feature = "payouts")]
use api_models::payouts::{PayoutMethodData, Wallet as WalletPayout};
-use api_models::{enums, webhooks::IncomingWebhookEvent};
+use api_models::{
+ enums,
+ payments::{NextActionCall, PaypalSessionTokenResponse, SdkNextAction, SessionToken},
+ webhooks::IncomingWebhookEvent,
+};
use base64::Engine;
use common_enums::enums as storage_enums;
#[cfg(feature = "payouts")]
@@ -14,7 +18,7 @@ use hyperswitch_domain_models::{
},
router_data::{
AccessToken, ConnectorAuthType, ConnectorResponseData, ErrorResponse,
- ExtendedAuthorizationResponseData, RouterData,
+ ExtendedAuthorizationResponseData, FeatureData, RouterData,
},
router_flow_types::{
payments::{Authorize, PostSessionTokens},
@@ -33,9 +37,9 @@ use hyperswitch_domain_models::{
types::{
PaymentsAuthorizeRouterData, PaymentsCaptureRouterData,
PaymentsExtendAuthorizationRouterData, PaymentsIncrementalAuthorizationRouterData,
- PaymentsPostSessionTokensRouterData, PaymentsSyncRouterData, RefreshTokenRouterData,
- RefundsRouterData, SdkSessionUpdateRouterData, SetupMandateRouterData,
- VerifyWebhookSourceRouterData,
+ PaymentsPostSessionTokensRouterData, PaymentsSessionRouterData, PaymentsSyncRouterData,
+ RefreshTokenRouterData, RefundsRouterData, SdkSessionUpdateRouterData,
+ SetupMandateRouterData, VerifyWebhookSourceRouterData,
},
};
#[cfg(feature = "payouts")]
@@ -58,8 +62,8 @@ use crate::{constants, types::PayoutsResponseRouterData};
use crate::{
types::{
PaymentsCaptureResponseRouterData, PaymentsExtendAuthorizationResponseRouterData,
- PaymentsResponseRouterData, PaymentsSyncResponseRouterData, RefundsResponseRouterData,
- ResponseRouterData,
+ PaymentsResponseRouterData, PaymentsSessionResponseRouterData,
+ PaymentsSyncResponseRouterData, RefundsResponseRouterData, ResponseRouterData,
},
utils::{
self, is_payment_failure, missing_field_err, to_connector_meta, AccessTokenRequestInfo,
@@ -550,6 +554,8 @@ pub struct AttributeResponse {
pub struct PaypalVault {
store_in_vault: StoreInVault,
usage_type: UsageType,
+ // required for vaulting multiple payment tokens for a customer, as per Paypal's documentation. If false or not provided, only one payment token can be vaulted for a customer. If true, multiple payment tokens can be vaulted for a customer. and this will be required for returning customer flow.
+ permit_multiple_payment_tokens: Option<bool>,
}
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct PaypalVaultResponse {
@@ -881,6 +887,7 @@ impl TryFrom<&PaypalRouterData<&PaymentsPostSessionTokensRouterData>> for Paypal
vault: PaypalVault {
store_in_vault: StoreInVault::OnSuccess,
usage_type: UsageType::Merchant,
+ permit_multiple_payment_tokens: Some(true),
},
}),
enums::FutureUsage::OnSession => None,
@@ -1007,6 +1014,8 @@ impl TryFrom<&PaypalRouterData<&PaymentsAuthorizeRouterData>> for PaypalPayments
enums::FutureUsage::OffSession => Some(PaypalVault {
store_in_vault: StoreInVault::OnSuccess,
usage_type: UsageType::Merchant,
+ // only required for paypal
+ permit_multiple_payment_tokens: Some(false),
}),
enums::FutureUsage::OnSession => None,
@@ -1057,6 +1066,7 @@ impl TryFrom<&PaypalRouterData<&PaymentsAuthorizeRouterData>> for PaypalPayments
vault: PaypalVault {
store_in_vault: StoreInVault::OnSuccess,
usage_type: UsageType::Merchant,
+ permit_multiple_payment_tokens: Some(true),
},
}),
enums::FutureUsage::OnSession => None,
@@ -1089,6 +1099,7 @@ impl TryFrom<&PaypalRouterData<&PaymentsAuthorizeRouterData>> for PaypalPayments
vault: PaypalVault {
store_in_vault: StoreInVault::OnSuccess,
usage_type: UsageType::Merchant,
+ permit_multiple_payment_tokens: Some(true),
},
}),
enums::FutureUsage::OnSession => None,
@@ -1485,6 +1496,8 @@ pub struct PaypalAuthUpdateRequest {
grant_type: String,
client_id: Secret<String>,
client_secret: Secret<String>,
+ response_type: Option<PaypalAuthResponseType>,
+ target_customer_id: Option<Secret<String>>,
}
impl TryFrom<&RefreshTokenRouterData> for PaypalAuthUpdateRequest {
type Error = error_stack::Report<errors::ConnectorError>;
@@ -1493,6 +1506,63 @@ impl TryFrom<&RefreshTokenRouterData> for PaypalAuthUpdateRequest {
grant_type: "client_credentials".to_string(),
client_id: item.get_request_id()?,
client_secret: item.request.app_id.clone(),
+ target_customer_id: None,
+ response_type: None,
+ })
+ }
+}
+
+impl TryFrom<&PaymentsSessionRouterData> for PaypalAuthUpdateRequest {
+ type Error = error_stack::Report<errors::ConnectorError>;
+ fn try_from(item: &PaymentsSessionRouterData) -> Result<Self, Self::Error> {
+ let auth = PaypalAuthType::try_from(&item.connector_auth_type)?;
+ let credentials = auth.get_credentials()?;
+
+ let target_customer_id = match &item.feature_data {
+ Some(FeatureData::PaypalReturningCustomer(customer)) => {
+ customer.paypal_vault_customer_id.clone()
+ }
+ None => None,
+ };
+
+ Ok(Self {
+ grant_type: "client_credentials".to_string(),
+ client_id: credentials.get_client_id().clone(),
+ client_secret: credentials.get_client_secret().clone(),
+ response_type: Some(PaypalAuthResponseType::IdToken),
+ target_customer_id,
+ })
+ }
+}
+impl
+ ForeignTryFrom<(
+ PaymentsSessionResponseRouterData<PaypalAuthUpdateResponse>,
+ Self,
+ )> for PaymentsSessionRouterData
+{
+ type Error = error_stack::Report<errors::ConnectorError>;
+ fn foreign_try_from(
+ (item, data): (
+ PaymentsSessionResponseRouterData<PaypalAuthUpdateResponse>,
+ Self,
+ ),
+ ) -> Result<Self, Self::Error> {
+ let response = &item.response;
+ let auth = PaypalAuthType::try_from(&data.connector_auth_type)?;
+ let credentials = auth.get_credentials()?;
+ let session_token = SessionToken::Paypal(Box::new(PaypalSessionTokenResponse {
+ connector: "paypal".to_string(),
+ session_token: credentials.get_client_id().clone().expose(),
+ sdk_next_action: SdkNextAction {
+ next_action: NextActionCall::PostSessionTokens,
+ },
+ client_token: None,
+ data_user_id_token: response.id_token.clone().map(|id| id.expose()),
+ transaction_info: None,
+ }));
+ Ok(Self {
+ response: Ok(PaymentsResponseData::SessionResponse { session_token }),
+ ..data
})
}
}
@@ -1500,9 +1570,15 @@ impl TryFrom<&RefreshTokenRouterData> for PaypalAuthUpdateRequest {
#[derive(Default, Debug, Clone, Deserialize, PartialEq, Serialize)]
pub struct PaypalAuthUpdateResponse {
pub access_token: Secret<String>,
+ pub id_token: Option<Secret<String>>,
pub token_type: String,
pub expires_in: i64,
}
+#[derive(Debug, Clone, Deserialize, PartialEq, Serialize)]
+#[serde(rename_all = "snake_case")]
+pub enum PaypalAuthResponseType {
+ IdToken,
+}
impl<F, T> TryFrom<ResponseRouterData<F, PaypalAuthUpdateResponse, T, AccessToken>>
for RouterData<F, T, AccessToken>
@@ -2214,7 +2290,7 @@ pub struct PaypalMeta {
pub capture_id: Option<String>,
pub incremental_authorization_id: Option<String>,
pub psync_flow: PaypalPaymentIntent,
- pub next_action: Option<api_models::payments::NextActionCall>,
+ pub next_action: Option<NextActionCall>,
pub order_id: Option<String>,
}
@@ -2381,7 +2457,21 @@ where
},
payment_method_id: None,
mandate_metadata: None,
- connector_mandate_request_reference_id: None,
+ connector_mandate_request_reference_id: match item
+ .response
+ .payment_source
+ .clone()
+ {
+ Some(paypal_source) => match paypal_source {
+ PaymentSourceItemResponse::Paypal(paypal_source) => paypal_source
+ .attributes
+ .and_then(|attr| attr.vault.customer.map(|cus| cus.id)),
+ PaymentSourceItemResponse::Card(_)
+ | PaymentSourceItemResponse::Eps(_)
+ | PaymentSourceItemResponse::Ideal(_) => None,
+ },
+ None => None,
+ },
})),
connector_metadata: Some(connector_meta),
network_txn_id: None,
@@ -2479,7 +2569,7 @@ impl<F, T>
// For Paypal SDK flow, we need to trigger SDK client and then complete authorize
let next_action =
if let Some(common_enums::PaymentExperience::InvokeSdkClient) = payment_experience {
- Some(api_models::payments::NextActionCall::CompleteAuthorize)
+ Some(NextActionCall::CompleteAuthorize)
} else {
None
};
@@ -2592,7 +2682,7 @@ impl
let status = get_order_status(item.response.clone().status, item.response.intent.clone());
// For Paypal SDK flow, we need to trigger SDK client and then Confirm
- let next_action = Some(api_models::payments::NextActionCall::Confirm);
+ let next_action = Some(NextActionCall::Confirm);
let connector_meta = serde_json::json!(PaypalMeta {
authorize_id: None,
diff --git a/crates/hyperswitch_connectors/src/utils.rs b/crates/hyperswitch_connectors/src/utils.rs
index 1751c40fe7..6def04e302 100644
--- a/crates/hyperswitch_connectors/src/utils.rs
+++ b/crates/hyperswitch_connectors/src/utils.rs
@@ -7652,6 +7652,7 @@ pub(crate) fn convert_payment_authorize_router_response<F1, F2, T1, T2>(
minor_amount_capturable: data.minor_amount_capturable,
authorized_amount: data.authorized_amount,
customer_document_details: data.customer_document_details.clone(),
+ feature_data: data.feature_data.clone(),
}
}
diff --git a/crates/hyperswitch_domain_models/src/payment_methods.rs b/crates/hyperswitch_domain_models/src/payment_methods.rs
index 26b4bec021..ebded81dcb 100644
--- a/crates/hyperswitch_domain_models/src/payment_methods.rs
+++ b/crates/hyperswitch_domain_models/src/payment_methods.rs
@@ -1108,6 +1108,19 @@ pub trait PaymentMethodInterface {
storage_scheme: MerchantStorageScheme,
) -> CustomResult<Vec<PaymentMethod>, Self::Error>;
+ #[cfg(feature = "v1")]
+ #[allow(clippy::too_many_arguments)]
+ async fn find_payment_method_by_customer_id_merchant_id_status_pm_type(
+ &self,
+ key_store: &MerchantKeyStore,
+ customer_id: &id_type::CustomerId,
+ merchant_id: &id_type::MerchantId,
+ status: common_enums::PaymentMethodStatus,
+ payment_method_type: common_enums::PaymentMethodType,
+ limit: Option<i64>,
+ storage_scheme: MerchantStorageScheme,
+ ) -> CustomResult<Vec<PaymentMethod>, Self::Error>;
+
#[cfg(feature = "v2")]
#[allow(clippy::too_many_arguments)]
async fn find_payment_method_by_global_customer_id_merchant_id_status(
diff --git a/crates/hyperswitch_domain_models/src/router_data.rs b/crates/hyperswitch_domain_models/src/router_data.rs
index 3df34f4d77..72dea02708 100644
--- a/crates/hyperswitch_domain_models/src/router_data.rs
+++ b/crates/hyperswitch_domain_models/src/router_data.rs
@@ -123,8 +123,19 @@ pub struct RouterData<Flow, Request, Response> {
// Document details of the customer consisting of document number and type
pub customer_document_details: Option<CustomerDocumentDetails>,
+ // feature related data
+ pub feature_data: Option<FeatureData>,
}
+#[derive(Debug, Clone, Serialize, Deserialize)]
+pub enum FeatureData {
+ PaypalReturningCustomer(Box<PaypalReturningCustomerData>),
+}
+
+#[derive(Debug, Clone, Serialize, Deserialize)]
+pub struct PaypalReturningCustomerData {
+ pub paypal_vault_customer_id: Option<Secret<String>>,
+}
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct L2L3Data {
pub order_info: Option<OrderInfo>,
diff --git a/crates/hyperswitch_interfaces/src/conversion_impls.rs b/crates/hyperswitch_interfaces/src/conversion_impls.rs
index a112a81c83..8a1430d406 100644
--- a/crates/hyperswitch_interfaces/src/conversion_impls.rs
+++ b/crates/hyperswitch_interfaces/src/conversion_impls.rs
@@ -97,6 +97,7 @@ fn get_default_router_data<F, Req, Resp>(
minor_amount_capturable: None,
authorized_amount: None,
customer_document_details: None,
+ feature_data: None,
}
}
diff --git a/crates/router/src/core/authentication/transformers.rs b/crates/router/src/core/authentication/transformers.rs
index 7604694993..a61e714d13 100644
--- a/crates/router/src/core/authentication/transformers.rs
+++ b/crates/router/src/core/authentication/transformers.rs
@@ -215,6 +215,7 @@ pub fn construct_router_data<F: Clone, Req, Res>(
minor_amount_capturable: None,
authorized_amount: None,
customer_document_details: None,
+ feature_data: None,
})
}
diff --git a/crates/router/src/core/fraud_check/flows/checkout_flow.rs b/crates/router/src/core/fraud_check/flows/checkout_flow.rs
index 316df9de6c..06f681e066 100644
--- a/crates/router/src/core/fraud_check/flows/checkout_flow.rs
+++ b/crates/router/src/core/fraud_check/flows/checkout_flow.rs
@@ -181,6 +181,7 @@ impl ConstructFlowSpecificData<frm_api::Checkout, FraudCheckCheckoutData, FraudC
.attach_printable(
"Failed to extract customer document details from payment_intent",
)?,
+ feature_data: None,
};
Ok(router_data)
diff --git a/crates/router/src/core/fraud_check/flows/fulfillment_flow.rs b/crates/router/src/core/fraud_check/flows/fulfillment_flow.rs
index afce3dc6d6..d4d71930e3 100644
--- a/crates/router/src/core/fraud_check/flows/fulfillment_flow.rs
+++ b/crates/router/src/core/fraud_check/flows/fulfillment_flow.rs
@@ -141,6 +141,7 @@ pub async fn construct_fulfillment_router_data<'a>(
.get_customer_document_details()
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("Failed to extract customer document details from payment_intent")?,
+ feature_data: None,
};
Ok(router_data)
}
diff --git a/crates/router/src/core/fraud_check/flows/record_return.rs b/crates/router/src/core/fraud_check/flows/record_return.rs
index b494ca851f..62abf60c24 100644
--- a/crates/router/src/core/fraud_check/flows/record_return.rs
+++ b/crates/router/src/core/fraud_check/flows/record_return.rs
@@ -144,6 +144,7 @@ impl ConstructFlowSpecificData<RecordReturn, FraudCheckRecordReturnData, FraudCh
.attach_printable(
"Failed to extract customer document details from payment_intent",
)?,
+ feature_data: None,
};
Ok(router_data)
diff --git a/crates/router/src/core/fraud_check/flows/sale_flow.rs b/crates/router/src/core/fraud_check/flows/sale_flow.rs
index 5369b04cf7..6993aeb489 100644
--- a/crates/router/src/core/fraud_check/flows/sale_flow.rs
+++ b/crates/router/src/core/fraud_check/flows/sale_flow.rs
@@ -160,6 +160,7 @@ impl ConstructFlowSpecificData<frm_api::Sale, FraudCheckSaleData, FraudCheckResp
.attach_printable(
"Failed to extract customer document details from payment_intent",
)?,
+ feature_data: None,
};
Ok(router_data)
diff --git a/crates/router/src/core/fraud_check/flows/transaction_flow.rs b/crates/router/src/core/fraud_check/flows/transaction_flow.rs
index 1871357dff..d3cd4b520e 100644
--- a/crates/router/src/core/fraud_check/flows/transaction_flow.rs
+++ b/crates/router/src/core/fraud_check/flows/transaction_flow.rs
@@ -163,6 +163,7 @@ impl
.attach_printable(
"Failed to extract customer document details from payment_intent",
)?,
+ feature_data: None,
};
Ok(router_data)
diff --git a/crates/router/src/core/mandate/utils.rs b/crates/router/src/core/mandate/utils.rs
index e554477108..3e961e816d 100644
--- a/crates/router/src/core/mandate/utils.rs
+++ b/crates/router/src/core/mandate/utils.rs
@@ -93,6 +93,7 @@ pub async fn construct_mandate_revoke_router_data(
minor_amount_capturable: None,
authorized_amount: None,
customer_document_details: None,
+ feature_data: None,
};
Ok(router_data)
diff --git a/crates/router/src/core/merchant_connector_webhook_management/transformers.rs b/crates/router/src/core/merchant_connector_webhook_management/transformers.rs
index 039a6a56fb..34798f1d2e 100644
--- a/crates/router/src/core/merchant_connector_webhook_management/transformers.rs
+++ b/crates/router/src/core/merchant_connector_webhook_management/transformers.rs
@@ -109,6 +109,7 @@ pub async fn construct_webhook_register_router_data<'a>(
authorized_amount: None,
payout_id: None,
customer_document_details: None,
+ feature_data: None,
})
}
diff --git a/crates/router/src/core/payment_methods.rs b/crates/router/src/core/payment_methods.rs
index eeb0056dd2..48c874b703 100644
--- a/crates/router/src/core/payment_methods.rs
+++ b/crates/router/src/core/payment_methods.rs
@@ -5482,6 +5482,7 @@ async fn create_single_use_tokenization_flow(
minor_amount_capturable: None,
authorized_amount: None,
customer_document_details: None,
+ feature_data: None,
};
let payment_method_token_response = Box::pin(tokenization::add_token_for_payment_method(
diff --git a/crates/router/src/core/payments.rs b/crates/router/src/core/payments.rs
index 1fc714fca0..fc7fca4809 100644
--- a/crates/router/src/core/payments.rs
+++ b/crates/router/src/core/payments.rs
@@ -71,7 +71,7 @@ pub use hyperswitch_domain_models::{
};
use hyperswitch_domain_models::{
payments::{self, payment_intent::CustomerData, ClickToPayMetaData},
- router_data::AccessToken,
+ router_data::{AccessToken, FeatureData},
};
use hyperswitch_masking::{ExposeInterface, PeekInterface, Secret};
#[cfg(feature = "v2")]
@@ -7823,6 +7823,95 @@ fn is_google_pay_pre_decrypt_type_connector_tokenization(
}
}
+/// Feature-related data used by connector-specific flows.
+///
+/// # 1. PayPal returning customer flow
+///
+/// For PayPal, a returning customer flow requires the PayPal vault customer id
+/// (`customer.id`) that was returned when the initial Cardholder Initiated
+/// Transaction (CIT) was created. That id is obtained from the PayPal access
+/// token and persisted in the router database as part of the stored PayPal
+/// payment method for the customer and the relevant Merchant Connector
+/// Account (MCA).
+///
+/// This function:
+/// - identifies the PayPal context from the provided `customer_id`,
+/// `payment_method_type`, and `merchant_connector_account`,
+/// - selects the latest **active** PayPal payment method for that customer
+/// and connector/MCA combination (older entries are effectively
+/// overridden when multiple CITs are created), and
+/// - reads the persisted PayPal vault customer id from that payment method
+/// and places it into `FeatureData` so it can be passed to the PayPal SDK
+/// to initialize the returning-customer flow.
+///
+/// For non-PayPal or flows without a stored PayPal payment method, this
+/// function returns `None`.
+#[cfg(feature = "v1")]
+async fn get_feature_data(
+ customer_id: Option<id_type::CustomerId>,
+ payment_method_type: Option<enums::PaymentMethodType>,
+ merchant_connector_account: &helpers::MerchantConnectorAccountType,
+ state: &SessionState,
+ merchant_id: &id_type::MerchantId,
+ key_store: &domain::MerchantKeyStore,
+ storage_scheme: storage_enums::MerchantStorageScheme,
+) -> Option<FeatureData> {
+ match (customer_id, payment_method_type) {
+ (Some(customer_id), Some(enums::PaymentMethodType::Paypal)) => {
+ let mca_id = merchant_connector_account.get_mca_id();
+ let payment_methods = state
+ .store
+ .find_payment_method_by_customer_id_merchant_id_status_pm_type(
+ key_store,
+ &customer_id,
+ merchant_id,
+ storage_enums::PaymentMethodStatus::Active,
+ enums::PaymentMethodType::Paypal,
+ None,
+ storage_scheme,
+ )
+ .await
+ .inspect_err(|err| {
+ router_env::logger::error!(
+ error=?err,
+ "Failed to fetch payment methods for returning customer flow, proceeding without feature data"
+ );
+ })
+ .unwrap_or_default();
+
+ // Helper closure to extract payment reference by MCA ID
+ let get_payment_ref =
+ |pm: &hyperswitch_domain_models::payment_methods::PaymentMethod| {
+ pm.get_common_mandate_reference()
+ .ok()
+ .and_then(|mandate_ref| mandate_ref.payments)
+ .and_then(|payments| {
+ mca_id.as_ref().and_then(|id| payments.get(id).cloned())
+ })
+ };
+
+ let paypal_payment_ref = payment_methods
+ .iter()
+ .map(|pm| get_payment_ref(pm).map(|payment_ref| (pm.created_at, payment_ref)))
+ .max_by_key(|opt| opt.as_ref().map(|(created_at, _)| *created_at))
+ .flatten()
+ .map(|(_, pm_data)| pm_data);
+
+ paypal_payment_ref.map(|payment_ref| {
+ FeatureData::PaypalReturningCustomer(Box::new(
+ hyperswitch_domain_models::router_data::PaypalReturningCustomerData {
+ paypal_vault_customer_id: payment_ref
+ .connector_mandate_request_reference_id
+ .clone()
+ .map(Secret::new),
+ },
+ ))
+ })
+ }
+ _ => None,
+ }
+}
+
fn decide_apple_pay_flow(
state: &SessionState,
payment_method_type: Option<enums::PaymentMethodType>,
diff --git a/crates/router/src/core/payments/flows/session_flow.rs b/crates/router/src/core/payments/flows/session_flow.rs
index a492021d04..2dfca8392f 100644
--- a/crates/router/src/core/payments/flows/session_flow.rs
+++ b/crates/router/src/core/payments/flows/session_flow.rs
@@ -1340,6 +1340,7 @@ fn create_paypal_sdk_session_token(
sdk_next_action: payment_types::SdkNextAction {
next_action: payment_types::NextActionCall::PostSessionTokens,
},
+ data_user_id_token: None,
client_token: None,
transaction_info: None,
},
diff --git a/crates/router/src/core/payments/helpers.rs b/crates/router/src/core/payments/helpers.rs
index 3b98c34b12..4d6122b143 100644
--- a/crates/router/src/core/payments/helpers.rs
+++ b/crates/router/src/core/payments/helpers.rs
@@ -5099,6 +5099,7 @@ pub fn router_data_type_conversion<F1, F2, Req1, Req2, Res1, Res2>(
minor_amount_capturable: router_data.minor_amount_capturable,
authorized_amount: router_data.authorized_amount,
customer_document_details: router_data.customer_document_details,
+ feature_data: router_data.feature_data,
}
}
diff --git a/crates/router/src/core/payments/transformers.rs b/crates/router/src/core/payments/transformers.rs
index e6c67a67c3..e4bf88529c 100644
--- a/crates/router/src/core/payments/transformers.rs
+++ b/crates/router/src/core/payments/transformers.rs
@@ -222,6 +222,7 @@ where
minor_amount_capturable: None,
authorized_amount: None,
customer_document_details: None,
+ feature_data: None,
};
Ok(router_data)
}
@@ -582,6 +583,7 @@ pub async fn construct_payment_router_data_for_authorize<'a>(
minor_amount_capturable: None,
authorized_amount: None,
customer_document_details: None,
+ feature_data: None,
};
Ok(router_data)
@@ -929,6 +931,7 @@ pub async fn construct_payment_router_data_for_capture<'a>(
minor_amount_capturable: None,
authorized_amount: None,
customer_document_details: None,
+ feature_data: None,
};
Ok(router_data)
@@ -1065,6 +1068,7 @@ pub async fn construct_router_data_for_psync<'a>(
minor_amount_capturable: None,
authorized_amount: None,
customer_document_details: None,
+ feature_data: None,
};
Ok(router_data)
@@ -1436,6 +1440,7 @@ pub async fn construct_payment_router_data_for_sdk_session<'a>(
minor_amount_capturable: None,
authorized_amount: None,
customer_document_details: None,
+ feature_data: None,
};
Ok(router_data)
@@ -1666,6 +1671,7 @@ pub async fn construct_payment_router_data_for_setup_mandate<'a>(
minor_amount_capturable: None,
authorized_amount: None,
customer_document_details: None,
+ feature_data: None,
};
Ok(router_data)
@@ -1896,10 +1902,20 @@ where
.get_customer_document_details()
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("Failed to extract customer document details from payment_intent")?;
-
+ let merchant_id = processor.get_account().get_id().clone();
+ let feature_data = payments::get_feature_data(
+ customer_id.clone(),
+ payment_method_type,
+ merchant_connector_account,
+ state,
+ &merchant_id,
+ processor.get_key_store(),
+ processor.get_account().storage_scheme,
+ )
+ .await;
let router_data = types::RouterData {
flow: PhantomData,
- merchant_id: processor.get_account().get_id().clone(),
+ merchant_id,
customer_id,
tenant_id: state.tenant.tenant_id.clone(),
connector: connector_id.to_owned(),
@@ -1986,6 +2002,7 @@ where
minor_amount_capturable: None,
authorized_amount: None,
customer_document_details,
+ feature_data,
};
Ok(router_data)
@@ -2206,6 +2223,7 @@ pub async fn construct_payment_router_data_for_update_metadata<'a>(
.get_customer_document_details()
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("Failed to extract customer document details from payment_intent")?,
+ feature_data: None,
};
Ok(router_data)
diff --git a/crates/router/src/core/relay/utils.rs b/crates/router/src/core/relay/utils.rs
index 3e6ce94738..9e79be82cd 100644
--- a/crates/router/src/core/relay/utils.rs
+++ b/crates/router/src/core/relay/utils.rs
@@ -148,6 +148,7 @@ pub async fn construct_relay_refund_router_data<F>(
minor_amount_capturable: None,
authorized_amount: None,
customer_document_details: None,
+ feature_data: None,
};
Ok(router_data)
@@ -285,6 +286,7 @@ pub async fn construct_relay_capture_router_data(
minor_amount_capturable: None,
authorized_amount: None,
customer_document_details: None,
+ feature_data: None,
};
Ok(router_data)
@@ -407,6 +409,7 @@ pub async fn construct_relay_incremental_authorization_router_data(
minor_amount_capturable: None,
authorized_amount: None,
customer_document_details: None,
+ feature_data: None,
};
Ok(router_data)
@@ -538,6 +541,7 @@ pub async fn construct_relay_void_router_data(
minor_amount_capturable: None,
authorized_amount: None,
customer_document_details: None,
+ feature_data: None,
};
Ok(router_data)
@@ -682,6 +686,7 @@ pub async fn construct_relay_payments_retrieve_router_data(
minor_amount_capturable: None,
authorized_amount: None,
customer_document_details: None,
+ feature_data: None,
};
Ok(router_data)
diff --git a/crates/router/src/core/unified_authentication_service/utils.rs b/crates/router/src/core/unified_authentication_service/utils.rs
index 311c4a23ac..5b62a57af8 100644
--- a/crates/router/src/core/unified_authentication_service/utils.rs
+++ b/crates/router/src/core/unified_authentication_service/utils.rs
@@ -148,6 +148,7 @@ pub fn construct_uas_router_data<F: Clone, Req, Res>(
minor_amount_capturable: None,
authorized_amount: None,
customer_document_details: None,
+ feature_data: None,
})
}
@@ -700,6 +701,7 @@ pub fn construct_uas_webhook_router_data<F: Clone, Req, Res>(
raw_connector_response: None,
is_payment_id_from_merchant: None,
customer_document_details: None,
+ feature_data: None,
})
}
diff --git a/crates/router/src/core/unified_connector_service/transformers.rs b/crates/router/src/core/unified_connector_service/transformers.rs
index 04dbe092d1..8992c80731 100644
--- a/crates/router/src/core/unified_connector_service/transformers.rs
+++ b/crates/router/src/core/unified_connector_service/transformers.rs
@@ -4831,6 +4831,8 @@ impl transformers::ForeignTryFrom<payments_grpc::ClientAuthenticationTokenData>
.transaction_info
.map(PaypalTransactionInfo::foreign_try_from)
.transpose()?,
+ // todo UCS
+ data_user_id_token: None,
};
Ok(Self::Paypal(Box::new(paypal_session_token_response)))
diff --git a/crates/router/src/core/utils.rs b/crates/router/src/core/utils.rs
index 77f4f7c6fe..b64793ac62 100644
--- a/crates/router/src/core/utils.rs
+++ b/crates/router/src/core/utils.rs
@@ -286,6 +286,7 @@ pub async fn construct_payout_router_data<'a, F>(
minor_amount_capturable: None,
authorized_amount: None,
customer_document_details: None,
+ feature_data: None,
};
Ok(router_data)
@@ -463,6 +464,7 @@ pub async fn construct_refund_router_data<'a, F>(
minor_amount_capturable: None,
authorized_amount: None,
customer_document_details: None,
+ feature_data: None,
};
Ok(router_data)
@@ -659,6 +661,7 @@ pub async fn construct_refund_router_data<'a, F>(
.get_customer_document_details()
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("Failed to extract customer document details from payment_intent")?,
+ feature_data: None,
};
Ok(router_data)
@@ -1122,6 +1125,7 @@ pub async fn construct_accept_dispute_router_data<'a>(
.get_customer_document_details()
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("Failed to extract customer document details from payment_intent")?,
+ feature_data: None,
};
Ok(router_data)
}
@@ -1232,6 +1236,7 @@ pub async fn construct_submit_evidence_router_data<'a>(
.get_customer_document_details()
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("Failed to extract customer document details from payment_intent")?,
+ feature_data: None,
};
Ok(router_data)
}
@@ -1348,6 +1353,7 @@ pub async fn construct_upload_file_router_data<'a>(
minor_amount_capturable: None,
authorized_amount: None,
customer_document_details: None,
+ feature_data: None,
};
Ok(router_data)
}
@@ -1425,6 +1431,7 @@ pub async fn construct_dispute_list_router_data<'a>(
minor_amount_capturable: None,
authorized_amount: None,
customer_document_details: None,
+ feature_data: None,
})
}
@@ -1537,6 +1544,7 @@ pub async fn construct_dispute_sync_router_data<'a>(
.get_customer_document_details()
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("Failed to extract customer document details from payment_intent")?,
+ feature_data: None,
};
Ok(router_data)
}
@@ -1672,6 +1680,7 @@ pub async fn construct_payments_dynamic_tax_calculation_router_data<F: Clone>(
.get_customer_document_details()
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("Failed to extract customer document details from payment_intent")?,
+ feature_data: None,
};
Ok(router_data)
}
@@ -1785,6 +1794,7 @@ pub async fn construct_defend_dispute_router_data<'a>(
.get_customer_document_details()
.change_context(errors::ApiErrorResponse::InternalServerError)
.attach_printable("Failed to extract customer document details from payment_intent")?,
+ feature_data: None,
};
Ok(router_data)
}
@@ -1888,6 +1898,7 @@ pub async fn construct_retrieve_file_router_data<'a>(
minor_amount_capturable: None,
authorized_amount: None,
customer_document_details: None,
+ feature_data: None,
};
Ok(router_data)
}
diff --git a/crates/router/src/core/webhooks/utils.rs b/crates/router/src/core/webhooks/utils.rs
index 7d2f23404c..157328cda1 100644
--- a/crates/router/src/core/webhooks/utils.rs
+++ b/crates/router/src/core/webhooks/utils.rs
@@ -148,6 +148,7 @@ pub async fn construct_webhook_router_data(
minor_amount_capturable: None,
authorized_amount: None,
customer_document_details: None,
+ feature_data: None,
};
Ok(router_data)
}
diff --git a/crates/router/src/db/kafka_store.rs b/crates/router/src/db/kafka_store.rs
index 826d21ddea..c5bafb0507 100644
--- a/crates/router/src/db/kafka_store.rs
+++ b/crates/router/src/db/kafka_store.rs
@@ -2163,6 +2163,30 @@ impl PaymentMethodInterface for KafkaStore {
.await
}
+ #[cfg(feature = "v1")]
+ async fn find_payment_method_by_customer_id_merchant_id_status_pm_type(
+ &self,
+ key_store: &domain::MerchantKeyStore,
+ customer_id: &id_type::CustomerId,
+ merchant_id: &id_type::MerchantId,
+ status: common_enums::PaymentMethodStatus,
+ payment_method_type: common_enums::PaymentMethodType,
+ limit: Option<i64>,
+ storage_scheme: MerchantStorageScheme,
+ ) -> CustomResult<Vec<domain::PaymentMethod>, errors::StorageError> {
+ self.diesel_store
+ .find_payment_method_by_customer_id_merchant_id_status_pm_type(
+ key_store,
+ customer_id,
+ merchant_id,
+ status,
+ payment_method_type,
+ limit,
+ storage_scheme,
+ )
+ .await
+ }
+
#[cfg(feature = "v2")]
async fn find_payment_method_by_global_customer_id_merchant_id_status(
&self,
diff --git a/crates/router/src/types.rs b/crates/router/src/types.rs
index e0fb09e223..081e173ab5 100644
--- a/crates/router/src/types.rs
+++ b/crates/router/src/types.rs
@@ -1411,6 +1411,7 @@ impl<F1, F2, T1, T2> ForeignFrom<(&RouterData<F1, T1, PaymentsResponseData>, T2)
minor_amount_capturable: data.minor_amount_capturable,
authorized_amount: data.authorized_amount,
customer_document_details: data.customer_document_details.clone(),
+ feature_data: data.feature_data.clone(),
}
}
}
@@ -1485,6 +1486,7 @@ impl<F1, F2>
minor_amount_capturable: None,
authorized_amount: None,
customer_document_details: None,
+ feature_data: data.feature_data.clone(),
}
}
}
diff --git a/crates/router/src/types/api/verify_connector.rs b/crates/router/src/types/api/verify_connector.rs
index 38feb07823..9739504178 100644
--- a/crates/router/src/types/api/verify_connector.rs
+++ b/crates/router/src/types/api/verify_connector.rs
@@ -148,6 +148,7 @@ impl VerifyConnectorData {
minor_amount_capturable: None,
authorized_amount: None,
customer_document_details: None,
+ feature_data: None,
}
}
}
diff --git a/crates/router/tests/connectors/utils.rs b/crates/router/tests/connectors/utils.rs
index 65587e7658..8e250f709e 100644
--- a/crates/router/tests/connectors/utils.rs
+++ b/crates/router/tests/connectors/utils.rs
@@ -569,6 +569,7 @@ pub trait ConnectorActions: Connector {
minor_amount_capturable: None,
authorized_amount: None,
customer_document_details: None,
+ feature_data: None,
}
}
diff --git a/crates/storage_impl/src/payment_method.rs b/crates/storage_impl/src/payment_method.rs
index c16c795dab..ff731f03ca 100644
--- a/crates/storage_impl/src/payment_method.rs
+++ b/crates/storage_impl/src/payment_method.rs
@@ -337,6 +337,43 @@ impl<T: DatabaseStore> PaymentMethodInterface for KVRouterStore<T> {
.await
}
+ #[cfg(feature = "v1")]
+ #[instrument(skip_all)]
+ async fn find_payment_method_by_customer_id_merchant_id_status_pm_type(
+ &self,
+ key_store: &MerchantKeyStore,
+ customer_id: &id_type::CustomerId,
+ merchant_id: &id_type::MerchantId,
+ status: common_enums::PaymentMethodStatus,
+ payment_method_type: common_enums::PaymentMethodType,
+ limit: Option<i64>,
+ storage_scheme: MerchantStorageScheme,
+ ) -> CustomResult<Vec<DomainPaymentMethod>, Self::Error> {
+ let conn = pg_connection_read(self).await?;
+ self.filter_resources(
+ key_store,
+ storage_scheme,
+ PaymentMethod::find_by_customer_id_merchant_id_status_pm_type(
+ &conn,
+ customer_id,
+ merchant_id,
+ status,
+ payment_method_type,
+ limit,
+ ),
+ |pm| pm.status == status && pm.payment_method_type == Some(payment_method_type),
+ FilterResourceParams {
+ key: PartitionKey::MerchantIdCustomerId {
+ merchant_id,
+ customer_id,
+ },
+ pattern: "payment_method_id_*",
+ limit,
+ },
+ )
+ .await
+ }
+
#[cfg(feature = "v2")]
#[instrument(skip_all)]
async fn find_payment_method_by_global_customer_id_merchant_id_status(
@@ -650,6 +687,33 @@ impl<T: DatabaseStore> PaymentMethodInterface for RouterStore<T> {
.await
}
+ #[cfg(feature = "v1")]
+ #[instrument(skip_all)]
+ async fn find_payment_method_by_customer_id_merchant_id_status_pm_type(
+ &self,
+ key_store: &MerchantKeyStore,
+ customer_id: &id_type::CustomerId,
+ merchant_id: &id_type::MerchantId,
+ status: common_enums::PaymentMethodStatus,
+ payment_method_type: common_enums::PaymentMethodType,
+ limit: Option<i64>,
+ _storage_scheme: MerchantStorageScheme,
+ ) -> CustomResult<Vec<DomainPaymentMethod>, Self::Error> {
+ let conn = pg_connection_read(self).await?;
+ self.find_resources(
+ key_store,
+ PaymentMethod::find_by_customer_id_merchant_id_status_pm_type(
+ &conn,
+ customer_id,
+ merchant_id,
+ status,
+ payment_method_type,
+ limit,
+ ),
+ )
+ .await
+ }
+
#[cfg(feature = "v2")]
#[instrument(skip_all)]
async fn find_payment_method_by_global_customer_id_merchant_id_status(
@@ -933,7 +997,31 @@ impl PaymentMethodInterface for MockDb {
)
.await
}
-
+ #[cfg(feature = "v1")]
+ async fn find_payment_method_by_customer_id_merchant_id_status_pm_type(
+ &self,
+ key_store: &MerchantKeyStore,
+ customer_id: &id_type::CustomerId,
+ merchant_id: &id_type::MerchantId,
+ status: common_enums::PaymentMethodStatus,
+ payment_method_type: common_enums::PaymentMethodType,
+ _limit: Option<i64>,
+ _storage_scheme: MerchantStorageScheme,
+ ) -> CustomResult<Vec<DomainPaymentMethod>, Self::Error> {
+ let payment_methods = self.payment_methods.lock().await;
+ self.get_resources(
+ key_store,
+ payment_methods,
+ |pm| {
+ pm.customer_id == *customer_id
+ && pm.merchant_id == *merchant_id
+ && pm.status == status
+ && pm.payment_method_type == Some(payment_method_type)
+ },
+ "cannot find payment method".to_string(),
+ )
+ .await
+ }
#[cfg(feature = "v2")]
async fn find_payment_method_by_global_customer_id_merchant_id_status(
&self,