Skip to content

Instantly share code, notes, and snippets.

@dcomartin
Created June 13, 2024 19:23
Show Gist options
  • Save dcomartin/6d1ff69d737c51110c0a2de38db5f391 to your computer and use it in GitHub Desktop.
Save dcomartin/6d1ff69d737c51110c0a2de38db5f391 to your computer and use it in GitHub Desktop.
public class Procedural
{
private readonly Database _db;
private readonly PaymentGateway _paymentGateway;
private readonly Emailer _email;
public Procedural(Database db, PaymentGateway paymentGateway, Emailer email)
{
_db = db;
_paymentGateway = paymentGateway;
_email = email;
}
public async Task PlaceOrder(Order order, CreditCard creditCard)
{
// Add the Order to DB
_db.Add(order);
// Process Payment
try
{
await _paymentGateway.Process(creditCard);
}
catch (TaskCanceledException)
{
order.Status = OrderStatus.Cancelled;
_db.Save(order);
return;
}
// Email Confirmation
try
{
await _email.SendConfirmation(order);
}
catch (Exception)
{
// Swallow/Log because we don't the whole thing to blow up...
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment