Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 46 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from 41 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
1c138f2
fix: handle session and confirm flow discrepancy in surcharge details
hrithikesh026 Oct 25, 2023
24e3cf4
take surcharge from payment attempt if not passed in confirm call
hrithikesh026 Oct 26, 2023
90c9880
Merge branch 'main' into handle-session-flow-surcharge-discrepancy
hrithikesh026 Oct 26, 2023
7d6c58f
confirm surcharge details if payment method requires sdk
hrithikesh026 Oct 29, 2023
06d8706
Merge branch 'main' into handle-session-flow-surcharge-discrepancy
hrithikesh026 Oct 31, 2023
6e011cf
address comments
hrithikesh026 Nov 2, 2023
8263347
address comments
hrithikesh026 Nov 2, 2023
149f4d0
cover generated surcharge case
hrithikesh026 Nov 3, 2023
193f984
introduce SessionSurchargeDetails enum
hrithikesh026 Nov 3, 2023
2d88f2c
address spell check
hrithikesh026 Nov 3, 2023
f59aac7
move functions to SurchargeMetadata
hrithikesh026 Nov 3, 2023
b8d7b6e
Merge branch 'main' into handle-session-flow-surcharge-discrepancy
hrithikesh026 Nov 3, 2023
d294983
chore: update Cargo.lock
github-actions[bot] Nov 3, 2023
6ade782
add util functions
hrithikesh026 Nov 3, 2023
eb544b6
Merge branch 'main' into handle-session-flow-surcharge-discrepancy
hrithikesh026 Nov 3, 2023
b457f74
chore: update Cargo.lock
github-actions[bot] Nov 3, 2023
884e211
accept reference for function inputs
hrithikesh026 Nov 6, 2023
3180b39
remove serde_with module
hrithikesh026 Nov 6, 2023
f44141f
chore: update Cargo.lock
github-actions[bot] Nov 6, 2023
07b4590
address comments
hrithikesh026 Nov 7, 2023
ab3e3ca
address comments
hrithikesh026 Nov 8, 2023
700625d
remove comments
hrithikesh026 Nov 8, 2023
465a0bf
don't update surcharge_amount in confirm call
hrithikesh026 Nov 8, 2023
19487ba
Merge branch 'main' into handle-session-flow-surcharge-discrepancy
hrithikesh026 Nov 8, 2023
0d26d18
chore: update Cargo.lock
github-actions[bot] Nov 8, 2023
bbcf3f0
add support for updating surcharge details in payment update
hrithikesh026 Nov 9, 2023
cd316f7
change function name
hrithikesh026 Nov 9, 2023
0d57a81
don't write to redis if surcharge result is empty
hrithikesh026 Nov 9, 2023
5033f88
Merge branch 'main' into handle-session-flow-surcharge-discrepancy
hrithikesh026 Nov 10, 2023
cd21892
check in redis only if surcharge not found in payment attempt
hrithikesh026 Nov 10, 2023
4f7f43a
Merge branch 'main' into handle-session-flow-surcharge-discrepancy
hrithikesh026 Nov 13, 2023
2fe917a
chore: update Cargo.lock
github-actions[bot] Nov 13, 2023
700031e
add support for smart 3ds and surcharge decision management
hrithikesh026 Nov 14, 2023
84ae992
Merge branch 'main' into move-surcharge-and-3ds-to-oss
hrithikesh026 Nov 14, 2023
8c90389
address compilation failure and spell check
hrithikesh026 Nov 14, 2023
0c6ded7
chore: update Cargo.lock
github-actions[bot] Nov 14, 2023
c92ee05
add support for surcharge
hrithikesh026 Nov 14, 2023
c516180
Merge branch 'main' into move-surcharge-and-3ds-to-oss
hrithikesh026 Nov 14, 2023
711b9f1
make call_surcharge_decision_management_for_session_flow public
hrithikesh026 Nov 14, 2023
d319c5c
make call_surcharge_decision_management public
hrithikesh026 Nov 16, 2023
91f8815
add instrument to functions
hrithikesh026 Nov 20, 2023
a533dc4
should not update surcharge amount and tax amount in confirm call
hrithikesh026 Nov 21, 2023
5abda8d
Merge branch 'main' into move-surcharge-and-3ds-to-oss
hrithikesh026 Nov 21, 2023
54fbbb1
cargo clippy
hrithikesh026 Nov 21, 2023
b08ee5e
chore: update Cargo.lock
github-actions[bot] Nov 21, 2023
b39d2b4
Merge branch 'main' into move-surcharge-and-3ds-to-oss
hrithikesh026 Nov 21, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
113 changes: 113 additions & 0 deletions crates/api_models/src/conditional_configs.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
use common_utils::events;
use euclid::{
dssa::types::EuclidAnalysable,
enums,
frontend::{
ast::Program,
dir::{DirKeyKind, DirValue, EuclidDirFilter},
},
types::Metadata,
};
use serde::{Deserialize, Serialize};

