diff options
author | Teddy Wing | 2018-11-19 19:12:52 +0100 |
---|---|---|
committer | Teddy Wing | 2018-11-19 19:58:42 +0100 |
commit | 027fe4276a79a453f27ed9048bb32cc928f3e29b (patch) | |
tree | a2bbc9c48e866d1e89262b3c87ca4feb2c3824d1 | |
parent | 0bc161c20f283d641919d8f369d309d1fc9081b6 (diff) | |
download | dome-key-web-027fe4276a79a453f27ed9048bb32cc928f3e29b.tar.bz2 |
license-generator: Respond with text for fulfillment email
Paddle will take the text from the response of this endpoint and include
it in the purchase fulfillment email to a customer.
Include the URL for the purchaser to download their license. Use the
'url' crate's parser to build the URL in order to URL-escape special
characters.
Honestly I'd rather have had a system where the license file gets
included in the receipt email. Unfortunately, with the Paddle
fulfillment mechanism I'm using, we can only send text. I learned after
building the download endpoint that I could manage fulfillment myself.
This would require me to listen to an "alert"-type Paddle webhook, and
send the email myself (which would include the license file). Since I
already built the license download page, I decided to just use it
instead of doing the emailing. Also, my web host limits my SMTP usage,
so there could be issues there. I'd have to do the emailing in a
separate batch process instead of in the webhook handler to ensure that
no emails would get dropped.
-rw-r--r-- | license-generator/src/bin/license-generator.rs | 37 | ||||
-rw-r--r-- | license-generator/src/errors.rs | 2 | ||||
-rw-r--r-- | license-generator/src/purchaser.rs | 6 |
3 files changed, 40 insertions, 5 deletions
diff --git a/license-generator/src/bin/license-generator.rs b/license-generator/src/bin/license-generator.rs index d99af57..e19ac85 100644 --- a/license-generator/src/bin/license-generator.rs +++ b/license-generator/src/bin/license-generator.rs @@ -4,11 +4,14 @@ extern crate fastcgi; extern crate log; extern crate mysql; extern crate simplelog; +extern crate url; extern crate license_generator; use std::io::{Read, Write}; +use url::Url; + use license_generator::database; use license_generator::errors::*; use license_generator::logger; @@ -79,9 +82,39 @@ fn main() -> Result<()> { Ok(_) => { // TODO: Print message to be appended to user email - write!(&mut req.stdout(), "Content-Type: text/plain + let secret = match purchaser.secret { + Some(s) => s, + None => return response::error_500( + &mut req.stdout(), + Some("Empty secret".into()) + ), + }; + + let license_download_url = match Url::parse_with_params( + "https://domekey.teddywing.com/license", + &[ + ("name", purchaser.name), + ("email", purchaser.email), + ("secret", &secret), + ], + ) { + Ok(u) => u, + Err(e) => return response::error_500( + &mut req.stdout(), + Some(e.into()) + ), + }; + + write!( + &mut req.stdout(), + "Content-Type: text/plain + +Thanks so much for purchasing DomeKey! -200 OK") +Download your license here: +{url}", + url = license_download_url, + ) .unwrap_or(()); return; diff --git a/license-generator/src/errors.rs b/license-generator/src/errors.rs index 2d1182b..79bc49b 100644 --- a/license-generator/src/errors.rs +++ b/license-generator/src/errors.rs @@ -2,6 +2,7 @@ use aquatic_prime; use log; use mysql; use paddle; +use url; use zip_lib; error_chain! { @@ -12,6 +13,7 @@ error_chain! { Log(log::SetLoggerError); MySql(mysql::error::Error); + UrlParse(url::ParseError); Zip(zip_lib::result::ZipError); AquaticPrime(aquatic_prime::errors::Error); diff --git a/license-generator/src/purchaser.rs b/license-generator/src/purchaser.rs index 60e389a..1fe1ec6 100644 --- a/license-generator/src/purchaser.rs +++ b/license-generator/src/purchaser.rs @@ -6,9 +6,9 @@ use sha1; use errors::*; pub struct Purchaser<'a> { - name: &'a str, - email: &'a str, - secret: Option<String>, + pub name: &'a str, + pub email: &'a str, + pub secret: Option<String>, } impl<'a> Purchaser<'a> { |