-
-
Save dcomartin/6d1ff69d737c51110c0a2de38db5f391 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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