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(connector): [Stripe] Googlepay Predecrypted flow stripe (#11604)
Swangi Kumari3f8243ddde59
diff --git a/config/deployments/integration_test.toml b/config/deployments/integration_test.tomlindex c433a91ce0..ee06ec7880 100644--- a/config/deployments/integration_test.toml+++ b/config/deployments/integration_test.toml@@ -959,7 +959,7 @@ mollie = { long_lived_token = false, payment_method = "card" }payme = { long_lived_token = false, payment_method = "card" }square = { long_lived_token = false, payment_method = "card" }stax = { long_lived_token = true, payment_method = "card,bank_debit" }-stripe = { long_lived_token = false, payment_method = "wallet", payment_method_type = { list = "google_pay", type = "disable_only" } }+stripe = { long_lived_token = false, payment_method = "wallet", google_pay_pre_decrypt_flow = "connector_tokenization" ,payment_method_type = { list = "google_pay", type = "disable_only" }}billwerk = {long_lived_token = false, payment_method = "card"}globalpay = { long_lived_token = false, payment_method = "card", flow = "mandates" }dwolla = { long_lived_token = true, payment_method = "bank_debit" }diff --git a/config/deployments/production.toml b/config/deployments/production.tomlindex 609330c3b0..9ca339b20d 100644--- a/config/deployments/production.toml+++ b/config/deployments/production.toml@@ -970,7 +970,7 @@ mollie = { long_lived_token = false, payment_method = "card" }payme = { long_lived_token = false, payment_method = "card" }square = { long_lived_token = false, payment_method = "card" }stax = { long_lived_token = true, payment_method = "card,bank_debit" }-stripe = { long_lived_token = false, payment_method = "wallet", payment_method_type = { list = "google_pay", type = "disable_only" } }+stripe = { long_lived_token = false, payment_method = "wallet", google_pay_pre_decrypt_flow = "connector_tokenization" ,payment_method_type = { list = "google_pay", type = "disable_only" }}billwerk = {long_lived_token = false, payment_method = "card"}globalpay = { long_lived_token = false, payment_method = "card", flow = "mandates" }dwolla = { long_lived_token = true, payment_method = "bank_debit" }diff --git a/config/deployments/sandbox.toml b/config/deployments/sandbox.tomlindex 59a3e7b355..9b1f855780 100644--- a/config/deployments/sandbox.toml+++ b/config/deployments/sandbox.toml@@ -977,7 +977,7 @@ mollie = { long_lived_token = false, payment_method = "card" }payme = { long_lived_token = false, payment_method = "card" }square = { long_lived_token = false, payment_method = "card" }stax = { long_lived_token = true, payment_method = "card,bank_debit" }-stripe = { long_lived_token = false, payment_method = "wallet", payment_method_type = { list = "google_pay", type = "disable_only" } }+stripe = { long_lived_token = false, payment_method = "wallet", google_pay_pre_decrypt_flow = "connector_tokenization" ,payment_method_type = { list = "google_pay", type = "disable_only" }}billwerk = {long_lived_token = false, payment_method = "card"}globalpay = { long_lived_token = false, payment_method = "card", flow = "mandates" }dwolla = { long_lived_token = true, payment_method = "bank_debit" }diff --git a/config/development.toml b/config/development.tomlindex 5ca950de35..561c8cfeea 100644--- a/config/development.toml+++ b/config/development.toml@@ -1092,7 +1092,7 @@ payjustnow = { country = "ZA", currency = "ZAR" }payjustnow = { country = "ZA", currency = "ZAR" }[tokenization]-stripe = { long_lived_token = false, payment_method = "wallet", payment_method_type = { type = "disable_only", list = "google_pay" } }+stripe = { long_lived_token = false, payment_method = "wallet", google_pay_pre_decrypt_flow = "connector_tokenization" ,payment_method_type = { list = "google_pay", type = "disable_only" }}checkout = { long_lived_token = false, payment_method = "wallet", apple_pay_pre_decrypt_flow = "network_tokenization", google_pay_pre_decrypt_flow = "network_tokenization" }stax = { long_lived_token = true, payment_method = "card,bank_debit" }mollie = { long_lived_token = false, payment_method = "card" }diff --git a/crates/hyperswitch_connectors/src/connectors/stripe/transformers.rs b/crates/hyperswitch_connectors/src/connectors/stripe/transformers.rsindex 47dff203c4..a5b7d40ba3 100644--- a/crates/hyperswitch_connectors/src/connectors/stripe/transformers.rs+++ b/crates/hyperswitch_connectors/src/connectors/stripe/transformers.rs@@ -700,6 +700,7 @@ pub enum StripeWallet {Cashapp(CashappPayment),RevolutPay(RevolutpayPayment),ApplePayPredecryptToken(Box<StripeApplePayPredecrypt>),+ GooglePayPredecryptToken(Box<StripeGooglePayPredecrypt>),}#[derive(Debug, Eq, PartialEq, Serialize)]@@ -718,6 +719,22 @@ pub struct StripeApplePayPredecrypt {tokenization_method: String,}+#[derive(Debug, Eq, PartialEq, Serialize)]+pub struct StripeGooglePayPredecrypt {+ #[serde(rename = "card[number]")]+ number: cards::CardNumber,+ #[serde(rename = "card[exp_year]")]+ exp_year: Secret<String>,+ #[serde(rename = "card[exp_month]")]+ exp_month: Secret<String>,+ #[serde(rename = "card[cryptogram]")]+ cryptogram: Option<Secret<String>>,+ #[serde(rename = "card[eci]")]+ eci: Option<String>,+ #[serde(rename = "card[tokenization_method]")]+ tokenization_method: String,+}+#[derive(Debug, Eq, PartialEq, Serialize)]pub struct StripeApplePay {pub pk_token: Secret<String>,@@ -779,14 +796,6 @@ pub enum WechatClient {Web,}-#[derive(Debug, Eq, PartialEq, Serialize)]-pub struct GooglepayPayment {- #[serde(rename = "payment_method_data[card][token]")]- pub token: Secret<String>,- #[serde(rename = "payment_method_data[type]")]- pub payment_method_types: StripePaymentMethodType,-}-// All supported payment_method_types in stripe// This enum goes in payment_method_types[] field in stripe request body// https://stripe.com/docs/api/payment_intents/create#create_payment_intent-payment_method_types@@ -1784,7 +1793,9 @@ impl TryFrom<(&WalletData, Option<PaymentMethodToken>)> for StripePaymentMethodDpayment_method_types: StripePaymentMethodType::RevolutPay,})))}- WalletData::GooglePay(gpay_data) => Ok(Self::try_from(gpay_data)?),+ WalletData::GooglePay(gpay_data) => {+ Ok(Self::try_from((gpay_data, payment_method_token))?)+ }WalletData::PaypalRedirect(_) | WalletData::MobilePayRedirect(_) => Err(ConnectorError::NotImplemented(get_unimplemented_payment_method_error_message("stripe",@@ -1902,26 +1913,59 @@ impl TryFrom<&BankRedirectData> for StripePaymentMethodData {}}-impl TryFrom<&GooglePayWalletData> for StripePaymentMethodData {+impl TryFrom<(&GooglePayWalletData, Option<PaymentMethodToken>)> for StripePaymentMethodData {type Error = error_stack::Report<ConnectorError>;- fn try_from(gpay_data: &GooglePayWalletData) -> Result<Self, Self::Error> {- Ok(Self::Wallet(StripeWallet::GooglepayToken(GooglePayToken {- token: Secret::new(- gpay_data- .tokenization_data- .get_encrypted_google_pay_token()- .change_context(ConnectorError::MissingRequiredField {- field_name: "gpay wallet_token",- })?- .as_bytes()- .parse_struct::<StripeGpayToken>("StripeGpayToken")- .change_context(ConnectorError::InvalidWalletToken {- wallet_name: "Google Pay".to_string(),- })?- .id,- ),- payment_type: StripePaymentMethodType::Card,- })))+ fn try_from(+ (gpay_data, payment_method_token): (&GooglePayWalletData, Option<PaymentMethodToken>),+ ) -> Result<Self, error_stack::Report<ConnectorError>> {+ match payment_method_token {+ Some(PaymentMethodToken::GooglePayDecrypt(predecrypted_data)) => {+ // Use predecrypted token flow+ let expiry_year_4_digit = predecrypted_data+ .get_four_digit_expiry_year()+ .change_context(ConnectorError::InvalidDataFormat {+ field_name: "expiry_year_4_digit",+ })?;++ Ok(Self::Wallet(StripeWallet::GooglePayPredecryptToken(+ Box::new(StripeGooglePayPredecrypt {+ number: predecrypted_data.application_primary_account_number.clone(),+ exp_year: expiry_year_4_digit,+ exp_month: predecrypted_data.card_exp_month.clone(),+ eci: predecrypted_data.eci_indicator.clone(),+ cryptogram: predecrypted_data.cryptogram.clone(),+ tokenization_method: "android_pay".to_string(),+ }),+ )))+ }+ Some(PaymentMethodToken::Token(gpay_token)) => {+ // Use decrypted token flow+ Ok(Self::Wallet(StripeWallet::GooglepayToken(GooglePayToken {+ token: gpay_token,+ payment_type: StripePaymentMethodType::Card,+ })))+ }+ _ => {+ // Use encrypted token flow+ Ok(Self::Wallet(StripeWallet::GooglepayToken(GooglePayToken {+ token: Secret::new(+ gpay_data+ .tokenization_data+ .get_encrypted_google_pay_token()+ .change_context(ConnectorError::MissingRequiredField {+ field_name: "gpay wallet_token",+ })?+ .as_bytes()+ .parse_struct::<StripeGpayToken>("StripeGpayToken")+ .change_context(ConnectorError::InvalidWalletToken {+ wallet_name: "Google Pay".to_string(),+ })?+ .id,+ ),+ payment_type: StripePaymentMethodType::Card,+ })))+ }+ }}}diff --git a/crates/router/src/core/payments.rs b/crates/router/src/core/payments.rsindex b693866806..3d8ef993e0 100644--- a/crates/router/src/core/payments.rs+++ b/crates/router/src/core/payments.rs@@ -120,8 +120,6 @@ use crate::core::fraud_check as frm_core;#[cfg(any(feature = "v2", all(feature = "v1", feature = "pm_modular")))]use crate::core::payment_methods::vault;#[cfg(feature = "v2")]-use crate::core::revenue_recovery::get_workflow_entries;-#[cfg(feature = "v2")]use crate::core::revenue_recovery::map_to_recovery_payment_item;#[cfg(feature = "v1")]use crate::core::routing::helpers as routing_helpers;@@ -129,7 +127,8 @@ use crate::core::routing::helpers as routing_helpers;use crate::types::api::convert_connector_data_to_routable_connectors;use crate::{configs::settings::{- ApplePayPreDecryptFlow, GooglePayPreDecryptFlow, PaymentFlow, PaymentMethodTypeTokenFilter,+ ApplePayPreDecryptFlow, GooglePayPreDecryptFlow, PaymentFlow, PaymentMethodTokenFilter,+ PaymentMethodTypeTokenFilter,},consts,core::{@@ -162,6 +161,8 @@ use crate::{},workflows::payment_sync,};+#[cfg(feature = "v2")]+use crate::{core::revenue_recovery::get_workflow_entries, db::storage::payment_method};#[cfg(feature = "v1")]use crate::{core::{@@ -7804,6 +7805,7 @@ fn is_payment_method_tokenization_enabled_for_connector(payment_method: storage::enums::PaymentMethod,payment_method_type: Option<storage::enums::PaymentMethodType>,mandate_flow_enabled: storage_enums::FutureUsage,+ payment_method_token: Option<&PaymentMethodToken>,) -> RouterResult<bool> {let connector_tokenization_filter = state.conf.tokenization.0.get(connector_name);@@ -7815,7 +7817,8 @@ fn is_payment_method_tokenization_enabled_for_connector(.contains(&payment_method)&& is_payment_method_type_allowed_for_connector(payment_method_type,- connector_filter.payment_method_type.clone(),+ payment_method_token,+ connector_filter,)&& is_payment_flow_allowed_for_connector(mandate_flow_enabled,@@ -7857,18 +7860,9 @@ fn is_payment_method_tokenization_enabled_for_connector(.clone().contains(&payment_method)&& is_payment_method_type_allowed_for_connector(- payment_method_type,- connector_filter.payment_method_type.clone(),- )- && is_apple_pay_pre_decrypt_type_connector_tokenization(payment_method_type,payment_method_token,- connector_filter.apple_pay_pre_decrypt_flow.clone(),- )- && is_google_pay_pre_decrypt_type_connector_tokenization(- payment_method_type,- payment_method_token,- connector_filter.google_pay_pre_decrypt_flow.clone(),+ connector_filter,)&& is_payment_flow_allowed_for_connector(mandate_flow_enabled,@@ -7919,16 +7913,22 @@ fn is_apple_pay_pre_decrypt_type_connector_tokenization(payment_method_type: Option<storage::enums::PaymentMethodType>,payment_method_token: Option<&PaymentMethodToken>,apple_pay_pre_decrypt_flow_filter: Option<ApplePayPreDecryptFlow>,-) -> bool {- match (payment_method_type, payment_method_token) {+) -> Option<bool> {+ match (+ payment_method_type,+ payment_method_token,+ apple_pay_pre_decrypt_flow_filter,+ ) {(Some(storage::enums::PaymentMethodType::ApplePay),Some(PaymentMethodToken::ApplePayDecrypt(..)),- ) => !matches!(+ Some(apple_pay_pre_decrypt_flow_filter),+ ) => Some(matches!(apple_pay_pre_decrypt_flow_filter,- Some(ApplePayPreDecryptFlow::NetworkTokenization)- ),- _ => true,+ ApplePayPreDecryptFlow::ConnectorTokenization+ )),+ // not applicable+ _ => None,}}@@ -7936,21 +7936,22 @@ fn is_google_pay_pre_decrypt_type_connector_tokenization(payment_method_type: Option<storage::enums::PaymentMethodType>,payment_method_token: Option<&PaymentMethodToken>,google_pay_pre_decrypt_flow_filter: Option<GooglePayPreDecryptFlow>,-) -> bool {- if let (- Some(storage::enums::PaymentMethodType::GooglePay),- Some(PaymentMethodToken::GooglePayDecrypt(..)),- ) = (payment_method_type, payment_method_token)- {- !matches!(+) -> Option<bool> {+ match (+ payment_method_type,+ payment_method_token,+ google_pay_pre_decrypt_flow_filter,+ ) {+ (+ Some(storage::enums::PaymentMethodType::GooglePay),+ Some(PaymentMethodToken::GooglePayDecrypt(..)),+ Some(google_pay_pre_decrypt_flow_filter),+ ) => Some(matches!(google_pay_pre_decrypt_flow_filter,- Some(GooglePayPreDecryptFlow::NetworkTokenization)- )- } else {- // Always return true for non–Google Pay pre-decrypt cases,- // because the filter is only relevant for Google Pay pre-decrypt tokenization.- // Returning true ensures that other payment methods or token types are not blocked.- true+ GooglePayPreDecryptFlow::ConnectorTokenization+ )),+ // not applicable+ _ => None,}}@@ -8186,8 +8187,24 @@ fn get_google_pay_connector_wallet_details(fn is_payment_method_type_allowed_for_connector(current_pm_type: Option<storage::enums::PaymentMethodType>,- pm_type_filter: Option<PaymentMethodTypeTokenFilter>,+ payment_method_token: Option<&PaymentMethodToken>,+ connector_filter: &PaymentMethodTokenFilter,) -> bool {+ if let Some(apple_pay_enabled) = is_apple_pay_pre_decrypt_type_connector_tokenization(+ current_pm_type,+ payment_method_token,+ connector_filter.apple_pay_pre_decrypt_flow.clone(),+ ) {+ return apple_pay_enabled;+ }+ if let Some(google_pay_enabled) = is_google_pay_pre_decrypt_type_connector_tokenization(+ current_pm_type,+ payment_method_token,+ connector_filter.google_pay_pre_decrypt_flow.clone(),+ ) {+ return google_pay_enabled;+ }+ let pm_type_filter = connector_filter.payment_method_type.clone();match (current_pm_type).zip(pm_type_filter) {Some((pm_type, type_filter)) => match type_filter {PaymentMethodTypeTokenFilter::AllAccepted => true,diff --git a/crates/router/src/core/payments/operations/payment_confirm_intent.rs b/crates/router/src/core/payments/operations/payment_confirm_intent.rsindex 9e9620dad0..ade6a41678 100644--- a/crates/router/src/core/payments/operations/payment_confirm_intent.rs+++ b/crates/router/src/core/payments/operations/payment_confirm_intent.rs@@ -729,6 +729,7 @@ impl<F: Clone + Send + Sync> Domain<F, PaymentsConfirmIntentRequest, PaymentConfpayment_method,payment_method_type,mandate_flow_enabled,+ None,)?;if is_connector_tokenization_enabled {