diff --git a/agent/provider/src/payments/agreement.rs b/agent/provider/src/payments/agreement.rs index fa0fcb7a37..0096626c95 100644 --- a/agent/provider/src/payments/agreement.rs +++ b/agent/provider/src/payments/agreement.rs @@ -248,7 +248,7 @@ pub async fn compute_cost( let cost = payment_model.compute_cost(&usage)?; - Ok(CostInfo { cost, usage }) + Ok(CostInfo::new(usage, cost)) } impl ActivitiesWaiter { diff --git a/core/payment/src/dao/agreement.rs b/core/payment/src/dao/agreement.rs index 1254e5743d..27938fd7ee 100644 --- a/core/payment/src/dao/agreement.rs +++ b/core/payment/src/dao/agreement.rs @@ -1,5 +1,5 @@ use crate::dao::{invoice, invoice_event}; -use crate::error::DbResult; +use crate::error::{DbError, DbResult}; use crate::models::agreement::{ReadObj, WriteObj}; use crate::schema::pay_activity::dsl as activity_dsl; use crate::schema::pay_agreement::dsl; @@ -41,7 +41,9 @@ pub fn set_amount_due( let agreement: ReadObj = dsl::pay_agreement .find((agreement_id, owner_id)) .first(conn)?; - assert!(total_amount_due >= &agreement.total_amount_due); // TODO: Remove when payment service is production-ready. + if total_amount_due < &agreement.total_amount_due { + return Err(DbError::Query(format!("Requested amount for agreement cannot be lowered. Current amount requested: {} Amount on invoice: {}", agreement.total_amount_due, total_amount_due))); + } diesel::update(&agreement) .set(dsl::total_amount_due.eq(total_amount_due)) .execute(conn)?;