mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-11-02 04:04:43 +08:00
fix(connector): [Bluesnap] Throw proper error message for redirection scenario (#1367)
Signed-off-by: chikke srujan <121822803+srujanchikke@users.noreply.github.com> Co-authored-by: Prasunna Soppa <prasunna.soppa@juspay.in>
This commit is contained in:
@ -1094,9 +1094,15 @@ impl services::ConnectorRedirectResponse for Bluesnap {
|
||||
|
||||
match redirection_result.status.as_str() {
|
||||
"Success" => Ok(payments::CallConnectorAction::Trigger),
|
||||
_ => Ok(payments::CallConnectorAction::StatusUpdate(
|
||||
enums::AttemptStatus::AuthenticationFailed,
|
||||
)),
|
||||
_ => Ok(payments::CallConnectorAction::StatusUpdate {
|
||||
status: enums::AttemptStatus::AuthenticationFailed,
|
||||
error_code: redirection_result.code,
|
||||
error_message: redirection_result
|
||||
.info
|
||||
.as_ref()
|
||||
.and_then(|info| info.errors.as_ref().and_then(|error| error.first()))
|
||||
.cloned(),
|
||||
}),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
use api_models::enums as api_enums;
|
||||
use base64::Engine;
|
||||
use common_utils::{
|
||||
errors::CustomResult,
|
||||
ext_traits::{ByteSliceExt, StringExt, ValueExt},
|
||||
pii::Email,
|
||||
};
|
||||
@ -9,7 +10,7 @@ use masking::ExposeInterface;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{
|
||||
connector::utils::{self, RouterData},
|
||||
connector::utils::{self, AddressDetailsData, PaymentsAuthorizeRequestData, RouterData},
|
||||
consts,
|
||||
core::errors,
|
||||
pii::Secret,
|
||||
@ -27,6 +28,15 @@ pub struct BluesnapPaymentsRequest {
|
||||
card_transaction_type: BluesnapTxnType,
|
||||
three_d_secure: Option<BluesnapThreeDSecureInfo>,
|
||||
transaction_fraud_info: Option<TransactionFraudInfo>,
|
||||
card_holder_info: Option<BluesnapCardHolderInfo>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct BluesnapCardHolderInfo {
|
||||
first_name: Secret<String>,
|
||||
last_name: Secret<String>,
|
||||
email: Email,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
@ -149,13 +159,16 @@ impl TryFrom<&types::PaymentsAuthorizeRouterData> for BluesnapPaymentsRequest {
|
||||
Some(enums::CaptureMethod::Manual) => BluesnapTxnType::AuthOnly,
|
||||
_ => BluesnapTxnType::AuthCapture,
|
||||
};
|
||||
let payment_method = match item.request.payment_method_data.clone() {
|
||||
api::PaymentMethodData::Card(ccard) => Ok(PaymentMethodDetails::CreditCard(Card {
|
||||
card_number: ccard.card_number,
|
||||
expiration_month: ccard.card_exp_month.clone(),
|
||||
expiration_year: ccard.card_exp_year.clone(),
|
||||
security_code: ccard.card_cvc,
|
||||
})),
|
||||
let (payment_method, card_holder_info) = match item.request.payment_method_data.clone() {
|
||||
api::PaymentMethodData::Card(ccard) => Ok((
|
||||
PaymentMethodDetails::CreditCard(Card {
|
||||
card_number: ccard.card_number,
|
||||
expiration_month: ccard.card_exp_month.clone(),
|
||||
expiration_year: ccard.card_exp_year.clone(),
|
||||
security_code: ccard.card_cvc,
|
||||
}),
|
||||
get_card_holder_info(item)?,
|
||||
)),
|
||||
api::PaymentMethodData::Wallet(wallet_data) => match wallet_data {
|
||||
api_models::payments::WalletData::GooglePay(payment_method_data) => {
|
||||
let gpay_object = Encode::<BluesnapGooglePayObject>::encode_to_string_of_json(
|
||||
@ -166,10 +179,13 @@ impl TryFrom<&types::PaymentsAuthorizeRouterData> for BluesnapPaymentsRequest {
|
||||
},
|
||||
)
|
||||
.change_context(errors::ConnectorError::RequestEncodingFailed)?;
|
||||
Ok(PaymentMethodDetails::Wallet(BluesnapWallet {
|
||||
wallet_type: BluesnapWalletTypes::GooglePay,
|
||||
encoded_payment_token: consts::BASE64_ENGINE.encode(gpay_object),
|
||||
}))
|
||||
Ok((
|
||||
PaymentMethodDetails::Wallet(BluesnapWallet {
|
||||
wallet_type: BluesnapWalletTypes::GooglePay,
|
||||
encoded_payment_token: consts::BASE64_ENGINE.encode(gpay_object),
|
||||
}),
|
||||
None,
|
||||
))
|
||||
}
|
||||
api_models::payments::WalletData::ApplePay(payment_method_data) => {
|
||||
let apple_pay_payment_data = consts::BASE64_ENGINE
|
||||
@ -230,10 +246,13 @@ impl TryFrom<&types::PaymentsAuthorizeRouterData> for BluesnapPaymentsRequest {
|
||||
)
|
||||
.change_context(errors::ConnectorError::RequestEncodingFailed)?;
|
||||
|
||||
Ok(PaymentMethodDetails::Wallet(BluesnapWallet {
|
||||
wallet_type: BluesnapWalletTypes::ApplePay,
|
||||
encoded_payment_token: consts::BASE64_ENGINE.encode(apple_pay_object),
|
||||
}))
|
||||
Ok((
|
||||
PaymentMethodDetails::Wallet(BluesnapWallet {
|
||||
wallet_type: BluesnapWalletTypes::ApplePay,
|
||||
encoded_payment_token: consts::BASE64_ENGINE.encode(apple_pay_object),
|
||||
}),
|
||||
None,
|
||||
))
|
||||
}
|
||||
_ => Err(errors::ConnectorError::NotImplemented(
|
||||
"Wallets".to_string(),
|
||||
@ -252,6 +271,7 @@ impl TryFrom<&types::PaymentsAuthorizeRouterData> for BluesnapPaymentsRequest {
|
||||
transaction_fraud_info: Some(TransactionFraudInfo {
|
||||
fraud_session_id: item.payment_id.clone(),
|
||||
}),
|
||||
card_holder_info,
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -397,6 +417,7 @@ impl TryFrom<&types::PaymentsCompleteAuthorizeRouterData> for BluesnapPaymentsRe
|
||||
transaction_fraud_info: Some(TransactionFraudInfo {
|
||||
fraud_session_id: item.payment_id.clone(),
|
||||
}),
|
||||
card_holder_info: None,
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -411,6 +432,14 @@ pub struct BluesnapRedirectionResponse {
|
||||
pub struct BluesnapThreeDsResult {
|
||||
three_d_secure: Option<BluesnapThreeDsReference>,
|
||||
pub status: String,
|
||||
pub code: Option<String>,
|
||||
pub info: Option<RedirectErrorMessage>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct RedirectErrorMessage {
|
||||
pub errors: Option<Vec<String>>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
@ -759,3 +788,14 @@ pub enum BluesnapErrors {
|
||||
PaymentError(BluesnapErrorResponse),
|
||||
AuthError(BluesnapAuthErrorResponse),
|
||||
}
|
||||
|
||||
fn get_card_holder_info(
|
||||
item: &types::PaymentsAuthorizeRouterData,
|
||||
) -> CustomResult<Option<BluesnapCardHolderInfo>, errors::ConnectorError> {
|
||||
let address = item.get_billing_address()?;
|
||||
Ok(Some(BluesnapCardHolderInfo {
|
||||
first_name: address.get_first_name()?.clone(),
|
||||
last_name: address.get_last_name()?.clone(),
|
||||
email: item.request.get_email()?,
|
||||
}))
|
||||
}
|
||||
|
||||
@ -1199,9 +1199,13 @@ impl services::ConnectorRedirectResponse for Checkout {
|
||||
.change_context(errors::ConnectorError::ResponseDeserializationFailed)?;
|
||||
let connector_action = query
|
||||
.status
|
||||
.map(|checkout_status| {
|
||||
payments::CallConnectorAction::StatusUpdate(checkout_status.into())
|
||||
})
|
||||
.map(
|
||||
|checkout_status| payments::CallConnectorAction::StatusUpdate {
|
||||
status: storage_models::enums::AttemptStatus::from(checkout_status),
|
||||
error_code: None,
|
||||
error_message: None,
|
||||
},
|
||||
)
|
||||
.unwrap_or(payments::CallConnectorAction::Trigger);
|
||||
Ok(connector_action)
|
||||
}
|
||||
|
||||
@ -914,9 +914,11 @@ impl services::ConnectorRedirectResponse for Globalpay {
|
||||
payments::CallConnectorAction::Trigger,
|
||||
|status| match status {
|
||||
response::GlobalpayPaymentStatus::Captured => {
|
||||
payments::CallConnectorAction::StatusUpdate(
|
||||
storage_models::enums::AttemptStatus::from(status),
|
||||
)
|
||||
payments::CallConnectorAction::StatusUpdate {
|
||||
status: storage_models::enums::AttemptStatus::from(status),
|
||||
error_code: None,
|
||||
error_message: None,
|
||||
}
|
||||
}
|
||||
_ => payments::CallConnectorAction::Trigger,
|
||||
},
|
||||
|
||||
@ -957,9 +957,11 @@ impl services::ConnectorRedirectResponse for Nuvei {
|
||||
.switch()?;
|
||||
match acs_response.trans_status {
|
||||
None | Some(nuvei::LiabilityShift::Failed) => {
|
||||
Ok(payments::CallConnectorAction::StatusUpdate(
|
||||
enums::AttemptStatus::AuthenticationFailed,
|
||||
))
|
||||
Ok(payments::CallConnectorAction::StatusUpdate {
|
||||
status: enums::AttemptStatus::AuthenticationFailed,
|
||||
error_code: None,
|
||||
error_message: None,
|
||||
})
|
||||
}
|
||||
_ => Ok(payments::CallConnectorAction::Trigger),
|
||||
}
|
||||
|
||||
@ -1831,9 +1831,11 @@ impl services::ConnectorRedirectResponse for Stripe {
|
||||
transformers::StripePaymentStatus::Failed => {
|
||||
payments::CallConnectorAction::Trigger
|
||||
}
|
||||
_ => payments::CallConnectorAction::StatusUpdate(enums::AttemptStatus::from(
|
||||
status,
|
||||
)),
|
||||
_ => payments::CallConnectorAction::StatusUpdate {
|
||||
status: enums::AttemptStatus::from(status),
|
||||
error_code: None,
|
||||
error_message: None,
|
||||
},
|
||||
},
|
||||
))
|
||||
}
|
||||
|
||||
@ -802,9 +802,11 @@ impl services::ConnectorRedirectResponse for Trustpay {
|
||||
Ok(query.status.map_or(
|
||||
payments::CallConnectorAction::Trigger,
|
||||
|status| match status.as_str() {
|
||||
"SuccessOk" => payments::CallConnectorAction::StatusUpdate(
|
||||
storage_models::enums::AttemptStatus::Charged,
|
||||
),
|
||||
"SuccessOk" => payments::CallConnectorAction::StatusUpdate {
|
||||
status: storage_models::enums::AttemptStatus::Charged,
|
||||
error_code: None,
|
||||
error_message: None,
|
||||
},
|
||||
_ => payments::CallConnectorAction::Trigger,
|
||||
},
|
||||
))
|
||||
|
||||
@ -429,6 +429,7 @@ pub trait CardData {
|
||||
delimiter: String,
|
||||
) -> Secret<String>;
|
||||
fn get_expiry_date_as_yyyymm(&self, delimiter: &str) -> Secret<String>;
|
||||
fn get_expiry_year_4_digit(&self) -> Secret<String>;
|
||||
}
|
||||
|
||||
impl CardData for api::Card {
|
||||
@ -453,17 +454,21 @@ impl CardData for api::Card {
|
||||
))
|
||||
}
|
||||
fn get_expiry_date_as_yyyymm(&self, delimiter: &str) -> Secret<String> {
|
||||
let mut x = self.card_exp_year.peek().clone();
|
||||
if x.len() == 2 {
|
||||
x = format!("20{}", x);
|
||||
}
|
||||
let year = self.get_expiry_year_4_digit();
|
||||
Secret::new(format!(
|
||||
"{}{}{}",
|
||||
x,
|
||||
year.peek(),
|
||||
delimiter,
|
||||
self.card_exp_month.peek().clone()
|
||||
))
|
||||
}
|
||||
fn get_expiry_year_4_digit(&self) -> Secret<String> {
|
||||
let mut year = self.card_exp_year.peek().clone();
|
||||
if year.len() == 2 {
|
||||
year = format!("20{}", year);
|
||||
}
|
||||
Secret::new(year)
|
||||
}
|
||||
}
|
||||
|
||||
#[track_caller]
|
||||
|
||||
@ -937,7 +937,11 @@ where
|
||||
pub enum CallConnectorAction {
|
||||
Trigger,
|
||||
Avoid,
|
||||
StatusUpdate(storage_enums::AttemptStatus),
|
||||
StatusUpdate {
|
||||
status: storage_enums::AttemptStatus,
|
||||
error_code: Option<String>,
|
||||
error_message: Option<String>,
|
||||
},
|
||||
HandleResponse(Vec<u8>),
|
||||
}
|
||||
|
||||
|
||||
@ -21,6 +21,7 @@ use self::request::{ContentType, HeaderExt, RequestBuilderExt};
|
||||
pub use self::request::{Method, Request, RequestBuilder};
|
||||
use crate::{
|
||||
configs::settings::Connectors,
|
||||
consts,
|
||||
core::{
|
||||
errors::{self, CustomResult},
|
||||
payments,
|
||||
@ -190,8 +191,23 @@ where
|
||||
connector_integration.handle_response(req, response)
|
||||
}
|
||||
payments::CallConnectorAction::Avoid => Ok(router_data),
|
||||
payments::CallConnectorAction::StatusUpdate(status) => {
|
||||
payments::CallConnectorAction::StatusUpdate {
|
||||
status,
|
||||
error_code,
|
||||
error_message,
|
||||
} => {
|
||||
router_data.status = status;
|
||||
let error_response = if error_code.is_some() | error_message.is_some() {
|
||||
Some(ErrorResponse {
|
||||
code: error_code.unwrap_or(consts::NO_ERROR_CODE.to_string()),
|
||||
message: error_message.unwrap_or(consts::NO_ERROR_MESSAGE.to_string()),
|
||||
status_code: 200, // This status code is ignored in redirection response it will override with 302 status code.
|
||||
reason: None,
|
||||
})
|
||||
} else {
|
||||
None
|
||||
};
|
||||
router_data.response = error_response.map(Err).unwrap_or(router_data.response);
|
||||
Ok(router_data)
|
||||
}
|
||||
payments::CallConnectorAction::Trigger => {
|
||||
|
||||
Reference in New Issue
Block a user