#[derive(
Clone,
Debug,
Hash,
PartialEq,
Eq,
strum::Display,
strum::EnumVariantNames,
strum::EnumIter,
strum::EnumString,
Serialize,
Deserialize,
)]
#[serde(rename_all = "snake_case")]
#[strum(serialize_all = "snake_case")]
pub enum AuthenticationType {
ThreeDs,
NoThreeDs,
}
impl AuthenticationType {
pub fn to_dir_value(&self) -> DirValue {
match self {
Self::ThreeDs => DirValue::AuthenticationType(enums::AuthenticationType::ThreeDs),
Self::NoThreeDs => DirValue::AuthenticationType(enums::AuthenticationType::NoThreeDs),
}
}
}

impl EuclidAnalysable for AuthenticationType {
fn get_dir_value_for_analysis(&self, rule_name: String) -> Vec<(DirValue, Metadata)> {
let auth = self.to_string();

vec![(
self.to_dir_value(),
std::collections::HashMap::from_iter([(
"AUTHENTICATION_TYPE".to_string(),
serde_json::json!({
"rule_name":rule_name,
"Authentication_type": auth,
}),
)]),
)]
}
}

#[derive(Debug, Default, Clone, Serialize, Deserialize)]
pub struct ConditionalConfigs {
pub override_3ds: Option<AuthenticationType>,
}
impl EuclidDirFilter for ConditionalConfigs {
const ALLOWED: &'static [DirKeyKind] = &[
DirKeyKind::PaymentMethod,
DirKeyKind::CardType,
DirKeyKind::CardNetwork,
DirKeyKind::MetaData,
DirKeyKind::PaymentAmount,
DirKeyKind::PaymentCurrency,
DirKeyKind::CaptureMethod,
DirKeyKind::BillingCountry,
DirKeyKind::BusinessCountry,
];
}

#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct DecisionManagerRecord {
pub name: String,
pub program: Program<ConditionalConfigs>,
pub created_at: i64,
pub modified_at: i64,
}
impl events::ApiEventMetric for DecisionManagerRecord {
fn get_api_event_type(&self) -> Option<events::ApiEventsType> {
Some(events::ApiEventsType::Routing)
}
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(deny_unknown_fields)]
pub struct ConditionalConfigReq {
pub name: Option<String>,
pub algorithm: Option<Program<ConditionalConfigs>>,
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]

pub struct DecisionManagerRequest {
pub name: Option<String>,
pub program: Option<Program<ConditionalConfigs>>,
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(untagged)]
pub enum DecisionManager {
DecisionManagerv0(ConditionalConfigReq),
DecisionManagerv1(DecisionManagerRequest),
}

impl events::ApiEventMetric for DecisionManager {
fn get_api_event_type(&self) -> Option<events::ApiEventsType> {
Some(events::ApiEventsType::Routing)
}
}

