Skip to content

Commit

Permalink
fix(connectors): fix wallet token deserialization error (#4133)
Browse files Browse the repository at this point in the history
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
  • Loading branch information
AkshayaFoiger and hyperswitch-bot[bot] authored Mar 27, 2024
1 parent 0706221 commit 929848f
Show file tree
Hide file tree
Showing 22 changed files with 147 additions and 61 deletions.
10 changes: 10 additions & 0 deletions crates/router/src/compatibility/stripe/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ pub enum StripeErrorCode {
#[error(error_type = StripeErrorType::CardError, code = "invalid_card_type", message = "Card data is invalid")]
InvalidCardType,

#[error(
error_type = StripeErrorType::ConnectorError, code = "invalid_wallet_token",
message = "Invalid {wallet_name} wallet token"
)]
InvalidWalletToken { wallet_name: String },

#[error(error_type = StripeErrorType::ApiError, code = "refund_failed", message = "refund has failed")]
RefundFailed, // stripe error code

Expand Down Expand Up @@ -625,6 +631,9 @@ impl From<errors::ApiErrorResponse> for StripeErrorCode {
}
errors::ApiErrorResponse::CurrencyConversionFailed => Self::CurrencyConversionFailed,
errors::ApiErrorResponse::PaymentMethodDeleteFailed => Self::PaymentMethodDeleteFailed,
errors::ApiErrorResponse::InvalidWalletToken { wallet_name } => {
Self::InvalidWalletToken { wallet_name }
}
}
}
}
Expand Down Expand Up @@ -671,6 +680,7 @@ impl actix_web::ResponseError for StripeErrorCode {
| Self::PaymentIntentInvalidParameter { .. }
| Self::SerdeQsError { .. }
| Self::InvalidRequestData { .. }
| Self::InvalidWalletToken { .. }
| Self::PreconditionFailed { .. }
| Self::DuplicateMandate
| Self::SuccessfulPaymentNotFound
Expand Down
7 changes: 6 additions & 1 deletion crates/router/src/connector/bankofamerica/transformers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use crate::{
transformers::ForeignFrom,
ApplePayPredecryptData,
},
unimplemented_payment_method,
};

