private PurchaseReceipt RecordOrder(Guid ownerId, Order order, Purchaser purchaser, AppleReceipt receipt) { // Save the order. order.OwnerId = ownerId; order.PurchaserId = purchaser.Id; _repository.CreateOrder(order); // Save the receipt. receipt.Prepare(); receipt.Validate(); _repository.CreateReceipt(order.Id, receipt); // Allocate the credits. var products = (from i in order.Items select _productsQuery.GetProduct(i.ProductId)).ToList(); foreach (var product in products) { AllocateCredits(order.OwnerId, product, order.Id); } // Fire events. var handlers = OrderPurchased; if (handlers != null) { handlers(this, new OrderPurchasedEventArgs(order, receipt)); } return(receipt); }