static void Main(string[] args) { //var client = new RestbucksClient("http://restbucks.net"); var client = new RestbucksClient("http://localhost/Restbucks"); System.Console.WriteLine("Press enter to send order"); System.Console.ReadLine(); var order = client.CreateOrder(CreateOrder()); System.Console.WriteLine("Order total: {0}", order.Cost); System.Console.WriteLine("Press enter to check order state"); order = client.GetOrder(order.SelfLink); System.Console.WriteLine("Order state: {0}", order.Status); System.Console.WriteLine("Press enter to pay for the order"); System.Console.ReadLine(); var payment = new PaymentRepresentation { Amount = 2.8m, CardholderName = "Szymon", CardNumber = "XXX", ExpiryMonth = 12, ExpiryYear = 12 }; payment = client.PayForOrder(order.PaymentLink, payment); System.Console.WriteLine("Press enter to get the receipt"); System.Console.ReadLine(); var receipt = client.GetReceipt(payment.ReceiptLink); System.Console.WriteLine("You paid ${0} at {1} UTC", receipt.AmountPaid, receipt.PaymentDate); System.Console.WriteLine("Press enter to complete order"); System.Console.ReadLine(); client.TakeCoffee(receipt.CompleteLink); System.Console.WriteLine("Press enter to exit"); System.Console.ReadLine(); }
public PaymentRepresentation PayForOrder(string paymentUri, PaymentRepresentation payment) { var httpClient = GetHttpClient(_baseUri); var content = new ObjectContent<PaymentRepresentation>(payment, new[] { new RestbucksMediaTypeFormatter() }); content.Headers.ContentType = new MediaTypeHeaderValue(RepresentationBase.RestbucksMediaType); var responseMessage = httpClient.Put(paymentUri, content); var responseContent = responseMessage.Content.ReadAs<PaymentRepresentation>(new [] {new RestbucksMediaTypeFormatter()}); return responseContent; }
public PaymentRepresentation Pay(int orderId, PaymentRepresentation paymentRepresentation, Uri requestUri) { var order = _repository.FindById(orderId); if (order == null) { throw new NoSuchOrderException(orderId); } if (order.Status != OrderStatus.Unpaid) { throw new UnexpectedOrderStateException(orderId); } var payment = _paymentMapper.GetDomainObject(paymentRepresentation); order.Pay(payment); var representation = _paymentMapper.GetRepresentation(order.PaymentInfo); representation.OrderLink = RestbucksResources.GetResourceUri<OrderResource>(requestUri, order.Id.ToString()); representation.ReceiptLink = RestbucksResources.GetResourceUri<ReceiptResource>(requestUri, orderId.ToString()); return representation; }
public PaymentInformation GetDomainObject(PaymentRepresentation paymentRepresentation) { return new PaymentInformation(paymentRepresentation.Amount, paymentRepresentation.CardholderName, paymentRepresentation.CardNumber, paymentRepresentation.ExpiryMonth, paymentRepresentation.ExpiryYear); }