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
chore(connector): [paypal] store paypal email and payer_id in payment_method_data (#13902)
Nithin N79a3aae8a0c2
diff --git a/api-reference/v1/openapi_spec_v1.json b/api-reference/v1/openapi_spec_v1.jsonindex ee8da0bcfb..5c4ef69f52 100644--- a/api-reference/v1/openapi_spec_v1.json+++ b/api-reference/v1/openapi_spec_v1.json@@ -39430,6 +39430,23 @@}}},+ "PaypalWalletAdditionalData": {+ "type": "object",+ "properties": {+ "email": {+ "type": "string",+ "description": "Email address associated with the payer's PayPal account",+ "example": "[email protected]",+ "nullable": true+ },+ "payer_id": {+ "type": "string",+ "description": "Unique identifier of the payer in PayPal",+ "example": "7DY7FRMPQ8CT6",+ "nullable": true+ }+ }+ },"PayseraData": {"type": "object"},@@ -48269,6 +48286,17 @@"$ref": "#/components/schemas/WalletAdditionalDataForCard"}}+ },+ {+ "type": "object",+ "required": [+ "paypal"+ ],+ "properties": {+ "paypal": {+ "$ref": "#/components/schemas/PaypalWalletAdditionalData"+ }+ }}],"description": "Hyperswitch supports SDK integration with Apple Pay and Google Pay wallets. For other wallets, we integrate with their respective connectors, redirecting the customer to the connector for wallet payments. As a result, we don’t receive any payment method data in the confirm call for payments made through other wallets."diff --git a/api-reference/v2/openapi_spec_v2.json b/api-reference/v2/openapi_spec_v2.jsonindex a78836cfe3..c23c481b16 100644--- a/api-reference/v2/openapi_spec_v2.json+++ b/api-reference/v2/openapi_spec_v2.json@@ -27938,6 +27938,23 @@}}},+ "PaypalWalletAdditionalData": {+ "type": "object",+ "properties": {+ "email": {+ "type": "string",+ "description": "Email address associated with the payer's PayPal account",+ "example": "[email protected]",+ "nullable": true+ },+ "payer_id": {+ "type": "string",+ "description": "Unique identifier of the payer in PayPal",+ "example": "7DY7FRMPQ8CT6",+ "nullable": true+ }+ }+ },"PayseraData": {"type": "object"},@@ -35367,6 +35384,17 @@"$ref": "#/components/schemas/WalletAdditionalDataForCard"}}+ },+ {+ "type": "object",+ "required": [+ "paypal"+ ],+ "properties": {+ "paypal": {+ "$ref": "#/components/schemas/PaypalWalletAdditionalData"+ }+ }}],"description": "Hyperswitch supports SDK integration with Apple Pay and Google Pay wallets. For other wallets, we integrate with their respective connectors, redirecting the customer to the connector for wallet payments. As a result, we don’t receive any payment method data in the confirm call for payments made through other wallets."diff --git a/crates/api_models/src/payments.rs b/crates/api_models/src/payments.rsindex 8145ddfabd..6a3e404658 100644--- a/crates/api_models/src/payments.rs+++ b/crates/api_models/src/payments.rs@@ -89,8 +89,8 @@ use crate::{payment_methods,payments::additional_info::{BankDebitAdditionalData, BankRedirectDetails, BankTransferAdditionalData,- CardTokenAdditionalData, GiftCardAdditionalData, UpiAdditionalData,- WalletAdditionalDataForCard,+ CardTokenAdditionalData, GiftCardAdditionalData, PaypalWalletAdditionalData,+ UpiAdditionalData, WalletAdditionalDataForCard,},platform,};@@ -4254,6 +4254,7 @@ pub enum AdditionalPaymentData {apple_pay: Option<Box<ApplepayPaymentMethod>>,google_pay: Option<Box<WalletAdditionalDataForCard>>,samsung_pay: Option<Box<WalletAdditionalDataForCard>>,+ paypal: Option<Box<PaypalWalletAdditionalData>>,},PayLater {klarna_sdk: Option<KlarnaSdkPaymentMethod>,@@ -6316,6 +6317,9 @@ pub enum WalletResponseData {#[schema(value_type = WalletAdditionalDataForCard)]#[smithy(value_type = "Option<WalletAdditionalDataForCard>")]SamsungPay(Box<WalletAdditionalDataForCard>),+ #[schema(value_type = PaypalWalletAdditionalData)]+ #[smithy(value_type = "Option<PaypalWalletAdditionalData>")]+ Paypal(Box<PaypalWalletAdditionalData>),}#[derive(@@ -9532,8 +9536,9 @@ impl From<AdditionalPaymentData> for PaymentMethodDataResponse {apple_pay,google_pay,samsung_pay,- } => match (apple_pay, google_pay, samsung_pay) {- (Some(apple_pay_pm), _, _) => Self::Wallet(Box::new(WalletResponse {+ paypal,+ } => match (apple_pay, google_pay, samsung_pay, paypal) {+ (Some(apple_pay_pm), _, _, _) => Self::Wallet(Box::new(WalletResponse {details: Some(WalletResponseData::ApplePay(Box::new(WalletAdditionalDataForCard {last4: Some(@@ -9557,12 +9562,15 @@ impl From<AdditionalPaymentData> for PaymentMethodDataResponse {},))),})),- (_, Some(google_pay_pm), _) => Self::Wallet(Box::new(WalletResponse {+ (_, Some(google_pay_pm), _, _) => Self::Wallet(Box::new(WalletResponse {details: Some(WalletResponseData::GooglePay(google_pay_pm)),})),- (_, _, Some(samsung_pay_pm)) => Self::Wallet(Box::new(WalletResponse {+ (_, _, Some(samsung_pay_pm), _) => Self::Wallet(Box::new(WalletResponse {details: Some(WalletResponseData::SamsungPay(samsung_pay_pm)),})),+ (_, _, _, Some(paypal_pm)) => Self::Wallet(Box::new(WalletResponse {+ details: Some(WalletResponseData::Paypal(paypal_pm)),+ })),_ => Self::Wallet(Box::new(WalletResponse { details: None })),},AdditionalPaymentData::BankRedirect {diff --git a/crates/api_models/src/payments/additional_info.rs b/crates/api_models/src/payments/additional_info.rsindex 6c0bf70c98..896c68c5b1 100644--- a/crates/api_models/src/payments/additional_info.rs+++ b/crates/api_models/src/payments/additional_info.rs@@ -423,6 +423,20 @@ pub enum UpiAdditionalData {UpiQr(Box<super::UpiQrData>),}+#[derive(+ Debug, Clone, Eq, PartialEq, serde::Deserialize, serde::Serialize, ToSchema, SmithyModel,+)]+#[smithy(namespace = "com.hyperswitch.smithy.types")]+pub struct PaypalWalletAdditionalData {+ /// Email address associated with the payer's PayPal account+ #[schema(value_type = Option<String>, example = "[email protected]")]+ pub email: Option<common_utils::pii::Email>,+ /// Unique identifier of the payer in PayPal+ #[schema(value_type = Option<String>, example = "7DY7FRMPQ8CT6")]+ #[smithy(value_type = "Option<String>")]+ pub payer_id: Option<String>,+}+#[derive(Debug, Clone, Eq, PartialEq, serde::Deserialize, serde::Serialize, ToSchema, SmithyModel,)]diff --git a/crates/common_enums/src/enums.rs b/crates/common_enums/src/enums.rsindex 790637981a..351a4f1c75 100644--- a/crates/common_enums/src/enums.rs+++ b/crates/common_enums/src/enums.rs@@ -2899,23 +2899,30 @@ impl PaymentMethod {}}- pub fn is_additional_payment_method_data_sensitive(&self) -> bool {- match self {- Self::BankTransfer | Self::BankRedirect => true,- Self::Card- | Self::CardRedirect- | Self::PayLater- | Self::Wallet- | Self::GiftCard- | Self::Crypto- | Self::BankDebit- | Self::Reward- | Self::RealTimePayment- | Self::Upi- | Self::Voucher- | Self::OpenBanking- | Self::MobilePayment- | Self::NetworkToken => false,+ pub fn is_additional_payment_method_data_sensitive(+ &self,+ payment_method_type: Option<PaymentMethodType>,+ ) -> bool {+ match (self, payment_method_type) {+ (Self::BankTransfer | Self::BankRedirect, _)+ | (Self::Wallet, Some(PaymentMethodType::Paypal)) => true,+ (+ Self::Card+ | Self::CardRedirect+ | Self::PayLater+ | Self::Wallet+ | Self::GiftCard+ | Self::Crypto+ | Self::BankDebit+ | Self::Reward+ | Self::RealTimePayment+ | Self::Upi+ | Self::Voucher+ | Self::OpenBanking+ | Self::MobilePayment+ | Self::NetworkToken,+ _,+ ) => false,}}}diff --git a/crates/hyperswitch_connectors/src/connectors/paypal/transformers.rs b/crates/hyperswitch_connectors/src/connectors/paypal/transformers.rsindex 595415a630..ab80056cc8 100644--- a/crates/hyperswitch_connectors/src/connectors/paypal/transformers.rs+++ b/crates/hyperswitch_connectors/src/connectors/paypal/transformers.rs@@ -10,9 +10,9 @@ use api_models::{};use base64::Engine;use common_enums::enums as storage_enums;-#[cfg(feature = "payouts")]-use common_utils::pii::Email;-use common_utils::{consts, errors::CustomResult, request::Method, types::StringMajorUnit};+use common_utils::{+ consts, errors::CustomResult, pii::Email, request::Method, types::StringMajorUnit,+};use error_stack::ResultExt;use hyperswitch_domain_models::{payment_method_data::{@@ -20,8 +20,9 @@ use hyperswitch_domain_models::{PayLaterData, PaymentMethodData, VoucherData, WalletData,},router_data::{- AccessToken, ConnectorAuthType, ConnectorResponseData, ErrorResponse,- ExtendedAuthorizationResponseData, FeatureData, RouterData,+ AccessToken, AdditionalPaymentMethodConnectorResponse, ConnectorAuthType,+ ConnectorResponseData, ErrorResponse, ExtendedAuthorizationResponseData, FeatureData,+ RouterData,},router_flow_types::{payments::{Authorize, PostSessionTokens},@@ -2578,6 +2579,11 @@ wherelet status = payment_collection_item.status.clone();let status = get_payment_attempt_status(status, item.data.status);+ let connector_response = get_connector_response_with_payer_details(+ item.data.payment_method_type,+ item.response.payer.as_ref(),+ );+if is_payment_failure(status) {let error_code = payment_collection_item.processor_response@@ -2663,6 +2669,7 @@ wherecharges: None,payment_account_reference: None,}),+ connector_response,sender_payment_instrument_id: item.response.payer@@ -2767,6 +2774,10 @@ impl<F, T>order_id: None,});let purchase_units = item.response.purchase_units.first();+ let connector_response = get_connector_response_with_payer_details(+ item.data.payment_method_type,+ item.response.payer.as_ref(),+ );Ok(Self {status,response: Ok(PaymentsResponseData::TransactionResponse {@@ -2787,6 +2798,7 @@ impl<F, T>charges: None,payment_account_reference: None,}),+ connector_response,sender_payment_instrument_id: item.response.payer@@ -2831,6 +2843,10 @@ implorder_id: None,});let purchase_units = item.response.purchase_units.first();+ let connector_response = get_connector_response_with_payer_details(+ item.data.payment_method_type,+ item.response.payer.as_ref(),+ );Ok(Self {status,response: Ok(PaymentsResponseData::TransactionResponse {@@ -2851,6 +2867,7 @@ implcharges: None,payment_account_reference: None,}),+ connector_response,..item.data})}@@ -3046,6 +3063,10 @@ impl<F, T> TryFrom<ResponseRouterData<F, PaypalPaymentsSyncResponse, T, Paymentscharges: None,payment_account_reference: None,}),+ connector_response: get_connector_response_with_payer_details(+ item.data.payment_method_type,+ item.response.payer.as_ref(),+ ),sender_payment_instrument_id: item.response.payer@@ -3404,6 +3425,34 @@ pub struct PaypalCaptureResponse {#[derive(Debug, Clone, Serialize, Deserialize)]pub struct Payer {payer_id: Option<Secret<String>>,+ email_address: Option<Email>,+}++impl Payer {+ fn get_wallet_additional_data(&self) -> Option<AdditionalPaymentMethodConnectorResponse> {+ match (self.email_address.clone(), self.payer_id.clone()) {+ (None, None) => None,+ (email, payer_id) => {+ Some(AdditionalPaymentMethodConnectorResponse::Paypal { email, payer_id })+ }+ }+ }+}++/// Builds the connector response with the payer details received from paypal.+/// This should only be populated for paypal wallet payments (PaypalRedirect and PaypalSdk+/// flows, both of which use `PaymentMethodType::Paypal`), and not for payments processed+/// via paypal as a card processor.+fn get_connector_response_with_payer_details(+ payment_method_type: Option<common_enums::PaymentMethodType>,+ payer: Option<&Payer>,+) -> Option<ConnectorResponseData> {+ match payment_method_type {+ Some(common_enums::PaymentMethodType::Paypal) => payer+ .and_then(|payer| payer.get_wallet_additional_data())+ .map(ConnectorResponseData::with_additional_payment_method_data),+ _ => None,+ }}fn get_payment_attempt_status(@@ -3501,6 +3550,10 @@ impl TryFrom<PaymentsCaptureResponseRouterData<PaypalCaptureResponse>>charges: None,payment_account_reference: None,}),+ connector_response: get_connector_response_with_payer_details(+ item.data.payment_method_type,+ item.response.payer.as_ref(),+ ),amount_captured: Some(amount_captured),..item.data})diff --git a/crates/hyperswitch_connectors/src/connectors/tesouro/transformers.rs b/crates/hyperswitch_connectors/src/connectors/tesouro/transformers.rsindex 1b488abb86..84c0d26ea9 100644--- a/crates/hyperswitch_connectors/src/connectors/tesouro/transformers.rs+++ b/crates/hyperswitch_connectors/src/connectors/tesouro/transformers.rs@@ -399,6 +399,7 @@ impl TesouroPaymentMethodDetails {apple_pay,google_pay,samsung_pay: _,+ paypal: _,} => {if let Some(google_pay_token) = google_pay {Ok((diff --git a/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs b/crates/hyperswitch_domain_models/src/payments/payment_attempt.rsindex 42f6d14841..37e35ab37d 100644--- a/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs+++ b/crates/hyperswitch_domain_models/src/payments/payment_attempt.rs@@ -1923,7 +1923,9 @@ impl PaymentAttempt {pub fn check_and_get_payment_method_data_based_on_encryption_strategy(&self) -> Option<Value> {if self.payment_method- .map(|payment_method| payment_method.is_additional_payment_method_data_sensitive())+ .map(|payment_method| {+ payment_method.is_additional_payment_method_data_sensitive(self.payment_method_type)+ }).unwrap_or(false){self.encrypted_payment_method_datadiff --git a/crates/hyperswitch_domain_models/src/router_data.rs b/crates/hyperswitch_domain_models/src/router_data.rsindex 7b65d3382a..0257279073 100644--- a/crates/hyperswitch_domain_models/src/router_data.rs+++ b/crates/hyperswitch_domain_models/src/router_data.rs@@ -822,6 +822,12 @@ pub enum AdditionalPaymentMethodConnectorResponse {ApplePay {auth_code: Option<String>,},+ Paypal {+ /// Email address associated with the payer's PayPal account+ email: Option<common_utils::pii::Email>,+ /// Unique identifier of the payer in PayPal+ payer_id: Option<Secret<String>>,+ },SepaBankTransfer {debitor_iban: Option<Secret<String>>,debitor_bic: Option<Secret<String>>,diff --git a/crates/openapi/src/openapi.rs b/crates/openapi/src/openapi.rsindex 74b5f42adc..f0bfb3fea1 100644--- a/crates/openapi/src/openapi.rs+++ b/crates/openapi/src/openapi.rs@@ -1074,6 +1074,7 @@ Never share your secret api keys. Keep them guarded and secure.api_models::payments::additional_info::UpiAdditionalData,api_models::payments::additional_info::UpiCollectAdditionalData,api_models::payments::additional_info::WalletAdditionalDataForCard,+ api_models::payments::additional_info::PaypalWalletAdditionalData,api_models::payments::additional_info::SepaBankTransferPaymentAdditionalData,api_models::payments::additional_info::PixAutomaticoPushAdditionalData,api_models::payments::PaymentsDynamicTaxCalculationRequest,diff --git a/crates/openapi/src/openapi_v2.rs b/crates/openapi/src/openapi_v2.rsindex eba371a2db..cf35019a2c 100644--- a/crates/openapi/src/openapi_v2.rs+++ b/crates/openapi/src/openapi_v2.rs@@ -956,6 +956,7 @@ Never share your secret api keys. Keep them guarded and secure.api_models::payments::additional_info::UpiAdditionalData,api_models::payments::additional_info::UpiCollectAdditionalData,api_models::payments::additional_info::WalletAdditionalDataForCard,+ api_models::payments::additional_info::PaypalWalletAdditionalData,api_models::payments::additional_info::SepaBankTransferPaymentAdditionalData,api_models::payments::additional_info::PixAutomaticoPushAdditionalData,api_models::payments::WalletResponse,diff --git a/crates/router/src/core/payments/helpers.rs b/crates/router/src/core/payments/helpers.rsindex 8d56ddb794..e22ac6773a 100644--- a/crates/router/src/core/payments/helpers.rs+++ b/crates/router/src/core/payments/helpers.rs@@ -6363,6 +6363,7 @@ pub async fn get_additional_payment_data(})),google_pay: None,samsung_pay: None,+ paypal: None,}))}domain::WalletData::GooglePay(google_pay_pm_data) => {@@ -6389,6 +6390,7 @@ pub async fn get_additional_payment_data(},)),samsung_pay: None,+ paypal: None,}))}domain::WalletData::SamsungPay(samsung_pay_pm_data) => {@@ -6417,12 +6419,14 @@ pub async fn get_additional_payment_data(email: None,},)),+ paypal: None,}))}_ => Ok(Some(api_models::payments::AdditionalPaymentData::Wallet {apple_pay: None,google_pay: None,samsung_pay: None,+ paypal: None,})),},domain::PaymentMethodData::PayLater(_) => Ok(Some(@@ -8383,6 +8387,7 @@ pub fn add_connector_response_to_additional_payment_data(apple_pay,google_pay,samsung_pay,+ paypal,},AdditionalPaymentMethodConnectorResponse::GooglePay { auth_code, .. }| AdditionalPaymentMethodConnectorResponse::ApplePay { auth_code, .. },@@ -8400,6 +8405,26 @@ pub fn add_connector_response_to_additional_payment_data(})}),samsung_pay: samsung_pay.clone(),+ paypal: paypal.clone(),+ },+ (+ api_models::payments::AdditionalPaymentData::Wallet {+ apple_pay,+ google_pay,+ samsung_pay,+ ..+ },+ AdditionalPaymentMethodConnectorResponse::Paypal { email, payer_id },+ ) => api_models::payments::AdditionalPaymentData::Wallet {+ apple_pay: apple_pay.clone(),+ google_pay: google_pay.clone(),+ samsung_pay: samsung_pay.clone(),+ paypal: Some(Box::new(+ payment_additional_types::PaypalWalletAdditionalData {+ email,+ payer_id: payer_id.map(|payer_id| payer_id.expose()),+ },+ )),},#[cfg(feature = "v2")](@@ -8455,7 +8480,10 @@ pub async fn get_payment_method_data_and_encrypted_payment_method_data(if payment_attempt.payment_method.as_ref()- .map(|payment_method| payment_method.is_additional_payment_method_data_sensitive())+ .map(|payment_method| {+ payment_method+ .is_additional_payment_method_data_sensitive(payment_attempt.payment_method_type)+ }).unwrap_or(false){let encrypted_payment_method_data = additional_payment_method_data_intermediatediff --git a/crates/router/src/core/payments/operations/payment_create.rs b/crates/router/src/core/payments/operations/payment_create.rsindex f46391c4c2..6164548fda 100644--- a/crates/router/src/core/payments/operations/payment_create.rs+++ b/crates/router/src/core/payments/operations/payment_create.rs@@ -1533,6 +1533,7 @@ impl PaymentCreate {.ok(),google_pay: None,samsung_pay: None,+ paypal: None,})}Some(enums::PaymentMethodType::GooglePay) => {@@ -1540,6 +1541,7 @@ impl PaymentCreate {apple_pay: None,google_pay: Some(Box::new(wallet.into())),samsung_pay: None,+ paypal: None,})}Some(enums::PaymentMethodType::SamsungPay) => {@@ -1547,6 +1549,7 @@ impl PaymentCreate {apple_pay: None,google_pay: None,samsung_pay: Some(Box::new(wallet.into())),+ paypal: None,})}_ => None,@@ -1559,6 +1562,7 @@ impl PaymentCreate {apple_pay: None,google_pay: None,samsung_pay: None,+ paypal: None,})}_ => None,