mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-30 01:27:31 +08:00
feat(connector): [Zen] add google pay redirect flow support (#1454)
This commit is contained in:
@ -816,6 +816,8 @@ pub enum WalletData {
|
|||||||
ApplePayRedirect(Box<ApplePayRedirectData>),
|
ApplePayRedirect(Box<ApplePayRedirectData>),
|
||||||
/// The wallet data for Google pay
|
/// The wallet data for Google pay
|
||||||
GooglePay(GooglePayWalletData),
|
GooglePay(GooglePayWalletData),
|
||||||
|
/// Wallet data for google pay redirect flow
|
||||||
|
GooglePayRedirect(Box<GooglePayRedirectData>),
|
||||||
MbWayRedirect(Box<MbWayRedirection>),
|
MbWayRedirect(Box<MbWayRedirection>),
|
||||||
/// The wallet data for MobilePay redirect
|
/// The wallet data for MobilePay redirect
|
||||||
MobilePayRedirect(Box<MobilePayRedirection>),
|
MobilePayRedirect(Box<MobilePayRedirection>),
|
||||||
@ -844,6 +846,9 @@ pub struct GooglePayWalletData {
|
|||||||
#[derive(Eq, PartialEq, Clone, Debug, serde::Deserialize, serde::Serialize, ToSchema)]
|
#[derive(Eq, PartialEq, Clone, Debug, serde::Deserialize, serde::Serialize, ToSchema)]
|
||||||
pub struct ApplePayRedirectData {}
|
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)]
|
#[derive(Eq, PartialEq, Clone, Debug, serde::Deserialize, serde::Serialize, ToSchema)]
|
||||||
pub struct WeChatPayRedirection {}
|
pub struct WeChatPayRedirection {}
|
||||||
|
|
||||||
|
|||||||
@ -164,9 +164,7 @@ impl ConnectorIntegration<api::Authorize, types::PaymentsAuthorizeData, types::P
|
|||||||
) -> CustomResult<Vec<(String, request::Maskable<String>)>, errors::ConnectorError> {
|
) -> CustomResult<Vec<(String, request::Maskable<String>)>, errors::ConnectorError> {
|
||||||
let mut headers = self.build_headers(req, connectors)?;
|
let mut headers = self.build_headers(req, connectors)?;
|
||||||
let api_headers = match req.request.payment_method_data {
|
let api_headers = match req.request.payment_method_data {
|
||||||
api_models::payments::PaymentMethodData::Wallet(
|
api_models::payments::PaymentMethodData::Wallet(_) => None,
|
||||||
api_models::payments::WalletData::ApplePayRedirect(_),
|
|
||||||
) => None,
|
|
||||||
_ => Some(Self::get_default_header()),
|
_ => Some(Self::get_default_header()),
|
||||||
};
|
};
|
||||||
if let Some(api_header) = api_headers {
|
if let Some(api_header) = api_headers {
|
||||||
@ -185,9 +183,7 @@ impl ConnectorIntegration<api::Authorize, types::PaymentsAuthorizeData, types::P
|
|||||||
connectors: &settings::Connectors,
|
connectors: &settings::Connectors,
|
||||||
) -> CustomResult<String, errors::ConnectorError> {
|
) -> CustomResult<String, errors::ConnectorError> {
|
||||||
let endpoint = match &req.request.payment_method_data {
|
let endpoint = match &req.request.payment_method_data {
|
||||||
api_models::payments::PaymentMethodData::Wallet(
|
api_models::payments::PaymentMethodData::Wallet(_) => {
|
||||||
api_models::payments::WalletData::ApplePayRedirect(_),
|
|
||||||
) => {
|
|
||||||
let base_url = connectors
|
let base_url = connectors
|
||||||
.zen
|
.zen
|
||||||
.secondary_base_url
|
.secondary_base_url
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
use api_models::payments::{ApplePayRedirectData, Card, GooglePayWalletData};
|
use api_models::payments::Card;
|
||||||
use cards::CardNumber;
|
use cards::CardNumber;
|
||||||
use common_utils::{ext_traits::ValueExt, pii};
|
use common_utils::{ext_traits::ValueExt, pii};
|
||||||
use error_stack::ResultExt;
|
use error_stack::ResultExt;
|
||||||
@ -116,7 +116,6 @@ pub struct ZenBrowserDetails {
|
|||||||
#[serde(rename_all = "snake_case")]
|
#[serde(rename_all = "snake_case")]
|
||||||
pub enum ZenPaymentTypes {
|
pub enum ZenPaymentTypes {
|
||||||
Onetime,
|
Onetime,
|
||||||
ExternalPaymentToken,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize)]
|
#[derive(Debug, Serialize)]
|
||||||
@ -138,11 +137,12 @@ pub struct ZenItemObject {
|
|||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
pub struct SessionObject {
|
pub struct SessionObject {
|
||||||
pub apple_pay: Option<ApplePaySessionData>,
|
pub apple_pay: Option<WalletSessionData>,
|
||||||
|
pub google_pay: Option<WalletSessionData>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
pub struct ApplePaySessionData {
|
pub struct WalletSessionData {
|
||||||
pub terminal_uuid: Option<String>,
|
pub terminal_uuid: Option<String>,
|
||||||
pub pay_wall_secret: Option<String>,
|
pub pay_wall_secret: Option<String>,
|
||||||
}
|
}
|
||||||
@ -181,6 +181,7 @@ impl TryFrom<(&types::PaymentsAuthorizeRouterData, &Card)> for ZenPaymentsReques
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
impl TryFrom<(&types::PaymentsAuthorizeRouterData, &GooglePayWalletData)> for ZenPaymentsRequest {
|
impl TryFrom<(&types::PaymentsAuthorizeRouterData, &GooglePayWalletData)> for ZenPaymentsRequest {
|
||||||
type Error = error_stack::Report<errors::ConnectorError>;
|
type Error = error_stack::Report<errors::ConnectorError>;
|
||||||
fn try_from(
|
fn try_from(
|
||||||
@ -213,7 +214,8 @@ impl TryFrom<(&types::PaymentsAuthorizeRouterData, &GooglePayWalletData)> for Ze
|
|||||||
})))
|
})))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
/*
|
||||||
impl
|
impl
|
||||||
TryFrom<(
|
TryFrom<(
|
||||||
&types::PaymentsAuthorizeRouterData,
|
&types::PaymentsAuthorizeRouterData,
|
||||||
@ -257,10 +259,67 @@ impl
|
|||||||
Ok(Self::CheckoutRequest(Box::new(checkout_request)))
|
Ok(Self::CheckoutRequest(Box::new(checkout_request)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
impl
|
||||||
|
TryFrom<(
|
||||||
|
&types::PaymentsAuthorizeRouterData,
|
||||||
|
&api_models::payments::WalletData,
|
||||||
|
)> for ZenPaymentsRequest
|
||||||
|
{
|
||||||
|
type Error = error_stack::Report<errors::ConnectorError>;
|
||||||
|
fn try_from(
|
||||||
|
(item, wallet_data): (
|
||||||
|
&types::PaymentsAuthorizeRouterData,
|
||||||
|
&api_models::payments::WalletData,
|
||||||
|
),
|
||||||
|
) -> Result<Self, Self::Error> {
|
||||||
|
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(
|
fn get_checkout_signature(
|
||||||
checkout_request: &CheckoutRequest,
|
checkout_request: &CheckoutRequest,
|
||||||
session: &ApplePaySessionData,
|
session: &WalletSessionData,
|
||||||
) -> Result<Secret<String>, error_stack::Report<errors::ConnectorError>> {
|
) -> Result<Secret<String>, error_stack::Report<errors::ConnectorError>> {
|
||||||
let pay_wall_secret = session
|
let pay_wall_secret = session
|
||||||
.pay_wall_secret
|
.pay_wall_secret
|
||||||
@ -426,17 +485,9 @@ impl TryFrom<&types::PaymentsAuthorizeRouterData> for ZenPaymentsRequest {
|
|||||||
fn try_from(item: &types::PaymentsAuthorizeRouterData) -> Result<Self, Self::Error> {
|
fn try_from(item: &types::PaymentsAuthorizeRouterData) -> Result<Self, Self::Error> {
|
||||||
match &item.request.payment_method_data {
|
match &item.request.payment_method_data {
|
||||||
api_models::payments::PaymentMethodData::Card(card) => Self::try_from((item, card)),
|
api_models::payments::PaymentMethodData::Card(card) => Self::try_from((item, card)),
|
||||||
api_models::payments::PaymentMethodData::Wallet(wallet_data) => match wallet_data {
|
api_models::payments::PaymentMethodData::Wallet(wallet_data) => {
|
||||||
api_models::payments::WalletData::ApplePayRedirect(apple_pay_redirect_data) => {
|
Self::try_from((item, wallet_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(),
|
|
||||||
))?,
|
|
||||||
},
|
|
||||||
_ => Err(errors::ConnectorError::NotImplemented(
|
_ => Err(errors::ConnectorError::NotImplemented(
|
||||||
"payment method".to_string(),
|
"payment method".to_string(),
|
||||||
))?,
|
))?,
|
||||||
|
|||||||
@ -231,6 +231,7 @@ Never share your secret api keys. Keep them guarded and secure.
|
|||||||
api_models::payments::ReceiverDetails,
|
api_models::payments::ReceiverDetails,
|
||||||
api_models::payments::AchTransfer,
|
api_models::payments::AchTransfer,
|
||||||
api_models::payments::ApplePayRedirectData,
|
api_models::payments::ApplePayRedirectData,
|
||||||
|
api_models::payments::GooglePayRedirectData,
|
||||||
api_models::payments::SepaBankTransferInstructions,
|
api_models::payments::SepaBankTransferInstructions,
|
||||||
api_models::payments::BacsBankTransferInstructions,
|
api_models::payments::BacsBankTransferInstructions,
|
||||||
api_models::payments::RedirectResponse,
|
api_models::payments::RedirectResponse,
|
||||||
|
|||||||
@ -3982,6 +3982,9 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"GooglePayRedirectData": {
|
||||||
|
"type": "object"
|
||||||
|
},
|
||||||
"GooglePayWalletData": {
|
"GooglePayWalletData": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"required": [
|
"required": [
|
||||||
@ -7898,6 +7901,17 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"type": "object",
|
||||||
|
"required": [
|
||||||
|
"google_pay_redirect"
|
||||||
|
],
|
||||||
|
"properties": {
|
||||||
|
"apple_pay_redirect": {
|
||||||
|
"$ref": "#/components/schemas/GooglePayRedirectData"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"required": [
|
"required": [
|
||||||
|
|||||||
Reference in New Issue
Block a user