Skip to content

Commit 790efea

Browse files
committed
fix: show confirmed donation count instead of created invoices
Dashboard was showing total_created (incremented on checkout) as the donation count. Now queries confirmed donations (campaign_counted=1) and returns total_confirmed for donation links.
1 parent a1641a9 commit 790efea

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

src/api/payment_links.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,21 @@ pub async fn list(
7777

7878
match payment_links::list_payment_links(pool.get_ref(), &merchant.id).await {
7979
Ok(links) => {
80-
let result: Vec<_> = links.iter().map(link_response).collect();
80+
let mut result = Vec::with_capacity(links.len());
81+
for link in &links {
82+
let mut resp = link_response(link);
83+
if link.is_donation() {
84+
let confirmed: i32 = sqlx::query_scalar(
85+
"SELECT COUNT(*) FROM invoices WHERE payment_link_id = ? AND is_donation = 1 AND campaign_counted = 1"
86+
)
87+
.bind(&link.id)
88+
.fetch_one(pool.get_ref())
89+
.await
90+
.unwrap_or(0);
91+
resp["total_confirmed"] = serde_json::json!(confirmed);
92+
}
93+
result.push(resp);
94+
}
8195
HttpResponse::Ok().json(result)
8296
}
8397
Err(e) => {

0 commit comments

Comments
 (0)