public static async Task <bool> RunOrchestrator(
            [OrchestrationTrigger] IDurableOrchestrationContext context)
        {
            Order order = context.GetInput <Order>();

            var customer = await context.CallActivityAsync <Customer>("GetCustomerDetailedInformations", order.CustomerId);

            for (int i = 0; i < 2 && !order.Paid; i++)
            {
                DateTime deadline = context.CurrentUtcDateTime.Add(TimeSpan.FromSeconds(5));
                await context.CreateTimer(deadline, CancellationToken.None);

                order.Paid = await context.CallActivityAsync <bool>("CheckPaymentStatus", order.Id);
            }
            if (order.Paid)
            {
                var invoiceUrl = await context.CallActivityAsync <string>("GenerateInvoice", order);

                var emailDetails = new EmailDetails()
                {
                    OrderId = order.Id, CustomerEmail = customer.Email, InvoiceUrl = invoiceUrl
                };
                await context.CallActivityAsync <string>("SendInvoice", emailDetails);

                order.MarkCompleted();
            }
            else
            {
                //compensate
            }
            return(order.Completed);
        }
 public void SendEmail([ActivityTrigger] EmailDetails emailDetails, [SendGrid(ApiKey = "SendGridKeyAppSettingName")] out SendGridMessage message, ILogger log)
 {
     message = new SendGridMessage();
     message.AddTo(new EmailAddress("*****@*****.**"));
     message.AddContent("text/html", $"Hi, thank you for your order no . Your invoce can be found under this link: {emailDetails.InvoiceUrl}");
     message.Subject = "Thanks for your order, your invoice is waiting for you";
     message.From    = new EmailAddress(emailDetails.CustomerEmail);
 }