| 1 |
|
| 2 |
|
| 3 |
use crate::email::EmailClient; |
| 4 |
use crate::error::Result; |
| 5 |
|
| 6 |
impl EmailClient { |
| 7 |
|
| 8 |
pub async fn send_purchase_confirmation( |
| 9 |
&self, |
| 10 |
to_email: &str, |
| 11 |
to_name: Option<&str>, |
| 12 |
item_title: &str, |
| 13 |
price: &str, |
| 14 |
) -> Result<()> { |
| 15 |
let subject = "Your purchase is confirmed"; |
| 16 |
let body = format!( |
| 17 |
r#"Hi{name}, |
| 18 |
|
| 19 |
Your purchase of {item} ({price}) is confirmed. |
| 20 |
|
| 21 |
You can access your purchase from your library at any time. |
| 22 |
|
| 23 |
- Makenotwork"#, |
| 24 |
name = crate::email::greeting(to_name), |
| 25 |
item = item_title, |
| 26 |
price = price |
| 27 |
); |
| 28 |
|
| 29 |
self.transport.send_email(to_email, subject, &body).await |
| 30 |
} |
| 31 |
|
| 32 |
|
| 33 |
pub async fn send_guest_purchase_confirmation( |
| 34 |
&self, |
| 35 |
to_email: &str, |
| 36 |
item_title: &str, |
| 37 |
price: &str, |
| 38 |
download_url: &str, |
| 39 |
claim_url: &str, |
| 40 |
) -> Result<()> { |
| 41 |
let subject = "Your purchase is confirmed"; |
| 42 |
let body = format!( |
| 43 |
r#"Hi, |
| 44 |
|
| 45 |
Your purchase of {item} ({price}) is confirmed. |
| 46 |
|
| 47 |
Download your purchase: |
| 48 |
{download_url} |
| 49 |
|
| 50 |
This link works without an account. You can download at any time. |
| 51 |
|
| 52 |
Want to keep all your purchases in one place? Create a Makenot.work account with this email address and your purchase will appear in your library automatically. Or use this link to claim it to an existing account: |
| 53 |
{claim_url} |
| 54 |
|
| 55 |
- Makenotwork"#, |
| 56 |
item = item_title, |
| 57 |
price = price, |
| 58 |
download_url = download_url, |
| 59 |
claim_url = claim_url, |
| 60 |
); |
| 61 |
|
| 62 |
self.transport.send_email(to_email, subject, &body).await |
| 63 |
} |
| 64 |
|
| 65 |
|
| 66 |
pub async fn send_subscription_started( |
| 67 |
&self, |
| 68 |
to_email: &str, |
| 69 |
to_name: Option<&str>, |
| 70 |
tier_name: &str, |
| 71 |
project_title: &str, |
| 72 |
price: &str, |
| 73 |
) -> Result<()> { |
| 74 |
let subject = &format!("You're subscribed to {}", project_title); |
| 75 |
let body = format!( |
| 76 |
r#"Hi{name}, |
| 77 |
|
| 78 |
You're now subscribed to {project} ({tier} - {price}/mo). |
| 79 |
|
| 80 |
You have access to all content included in this tier. Your subscription will renew automatically each month. |
| 81 |
|
| 82 |
- Makenotwork"#, |
| 83 |
name = crate::email::greeting(to_name), |
| 84 |
project = project_title, |
| 85 |
tier = tier_name, |
| 86 |
price = price |
| 87 |
); |
| 88 |
|
| 89 |
self.transport.send_email(to_email, subject, &body).await |
| 90 |
} |
| 91 |
|
| 92 |
|
| 93 |
pub async fn send_subscription_cancelled( |
| 94 |
&self, |
| 95 |
to_email: &str, |
| 96 |
to_name: Option<&str>, |
| 97 |
tier_name: &str, |
| 98 |
project_title: &str, |
| 99 |
) -> Result<()> { |
| 100 |
let subject = "Your subscription has been cancelled"; |
| 101 |
let body = format!( |
| 102 |
r#"Hi{name}, |
| 103 |
|
| 104 |
Your subscription to {project} ({tier}) has been cancelled. |
| 105 |
|
| 106 |
You will retain access until the end of your current billing period. |
| 107 |
|
| 108 |
- Makenotwork"#, |
| 109 |
name = crate::email::greeting(to_name), |
| 110 |
project = project_title, |
| 111 |
tier = tier_name |
| 112 |
); |
| 113 |
|
| 114 |
self.transport.send_email(to_email, subject, &body).await |
| 115 |
} |
| 116 |
|
| 117 |
|
| 118 |
pub async fn send_subscription_renewed( |
| 119 |
&self, |
| 120 |
to_email: &str, |
| 121 |
to_name: Option<&str>, |
| 122 |
tier_name: &str, |
| 123 |
price: &str, |
| 124 |
) -> Result<()> { |
| 125 |
let subject = "Your subscription has been renewed"; |
| 126 |
let body = format!( |
| 127 |
r#"Hi{name}, |
| 128 |
|
| 129 |
Your subscription ({tier} - {price}/mo) has been renewed for another month. |
| 130 |
|
| 131 |
- Makenotwork"#, |
| 132 |
name = crate::email::greeting(to_name), |
| 133 |
tier = tier_name, |
| 134 |
price = price |
| 135 |
); |
| 136 |
|
| 137 |
self.transport.send_email(to_email, subject, &body).await |
| 138 |
} |
| 139 |
|
| 140 |
|
| 141 |
pub async fn send_fan_plus_welcome( |
| 142 |
&self, |
| 143 |
to_email: &str, |
| 144 |
to_name: Option<&str>, |
| 145 |
) -> Result<()> { |
| 146 |
let subject = "Welcome to Fan+"; |
| 147 |
let body = format!( |
| 148 |
r#"Hi{name}, |
| 149 |
|
| 150 |
You're now a Fan+ member. |
| 151 |
|
| 152 |
Each month you'll receive a $5 credit code you can use toward any purchase on the platform. Your first credit will arrive with your next billing cycle. |
| 153 |
|
| 154 |
Thank you for supporting Makenotwork. |
| 155 |
|
| 156 |
- Makenotwork"#, |
| 157 |
name = crate::email::greeting(to_name), |
| 158 |
); |
| 159 |
|
| 160 |
self.transport.send_email(to_email, subject, &body).await |
| 161 |
} |
| 162 |
|
| 163 |
|
| 164 |
pub async fn send_fan_plus_credit( |
| 165 |
&self, |
| 166 |
to_email: &str, |
| 167 |
to_name: Option<&str>, |
| 168 |
code: &str, |
| 169 |
expiry: Option<&chrono::DateTime<chrono::Utc>>, |
| 170 |
) -> Result<()> { |
| 171 |
let subject = "Your Fan+ monthly credit"; |
| 172 |
let expiry_line = expiry |
| 173 |
.map(|d| format!("\n\nThis code expires on {}.", d.format("%B %-d, %Y"))) |
| 174 |
.unwrap_or_default(); |
| 175 |
let body = format!( |
| 176 |
r#"Hi{name}, |
| 177 |
|
| 178 |
Your $5 Fan+ credit for this month is ready. |
| 179 |
|
| 180 |
Code: {code} |
| 181 |
|
| 182 |
Enter this code at checkout to apply it toward any purchase on the platform.{expiry} |
| 183 |
|
| 184 |
- Makenotwork"#, |
| 185 |
name = crate::email::greeting(to_name), |
| 186 |
code = code, |
| 187 |
expiry = expiry_line, |
| 188 |
); |
| 189 |
|
| 190 |
self.transport.send_email(to_email, subject, &body).await |
| 191 |
} |
| 192 |
|
| 193 |
|
| 194 |
pub async fn send_fan_plus_cancelled( |
| 195 |
&self, |
| 196 |
to_email: &str, |
| 197 |
to_name: Option<&str>, |
| 198 |
period_end: Option<&chrono::DateTime<chrono::Utc>>, |
| 199 |
) -> Result<()> { |
| 200 |
let subject = "Your Fan+ membership has been cancelled"; |
| 201 |
let access_line = period_end |
| 202 |
.map(|d| format!("You will retain your Fan+ benefits until {}.", d.format("%B %-d, %Y"))) |
| 203 |
.unwrap_or_else(|| "Your Fan+ benefits have ended.".to_string()); |
| 204 |
let body = format!( |
| 205 |
r#"Hi{name}, |
| 206 |
|
| 207 |
Your Fan+ membership has been cancelled. |
| 208 |
|
| 209 |
{access} |
| 210 |
|
| 211 |
Any unused credit codes remain valid until their expiry date. |
| 212 |
|
| 213 |
- Makenotwork"#, |
| 214 |
name = crate::email::greeting(to_name), |
| 215 |
access = access_line, |
| 216 |
); |
| 217 |
|
| 218 |
self.transport.send_email(to_email, subject, &body).await |
| 219 |
} |
| 220 |
} |
| 221 |
|