Skip to content

Commit

Permalink
Fix promo activation on /start command
Browse files Browse the repository at this point in the history
  • Loading branch information
Leonid Kozarin committed Jul 17, 2024
1 parent 1cb8cc3 commit 237a465
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/handlers/start.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ pub async fn start_cmd_handler(bot: Bot, msg: Message, cmd: StartCommands,
StartCommands::Start(promo_code) if promo_code.starts_with(PROMO_START_PARAM_PREFIX) => {
metrics::CMD_PROMO.invoked_by_deeplink.inc();
let user = msg.from().expect("user must be present here");
let promo_code = promo_code.strip_prefix(PROMO_START_PARAM_PREFIX)
let encoded_promo_code = promo_code.strip_prefix(PROMO_START_PARAM_PREFIX)
.expect("promo start param prefix must be present here");
promo_activation_impl(repos.promo, user, promo_code).await?
let promo_code = decode_promo_code(encoded_promo_code)?;
promo_activation_impl(repos.promo, user, &promo_code).await?
}
StartCommands::Start(_) => {
metrics::CMD_START_COUNTER.inc();
Expand All @@ -36,3 +37,9 @@ pub async fn start_cmd_handler(bot: Bot, msg: Message, cmd: StartCommands,
reply_html(bot, msg, answer).await?;
Ok(())
}

fn decode_promo_code(promo_code_base64: &str) -> anyhow::Result<String> {
let bytes = base64::decode_engine(promo_code_base64, &base64::engine::general_purpose::URL_SAFE_NO_PAD)?;
let promo_code = String::from_utf8(bytes)?;
Ok(promo_code)
}

0 comments on commit 237a465

Please sign in to comment.