feat: add support for 3ds and surcharge decision through routing rules (#2869)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
This commit is contained in:
Hrithikesh
2023-11-21 20:25:50 +05:30
committed by GitHub
parent 3f3b797dc6
commit f8618e0770
23 changed files with 1717 additions and 58 deletions

View File

@ -1,5 +1,6 @@
use std::borrow::Cow;
use api_models::payments::GetPaymentMethodType;
use base64::Engine;
use common_utils::{
ext_traits::{AsyncExt, ByteSliceExt, ValueExt},
@ -3516,6 +3517,106 @@ impl ApplePayData {
}
}
pub fn get_key_params_for_surcharge_details(
payment_method_data: api_models::payments::PaymentMethodData,
) -> RouterResult<(
common_enums::PaymentMethod,
common_enums::PaymentMethodType,
Option<common_enums::CardNetwork>,
)> {
match payment_method_data {
api_models::payments::PaymentMethodData::Card(card) => {
let card_type = card
.card_type
.get_required_value("payment_method_data.card.card_type")?;
let card_network = card
.card_network
.get_required_value("payment_method_data.card.card_network")?;
match card_type.to_lowercase().as_str() {
"credit" => Ok((
common_enums::PaymentMethod::Card,
common_enums::PaymentMethodType::Credit,
Some(card_network),
)),
"debit" => Ok((
common_enums::PaymentMethod::Card,
common_enums::PaymentMethodType::Debit,
Some(card_network),
)),
_ => {
logger::debug!("Invalid Card type found in payment confirm call, hence surcharge not applicable");
Err(errors::ApiErrorResponse::InvalidDataValue {
field_name: "payment_method_data.card.card_type",
}
.into())
}
}
}
api_models::payments::PaymentMethodData::CardRedirect(card_redirect_data) => Ok((
common_enums::PaymentMethod::CardRedirect,
card_redirect_data.get_payment_method_type(),
None,
)),
api_models::payments::PaymentMethodData::Wallet(wallet) => Ok((
common_enums::PaymentMethod::Wallet,
wallet.get_payment_method_type(),
None,
)),
api_models::payments::PaymentMethodData::PayLater(pay_later) => Ok((
common_enums::PaymentMethod::PayLater,
pay_later.get_payment_method_type(),
None,
)),
api_models::payments::PaymentMethodData::BankRedirect(bank_redirect) => Ok((
common_enums::PaymentMethod::BankRedirect,
bank_redirect.get_payment_method_type(),
None,
)),
api_models::payments::PaymentMethodData::BankDebit(bank_debit) => Ok((
common_enums::PaymentMethod::BankDebit,
bank_debit.get_payment_method_type(),
None,
)),
api_models::payments::PaymentMethodData::BankTransfer(bank_transfer) => Ok((
common_enums::PaymentMethod::BankTransfer,
bank_transfer.get_payment_method_type(),
None,
)),
api_models::payments::PaymentMethodData::Crypto(crypto) => Ok((
common_enums::PaymentMethod::Crypto,
crypto.get_payment_method_type(),
None,
)),
api_models::payments::PaymentMethodData::MandatePayment => {
Err(errors::ApiErrorResponse::InvalidDataValue {
field_name: "payment_method_data",
}
.into())
}
api_models::payments::PaymentMethodData::Reward => {
Err(errors::ApiErrorResponse::InvalidDataValue {
field_name: "payment_method_data",
}
.into())
}
api_models::payments::PaymentMethodData::Upi(_) => Ok((
common_enums::PaymentMethod::Upi,
common_enums::PaymentMethodType::UpiCollect,
None,
)),
api_models::payments::PaymentMethodData::Voucher(voucher) => Ok((
common_enums::PaymentMethod::Voucher,
voucher.get_payment_method_type(),
None,
)),
api_models::payments::PaymentMethodData::GiftCard(gift_card) => Ok((
common_enums::PaymentMethod::GiftCard,
gift_card.get_payment_method_type(),
None,
)),
}
}
pub fn validate_payment_link_request(
payment_link_object: &api_models::payments::PaymentLinkObject,
confirm: Option<bool>,