As a result, we now have five microservices catering to the checkout process:
ShoppingCartApi – Exposes the /checkout endpoint to UI client and triggers checkout process
StockValidatorService – Validates the availability of stocks for all the line items
TaxCalculatorService – Calculates the tax based online items and customer address
PaymentProcessingService – Processes the payment based on the credit card details, line items, and calculated tax
ReceptGeneratorService – Generates and saves the receipt for the purchase. Also, responsible for email communication with the customer
xxxxxxxxxx
public class CheckoutProcessor : ICheckoutProcessor
{
public BlockingCollection<CheckoutItem> CheckoutQueue { get; }
public CheckoutProcessor()
{
CheckoutQueue = new BlockingCollection<CheckoutItem>(new ConcurrentQueue<CheckoutItem>());
}
public Task<CheckoutResponse> ProcessCheckoutAsync(CheckoutRequest request)
{
var response = new CheckoutResponse
{
OrderId = Guid.NewGuid(),
OrderStatus = OrderStatus.Inprogress,
Message = "Your order is in progress,"
+ "you will receive an email with all details."
};
var item = new CheckoutItem
{
OrderId = response.OrderId,
Request = request
};
CheckoutQueue.Add(item);
return Task.FromResult(response);
}
}