use std::collections::HashMap; use common_utils::types::TimeRange; use masking::{Deserialize, Serialize}; use serde::de::Error; use time::PrimitiveDateTime; use utoipa::ToSchema; use super::enums::{DisputeStage, DisputeStatus}; use crate::{admin::MerchantConnectorInfo, enums, files}; #[derive(Clone, Debug, Serialize, ToSchema, Eq, PartialEq)] pub struct DisputeResponse { /// The identifier for dispute pub dispute_id: String, /// The identifier for payment_intent #[schema(value_type = String)] pub payment_id: common_utils::id_type::PaymentId, /// The identifier for payment_attempt pub attempt_id: String, /// The dispute amount pub amount: String, /// The three-letter ISO currency code pub currency: String, /// Stage of the dispute pub dispute_stage: DisputeStage, /// Status of the dispute pub dispute_status: DisputeStatus, /// connector to which dispute is associated with pub connector: String, /// Status of the dispute sent by connector pub connector_status: String, /// Dispute id sent by connector pub connector_dispute_id: String, /// Reason of dispute sent by connector pub connector_reason: Option, /// Reason code of dispute sent by connector pub connector_reason_code: Option, /// Evidence deadline of dispute sent by connector #[serde(with = "common_utils::custom_serde::iso8601::option")] pub challenge_required_by: Option, /// Dispute created time sent by connector #[serde(with = "common_utils::custom_serde::iso8601::option")] pub connector_created_at: Option, /// Dispute updated time sent by connector #[serde(with = "common_utils::custom_serde::iso8601::option")] pub connector_updated_at: Option, /// Time at which dispute is received #[serde(with = "common_utils::custom_serde::iso8601")] pub created_at: PrimitiveDateTime, /// The `profile_id` associated with the dispute #[schema(value_type = Option)] pub profile_id: Option, /// The `merchant_connector_id` of the connector / processor through which the dispute was processed #[schema(value_type = Option)] pub merchant_connector_id: Option, } #[derive(Clone, Debug, Serialize, ToSchema, Eq, PartialEq)] pub struct DisputeResponsePaymentsRetrieve { /// The identifier for dispute pub dispute_id: String, /// Stage of the dispute pub dispute_stage: DisputeStage, /// Status of the dispute pub dispute_status: DisputeStatus, /// Status of the dispute sent by connector pub connector_status: String, /// Dispute id sent by connector pub connector_dispute_id: String, /// Reason of dispute sent by connector pub connector_reason: Option, /// Reason code of dispute sent by connector pub connector_reason_code: Option, /// Evidence deadline of dispute sent by connector #[serde(with = "common_utils::custom_serde::iso8601::option")] pub challenge_required_by: Option, /// Dispute created time sent by connector #[serde(with = "common_utils::custom_serde::iso8601::option")] pub connector_created_at: Option, /// Dispute updated time sent by connector #[serde(with = "common_utils::custom_serde::iso8601::option")] pub connector_updated_at: Option, /// Time at which dispute is received #[serde(with = "common_utils::custom_serde::iso8601")] pub created_at: PrimitiveDateTime, } #[derive(Debug, Serialize, Deserialize, strum::Display, Clone)] #[serde(rename_all = "snake_case")] #[strum(serialize_all = "snake_case")] pub enum EvidenceType { CancellationPolicy, CustomerCommunication, CustomerSignature, Receipt, RefundPolicy, ServiceDocumentation, ShippingDocumentation, InvoiceShowingDistinctTransactions, RecurringTransactionAgreement, UncategorizedFile, } #[derive(Clone, Debug, Serialize, ToSchema)] pub struct DisputeEvidenceBlock { /// Evidence type pub evidence_type: EvidenceType, /// File metadata pub file_metadata_response: files::FileMetadataResponse, } #[derive(Clone, Debug, Deserialize, Serialize, ToSchema)] #[serde(deny_unknown_fields)] pub struct DisputeListGetConstraints { /// The identifier for dispute pub dispute_id: Option, /// The payment_id against which dispute is raised pub payment_id: Option, /// Limit on the number of objects to return pub limit: Option, /// The starting point within a list of object pub offset: Option, /// The identifier for business profile #[schema(value_type = Option)] pub profile_id: Option, /// The comma separated list of status of the disputes #[serde(default, deserialize_with = "parse_comma_separated")] pub dispute_status: Option>, /// The comma separated list of stages of the disputes #[serde(default, deserialize_with = "parse_comma_separated")] pub dispute_stage: Option>, /// Reason for the dispute pub reason: Option, /// The comma separated list of connectors linked to disputes #[serde(default, deserialize_with = "parse_comma_separated")] pub connector: Option>, /// The comma separated list of currencies of the disputes #[serde(default, deserialize_with = "parse_comma_separated")] pub currency: Option>, /// The merchant connector id to filter the disputes list pub merchant_connector_id: Option, /// The time range for which objects are needed. TimeRange has two fields start_time and end_time from which objects can be filtered as per required scenarios (created_at, time less than, greater than etc). #[serde(flatten)] pub time_range: Option, } #[derive(Clone, Debug, serde::Serialize, ToSchema)] pub struct DisputeListFilters { /// The map of available connector filters, where the key is the connector name and the value is a list of MerchantConnectorInfo instances pub connector: HashMap>, /// The list of available currency filters pub currency: Vec, /// The list of available dispute status filters pub dispute_status: Vec, /// The list of available dispute stage filters pub dispute_stage: Vec, } #[derive(Default, Clone, Debug, Serialize, Deserialize, ToSchema)] pub struct SubmitEvidenceRequest { ///Dispute Id pub dispute_id: String, /// Logs showing the usage of service by customer pub access_activity_log: Option, /// Billing address of the customer pub billing_address: Option, /// File Id of cancellation policy pub cancellation_policy: Option, /// Details of showing cancellation policy to customer before purchase pub cancellation_policy_disclosure: Option, /// Details telling why customer's subscription was not cancelled pub cancellation_rebuttal: Option, /// File Id of customer communication pub customer_communication: Option, /// Customer email address pub customer_email_address: Option, /// Customer name pub customer_name: Option, /// IP address of the customer pub customer_purchase_ip: Option, /// Fild Id of customer signature pub customer_signature: Option, /// Product Description pub product_description: Option, /// File Id of receipt pub receipt: Option, /// File Id of refund policy pub refund_policy: Option, /// Details of showing refund policy to customer before purchase pub refund_policy_disclosure: Option, /// Details why customer is not entitled to refund pub refund_refusal_explanation: Option, /// Customer service date pub service_date: Option, /// File Id service documentation pub service_documentation: Option, /// Shipping address of the customer pub shipping_address: Option, /// Delivery service that shipped the product pub shipping_carrier: Option, /// Shipping date pub shipping_date: Option, /// File Id shipping documentation pub shipping_documentation: Option, /// Tracking number of shipped product pub shipping_tracking_number: Option, /// File Id showing two distinct transactions when customer claims a payment was charged twice pub invoice_showing_distinct_transactions: Option, /// File Id of recurring transaction agreement pub recurring_transaction_agreement: Option, /// Any additional supporting file pub uncategorized_file: Option, /// Any additional evidence statements pub uncategorized_text: Option, } #[derive(Clone, Debug, Serialize, Deserialize, ToSchema)] pub struct DeleteEvidenceRequest { /// Id of the dispute pub dispute_id: String, /// Evidence Type to be deleted pub evidence_type: EvidenceType, } #[derive(Clone, Debug, serde::Serialize)] pub struct DisputesAggregateResponse { /// Different status of disputes with their count pub status_with_count: HashMap, } fn parse_comma_separated<'de, D, T>(v: D) -> Result>, D::Error> where D: serde::Deserializer<'de>, T: std::str::FromStr, ::Err: std::fmt::Debug + std::fmt::Display + std::error::Error, { let output = Option::<&str>::deserialize(v)?; output .map(|s| { s.split(",") .map(|x| x.parse::().map_err(D::Error::custom)) .collect::>() }) .transpose() }