Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 6 additions & 1 deletion api-reference/v1/openapi_spec_v1.json
Original file line number Diff line number Diff line change
Expand Up @@ -17296,7 +17296,8 @@
"connector",
"connector_status",
"connector_dispute_id",
"created_at"
"created_at",
"is_already_refunded"
],
"properties": {
"dispute_id": {
Expand Down Expand Up @@ -17377,6 +17378,10 @@
"type": "string",
"description": "The `merchant_connector_id` of the connector / processor through which the dispute was processed",
"nullable": true
},
"is_already_refunded": {
"type": "boolean",
"description": "Shows if the disputed amount is already refunded in the payment"
}
}
},
Expand Down
7 changes: 6 additions & 1 deletion api-reference/v2/openapi_spec_v2.json
Original file line number Diff line number Diff line change
Expand Up @@ -11057,7 +11057,8 @@
"connector",
"connector_status",
"connector_dispute_id",
"created_at"
"created_at",
"is_already_refunded"
],
"properties": {
"dispute_id": {
Expand Down Expand Up @@ -11138,6 +11139,10 @@
"type": "string",
"description": "The `merchant_connector_id` of the connector / processor through which the dispute was processed",
"nullable": true
},
"is_already_refunded": {
"type": "boolean",
"description": "Shows if the disputed amount is already refunded in the payment"
}
}
},
Expand Down
4 changes: 3 additions & 1 deletion crates/api_models/src/disputes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use utoipa::ToSchema;
use super::enums::{Currency, DisputeStage, DisputeStatus};
use crate::{admin::MerchantConnectorInfo, files};

#[derive(Clone, Debug, Serialize, ToSchema, Eq, PartialEq)]
#[derive(Clone, Debug, Serialize, ToSchema)]
pub struct DisputeResponse {
/// The identifier for dispute
pub dispute_id: String,
Expand Down Expand Up @@ -56,6 +56,8 @@ pub struct DisputeResponse {
/// The `merchant_connector_id` of the connector / processor through which the dispute was processed
#[schema(value_type = Option<String>)]
pub merchant_connector_id: Option<common_utils::id_type::MerchantConnectorAccountId>,
/// Shows if the disputed amount is already refunded in the payment
pub is_already_refunded: bool,
}

#[derive(Clone, Debug, Serialize, ToSchema, Eq, PartialEq, SmithyModel)]
Expand Down
36 changes: 36 additions & 0 deletions crates/common_types/src/payments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -952,3 +952,39 @@ pub struct PartnerMerchantIdentifierDetails {
}

impl_to_sql_from_sql_json!(PartnerMerchantIdentifierDetails);

/// Additional metadata for payment intent state containing refunded and disputed amounts
#[derive(
Default,
Serialize,
Deserialize,
Debug,
Clone,
PartialEq,
Eq,
AsExpression,
FromSqlRow,
utoipa::ToSchema,
)]
#[diesel(sql_type = Jsonb)]
pub struct PaymentIntentStateMetadata {
/// Shows up the total refunded amount for a payment
pub total_refunded_amount: Option<MinorUnit>,
/// Shows up the total disputed amount across all disputes for a particular payment
pub total_disputed_amount: Option<MinorUnit>,
}

impl PaymentIntentStateMetadata {
/// Builder method to set total_refunded_amount
pub fn with_total_refunded_amount(mut self, amount: MinorUnit) -> Self {
self.total_refunded_amount = Some(amount);
self
}
/// Builder method to set total_disputed_amount
pub fn with_total_disputed_amount(mut self, amount: MinorUnit) -> Self {
self.total_disputed_amount = Some(amount);
self
}
}

common_utils::impl_to_sql_from_sql_json!(PaymentIntentStateMetadata);
1 change: 0 additions & 1 deletion crates/diesel_models/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ strum = { version = "0.26.3", features = ["derive"] }
thiserror = "1.0.69"
time = { version = "0.3.41", features = ["serde", "serde-well-known", "std"] }


# First party crates
common_enums = { version = "0.1.0", path = "../common_enums" }
common_utils = { version = "0.1.0", path = "../common_utils" }
Expand Down
10 changes: 10 additions & 0 deletions crates/diesel_models/src/dispute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,16 @@ pub struct Dispute {
pub dispute_currency: Option<storage_enums::Currency>,
}

impl Dispute {
/// Returns true if the dispute_status is either DisputeLost, or the option is None
pub fn is_not_lost_or_none(option: &Option<Self>) -> bool {
option
.as_ref()
.map(|d| d.dispute_status != common_enums::DisputeStatus::DisputeLost)
.unwrap_or(true)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it is None, we do not want to update the intent state right?

}
}

#[derive(Debug)]
pub enum DisputeUpdate {
Update {
Expand Down
Loading
Loading