Skip to content

Commit f474003

Browse files
committed
feat: include social_share_text and slug in donation invoice response
Add social_share_text and the payment link slug to the donation_meta object returned by GET /api/invoices/{id}. Enables the frontend to build a share URL for post-donation social sharing.
1 parent 8cd959c commit f474003

1 file changed

Lines changed: 13 additions & 10 deletions

File tree

src/api/invoices.rs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -128,22 +128,25 @@ pub async fn get(
128128

129129
let donation_meta = if inv.is_donation == 1 {
130130
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 = ?"
131+
let row: Option<(Option<String>, String)> = sqlx::query_as(
132+
"SELECT donation_config, slug FROM payment_links WHERE id = ?"
133133
)
134134
.bind(link_id)
135135
.fetch_optional(pool.get_ref())
136136
.await
137137
.ok()
138-
.flatten()
139138
.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-
}))
139+
row.map(|(dc_json, slug)| {
140+
let dc: Option<crate::payment_links::DonationConfig> = dc_json
141+
.as_deref()
142+
.and_then(|j| serde_json::from_str(j).ok());
143+
serde_json::json!({
144+
"thank_you": dc.as_ref().and_then(|d| d.thank_you.clone()),
145+
"campaign_name": dc.as_ref().and_then(|d| d.campaign_name.clone()),
146+
"contact_email": dc.as_ref().and_then(|d| d.contact_email.clone()),
147+
"social_share_text": dc.as_ref().and_then(|d| d.social_share_text.clone()),
148+
"slug": slug,
149+
})
147150
})
148151
} else {
149152
None

0 commit comments

Comments
 (0)