Skip to content

Commit 8cd959c

Browse files
committed
feat: include donation thank_you and contact_email in invoice response
When fetching a donation invoice, look up the linked payment_link's donation_config and return thank_you, campaign_name, and contact_email in a new donation_meta field. Enables the frontend to show the merchant's custom thank-you message on the confirmation screen.
1 parent f48867e commit 8cd959c

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

src/api/invoices.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,32 @@ pub async fn get(
126126
false
127127
};
128128

129+
let donation_meta = if inv.is_donation == 1 {
130+
if let Some(ref link_id) = inv.payment_link_id {
131+
let dc_json: Option<String> = sqlx::query_scalar(
132+
"SELECT donation_config FROM payment_links WHERE id = ?"
133+
)
134+
.bind(link_id)
135+
.fetch_optional(pool.get_ref())
136+
.await
137+
.ok()
138+
.flatten()
139+
.flatten();
140+
dc_json.and_then(|json| {
141+
let dc: crate::payment_links::DonationConfig = serde_json::from_str(&json).ok()?;
142+
Some(serde_json::json!({
143+
"thank_you": dc.thank_you,
144+
"campaign_name": dc.campaign_name,
145+
"contact_email": dc.contact_email,
146+
}))
147+
})
148+
} else {
149+
None
150+
}
151+
} else {
152+
None
153+
};
154+
129155
HttpResponse::Ok().json(serde_json::json!({
130156
"id": inv.id,
131157
"memo_code": inv.memo_code,
@@ -158,6 +184,7 @@ pub async fn get(
158184
"is_luma": is_luma,
159185
"is_donation": inv.is_donation == 1,
160186
"payment_link_id": inv.payment_link_id,
187+
"donation_meta": donation_meta,
161188
}))
162189
}
163190
None => HttpResponse::NotFound().json(serde_json::json!({

0 commit comments

Comments
 (0)