pub struct BankOfAmericaAuthType {
Expand Down Expand Up @@ -708,7 +709,11 @@ impl TryFrom<&BankOfAmericaRouterData<&types::PaymentsAuthorizeRouterData>>
Self::try_from((item, decrypt_data, apple_pay_data))
}
types::PaymentMethodToken::Token(_) => {
Err(errors::ConnectorError::InvalidWalletToken)?
Err(unimplemented_payment_method!(
"Apple Pay",
"Manual",
"Bank Of America"
))?
}
},
None => {
Expand Down
9 changes: 5 additions & 4 deletions crates/router/src/connector/bluesnap/transformers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,14 +310,15 @@ impl TryFrom<&BluesnapRouterData<&types::PaymentsAuthorizeRouterData>> for Blues
))
}
api_models::payments::WalletData::ApplePay(payment_method_data) => {
let apple_pay_payment_data = payment_method_data
.get_applepay_decoded_payment_data()
.change_context(errors::ConnectorError::RequestEncodingFailed)?;
let apple_pay_payment_data =
payment_method_data.get_applepay_decoded_payment_data()?;
let apple_pay_payment_data: ApplePayEncodedPaymentData = apple_pay_payment_data
.expose()[..]
.as_bytes()
.parse_struct("ApplePayEncodedPaymentData")
.change_context(errors::ConnectorError::RequestEncodingFailed)?;
.change_context(errors::ConnectorError::InvalidWalletToken {
wallet_name: "Apple Pay".to_string(),
})?;

let billing = item.router_data.get_billing()?.to_owned();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use crate::{
core::errors,
services,
types::{self, api, storage::enums},
unimplemented_payment_method,
};

pub const CLIENT_TOKEN_MUTATION: &str = "mutation createClientToken($input: CreateClientTokenInput!) { createClientToken(input: $input) { clientToken}}";
Expand Down Expand Up @@ -1334,9 +1335,9 @@ impl
input: PaymentInput {
payment_method_id: match item.router_data.get_payment_method_token()? {
types::PaymentMethodToken::Token(token) => token.into(),
types::PaymentMethodToken::ApplePayDecrypt(_) => {
Err(errors::ConnectorError::InvalidWalletToken)?
}
types::PaymentMethodToken::ApplePayDecrypt(_) => Err(
unimplemented_payment_method!("Apple Pay", "Simplified", "Braintree"),
)?,
},
transaction: TransactionBody {
amount: item.amount.to_owned(),
Expand Down Expand Up @@ -1416,9 +1417,11 @@ fn get_braintree_redirect_form(
.expose(),
card_token: match payment_method_token {
types::PaymentMethodToken::Token(token) => token,
types::PaymentMethodToken::ApplePayDecrypt(_) => {
Err(errors::ConnectorError::InvalidWalletToken)?
}
types::PaymentMethodToken::ApplePayDecrypt(_) => Err(unimplemented_payment_method!(
"Apple Pay",
"Simplified",
"Braintree"
))?,
},
bin: match card_details {
api_models::payments::PaymentMethodData::Card(card_details) => {
Expand Down
11 changes: 8 additions & 3 deletions crates/router/src/connector/checkout/transformers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use crate::{
core::errors,
services,
types::{self, api, storage::enums, transformers::ForeignFrom},
unimplemented_payment_method,
};

#[derive(Debug, Serialize)]
Expand Down Expand Up @@ -92,12 +93,12 @@ impl TryFrom<&types::TokenizationRouterData> for TokenRequest {
api::PaymentMethodData::Wallet(wallet_data) => match wallet_data.clone() {
api_models::payments::WalletData::GooglePay(_data) => {
let json_wallet_data: CheckoutGooglePayData =
wallet_data.get_wallet_token_as_json()?;
wallet_data.get_wallet_token_as_json("Google Pay".to_string())?;
Ok(Self::Googlepay(json_wallet_data))
}
api_models::payments::WalletData::ApplePay(_data) => {
let json_wallet_data: CheckoutApplePayData =
wallet_data.get_wallet_token_as_json()?;
wallet_data.get_wallet_token_as_json("Apple Pay".to_string())?;
Ok(Self::Applepay(json_wallet_data))
}
api_models::payments::WalletData::AliPayQr(_)
Expand Down Expand Up @@ -308,7 +309,11 @@ impl TryFrom<&CheckoutRouterData<&types::PaymentsAuthorizeRouterData>> for Payme
token: match item.router_data.get_payment_method_token()? {
types::PaymentMethodToken::Token(token) => token.into(),
types::PaymentMethodToken::ApplePayDecrypt(_) => {
Err(errors::ConnectorError::InvalidWalletToken)?
Err(unimplemented_payment_method!(
"Apple Pay",
"Simplified",
"Checkout"
))?
}
},
}))
Expand Down
13 changes: 9 additions & 4 deletions crates/router/src/connector/cybersource/transformers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use crate::{
transformers::ForeignFrom,
ApplePayPredecryptData,
},
unimplemented_payment_method,
};

#[derive(Debug, Serialize)]
Expand Down Expand Up @@ -139,9 +140,9 @@ impl TryFrom<&types::SetupMandateRouterData> for CybersourceZeroMandateRequest {
Some(PaymentSolution::ApplePay),
)
}
types::PaymentMethodToken::Token(_) => {
Err(errors::ConnectorError::InvalidWalletToken)?
}
types::PaymentMethodToken::Token(_) => Err(
unimplemented_payment_method!("Apple Pay", "Manual", "Cybersource"),
)?,
},
None => (
PaymentInformation::ApplePayToken(ApplePayTokenPaymentInformation {
Expand Down Expand Up @@ -980,7 +981,11 @@ impl TryFrom<&CybersourceRouterData<&types::PaymentsAuthorizeRouterData>>
Self::try_from((item, decrypt_data, apple_pay_data))
}
types::PaymentMethodToken::Token(_) => {
Err(errors::ConnectorError::InvalidWalletToken)?
Err(unimplemented_payment_method!(
"Apple Pay",
"Manual",
"Cybersource"
))?
}
},
None => {
Expand Down
2 changes: 1 addition & 1 deletion crates/router/src/connector/globalpay/transformers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ fn get_wallet_data(
api_models::payments::WalletData::GooglePay(_) => {
Ok(PaymentMethodData::DigitalWallet(requests::DigitalWallet {
provider: Some(requests::DigitalWalletProvider::PayByGoogle),
payment_token: wallet_data.get_wallet_token_as_json()?,
payment_token: wallet_data.get_wallet_token_as_json("Google Pay".to_string())?,
}))
}
_ => Err(errors::ConnectorError::NotImplemented(
Expand Down
7 changes: 6 additions & 1 deletion crates/router/src/connector/mollie/transformers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use crate::{
core::errors,
services, types,
types::storage::enums as storage_enums,
unimplemented_payment_method,
};

type Error = error_stack::Report<errors::ConnectorError>;
Expand Down Expand Up @@ -178,7 +179,11 @@ impl TryFrom<&MollieRouterData<&types::PaymentsAuthorizeRouterData>> for MollieP
card_token: Some(Secret::new(match pm_token {
types::PaymentMethodToken::Token(token) => token,
types::PaymentMethodToken::ApplePayDecrypt(_) => {
Err(errors::ConnectorError::InvalidWalletToken)?
Err(unimplemented_payment_method!(
"Apple Pay",
"Simplified",
"Mollie"
))?
}
})),
},
Expand Down
2 changes: 1 addition & 1 deletion crates/router/src/connector/nexinets/transformers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,7 @@ fn get_applepay_details(
wallet_data: &api_models::payments::WalletData,
applepay_data: &api_models::payments::ApplePayWalletData,
) -> CustomResult<ApplePayDetails, errors::ConnectorError> {
let payment_data = wallet_data.get_wallet_token_as_json()?;
let payment_data = wallet_data.get_wallet_token_as_json("Apple Pay".to_string())?;
Ok(ApplePayDetails {
payment_data,
payment_method: ApplepayPaymentMethod {
Expand Down
3 changes: 2 additions & 1 deletion crates/router/src/connector/noon/transformers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,8 @@ impl TryFrom<&types::PaymentsAuthorizeRouterData> for NoonPaymentsRequest {
api_models::payments::WalletData::ApplePay(apple_pay_data) => {
let payment_token_data = NoonApplePayTokenData {
token: NoonApplePayData {
payment_data: wallet_data.get_wallet_token_as_json()?,
payment_data: wallet_data
.get_wallet_token_as_json("Apple Pay".to_string())?,
payment_method: NoonApplePayPaymentMethod {
display_name: apple_pay_data.payment_method.display_name,
network: apple_pay_data.payment_method.network,
Expand Down
7 changes: 4 additions & 3 deletions crates/router/src/connector/payme/transformers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use crate::{
core::errors,
services,
types::{self, api, storage::enums, MandateReference},
unimplemented_payment_method,
};

const LANGUAGE: &str = "en";
Expand Down Expand Up @@ -708,9 +709,9 @@ impl TryFrom<&types::PaymentsCompleteAuthorizeRouterData> for Pay3dsRequest {
let pm_token = item.get_payment_method_token()?;
let buyer_key = match pm_token {
types::PaymentMethodToken::Token(token) => token,
types::PaymentMethodToken::ApplePayDecrypt(_) => {
Err(errors::ConnectorError::InvalidWalletToken)?
}
types::PaymentMethodToken::ApplePayDecrypt(_) => Err(
unimplemented_payment_method!("Apple Pay", "Simplified", "Payme"),
)?,
};
Ok(Self {
buyer_email,
Expand Down
7 changes: 4 additions & 3 deletions crates/router/src/connector/square/transformers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use crate::{
self, api,
storage::{self, enums},
},
unimplemented_payment_method,
};

impl TryFrom<(&types::TokenizationRouterData, BankDebitData)> for SquareTokenRequest {
Expand Down Expand Up @@ -257,9 +258,9 @@ impl TryFrom<&types::PaymentsAuthorizeRouterData> for SquarePaymentsRequest {
idempotency_key: Secret::new(item.attempt_id.clone()),
source_id: Secret::new(match pm_token {
types::PaymentMethodToken::Token(token) => token,
types::PaymentMethodToken::ApplePayDecrypt(_) => {
Err(errors::ConnectorError::InvalidWalletToken)?
}
types::PaymentMethodToken::ApplePayDecrypt(_) => Err(
unimplemented_payment_method!("Apple Pay", "Simplified", "Square"),
)?,
}),
amount_money: SquarePaymentsAmountData {
amount: item.request.amount,
Expand Down
13 changes: 7 additions & 6 deletions crates/router/src/connector/stax/transformers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use crate::{
},
core::errors,
types::{self, api, storage::enums},
unimplemented_payment_method,
};

#[derive(Debug, Serialize)]
Expand Down Expand Up @@ -80,9 +81,9 @@ impl TryFrom<&StaxRouterData<&types::PaymentsAuthorizeRouterData>> for StaxPayme
pre_auth,
payment_method_id: Secret::new(match pm_token {
types::PaymentMethodToken::Token(token) => token,
types::PaymentMethodToken::ApplePayDecrypt(_) => {
Err(errors::ConnectorError::InvalidWalletToken)?
}
types::PaymentMethodToken::ApplePayDecrypt(_) => Err(
unimplemented_payment_method!("Apple Pay", "Simplified", "Stax"),
)?,
}),
idempotency_id: Some(item.router_data.connector_request_reference_id.clone()),
})
Expand All @@ -99,9 +100,9 @@ impl TryFrom<&StaxRouterData<&types::PaymentsAuthorizeRouterData>> for StaxPayme
pre_auth,
payment_method_id: Secret::new(match pm_token {
types::PaymentMethodToken::Token(token) => token,
types::PaymentMethodToken::ApplePayDecrypt(_) => {
Err(errors::ConnectorError::InvalidWalletToken)?
}
types::PaymentMethodToken::ApplePayDecrypt(_) => Err(
unimplemented_payment_method!("Apple Pay", "Simplified", "Stax"),
)?,
}),
idempotency_id: Some(item.router_data.connector_request_reference_id.clone()),
})
Expand Down
20 changes: 12 additions & 8 deletions crates/router/src/connector/stripe/transformers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ use crate::{
storage::enums,
transformers::{ForeignFrom, ForeignTryFrom},
},
unimplemented_payment_method,
utils::OptionExt,
};

Expand Down Expand Up @@ -1541,9 +1542,7 @@ impl TryFrom<(&payments::WalletData, Option<types::PaymentMethodToken>)>
if apple_pay_decrypt_data.is_none() {
apple_pay_decrypt_data =
Some(Self::Wallet(StripeWallet::ApplepayToken(StripeApplePay {
pk_token: applepay_data
.get_applepay_decoded_payment_data()
.change_context(errors::ConnectorError::RequestEncodingFailed)?,
pk_token: applepay_data.get_applepay_decoded_payment_data()?,
pk_token_instrument_name: applepay_data
.payment_method
.pm_type
Expand Down Expand Up @@ -1715,7 +1714,9 @@ impl TryFrom<&payments::GooglePayWalletData> for StripePaymentMethodData {
.token
.as_bytes()
.parse_struct::<StripeGpayToken>("StripeGpayToken")
.change_context(errors::ConnectorError::RequestEncodingFailed)?
.change_context(errors::ConnectorError::InvalidWalletToken {
wallet_name: "Google Pay".to_string(),
})?
.id,
),
payment_type: StripePaymentMethodType::Card,
Expand Down Expand Up @@ -1862,12 +1863,15 @@ impl TryFrom<&types::PaymentsAuthorizeRouterData> for PaymentIntentRequest {
.payment_method_token
.to_owned()
.get_required_value("payment_token")
.change_context(errors::ConnectorError::RequestEncodingFailed)?;
.change_context(errors::ConnectorError::InvalidWalletToken {
wallet_name: "Apple Pay".to_string(),
})?;

let payment_method_token = match payment_method_token {
types::PaymentMethodToken::Token(payment_method_token) => payment_method_token,
types::PaymentMethodToken::ApplePayDecrypt(_) => {
Err(errors::ConnectorError::InvalidWalletToken)?
}
types::PaymentMethodToken::ApplePayDecrypt(_) => Err(
unimplemented_payment_method!("Apple Pay", "Simplified", "Stripe"),
)?,
};
Some(StripePaymentMethodData::Wallet(
StripeWallet::ApplepayPayment(ApplepayPayment {
Expand Down
Loading

0 comments on commit 929848f

Please sign in to comment.