mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-11-02 04:04:43 +08:00
feat(euclid): add a new variant in payment type i.e ppt_mandate (#5681)
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
This commit is contained in:
@ -115,7 +115,7 @@ pub struct MandateListConstraints {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Details required for recurring payment
|
/// 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")]
|
#[serde(tag = "type", content = "data", rename_all = "snake_case")]
|
||||||
pub enum RecurringDetails {
|
pub enum RecurringDetails {
|
||||||
MandateId(String),
|
MandateId(String),
|
||||||
@ -124,7 +124,7 @@ pub enum RecurringDetails {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Processor payment token for MIT payments where payment_method_data is not available
|
/// 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 struct ProcessorPaymentToken {
|
||||||
pub processor_payment_token: String,
|
pub processor_payment_token: String,
|
||||||
#[schema(value_type = Connector, example = "stripe")]
|
#[schema(value_type = Connector, example = "stripe")]
|
||||||
|
|||||||
@ -198,6 +198,47 @@ mod test {
|
|||||||
assert_eq!(result.rule_name.expect("Rule Name").as_str(), "rule_1");
|
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]
|
#[test]
|
||||||
fn test_mandate_type() {
|
fn test_mandate_type() {
|
||||||
let program_str = r#"
|
let program_str = r#"
|
||||||
|
|||||||
@ -81,6 +81,7 @@ pub enum PaymentType {
|
|||||||
NonMandate,
|
NonMandate,
|
||||||
NewMandate,
|
NewMandate,
|
||||||
UpdateMandate,
|
UpdateMandate,
|
||||||
|
PptMandate,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(
|
#[derive(
|
||||||
|
|||||||
@ -208,10 +208,21 @@ where
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
}),
|
}),
|
||||||
payment_type: Some(payment_data.setup_mandate.clone().map_or_else(
|
payment_type: Some(
|
||||||
|| euclid_enums::PaymentType::NonMandate,
|
if payment_data.recurring_details.as_ref().is_some_and(|data| {
|
||||||
|_| euclid_enums::PaymentType::SetupMandate,
|
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 {
|
let payment_method_input = dsl_inputs::PaymentMethodInput {
|
||||||
payment_method: payment_data.payment_attempt.payment_method,
|
payment_method: payment_data.payment_attempt.payment_method,
|
||||||
|
|||||||
Reference in New Issue
Block a user