diff --git a/crates/api_models/src/payments.rs b/crates/api_models/src/payments.rs index e743e9a853..173b795efa 100644 --- a/crates/api_models/src/payments.rs +++ b/crates/api_models/src/payments.rs @@ -816,6 +816,8 @@ pub enum WalletData { ApplePayRedirect(Box), /// The wallet data for Google pay GooglePay(GooglePayWalletData), + /// Wallet data for google pay redirect flow + GooglePayRedirect(Box), MbWayRedirect(Box), /// The wallet data for MobilePay redirect MobilePayRedirect(Box), @@ -844,6 +846,9 @@ pub struct GooglePayWalletData { #[derive(Eq, PartialEq, Clone, Debug, serde::Deserialize, serde::Serialize, ToSchema)] pub struct ApplePayRedirectData {} +#[derive(Eq, PartialEq, Clone, Debug, serde::Deserialize, serde::Serialize, ToSchema)] +pub struct GooglePayRedirectData {} + #[derive(Eq, PartialEq, Clone, Debug, serde::Deserialize, serde::Serialize, ToSchema)] pub struct WeChatPayRedirection {} diff --git a/crates/router/src/connector/zen.rs b/crates/router/src/connector/zen.rs index e6429bde56..6b2d365828 100644 --- a/crates/router/src/connector/zen.rs +++ b/crates/router/src/connector/zen.rs @@ -164,9 +164,7 @@ impl ConnectorIntegration CustomResult)>, errors::ConnectorError> { let mut headers = self.build_headers(req, connectors)?; let api_headers = match req.request.payment_method_data { - api_models::payments::PaymentMethodData::Wallet( - api_models::payments::WalletData::ApplePayRedirect(_), - ) => None, + api_models::payments::PaymentMethodData::Wallet(_) => None, _ => Some(Self::get_default_header()), }; if let Some(api_header) = api_headers { @@ -185,9 +183,7 @@ impl ConnectorIntegration CustomResult { let endpoint = match &req.request.payment_method_data { - api_models::payments::PaymentMethodData::Wallet( - api_models::payments::WalletData::ApplePayRedirect(_), - ) => { + api_models::payments::PaymentMethodData::Wallet(_) => { let base_url = connectors .zen .secondary_base_url diff --git a/crates/router/src/connector/zen/transformers.rs b/crates/router/src/connector/zen/transformers.rs index 22ca65fb68..fa11f67f20 100644 --- a/crates/router/src/connector/zen/transformers.rs +++ b/crates/router/src/connector/zen/transformers.rs @@ -1,4 +1,4 @@ -use api_models::payments::{ApplePayRedirectData, Card, GooglePayWalletData}; +use api_models::payments::Card; use cards::CardNumber; use common_utils::{ext_traits::ValueExt, pii}; use error_stack::ResultExt; @@ -116,7 +116,6 @@ pub struct ZenBrowserDetails { #[serde(rename_all = "snake_case")] pub enum ZenPaymentTypes { Onetime, - ExternalPaymentToken, } #[derive(Debug, Serialize)] @@ -138,11 +137,12 @@ pub struct ZenItemObject { #[derive(Debug, Serialize, Deserialize)] pub struct SessionObject { - pub apple_pay: Option, + pub apple_pay: Option, + pub google_pay: Option, } #[derive(Debug, Serialize, Deserialize)] -pub struct ApplePaySessionData { +pub struct WalletSessionData { pub terminal_uuid: Option, pub pay_wall_secret: Option, } @@ -181,6 +181,7 @@ impl TryFrom<(&types::PaymentsAuthorizeRouterData, &Card)> for ZenPaymentsReques } } +/* impl TryFrom<(&types::PaymentsAuthorizeRouterData, &GooglePayWalletData)> for ZenPaymentsRequest { type Error = error_stack::Report; fn try_from( @@ -213,7 +214,8 @@ impl TryFrom<(&types::PaymentsAuthorizeRouterData, &GooglePayWalletData)> for Ze }))) } } - +*/ +/* impl TryFrom<( &types::PaymentsAuthorizeRouterData, @@ -257,10 +259,67 @@ impl Ok(Self::CheckoutRequest(Box::new(checkout_request))) } } +*/ + +impl + TryFrom<( + &types::PaymentsAuthorizeRouterData, + &api_models::payments::WalletData, + )> for ZenPaymentsRequest +{ + type Error = error_stack::Report; + fn try_from( + (item, wallet_data): ( + &types::PaymentsAuthorizeRouterData, + &api_models::payments::WalletData, + ), + ) -> Result { + let amount = utils::to_currency_base_unit(item.request.amount, item.request.currency)?; + let connector_meta = item.get_connector_meta()?; + let session: SessionObject = connector_meta + .parse_value("SessionObject") + .change_context(errors::ConnectorError::RequestEncodingFailed)?; + let (specified_payment_channel, session_data) = match wallet_data { + api_models::payments::WalletData::ApplePayRedirect(_) => ( + ZenPaymentChannels::PclApplepay, + session + .apple_pay + .ok_or(errors::ConnectorError::RequestEncodingFailed)?, + ), + api_models::payments::WalletData::GooglePayRedirect(_) => ( + ZenPaymentChannels::PclGooglepay, + session + .google_pay + .ok_or(errors::ConnectorError::RequestEncodingFailed)?, + ), + _ => Err(errors::ConnectorError::NotImplemented( + "payment method".to_string(), + ))?, + }; + let terminal_uuid = session_data + .terminal_uuid + .clone() + .ok_or(errors::ConnectorError::RequestEncodingFailed)?; + let mut checkout_request = CheckoutRequest { + merchant_transaction_id: item.attempt_id.clone(), + specified_payment_channel, + currency: item.request.currency, + custom_ipn_url: item.request.get_webhook_url()?, + items: get_item_object(item, amount.clone())?, + amount, + terminal_uuid: Secret::new(terminal_uuid), + signature: None, + url_redirect: item.request.get_return_url()?, + }; + checkout_request.signature = + Some(get_checkout_signature(&checkout_request, &session_data)?); + Ok(Self::CheckoutRequest(Box::new(checkout_request))) + } +} fn get_checkout_signature( checkout_request: &CheckoutRequest, - session: &ApplePaySessionData, + session: &WalletSessionData, ) -> Result, error_stack::Report> { let pay_wall_secret = session .pay_wall_secret @@ -426,17 +485,9 @@ impl TryFrom<&types::PaymentsAuthorizeRouterData> for ZenPaymentsRequest { fn try_from(item: &types::PaymentsAuthorizeRouterData) -> Result { match &item.request.payment_method_data { api_models::payments::PaymentMethodData::Card(card) => Self::try_from((item, card)), - api_models::payments::PaymentMethodData::Wallet(wallet_data) => match wallet_data { - api_models::payments::WalletData::ApplePayRedirect(apple_pay_redirect_data) => { - Self::try_from((item, apple_pay_redirect_data)) - } - api_models::payments::WalletData::GooglePay(gpay_redirect_data) => { - Self::try_from((item, gpay_redirect_data)) - } - _ => Err(errors::ConnectorError::NotImplemented( - "payment method".to_string(), - ))?, - }, + api_models::payments::PaymentMethodData::Wallet(wallet_data) => { + Self::try_from((item, wallet_data)) + } _ => Err(errors::ConnectorError::NotImplemented( "payment method".to_string(), ))?, diff --git a/crates/router/src/openapi.rs b/crates/router/src/openapi.rs index 7f1241817a..1ae4cce033 100644 --- a/crates/router/src/openapi.rs +++ b/crates/router/src/openapi.rs @@ -231,6 +231,7 @@ Never share your secret api keys. Keep them guarded and secure. api_models::payments::ReceiverDetails, api_models::payments::AchTransfer, api_models::payments::ApplePayRedirectData, + api_models::payments::GooglePayRedirectData, api_models::payments::SepaBankTransferInstructions, api_models::payments::BacsBankTransferInstructions, api_models::payments::RedirectResponse, diff --git a/openapi/openapi_spec.json b/openapi/openapi_spec.json index 7a87d11a24..59cdc11ae4 100644 --- a/openapi/openapi_spec.json +++ b/openapi/openapi_spec.json @@ -3982,6 +3982,9 @@ } } }, + "GooglePayRedirectData": { + "type": "object" + }, "GooglePayWalletData": { "type": "object", "required": [ @@ -7898,6 +7901,17 @@ } } }, + { + "type": "object", + "required": [ + "google_pay_redirect" + ], + "properties": { + "apple_pay_redirect": { + "$ref": "#/components/schemas/GooglePayRedirectData" + } + } + }, { "type": "object", "required": [