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(pm-modular): add wallet flows (#11712)

Kashif5d2eeb7d5ae5
diff --git a/api-reference/v1/openapi_spec_v1.json b/api-reference/v1/openapi_spec_v1.json
index f364c81e83..e6ffcff243 100644
--- a/api-reference/v1/openapi_spec_v1.json
+++ b/api-reference/v1/openapi_spec_v1.json
@@ -28550,18 +28550,16 @@
},
"PaymentMethodDataWalletInfo": {
"type": "object",
- "required": [
- "last4",
- "card_network"
- ],
"properties": {
"last4": {
"type": "string",
- "description": "Last 4 digits of the card number"
+ "description": "Last 4 digits of the card number",
+ "nullable": true
},
"card_network": {
"type": "string",
- "description": "The information of the payment method"
+ "description": "The information of the payment method",
+ "nullable": true
},
"type": {
"type": "string",
@@ -28585,6 +28583,12 @@
"description": "Unique authorisation code for the payment",
"example": "003225",
"nullable": true
+ },
+ "email": {
+ "type": "string",
+ "description": "Email address associated with the wallet (e.g. PayPal email)",
+ "example": "[email protected]",
+ "nullable": true
}
}
},
@@ -42351,18 +42355,16 @@
},
"WalletAdditionalDataForCard": {
"type": "object",
- "required": [
- "last4",
- "card_network"
- ],
"properties": {
"last4": {
"type": "string",
- "description": "Last 4 digits of the card number"
+ "description": "Last 4 digits of the card number",
+ "nullable": true
},
"card_network": {
"type": "string",
- "description": "The information of the payment method"
+ "description": "The information of the payment method",
+ "nullable": true
},
"type": {
"type": "string",
@@ -42386,6 +42388,12 @@
"description": "Unique authorisation code generated for the payment",
"example": "009825",
"nullable": true
+ },
+ "email": {
+ "type": "string",
+ "description": "Email address associated with the wallet (e.g. PayPal email)",
+ "example": "[email protected]",
+ "nullable": true
}
}
},
diff --git a/api-reference/v2/openapi_spec_v2.json b/api-reference/v2/openapi_spec_v2.json
index 6f7f9e8abe..0bed3a4600 100644
--- a/api-reference/v2/openapi_spec_v2.json
+++ b/api-reference/v2/openapi_spec_v2.json
@@ -21264,6 +21264,17 @@
"$ref": "#/components/schemas/BankDebitDetail"
}
}
+ },
+ {
+ "type": "object",
+ "required": [
+ "wallet"
+ ],
+ "properties": {
+ "wallet": {
+ "$ref": "#/components/schemas/WalletPaymentMethodData"
+ }
+ }
}
]
},
@@ -21730,6 +21741,50 @@
}
]
},
+ "PaymentMethodDataWalletInfo": {
+ "type": "object",
+ "properties": {
+ "last4": {
+ "type": "string",
+ "description": "Last 4 digits of the card number",
+ "nullable": true
+ },
+ "card_network": {
+ "type": "string",
+ "description": "The information of the payment method",
+ "nullable": true
+ },
+ "type": {
+ "type": "string",
+ "description": "The type of payment method",
+ "nullable": true
+ },
+ "card_exp_month": {
+ "type": "string",
+ "description": "The card's expiry month",
+ "example": "10",
+ "nullable": true
+ },
+ "card_exp_year": {
+ "type": "string",
+ "description": "The card's expiry year",
+ "example": "25",
+ "nullable": true
+ },
+ "auth_code": {
+ "type": "string",
+ "description": "Unique authorisation code for the payment",
+ "example": "003225",
+ "nullable": true
+ },
+ "email": {
+ "type": "string",
+ "description": "Email address associated with the wallet (e.g. PayPal email)",
+ "example": "[email protected]",
+ "nullable": true
+ }
+ }
+ },
"PaymentMethodDeleteResponse": {
"type": "object",
"required": [
@@ -21881,6 +21936,17 @@
"$ref": "#/components/schemas/Bank"
}
}
+ },
+ {
+ "type": "object",
+ "required": [
+ "wallet"
+ ],
+ "properties": {
+ "wallet": {
+ "$ref": "#/components/schemas/WalletPaymentMethodData"
+ }
+ }
}
]
},
@@ -22073,6 +22139,17 @@
"$ref": "#/components/schemas/BankDebitDetailsPaymentMethod"
}
}
+ },
+ {
+ "type": "object",
+ "required": [
+ "wallet"
+ ],
+ "properties": {
+ "wallet": {
+ "$ref": "#/components/schemas/WalletPaymentMethodData"
+ }
+ }
}
]
},
@@ -31896,18 +31973,16 @@
},
"WalletAdditionalDataForCard": {
"type": "object",
- "required": [
- "last4",
- "card_network"
- ],
"properties": {
"last4": {
"type": "string",
- "description": "Last 4 digits of the card number"
+ "description": "Last 4 digits of the card number",
+ "nullable": true
},
"card_network": {
"type": "string",
- "description": "The information of the payment method"
+ "description": "The information of the payment method",
+ "nullable": true
},
"type": {
"type": "string",
@@ -31931,6 +32006,12 @@
"description": "Unique authorisation code generated for the payment",
"example": "009825",
"nullable": true
+ },
+ "email": {
+ "type": "string",
+ "description": "Email address associated with the wallet (e.g. PayPal email)",
+ "example": "[email protected]",
+ "nullable": true
}
}
},
@@ -32350,6 +32431,43 @@
}
]
},
+ "WalletPaymentMethodData": {
+ "oneOf": [
+ {
+ "type": "object",
+ "required": [
+ "apple_pay"
+ ],
+ "properties": {
+ "apple_pay": {
+ "$ref": "#/components/schemas/PaymentMethodDataWalletInfo"
+ }
+ }
+ },
+ {
+ "type": "object",
+ "required": [
+ "google_pay"
+ ],
+ "properties": {
+ "google_pay": {
+ "$ref": "#/components/schemas/PaymentMethodDataWalletInfo"
+ }
+ }
+ },
+ {
+ "type": "object",
+ "required": [
+ "pay_pal"
+ ],
+ "properties": {
+ "pay_pal": {
+ "$ref": "#/components/schemas/PaypalRedirection"
+ }
+ }
+ }
+ ]
+ },
"WalletResponse": {
"allOf": [
{
diff --git a/crates/api_models/src/payment_methods.rs b/crates/api_models/src/payment_methods.rs
index 928fab02e6..daf1b894b1 100644
--- a/crates/api_models/src/payment_methods.rs
+++ b/crates/api_models/src/payment_methods.rs
@@ -221,6 +221,9 @@ impl PaymentMethodIntentConfirm {
PaymentMethodCreateData::Card(_) | PaymentMethodCreateData::ProxyCard(_)
)
}
+ api_enums::PaymentMethod::Wallet => {
+ matches!(payment_method_data, PaymentMethodCreateData::Wallet(_))
+ }
_ => false,
}
}
@@ -528,6 +531,9 @@ impl PaymentMethodCreate {
api_enums::PaymentMethod::BankDebit => {
matches!(payment_method_data, PaymentMethodCreateData::BankDebit(_))
}
+ api_enums::PaymentMethod::Wallet => {
+ matches!(payment_method_data, PaymentMethodCreateData::Wallet(_))
+ }
_ => false,
}
}
@@ -602,6 +608,17 @@ pub enum BankDebitDetailUpdate {
},
}
+#[cfg(feature = "v2")]
+#[derive(Debug, serde::Deserialize, serde::Serialize, Clone, ToSchema)]
+#[serde(deny_unknown_fields)]
+#[serde(rename_all = "snake_case")]
+pub enum WalletPaymentMethodData {
+ ApplePay(Box<PaymentMethodDataWalletInfo>),
+ GooglePay(Box<PaymentMethodDataWalletInfo>),
+ #[schema(value_type = PaypalRedirection)]
+ PayPal(Box<payments::PaypalRedirection>),
+}
+
#[cfg(feature = "v2")]
#[derive(Debug, serde::Deserialize, serde::Serialize, Clone, ToSchema)]
#[serde(deny_unknown_fields)]
@@ -611,6 +628,7 @@ pub enum PaymentMethodCreateData {
Card(CardDetail),
ProxyCard(ProxyCardDetails),
BankDebit(BankDebitDetail),
+ Wallet(WalletPaymentMethodData),
}
#[cfg(feature = "v2")]
@@ -1126,8 +1144,9 @@ impl CardDetailUpdate {
#[serde(rename_all = "snake_case")]
#[serde(rename = "payment_method_data")]
pub enum PaymentMethodResponseData {
- Card(CardDetailFromLocker),
+ Card(Box<CardDetailFromLocker>),
BankDebit(BankDebitDetailsPaymentMethod),
+ Wallet(WalletPaymentMethodData),
}
#[cfg(feature = "v2")]
@@ -1430,6 +1449,27 @@ impl PaymentMethodsData {
}
}
+#[cfg(feature = "v2")]
+impl From<WalletPaymentMethodData> for PaymentMethodsData {
+ fn from(wallet_data: WalletPaymentMethodData) -> Self {
+ match wallet_data {
+ WalletPaymentMethodData::ApplePay(data) => Self::WalletDetails(*data),
+ WalletPaymentMethodData::GooglePay(data) => Self::WalletDetails(*data),
+ WalletPaymentMethodData::PayPal(data) => {
+ Self::WalletDetails(PaymentMethodDataWalletInfo {
+ last4: None,
+ card_network: None,
+ card_type: None,
+ card_exp_month: None,
+ card_exp_year: None,
+ auth_code: None,
+ email: data.email,
+ })
+ }
+ }
+ }
+}
+
#[derive(Clone, Debug, PartialEq, serde::Deserialize, serde::Serialize)]
pub struct ExternalVaultTokenData {
/// Tokenized reference for Card Number
@@ -1579,9 +1619,9 @@ pub struct PaymentMethodDataBankCreds {
#[derive(Clone, Debug, Eq, PartialEq, serde::Deserialize, serde::Serialize, ToSchema)]
pub struct PaymentMethodDataWalletInfo {
/// Last 4 digits of the card number
- pub last4: String,
+ pub last4: Option<String>,
/// The information of the payment method
- pub card_network: String,
+ pub card_network: Option<String>,
/// The type of payment method
#[serde(rename = "type")]
pub card_type: Option<String>,
@@ -1594,6 +1634,9 @@ pub struct PaymentMethodDataWalletInfo {
/// Unique authorisation code for the payment
#[schema(value_type = Option<String>,example = "003225")]
pub auth_code: Option<String>,
+ /// Email address associated with the wallet (e.g. PayPal email)
+ #[schema(value_type = Option<String>, example = "[email protected]")]
+ pub email: Option<pii::Email>,
}
impl From<payments::additional_info::WalletAdditionalDataForCard> for PaymentMethodDataWalletInfo {
@@ -1605,6 +1648,7 @@ impl From<payments::additional_info::WalletAdditionalDataForCard> for PaymentMet
card_exp_month: item.card_exp_month,
card_exp_year: item.card_exp_year,
auth_code: item.auth_code,
+ email: item.email,
}
}
}
@@ -1618,6 +1662,7 @@ impl From<PaymentMethodDataWalletInfo> for payments::additional_info::WalletAddi
card_exp_month: item.card_exp_month,
card_exp_year: item.card_exp_year,
auth_code: item.auth_code,
+ email: item.email,
}
}
}
@@ -1625,20 +1670,22 @@ impl From<PaymentMethodDataWalletInfo> for payments::additional_info::WalletAddi
impl From<payments::ApplepayPaymentMethod> for PaymentMethodDataWalletInfo {
fn from(item: payments::ApplepayPaymentMethod) -> Self {
Self {
- last4: item
- .display_name
- .chars()
- .rev()
- .take(4)
- .collect::<Vec<_>>()
- .into_iter()
- .rev()
- .collect(),
- card_network: item.network,
+ last4: Some(
+ item.display_name
+ .chars()
+ .rev()
+ .take(4)
+ .collect::<Vec<_>>()
+ .into_iter()
+ .rev()
+ .collect(),
+ ),
+ card_network: Some(item.network),
card_type: Some(item.pm_type),
card_exp_month: item.card_exp_month,
card_exp_year: item.card_exp_year,
auth_code: item.auth_code,
+ email: None,
}
}
}
@@ -1647,8 +1694,8 @@ impl TryFrom<PaymentMethodDataWalletInfo> for Box<payments::ApplepayPaymentMetho
type Error = error_stack::Report<errors::ValidationError>;
fn try_from(item: PaymentMethodDataWalletInfo) -> Result<Self, Self::Error> {
Ok(Self::new(payments::ApplepayPaymentMethod {
- display_name: item.last4,
- network: item.card_network,
+ display_name: item.last4.get_required_value("last4")?,
+ network: item.card_network.get_required_value("card_network")?,
pm_type: item.card_type.get_required_value("card_type")?,
card_exp_month: item.card_exp_month,
card_exp_year: item.card_exp_year,
@@ -3091,6 +3138,7 @@ pub enum PaymentMethodListData {
#[cfg(feature = "payouts")]
#[schema(value_type = Bank)]
Bank(payouts::Bank),
+ Wallet(WalletPaymentMethodData),
}
#[cfg(feature = "v1")]
diff --git a/crates/api_models/src/payments.rs b/crates/api_models/src/payments.rs
index e22471f88d..13b3d25269 100644
--- a/crates/api_models/src/payments.rs
+++ b/crates/api_models/src/payments.rs
@@ -9319,21 +9319,24 @@ impl From<AdditionalPaymentData> for PaymentMethodDataResponse {
(Some(apple_pay_pm), _, _) => Self::Wallet(Box::new(WalletResponse {
details: Some(WalletResponseData::ApplePay(Box::new(
WalletAdditionalDataForCard {
- last4: apple_pay_pm
- .display_name
- .clone()
- .chars()
- .rev()
- .take(4)
- .collect::<String>()
- .chars()
- .rev()
- .collect::<String>(),
- card_network: apple_pay_pm.network.clone(),
+ last4: Some(
+ apple_pay_pm
+ .display_name
+ .clone()
+ .chars()
+ .rev()
+ .take(4)
+ .collect::<String>()
+ .chars()
+ .rev()
+ .collect::<String>(),
+ ),
+ card_network: Some(apple_pay_pm.network.clone()),
card_type: Some(apple_pay_pm.pm_type.clone()),
card_exp_month: apple_pay_pm.card_exp_month,
card_exp_year: apple_pay_pm.card_exp_year,
auth_code: apple_pay_pm.auth_code,
+ email: None,
},
))),
})),
diff --git a/crates/api_models/src/payments/additional_info.rs b/crates/api_models/src/payments/additional_info.rs
index a2adc863c5..3549f937da 100644
--- a/crates/api_models/src/payments/additional_info.rs
+++ b/crates/api_models/src/payments/additional_info.rs
@@ -405,11 +405,11 @@ pub struct UpiCollectAdditionalData {
#[smithy(namespace = "com.hyperswitch.smithy.types")]
pub struct WalletAdditionalDataForCard {
/// Last 4 digits of the card number
- #[smithy(value_type = "String")]
- pub last4: String,
+ #[smithy(value_type = "Option<String>")]
+ pub last4: Option<String>,
/// The information of the payment method
- #[smithy(value_type = "String")]
- pub card_network: String,
+ #[smithy(value_type = "Option<String>")]
+ pub card_network: Option<String>,
/// The type of payment method
#[serde(rename = "type")]
#[smithy(value_type = "Option<String>")]
@@ -423,4 +423,7 @@ pub struct WalletAdditionalDataForCard {
/// Unique authorisation code generated for the payment
#[schema(value_type = Option<String>, example = "009825")]
pub auth_code: Option<String>,
+ /// Email address associated with the wallet (e.g. PayPal email)
+ #[schema(value_type = Option<String>, example = "[email protected]")]
+ pub email: Option<common_utils::pii::Email>,
}
diff --git a/crates/hyperswitch_domain_models/src/payment_method_data.rs b/crates/hyperswitch_domain_models/src/payment_method_data.rs
index d942695efe..9eb56c7250 100644
--- a/crates/hyperswitch_domain_models/src/payment_method_data.rs
+++ b/crates/hyperswitch_domain_models/src/payment_method_data.rs
@@ -1751,12 +1751,6 @@ impl TryFrom<payment_methods::PaymentMethodCreateData> for PaymentMethodData {
card_holder_name,
co_badged_card_data: None,
})),
- payment_methods::PaymentMethodCreateData::ProxyCard(_) => Err(
- common_utils::errors::ValidationError::IncorrectValueProvided {
- field_name: "Payment method data",
- }
- .into(),
- ),
payment_methods::PaymentMethodCreateData::BankDebit(
payment_methods::BankDebitDetail::Ach {
account_number,
@@ -1774,6 +1768,18 @@ impl TryFrom<payment_methods::PaymentMethodCreateData> for PaymentMethodData {
bank_type,
bank_holder_type,
})),
+ payment_methods::PaymentMethodCreateData::ProxyCard(_) => Err(
+ common_utils::errors::ValidationError::IncorrectValueProvided {
+ field_name: "Payment method data",
+ }
+ .into(),
+ ),
+ payment_methods::PaymentMethodCreateData::Wallet(_) => Err(
+ common_utils::errors::ValidationError::IncorrectValueProvided {
+ field_name: "Payment method data",
+ }
+ .into(),
+ ),
}
}
}
@@ -3440,22 +3446,24 @@ pub fn get_applepay_wallet_info(
_ => (None, None),
};
payment_methods::PaymentMethodDataWalletInfo {
- last4: item
- .payment_method
- .display_name
- .chars()
- .rev()
- .take(4)
- .collect::<Vec<_>>()
- .into_iter()
- .rev()
- .collect(),
- card_network: item.payment_method.network,
+ last4: Some(
+ item.payment_method
+ .display_name
+ .chars()
+ .rev()
+ .take(4)
+ .collect::<Vec<_>>()
+ .into_iter()
+ .rev()
+ .collect(),
+ ),
+ card_network: Some(item.payment_method.network),
card_type: Some(item.payment_method.pm_type),
card_exp_month,
card_exp_year,
// To be populated after connector response
auth_code: None,
+ email: None,
}
}
@@ -3471,13 +3479,14 @@ pub fn get_googlepay_wallet_info(
_ => (None, None),
};
payment_methods::PaymentMethodDataWalletInfo {
- last4: item.info.card_details,
- card_network: item.info.card_network,
+ last4: Some(item.info.card_details),
+ card_network: Some(item.info.card_network),
card_type: Some(item.pm_type),
card_exp_month,
card_exp_year,
// to be populated after connector response
auth_code: None,
+ email: None,
}
}
diff --git a/crates/hyperswitch_domain_models/src/payment_methods.rs b/crates/hyperswitch_domain_models/src/payment_methods.rs
index 8658abadea..36df49150d 100644
--- a/crates/hyperswitch_domain_models/src/payment_methods.rs
+++ b/crates/hyperswitch_domain_models/src/payment_methods.rs
@@ -423,7 +423,8 @@ impl
bank_account_holder_name: bank_account_holder_name.clone(),
},
)),
- payment_methods::PaymentMethodCreateData::ProxyCard(_) => None,
+ payment_methods::PaymentMethodCreateData::ProxyCard(_)
+ | payment_methods::PaymentMethodCreateData::Wallet(_) => None,
};
Self {
diff --git a/crates/hyperswitch_domain_models/src/vault.rs b/crates/hyperswitch_domain_models/src/vault.rs
index 91e608ae01..c7637b86f3 100644
--- a/crates/hyperswitch_domain_models/src/vault.rs
+++ b/crates/hyperswitch_domain_models/src/vault.rs
@@ -342,15 +342,21 @@ impl TryFrom<payment_methods::PaymentMethodCreateData> for PaymentMethodVaulting
..card
}))
}
+ payment_methods::PaymentMethodCreateData::BankDebit(bank_debit) => {
+ Ok(Self::BankDebit(bank_debit.into()))
+ }
payment_methods::PaymentMethodCreateData::ProxyCard(card) => Err(
errors::api_error_response::ApiErrorResponse::UnprocessableEntity {
message: "Proxy Card for PaymentMethodCreateData".to_string(),
}
.into(),
),
- payment_methods::PaymentMethodCreateData::BankDebit(bank_debit) => {
- Ok(Self::BankDebit(bank_debit.into()))
- }
+ payment_methods::PaymentMethodCreateData::Wallet(_) => Err(
+ errors::api_error_response::ApiErrorResponse::UnprocessableEntity {
+ message: "Wallet for PaymentMethodCreateData".to_string(),
+ }
+ .into(),
+ ),
}
}
}
diff --git a/crates/openapi/src/openapi_v2.rs b/crates/openapi/src/openapi_v2.rs
index 614e9de764..0ae55ea9ef 100644
--- a/crates/openapi/src/openapi_v2.rs
+++ b/crates/openapi/src/openapi_v2.rs
@@ -326,6 +326,8 @@ Never share your secret api keys. Keep them guarded and secure.
api_models::payment_methods::NetworkTokenStatusCheckFailureResponse,
api_models::payment_methods::PaymentMethodGetTokenDetailsResponse,
api_models::payment_methods::RawCardWithNTDetails,
+ api_models::payment_methods::PaymentMethodDataWalletInfo,
+ api_models::payment_methods::WalletPaymentMethodData,
api_models::enums::TokenStatus,
api_models::poll::PollResponse,
api_models::poll::PollStatus,
diff --git a/crates/payment_methods/src/client/create.rs b/crates/payment_methods/src/client/create.rs
index 4cd321c217..43585997f7 100644
--- a/crates/payment_methods/src/client/create.rs
+++ b/crates/payment_methods/src/client/create.rs
@@ -12,7 +12,7 @@ use hyperswitch_masking::Secret;
use serde::{Deserialize, Serialize};
use time::PrimitiveDateTime;
-use crate::types::{BankDebitDetail, BankDebitDetailsPaymentMethod};
+use crate::types::{BankDebitDetail, PaymentMethodResponseData};
/// V1-facing create flow type.
#[derive(Debug)]
@@ -61,11 +61,20 @@ pub struct CardDetail {
pub card_cvc: Option<Secret<String>>,
}
+#[derive(Debug, Clone, Serialize, Deserialize)]
+#[serde(rename_all = "snake_case")]
+pub enum WalletPaymentMethodData {
+ ApplePay(Box<api_models::payment_methods::PaymentMethodDataWalletInfo>),
+ GooglePay(Box<api_models::payment_methods::PaymentMethodDataWalletInfo>),
+ PayPal(Box<payments::PaypalRedirection>),
+}
+
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum PaymentMethodCreateData {
Card(CardDetail),
BankDebit(BankDebitDetail),
+ Wallet(WalletPaymentMethodData),
}
#[derive(Clone, Debug, Deserialize)]
@@ -88,13 +97,6 @@ pub struct ModularPaymentMethodResponse {
pub billing: Option<hyperswitch_domain_models::address::Address>,
}
-#[derive(Debug, serde::Deserialize, serde::Serialize, Clone)]
-#[serde(rename_all = "snake_case")]
-pub enum PaymentMethodResponseData {
- Card(Box<api_models::payment_methods::CardDetailFromLocker>),
- BankDebit(BankDebitDetailsPaymentMethod),
-}
-
#[derive(Clone, Debug)]
pub struct CreatePaymentMethodResponse {
//payment method id
@@ -173,6 +175,62 @@ impl TryFrom<PaymentMethodData> for PaymentMethodCreateData {
),
}),
},
+ PaymentMethodData::Wallet(wallet_data) => match wallet_data {
+ hyperswitch_domain_models::payment_method_data::WalletData::ApplePay(apple_pay) => {
+ let wallet_info = api_models::payment_methods::PaymentMethodDataWalletInfo {
+ last4: Some(
+ apple_pay
+ .payment_method
+ .display_name
+ .chars()
+ .rev()
+ .take(4)
+ .collect::<Vec<_>>()
+ .into_iter()
+ .rev()
+ .collect(),
+ ),
+ card_network: Some(apple_pay.payment_method.network.clone()),
+ card_type: Some(apple_pay.payment_method.pm_type.clone()),
+ card_exp_month: None,
+ card_exp_year: None,
+ auth_code: None,
+ email: None,
+ };
+ Ok(Self::Wallet(WalletPaymentMethodData::ApplePay(Box::new(
+ wallet_info,
+ ))))
+ }
+ hyperswitch_domain_models::payment_method_data::WalletData::GooglePay(
+ google_pay,
+ ) => {
+ let wallet_info = api_models::payment_methods::PaymentMethodDataWalletInfo {
+ last4: Some(google_pay.info.card_details.clone()),
+ card_network: Some(google_pay.info.card_network.clone()),
+ card_type: Some(google_pay.pm_type.clone()),
+ card_exp_month: None,
+ card_exp_year: None,
+ auth_code: None,
+ email: None,
+ };
+ Ok(Self::Wallet(WalletPaymentMethodData::GooglePay(Box::new(
+ wallet_info,
+ ))))
+ }
+ hyperswitch_domain_models::payment_method_data::WalletData::PaypalRedirect(
+ paypal,
+ ) => Ok(Self::Wallet(WalletPaymentMethodData::PayPal(Box::new(
+ payments::PaypalRedirection {
+ email: paypal.email,
+ },
+ )))),
+ _ => Err(MicroserviceClientError {
+ operation: "PaymentMethodCreateData::try_from".to_string(),
+ kind: MicroserviceClientErrorKind::InvalidRequest(
+ "Unsupported wallet type for modular PM creation".to_string(),
+ ),
+ }),
+ },
_ => Err(MicroserviceClientError {
operation: "CreatePaymentMethodV1Request to ModularPMCreateRequest".to_string(),
kind: MicroserviceClientErrorKind::InvalidRequest(
diff --git a/crates/payment_methods/src/client/list.rs b/crates/payment_methods/src/client/list.rs
index 7a8a293f97..e92372cdba 100644
--- a/crates/payment_methods/src/client/list.rs
+++ b/crates/payment_methods/src/client/list.rs
@@ -53,6 +53,7 @@ impl TryFrom<ModularListCustomerPaymentMethodsResponse> for ListCustomerPaymentM
card: pm.payment_method_data.and_then(|data| match data {
PaymentMethodResponseData::Card(card_detail) => Some(*card_detail),
PaymentMethodResponseData::BankDebit(_) => None,
+ PaymentMethodResponseData::Wallet(_) => None,
}),
metadata: None,
created: Some(pm.created),
diff --git a/crates/payment_methods/src/types.rs b/crates/payment_methods/src/types.rs
index ad25246ea6..6d2950de10 100644
--- a/crates/payment_methods/src/types.rs
+++ b/crates/payment_methods/src/types.rs
@@ -35,6 +35,16 @@ pub struct PaymentMethodResponseItem {
pub network_tokenization: Option<NetworkTokenResponse>,
pub psp_tokenization_enabled: bool,
}
+
+#[derive(Clone, Debug, Deserialize)]
+#[serde(deny_unknown_fields)]
+#[serde(rename_all = "snake_case")]
+pub enum WalletPaymentMethodData {
+ ApplePay(Box<api_models::payment_methods::PaymentMethodDataWalletInfo>),
+ GooglePay(Box<api_models::payment_methods::PaymentMethodDataWalletInfo>),
+ PayPal(Box<api_models::payments::PaypalRedirection>),
+}
+
/// V2 PaymentMethodResponseData enum
#[derive(Clone, Debug, Deserialize)]
#[serde(deny_unknown_fields)]
@@ -42,6 +52,7 @@ pub struct PaymentMethodResponseItem {
pub enum PaymentMethodResponseData {
Card(Box<CardDetailFromLocker>),
BankDebit(BankDebitDetailsPaymentMethod),
+ Wallet(WalletPaymentMethodData),
}
#[derive(Deserialize, Serialize, Debug, Clone)]
diff --git a/crates/router/src/core/payment_methods.rs b/crates/router/src/core/payment_methods.rs
index e44c2f8bdc..849aeab519 100644
--- a/crates/router/src/core/payment_methods.rs
+++ b/crates/router/src/core/payment_methods.rs
@@ -1216,6 +1216,21 @@ pub async fn create_persistent_payment_method_core(
)
.await
}
+ api::PaymentMethodCreateData::Wallet(wallet_data) => {
+ let additional_data = payment_methods::PaymentMethodsData::from(wallet_data.clone());
+ create_payment_method_wallet_core(
+ state,
+ req,
+ platform,
+ profile,
+ merchant_id,
+ &customer_id,
+ payment_method_id,
+ payment_method_billing_address,
+ additional_data,
+ )
+ .await
+ }
}
}
@@ -1295,6 +1310,11 @@ pub async fn create_volatile_payment_method_core(
message: "Proxy card payment method cannot be created as volatile".to_string()
}))
}
+ api::PaymentMethodCreateData::Wallet(_) => {
+ Err(report!(errors::ApiErrorResponse::UnprocessableEntity {
+ message: "Wallet payment method cannot be created as volatile".to_string()
+ }))
+ }
}
}
@@ -1899,6 +1919,121 @@ pub async fn create_generic_volatile_payment_method(
Ok((response, payment_method))
}
+#[cfg(feature = "v2")]
+#[allow(clippy::too_many_arguments)]
+#[instrument(skip_all)]
+pub async fn create_payment_method_wallet_core(
+ state: &SessionState,
+ req: api::PaymentMethodCreate,
+ platform: &domain::Platform,
+ _profile: &domain::Profile,
+ merchant_id: &id_type::MerchantId,
+ customer_id: &id_type::GlobalCustomerId,
+ payment_method_id: id_type::GlobalPaymentMethodId,
+ payment_method_billing_address: Option<
+ Encryptable<hyperswitch_domain_models::address::Address>,
+ >,
+ additional_payment_method_data: payment_methods::PaymentMethodsData,
+) -> RouterResult<(api::PaymentMethodResponse, domain::PaymentMethod)> {
+ use crate::core::payment_methods::cards;
+
+ let db = &*state.store;
+ let key_manager_state = &(state).into();
+
+ let encrypted_payment_method_data = Some(additional_payment_method_data)
+ .async_map(|payment_method_data| {
+ cards::create_encrypted_data(
+ key_manager_state,
+ platform.get_provider().get_key_store(),
+ payment_method_data,
+ )
+ })
+ .await
+ .transpose()
+ .change_context(errors::ApiErrorResponse::InternalServerError)
+ .attach_printable("Unable to encrypt wallet payment method data")?
+ .map(|encoded_pmd| {
+ encoded_pmd.deserialize_inner_value(|value| value.parse_value("PaymentMethodsData"))
+ })
+ .transpose()
+ .change_context(errors::ApiErrorResponse::InternalServerError)
+ .attach_printable("Unable to parse wallet payment method data")?;
+
+ let existing_payment_methods = db
+ .find_payment_method_by_global_customer_id_merchant_id_statuses(
+ platform.get_provider().get_key_store(),
+ customer_id,
+ merchant_id,
+ vec![
+ enums::PaymentMethodStatus::Active,
+ enums::PaymentMethodStatus::New,
+ ],
+ None,
+ platform.get_provider().get_account().storage_scheme,
+ )
+ .await;
+
+ let existing_wallet_pm = existing_payment_methods.ok().and_then(|pms| {
+ pms.into_iter()
+ .find(|pm| pm.get_payment_method_subtype() == req.payment_method_subtype)
+ });
+
+ let payment_method = match existing_wallet_pm {
+ Some(existing_pm) => {
+ let pm_update = storage::PaymentMethodUpdate::PaymentMethodDataUpdate {
+ payment_method_data: encrypted_payment_method_data.map(From::from),
+ last_modified_by: platform
+ .get_initiator()
+ .and_then(|initiator| initiator.to_created_by())
+ .map(|last_modified_by| last_modified_by.to_string()),
+ };
+
+ db.update_payment_method(
+ platform.get_provider().get_key_store(),
+ existing_pm,
+ pm_update,
+ platform.get_provider().get_account().storage_scheme,
+ )
+ .await
+ .change_context(errors::ApiErrorResponse::InternalServerError)
+ .attach_printable("Failed to update existing wallet payment method in db")?
+ }
+ None => {
+ create_payment_method_for_confirm(
+ state,
+ customer_id,
+ payment_method_id,
+ None,
+ merchant_id,
+ platform.get_provider().get_key_store(),
+ platform.get_provider().get_account().storage_scheme,
+ req.payment_method_type,
+ req.payment_method_subtype,
+ payment_method_billing_address,
+ encrypted_payment_method_data,
+ None,
+ None,
+ platform.get_initiator(),
+ enums::PaymentMethodStatus::New,
+ )
+ .await?
+ }
+ };
+
+ let payment_method_response = pm_transforms::generate_payment_method_response(
+ &payment_method,
+ &None,
+ req.storage_type,
+ None,
+ req.customer_id,
+ None,
+ None,
+ None,
+ )?;
+
+ Ok((payment_method_response, payment_method))
+}
+
// network tokenization and vaulting to locker is not required for proxy card since the card is already tokenized
#[cfg(feature = "v2")]
#[allow(clippy::too_many_arguments)]
@@ -1999,6 +2134,7 @@ pub async fn create_payment_method_proxy_card_core(
encrypted_external_vault_token_data,
vault_type,
platform.get_initiator(),
+ enums::PaymentMethodStatus::Inactive,
)
.await?;
@@ -2353,6 +2489,27 @@ impl PaymentMethodExt for payment_methods::PaymentMethodCreateData {
Self::BankDebit(bank_debit_details) => Ok(
payment_methods::PaymentMethodsData::BankDebit(bank_debit_details.clone().into()),
),
+ Self::Wallet(wallet_data) => match wallet_data {
+ api::WalletPaymentMethodData::ApplePay(data) => {
+ Ok(payment_methods::PaymentMethodsData::WalletDetails(*data))
+ }
+ api::WalletPaymentMethodData::GooglePay(data) => {
+ Ok(payment_methods::PaymentMethodsData::WalletDetails(*data))
+ }
+ api::WalletPaymentMethodData::PayPal(data) => {
+ Ok(payment_methods::PaymentMethodsData::WalletDetails(
+ payment_methods::PaymentMethodDataWalletInfo {
+ last4: None,
+ card_network: None,
+ card_type: None,
+ card_exp_month: None,
+ card_exp_year: None,
+ auth_code: None,
+ email: data.email,
+ },
+ ))
+ }
+ },
}
}
@@ -2361,7 +2518,7 @@ impl PaymentMethodExt for payment_methods::PaymentMethodCreateData {
Self::ProxyCard(card_details) => Some(payment_methods::ExternalVaultTokenData {
tokenized_card_number: card_details.card_number,
}),
- Self::Card(_) | Self::BankDebit(_) => None,
+ Self::Card(_) | Self::BankDebit(_) | Self::Wallet(_) => None,
}
}
}
@@ -2969,6 +3126,7 @@ pub async fn create_payment_method_for_confirm(
>,
vault_type: Option<common_enums::VaultType>,
initiator: Option<&domain::Initiator>,
+ status: enums::PaymentMethodStatus,
) -> CustomResult<domain::PaymentMethod, errors::ApiErrorResponse> {
let db = &*state.store;
let current_time = common_utils::date_time::now();
@@ -2987,7 +3145,7 @@ pub async fn create_payment_method_for_confirm(
connector_mandate_details: None,
customer_acceptance: None,
client_secret: None,
- status: enums::PaymentMethodStatus::Inactive,
+ status,
network_transaction_id: None,
created_at: current_time,
last_modified: current_time,
@@ -4257,26 +4415,34 @@ impl RawPaymentMethodFetchAccess {
}
Self::Allowed => {
- let vault_data = vault::retrieve_payment_method_data_from_storage(
- state,
- platform,
- profile,
- payment_method,
- storage_type,
- )
- .await
- .change_context(errors::ApiErrorResponse::InternalServerError)
- .attach_printable("Failed to retrieve payment method from vault")?
- .data;
+ let is_wallet =
+ payment_method.payment_method_type == Some(enums::PaymentMethod::Wallet);
- let payment_method_vault_data = vault_data
- .populated_payment_methods_data_and_get_payment_method_vaulting_data(
- payment_method.payment_method_data.as_ref(),
+ if is_wallet {
+ logger::debug!("Skipping raw payment method fetch for wallet payment method");
+ Ok(None)
+ } else {
+ let vault_data = vault::retrieve_payment_method_data_from_storage(
+ state,
+ platform,
+ profile,
+ payment_method,
+ storage_type,
)
- .attach_printable(
- "Failed to get card details for payment method vaulting data",
- )?;
- Ok(Some(payment_method_vault_data))
+ .await
+ .change_context(errors::ApiErrorResponse::InternalServerError)
+ .attach_printable("Failed to retrieve payment method from vault")?
+ .data;
+
+ let data = vault_data
+ .populated_payment_methods_data_and_get_payment_method_vaulting_data(
+ payment_method.payment_method_data.as_ref(),
+ )
+ .attach_printable(
+ "Failed to get card details for payment method vaulting data",
+ )?;
+ Ok(Some(data))
+ }
}
}
}
diff --git a/crates/router/src/core/payment_methods/transformers.rs b/crates/router/src/core/payment_methods/transformers.rs
index c4468c1a24..120d91d4fb 100644
--- a/crates/router/src/core/payment_methods/transformers.rs
+++ b/crates/router/src/core/payment_methods/transformers.rs
@@ -1,7 +1,10 @@
pub use ::payment_methods::controller::{DataDuplicationCheck, DeleteCardResp};
use api_models::payment_methods::Card;
#[cfg(feature = "v2")]
-use api_models::{enums as api_enums, payment_methods::PaymentMethodResponseItem};
+use api_models::{
+ enums as api_enums,
+ payment_methods::{PaymentMethodResponseItem, WalletPaymentMethodData},
+};
use common_enums::CardNetwork;
#[cfg(feature = "v1")]
use common_utils::{crypto::Encryptable, request::Headers, types::keymanager::KeyManagerState};
@@ -623,11 +626,31 @@ pub fn generate_payment_method_response(
.map(|data| data.into_inner())
.and_then(|data| match data {
payment_method_data::PaymentMethodsData::Card(card) => Some(
- api::PaymentMethodResponseData::Card(card.to_card_details_from_locker()),
+ api::PaymentMethodResponseData::Card(Box::new(card.to_card_details_from_locker())),
),
payment_method_data::PaymentMethodsData::BankDebit(bank_debit) => {
Some(api::PaymentMethodResponseData::BankDebit(bank_debit.into()))
}
+ payment_method_data::PaymentMethodsData::WalletDetails(info) => {
+ match payment_method.payment_method_subtype {
+ Some(common_enums::PaymentMethodType::ApplePay) => {
+ Some(api::PaymentMethodResponseData::Wallet(
+ WalletPaymentMethodData::ApplePay(Box::new(info)),
+ ))
+ }
+ Some(common_enums::PaymentMethodType::GooglePay) => {
+ Some(api::PaymentMethodResponseData::Wallet(
+ WalletPaymentMethodData::GooglePay(Box::new(info)),
+ ))
+ }
+ Some(common_enums::PaymentMethodType::Paypal) => Some(
+ api::PaymentMethodResponseData::Wallet(WalletPaymentMethodData::PayPal(
+ Box::new(api_models::payments::PaypalRedirection { email: info.email }),
+ )),
+ ),
+ _ => None,
+ }
+ }
_ => None,
});
let mut connector_tokens = payment_method
@@ -901,19 +924,42 @@ impl transformers::ForeignTryFrom<(domain::PaymentMethod, String)>
let payment_method_data = item
.payment_method_data
.map(|payment_method_data| payment_method_data.into_inner())
- .map(|payment_method_data| match payment_method_data {
+ .and_then(|payment_method_data| match payment_method_data {
payment_method_data::PaymentMethodsData::Card(card_details_payment_method) => {
let card_details = card_details_payment_method.to_card_details_from_locker();
- api_models::payment_methods::PaymentMethodListData::Card(card_details)
+ Some(api_models::payment_methods::PaymentMethodListData::Card(
+ card_details,
+ ))
}
payment_method_data::PaymentMethodsData::BankDetails(..) => todo!(),
- payment_method_data::PaymentMethodsData::BankDebit(bank_debit_details) => {
+ payment_method_data::PaymentMethodsData::BankDebit(bank_debit_details) => Some(
api_models::payment_methods::PaymentMethodListData::BankDebit(
bank_debit_details.into(),
- )
+ ),
+ ),
+ payment_method_data::PaymentMethodsData::WalletDetails(info) => {
+ match payment_method_subtype {
+ api_enums::PaymentMethodType::ApplePay => {
+ Some(api_models::payment_methods::PaymentMethodListData::Wallet(
+ WalletPaymentMethodData::ApplePay(Box::new(info)),
+ ))
+ }
+ api_enums::PaymentMethodType::GooglePay => {
+ Some(api_models::payment_methods::PaymentMethodListData::Wallet(
+ WalletPaymentMethodData::GooglePay(Box::new(info)),
+ ))
+ }
+ api_enums::PaymentMethodType::Paypal => {
+ Some(api_models::payment_methods::PaymentMethodListData::Wallet(
+ WalletPaymentMethodData::PayPal(Box::new(
+ api_models::payments::PaypalRedirection { email: info.email },
+ )),
+ ))
+ }
+ _ => None,
+ }
}
- payment_method_data::PaymentMethodsData::WalletDetails(..)
- | payment_method_data::PaymentMethodsData::NetworkToken(_) => {
+ payment_method_data::PaymentMethodsData::NetworkToken(_) => {
todo!()
}
});
@@ -971,19 +1017,42 @@ impl transformers::ForeignTryFrom<domain::PaymentMethod> for PaymentMethodRespon
let payment_method_data = item
.payment_method_data
.map(|payment_method_data| payment_method_data.into_inner())
- .map(|payment_method_data| match payment_method_data {
+ .and_then(|payment_method_data| match payment_method_data {
payment_method_data::PaymentMethodsData::Card(card_details_payment_method) => {
let card_details = card_details_payment_method.to_card_details_from_locker();
- api_models::payment_methods::PaymentMethodListData::Card(card_details)
+ Some(api_models::payment_methods::PaymentMethodListData::Card(
+ card_details,
+ ))
}
payment_method_data::PaymentMethodsData::BankDetails(..) => todo!(),
- payment_method_data::PaymentMethodsData::BankDebit(bank_debit_details) => {
+ payment_method_data::PaymentMethodsData::BankDebit(bank_debit_details) => Some(
api_models::payment_methods::PaymentMethodListData::BankDebit(
bank_debit_details.into(),
- )
+ ),
+ ),
+ payment_method_data::PaymentMethodsData::WalletDetails(info) => {
+ match payment_method_subtype {
+ api_enums::PaymentMethodType::ApplePay => {
+ Some(api_models::payment_methods::PaymentMethodListData::Wallet(
+ WalletPaymentMethodData::ApplePay(Box::new(info)),
+ ))
+ }
+ api_enums::PaymentMethodType::GooglePay => {
+ Some(api_models::payment_methods::PaymentMethodListData::Wallet(
+ WalletPaymentMethodData::GooglePay(Box::new(info)),
+ ))
+ }
+ api_enums::PaymentMethodType::Paypal => {
+ Some(api_models::payment_methods::PaymentMethodListData::Wallet(
+ WalletPaymentMethodData::PayPal(Box::new(
+ api_models::payments::PaypalRedirection { email: info.email },
+ )),
+ ))
+ }
+ _ => None,
+ }
}
- payment_method_data::PaymentMethodsData::WalletDetails(..)
- | payment_method_data::PaymentMethodsData::NetworkToken(_) => {
+ payment_method_data::PaymentMethodsData::NetworkToken(_) => {
todo!()
}
});
diff --git a/crates/router/src/core/payments/helpers.rs b/crates/router/src/core/payments/helpers.rs
index bd0c01571d..c7ae65a460 100644
--- a/crates/router/src/core/payments/helpers.rs
+++ b/crates/router/src/core/payments/helpers.rs
@@ -3403,6 +3403,13 @@ impl<'a>
co_badged_card_data: card_details.co_badged_card_data.clone(),
}))
}
+ // Wallet MIT via PSP token (ConnectorMandateId)
+ (
+ Some(domain::PaymentMethodData::Wallet(_)),
+ Some(&api_models::payments::MandateReferenceId::ConnectorMandateId(_)),
+ ) => Some(domain::PaymentMethodData::MandatePayment),
+ // Wallet CIT flow - pass through as-is
+ (Some(domain::PaymentMethodData::Wallet(_)), _) => payment_method_data.cloned(),
// Keep data as-is, otherwise.
(Some(payment_method_data), _) => Some(payment_method_data.clone()),
// Preserve empty input.
@@ -6042,13 +6049,14 @@ pub async fn get_additional_payment_data(
apple_pay: None,
google_pay: Some(Box::new(
payment_additional_types::WalletAdditionalDataForCard {
- last4: google_pay_pm_data.info.card_details.clone(),
- card_network: google_pay_pm_data.info.card_network.clone(),
+ last4: Some(google_pay_pm_data.info.card_details.clone()),
+ card_network: Some(google_pay_pm_data.info.card_network.clone()),
card_type: Some(google_pay_pm_data.pm_type.clone()),
card_exp_month,
card_exp_year,
// These are filled after calling the processor / connector
auth_code: None,
+ email: None,
},
)),
samsung_pay: None,
@@ -6060,19 +6068,24 @@ pub async fn get_additional_payment_data(
google_pay: None,
samsung_pay: Some(Box::new(
payment_additional_types::WalletAdditionalDataForCard {
- last4: samsung_pay_pm_data
- .payment_credential
- .card_last_four_digits
- .clone(),
- card_network: samsung_pay_pm_data
- .payment_credential
- .card_brand
- .to_string(),
+ last4: Some(
+ samsung_pay_pm_data
+ .payment_credential
+ .card_last_four_digits
+ .clone(),
+ ),
+ card_network: Some(
+ samsung_pay_pm_data
+ .payment_credential
+ .card_brand
+ .to_string(),
+ ),
card_type: None,
card_exp_month: None,
card_exp_year: None,
// These are filled after calling the processor / connector
auth_code: None,
+ email: None,
},
)),
}))
diff --git a/crates/router/src/core/payments/operations/payment_confirm.rs b/crates/router/src/core/payments/operations/payment_confirm.rs
index ba6cbf6ba5..0eecd26fb5 100644
--- a/crates/router/src/core/payments/operations/payment_confirm.rs
+++ b/crates/router/src/core/payments/operations/payment_confirm.rs
@@ -1192,59 +1192,77 @@ impl<F: Clone + Send + Sync> Domain<F, api::PaymentsRequest, PaymentData<F>> for
.and_then(|pmd| pmd.payment_method_data.as_ref())
{
Some(api_models::payments::PaymentMethodData::Card(_))
- | Some(api_models::payments::PaymentMethodData::BankDebit(_)) => {
- let payment_method = req.payment_method.ok_or(
- errors::ApiErrorResponse::MissingRequiredField {
- field_name: "payment_method",
- },
- )?;
-
- let payment_method_data = req
+ | Some(api_models::payments::PaymentMethodData::BankDebit(_))
+ | Some(api_models::payments::PaymentMethodData::Wallet(_)) => {
+ let should_create = match req
.payment_method_data
.as_ref()
- .and_then(|pmd| pmd.payment_method_data.clone())
- .map(Into::into)
- .ok_or(errors::ApiErrorResponse::MissingRequiredField {
- field_name: "payment_method_data",
- })?;
-
- match pm_transformers::create_payment_method_in_modular_service(
- state,
- platform.get_provider().get_account().get_id(),
- platform.get_processor().get_account().get_id(),
- business_profile.get_id(),
- payment_method,
- req.payment_method_type,
- payment_method_data,
- payment_data
- .address
- .get_request_payment_method_billing()
- .cloned(),
- payment_data
- .payment_intent
- .customer_id
- .clone()
- .get_required_value("customer_id")?,
- business_profile.is_network_tokenization_enabled,
- )
- .await
+ .and_then(|pmd| pmd.payment_method_data.as_ref())
{
- Ok(pm_info) => {
- logger::info!(
- "Payment method created in PM Modular service successfully"
- );
- //set payment_data.payment_method_info
- payment_data.set_payment_method_id_in_attempt(Some(
- pm_info.get_id().clone(),
- ));
- payment_data.set_payment_method_info(Some(pm_info));
+ Some(api_models::payments::PaymentMethodData::Wallet(_)) => {
+ req.setup_future_usage
+ .or(payment_data.payment_intent.setup_future_usage)
+ == Some(common_enums::FutureUsage::OffSession)
}
- Err(err) => {
- logger::error!(
- "Error creating payment method in PM Modular service: {:?}",
- err
- );
+ Some(api_models::payments::PaymentMethodData::Card(_)) => true,
+ _ => false,
+ };
+
+ if should_create {
+ let payment_method = req.payment_method.ok_or(
+ errors::ApiErrorResponse::MissingRequiredField {
+ field_name: "payment_method",
+ },
+ )?;
+
+ let payment_method_data = req
+ .payment_method_data
+ .as_ref()
+ .and_then(|pmd| pmd.payment_method_data.clone())
+ .map(Into::into)
+ .ok_or(errors::ApiErrorResponse::MissingRequiredField {
+ field_name: "payment_method_data",
+ })?;
+
+ match pm_transformers::create_payment_method_in_modular_service(
+ state,
+ platform.get_provider().get_account().get_id(),
+ platform.get_processor().get_account().get_id(),
+ business_profile.get_id(),
+ payment_method,
+ req.payment_method_type,
+ payment_method_data,
+ payment_data
+ .address
+ .get_request_payment_method_billing()
+ .cloned(),
+ payment_data
+ .payment_intent
+ .customer_id
+ .clone()
+ .get_required_value("customer_id")?,
+ business_profile.is_network_tokenization_enabled,
+ )
+ .await
+ {
+ Ok(pm_info) => {
+ logger::info!(
+ "Payment method created in PM Modular service successfully"
+ );
+ payment_data.set_payment_method_id_in_attempt(Some(
+ pm_info.get_id().clone(),
+ ));
+ payment_data.set_payment_method_info(Some(pm_info));
+ }
+ Err(err) => {
+ logger::error!(
+ "Error creating payment method in PM Modular service: {:?}",
+ err
+ );
+ }
}
+ } else {
+ logger::info!("Skipping wallet PM creation - setup_future_usage is not off_session");
}
}
_ => {
diff --git a/crates/router/src/core/payments/operations/payment_response.rs b/crates/router/src/core/payments/operations/payment_response.rs
index 2927f50361..94dccd5429 100644
--- a/crates/router/src/core/payments/operations/payment_response.rs
+++ b/crates/router/src/core/payments/operations/payment_response.rs
@@ -79,10 +79,16 @@ async fn update_modular_pm_and_mandate_impl<F, T>(
where
F: Clone + Send + Sync,
{
- if matches!(
+ let is_eligible_pm = matches!(
payment_data.payment_attempt.payment_method,
- Some(enums::PaymentMethod::Card | enums::PaymentMethod::BankDebit)
- ) {
+ Some(
+ enums::PaymentMethod::Card
+ | enums::PaymentMethod::BankDebit
+ | enums::PaymentMethod::Wallet
+ )
+ );
+
+ if is_eligible_pm {
let is_volatile = payment_data
.get_payment_method_info()
.map(|pm| pm.is_pm_volatile());
@@ -107,145 +113,147 @@ where
should_update
);
- // #2 - Derive network transaction ID from the connector response.
- let (network_transaction_id, connector_token_details) = if should_update
- && matches!(
+ if should_update {
+ // #1 - Derive network transaction ID from the connector response.
+ let (network_transaction_id, connector_token_details) = if matches!(
payment_data.payment_attempt.setup_future_usage_applied,
Some(common_enums::FutureUsage::OffSession)
) {
- let network_transaction_id = resp
- .response
- .as_ref()
- .map_err(|err| {
- logger::debug!(error=?err, "Failed to obtain the network_transaction_id from payment response in modular payment method update call");
- })
- .ok()
- .and_then(types::PaymentsResponseData::get_network_transaction_id);
-
- let connector_token_details = match resp
+ let network_transaction_id = resp
.response
.as_ref()
+ .map_err(|err| {
+ logger::debug!(error=?err, "Failed to obtain the network_transaction_id from payment response in modular payment method update call");
+ })
.ok()
- .and_then(types::PaymentsResponseData::get_mandate_reference)
- {
- Some(mandate_reference) => {
- let connector_id = payment_data
- .payment_attempt
- .merchant_connector_id
- .clone()
- .ok_or_else(|| {
- logger::error!("Missing required Param merchant_connector_id");
- ::payment_methods::errors::ModularPaymentMethodError::RetrieveFailed
- })?;
- let connector_customer_id = resp
- .connector_customer
+ .and_then(types::PaymentsResponseData::get_network_transaction_id);
+
+ let connector_token_details = match resp
+ .response
+ .as_ref()
+ .ok()
+ .and_then(types::PaymentsResponseData::get_mandate_reference)
+ {
+ Some(mandate_reference) => {
+ let connector_id = payment_data
+ .payment_attempt
+ .merchant_connector_id
.clone()
- .or_else(|| payment_data.get_connector_customer_id());
- update_connector_mandate_details_for_the_flow(
- mandate_reference.connector_mandate_id.clone(),
- mandate_reference.mandate_metadata.clone(),
+ .ok_or_else(|| {
+ logger::error!("Missing required Param merchant_connector_id");
+ ::payment_methods::errors::ModularPaymentMethodError::RetrieveFailed
+ })?;
+ let connector_customer_id = resp
+ .connector_customer
+ .clone()
+ .or_else(|| payment_data.get_connector_customer_id());
+ update_connector_mandate_details_for_the_flow(
+ mandate_reference.connector_mandate_id.clone(),
+ mandate_reference.mandate_metadata.clone(),
+ mandate_reference
+ .connector_mandate_request_reference_id
+ .clone(),
+ payment_data,
+ )
+ .change_context(
+ ::payment_methods::errors::ModularPaymentMethodError::UpdateFailed,
+ )?;
mandate_reference
- .connector_mandate_request_reference_id
- .clone(),
- payment_data,
- )
- .change_context(
- ::payment_methods::errors::ModularPaymentMethodError::UpdateFailed,
- )?;
- mandate_reference
- .connector_mandate_id
- .map(|connector_mandate_id| {
- ::payment_methods::types::ConnectorTokenDetails {
- connector_id,
- token_type: TokenizationType::MultiUse,
- status: ConnectorTokenStatus::Active,
- connector_token_request_reference_id: mandate_reference
- .connector_mandate_request_reference_id,
- original_payment_authorized_amount: Some(
- payment_data
+ .connector_mandate_id
+ .map(|connector_mandate_id| {
+ ::payment_methods::types::ConnectorTokenDetails {
+ connector_id,
+ token_type: TokenizationType::MultiUse,
+ status: ConnectorTokenStatus::Active,
+ connector_token_request_reference_id: mandate_reference
+ .connector_mandate_request_reference_id,
+ original_payment_authorized_amount: Some(
+ payment_data
+ .payment_attempt
+ .net_amount
+ .get_total_amount(),
+ ),
+ original_payment_authorized_currency: payment_data
.payment_attempt
- .net_amount
- .get_total_amount(),
- ),
- original_payment_authorized_currency: payment_data
- .payment_attempt
- .currency,
- metadata: mandate_reference.mandate_metadata,
- connector_customer_id: connector_customer_id.clone(),
- token: hyperswitch_masking::Secret::new(
- connector_mandate_id,
- ),
- }
- })
- }
- None => None,
- };
+ .currency,
+ metadata: mandate_reference.mandate_metadata,
+ connector_customer_id: connector_customer_id.clone(),
+ token: hyperswitch_masking::Secret::new(
+ connector_mandate_id,
+ ),
+ }
+ })
+ }
+ None => None,
+ };
- (network_transaction_id, connector_token_details)
- } else {
- (None, None)
- };
+ (network_transaction_id, connector_token_details)
+ } else {
+ (None, None)
+ };
- // #3 - Fill payment method data for cards (update card holder name, nick_name & cvc).
- // Use request payment method data for card_holder_name and nick_name
- let payment_method_data =
- request_payment_method_data.and_then(|method_data| match method_data {
- domain::PaymentMethodData::CardToken(card) => {
- Some(PaymentMethodUpdateData::Card(CardDetailUpdate {
- card_holder_name: card.card_holder_name.clone(),
- nick_name: card.card_holder_name.clone(),
- card_cvc: None,
- }))
- }
- domain::PaymentMethodData::BankDebit(
- domain::BankDebitData::AchBankDebit {
- bank_account_holder_name,
- ..
- },
- ) => Some(PaymentMethodUpdateData::BankDebit(
- BankDebitDetailUpdate::Ach {
- bank_account_holder_name: bank_account_holder_name.clone(),
- },
- )),
- _ => None,
- });
- let acknowledgement_status = should_update
- .then_some(common_enums::AcknowledgementStatus::Authenticated)
- .or(Some(common_enums::AcknowledgementStatus::Failed));
-
- let payload = UpdatePaymentMethodV1Payload {
- payment_method_data,
- connector_token_details,
- network_transaction_id: network_transaction_id
- .map(hyperswitch_masking::Secret::new),
- acknowledgement_status,
- };
+ // #2 - Fill payment method data for cards
+ let payment_method_data =
+ request_payment_method_data.and_then(|method_data| match method_data {
+ domain::PaymentMethodData::CardToken(card) => {
+ Some(PaymentMethodUpdateData::Card(CardDetailUpdate {
+ card_holder_name: card.card_holder_name.clone(),
+ nick_name: card.card_holder_name.clone(),
+ card_cvc: None,
+ }))
+ }
+ domain::PaymentMethodData::BankDebit(
+ domain::BankDebitData::AchBankDebit {
+ bank_account_holder_name,
+ ..
+ },
+ ) => Some(PaymentMethodUpdateData::BankDebit(
+ BankDebitDetailUpdate::Ach {
+ bank_account_holder_name: bank_account_holder_name.clone(),
+ },
+ )),
+ _ => None,
+ });
+ let acknowledgement_status =
+ Some(common_enums::AcknowledgementStatus::Authenticated);
+
+ let payload = UpdatePaymentMethodV1Payload {
+ payment_method_data,
+ connector_token_details,
+ network_transaction_id: network_transaction_id
+ .map(hyperswitch_masking::Secret::new),
+ acknowledgement_status,
+ };
- // #5 - Execute the modular payment-method update call if there is something to be updated
- if payload.payment_method_data.is_some()
- || payload.connector_token_details.is_some()
- || payload.network_transaction_id.is_some()
- || payload.acknowledgement_status.is_some()
- {
- match call_modular_payment_method_update(
- state,
- &payment_data.payment_attempt.processor_merchant_id,
- &payment_data.payment_attempt.profile_id,
- &pm_id,
- payload,
- )
- .await
+ // #3 - Execute the modular payment-method update call if there is something to be updated
+ if payload.payment_method_data.is_some()
+ || payload.connector_token_details.is_some()
+ || payload.network_transaction_id.is_some()
+ || payload.acknowledgement_status.is_some()
{
- Ok(_) => {
- logger::info!("Successfully called modular payment method update");
- }
- Err(err) => {
- logger::error!("Failed to call modular payment method update: {}", err);
- }
- };
- payment_data.payment_attempt.payment_method_id = Some(pm_id.clone());
- } else {
- logger::info!("No updates found for modular payment method update call");
+ match call_modular_payment_method_update(
+ state,
+ &payment_data.payment_attempt.processor_merchant_id,
+ &payment_data.payment_attempt.profile_id,
+ &pm_id,
+ payload,
+ )
+ .await
+ {
+ Ok(_) => {
+ logger::info!("Successfully called modular payment method update");
+ }
+ Err(err) => {
+ logger::error!(
+ "Failed to call modular payment method update: {}",
+ err
+ );
+ }
+ };
+ payment_data.payment_attempt.payment_method_id = Some(pm_id.clone());
+ } else {
+ logger::info!("No updates found for modular payment method update call");
+ }
}
}
(_, _) => {
diff --git a/crates/router/src/core/payments/operations/payment_status.rs b/crates/router/src/core/payments/operations/payment_status.rs
index 947d861f54..e8bd751ce9 100644
--- a/crates/router/src/core/payments/operations/payment_status.rs
+++ b/crates/router/src/core/payments/operations/payment_status.rs
@@ -8,6 +8,8 @@ use router_derive::PaymentOperation;
use router_env::{instrument, logger, tracing};
use super::{BoxedOperation, Domain, GetTracker, Operation, UpdateTracker, ValidateRequest};
+#[cfg(feature = "pm_modular")]
+use crate::core::{payment_methods::transformers as pm_transformers, utils as core_utils};
use crate::{
core::{
configs::dimension_state,
@@ -445,8 +447,25 @@ async fn get_tracker_for_sync<
id: profile_id.get_string_repr().to_owned(),
})?;
- let payment_method_info =
- if let Some(ref payment_method_id) = payment_attempt.payment_method_id.clone() {
+ let payment_method_info = if let Some(ref payment_method_id) =
+ payment_attempt.payment_method_id.clone()
+ {
+ #[cfg(feature = "pm_modular")]
+ if core_utils::get_feature_config(state, platform)
+ .await
+ .is_payment_method_modular_allowed
+ {
+ let pm_info = pm_transformers::fetch_payment_method_from_modular_service(
+ state,
+ platform,
+ profile_id,
+ payment_method_id,
+ None,
+ )
+ .await
+ .attach_printable("Failed to fetch payment method from modular service in sync flow")?;
+ Some(pm_info.payment_method.0)
+ } else {
match db
.find_payment_method(
platform.get_provider().get_key_store(),
@@ -467,9 +486,34 @@ async fn get_tracker_for_sync<
}
}
}
- } else {
- None
- };
+ }
+
+ #[cfg(not(feature = "pm_modular"))]
+ {
+ match db
+ .find_payment_method(
+ platform.get_provider().get_key_store(),
+ payment_method_id,
+ storage_scheme,
+ )
+ .await
+ {
+ Ok(payment_method) => Some(payment_method),
+ Err(error) => {
+ if error.current_context().is_db_not_found() {
+ logger::info!("Payment Method not found in db {:?}", error);
+ None
+ } else {
+ Err(error)
+ .change_context(errors::ApiErrorResponse::InternalServerError)
+ .attach_printable("Error retrieving payment method from db")?
+ }
+ }
+ }
+ }
+ } else {
+ None
+ };
let merchant_id = payment_intent.merchant_id.clone();
let key_manager_state = &(state).into();
diff --git a/crates/router/src/types/api/payment_methods.rs b/crates/router/src/types/api/payment_methods.rs
index 343a577adc..e497b1a3f6 100644
--- a/crates/router/src/types/api/payment_methods.rs
+++ b/crates/router/src/types/api/payment_methods.rs
@@ -14,7 +14,7 @@ pub use api_models::payment_methods::{
PaymentMethodsData, ProxyCardDetails, RequestPaymentMethodTypes, TokenDataResponse,
TokenDetailsResponse, TokenizePayloadEncrypted, TokenizePayloadRequest, TokenizedCardValue1,
TokenizedCardValue2, TokenizedWalletValue1, TokenizedWalletValue2,
- TotalPaymentMethodCountResponse,
+ TotalPaymentMethodCountResponse, WalletPaymentMethodData,
};
#[cfg(feature = "v1")]
pub use api_models::payment_methods::{