pub type DecisionManagerResponse = DecisionManagerRecord;
2 changes: 2 additions & 0 deletions crates/api_models/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pub mod analytics;
pub mod api_keys;
pub mod bank_accounts;
pub mod cards_info;
pub mod conditional_configs;
pub mod customers;
pub mod disputes;
pub mod enums;
Expand All @@ -21,6 +22,7 @@ pub mod payments;
pub mod payouts;
pub mod refunds;
pub mod routing;
pub mod surcharge_decision_configs;
pub mod user;
pub mod verifications;
pub mod webhooks;
77 changes: 77 additions & 0 deletions crates/api_models/src/surcharge_decision_configs.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
use common_utils::{consts::SURCHARGE_PERCENTAGE_PRECISION_LENGTH, events, types::Percentage};
use euclid::frontend::{
ast::Program,
dir::{DirKeyKind, EuclidDirFilter},
};
use serde::{Deserialize, Serialize};

#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub struct SurchargeDetails {
pub surcharge: Surcharge,
pub tax_on_surcharge: Option<Percentage<SURCHARGE_PERCENTAGE_PRECISION_LENGTH>>,
}

#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case", tag = "type", content = "value")]
pub enum Surcharge {
Fixed(i64),
Rate(Percentage<SURCHARGE_PERCENTAGE_PRECISION_LENGTH>),
}

#[derive(Debug, Default, Clone, Serialize, Deserialize)]
pub struct SurchargeDecisionConfigs {
pub surcharge_details: Option<SurchargeDetails>,
}
impl EuclidDirFilter for SurchargeDecisionConfigs {
const ALLOWED: &'static [DirKeyKind] = &[
DirKeyKind::PaymentMethod,
DirKeyKind::MetaData,
DirKeyKind::PaymentAmount,
DirKeyKind::PaymentCurrency,
DirKeyKind::BillingCountry,
DirKeyKind::CardType,
DirKeyKind::CardNetwork,
DirKeyKind::PayLaterType,
DirKeyKind::WalletType,
DirKeyKind::BankTransferType,
DirKeyKind::BankRedirectType,
DirKeyKind::BankDebitType,
DirKeyKind::CryptoType,
];
}

#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct SurchargeDecisionManagerRecord {
pub name: String,
pub merchant_surcharge_configs: MerchantSurchargeConfigs,
pub algorithm: Program<SurchargeDecisionConfigs>,
pub created_at: i64,
pub modified_at: i64,
}

impl events::ApiEventMetric for SurchargeDecisionManagerRecord {
fn get_api_event_type(&self) -> Option<events::ApiEventsType> {
Some(events::ApiEventsType::Routing)
}
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(deny_unknown_fields)]
pub struct SurchargeDecisionConfigReq {
pub name: Option<String>,
pub merchant_surcharge_configs: MerchantSurchargeConfigs,
pub algorithm: Option<Program<SurchargeDecisionConfigs>>,
}

impl events::ApiEventMetric for SurchargeDecisionConfigReq {
fn get_api_event_type(&self) -> Option<events::ApiEventsType> {
Some(events::ApiEventsType::Routing)
}
}

#[derive(Debug, Default, Clone, serde::Serialize, serde::Deserialize)]
pub struct MerchantSurchargeConfigs {
pub show_surcharge_breakup_screen: Option<bool>,
}

pub type SurchargeDecisionManagerResponse = SurchargeDecisionManagerRecord;
2 changes: 2 additions & 0 deletions crates/router/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ pub mod api_keys;
pub mod api_locking;
pub mod cache;
pub mod cards_info;
pub mod conditional_config;
pub mod configs;
pub mod customers;
pub mod disputes;
Expand All @@ -18,6 +19,7 @@ pub mod payments;
pub mod payouts;
pub mod refunds;
pub mod routing;
pub mod surcharge_decision_config;
#[cfg(feature = "olap")]
pub mod user;
pub mod utils;
Expand Down
Loading
Loading