Skip to content

Commit

Permalink
feat(euclid): add a new variant in payment type i.e ppt_mandate (#5681)
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
prajjwalkumar17 and hyperswitch-bot[bot] authored Aug 27, 2024
1 parent 716d76c commit 350aeb3
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 6 deletions.
4 changes: 2 additions & 2 deletions crates/api_models/src/mandates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ pub struct MandateListConstraints {
}

/// Details required for recurring payment
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, ToSchema)]
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, ToSchema, PartialEq, Eq)]
#[serde(tag = "type", content = "data", rename_all = "snake_case")]
pub enum RecurringDetails {
MandateId(String),
Expand All @@ -124,7 +124,7 @@ pub enum RecurringDetails {
}

/// Processor payment token for MIT payments where payment_method_data is not available
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, ToSchema)]
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, ToSchema, PartialEq, Eq)]
pub struct ProcessorPaymentToken {
pub processor_payment_token: String,
#[schema(value_type = Connector, example = "stripe")]
Expand Down
41 changes: 41 additions & 0 deletions crates/euclid/src/backend/vir_interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,47 @@ mod test {
assert_eq!(result.rule_name.expect("Rule Name").as_str(), "rule_1");
}

#[test]
fn test_ppt_flow() {
let program_str = r#"
default: ["stripe", "adyen"]
rule_1: ["stripe"]
{
payment_type = ppt_mandate
}
"#;

let (_, program) = ast::parser::program::<DummyOutput>(program_str).expect("Program");
let inp = inputs::BackendInput {
metadata: None,
payment: inputs::PaymentInput {
amount: MinorUnit::new(32),
currency: enums::Currency::USD,
card_bin: Some("123456".to_string()),
authentication_type: Some(enums::AuthenticationType::NoThreeDs),
capture_method: Some(enums::CaptureMethod::Automatic),
business_country: Some(enums::Country::UnitedStatesOfAmerica),
billing_country: Some(enums::Country::France),
business_label: None,
setup_future_usage: None,
},
payment_method: inputs::PaymentMethodInput {
payment_method: Some(enums::PaymentMethod::PayLater),
payment_method_type: Some(enums::PaymentMethodType::Affirm),
card_network: None,
},
mandate: inputs::MandateData {
mandate_acceptance_type: None,
mandate_type: None,
payment_type: Some(enums::PaymentType::PptMandate),
},
};

let backend = VirInterpreterBackend::<DummyOutput>::with_program(program).expect("Program");
let result = backend.execute(inp).expect("Execution");
assert_eq!(result.rule_name.expect("Rule Name").as_str(), "rule_1");
}

#[test]
fn test_mandate_type() {
let program_str = r#"
Expand Down
1 change: 1 addition & 0 deletions crates/euclid/src/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ pub enum PaymentType {
NonMandate,
NewMandate,
UpdateMandate,
PptMandate,
}

#[derive(
Expand Down
19 changes: 15 additions & 4 deletions crates/router/src/core/payments/routing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,10 +208,21 @@ where
}
})
}),
payment_type: Some(payment_data.setup_mandate.clone().map_or_else(
|| euclid_enums::PaymentType::NonMandate,
|_| euclid_enums::PaymentType::SetupMandate,
)),
payment_type: Some(
if payment_data.recurring_details.as_ref().is_some_and(|data| {
matches!(
data,
api_models::mandates::RecurringDetails::ProcessorPaymentToken(_)
)
}) {
euclid_enums::PaymentType::PptMandate
} else {
payment_data.setup_mandate.clone().map_or_else(
|| euclid_enums::PaymentType::NonMandate,
|_| euclid_enums::PaymentType::SetupMandate,
)
},
),
};
let payment_method_input = dsl_inputs::PaymentMethodInput {
payment_method: payment_data.payment_attempt.payment_method,
Expand Down

0 comments on commit 350aeb3

Please sign in to comment.