//DocumentPurchasedMessage public async Task DoOperationAsync(DocumentPurchasedMessage msg, IBinder binder, CancellationToken token) { //We wait for the db to persist. await Task.Delay(TimeSpan.FromSeconds(30), token); var query = new GetDocumentPurchasedEmailQuery(msg.TransactionId); var data = await _queryBus.QueryAsync(query, token); var template = await GetEmail("DocumentPurchased", data.Language, _queryBus, token); var dataProtector = _dataProtectProvider.CreateProtector("Spitball") .ToTimeLimitedDataProtector(); var code = dataProtector.Protect(data.UserId.ToString(), DateTimeOffset.UtcNow.AddDays(5)); foreach (var block in template.Blocks) { block.Subtitle = block.Subtitle.InjectSingleValue("Tokens", data.Tokens.ToString("f2")); block.Body = block.Body.Inject(new { data.CourseName, data.DocumentName }); } var templateData = new TemplateData() { Blocks = template.Blocks .Select(s => new Block(s.Title, s.Subtitle, s.Body, s.MinorTitle, s.Cta, _urlBuilder.BuildWalletEndPoint(code))), Referral = new Referral(_urlBuilder.BuildShareEndPoint(code)), Subject = template.Subject.InjectSingleValue("Tokens", data.Tokens.ToString("f2")), To = data.ToEmailAddress, }; await BuildEmail(data.ToEmailAddress, data.Language, binder, templateData, "DocumentPurchased", token); }