コード例 #1
0
        public async Task<IHttpActionResult> Get(int id)
        {
            var order = await repository.RetrieveAsync(id);
            if (order == null || order.UserName != User.Identity.Name)
            {
                return NotFound();
            }

            var response = new SecureOrderApiModel
            {
                OrderID = order.OrderID,
                EnteredOn = order.EnteredOn,
                OrderStatus = order.OrderStatus.ToString(),
                OrderTotal = order.OrderTotal,
                UserName = order.UserName,
                Tickets = new List<SecureTicketSeatApiModel>()
            };

            foreach (var x in order.Tickets)
            {
                var ticket = new SecureTicketSeatApiModel
                {
                    ConfirmationNumber = x.TicketSeat.PendingPurchaseConfirmation,
                    TicketSeatID = x.TicketSeat.TicketSeatID,
                    TicketPriceID = x.TicketPriceID,
                    AgeID = x.TicketPrice.EventAgeGroupID,
                    BasePrice = x.TicketPrice.BasePrice,
                    TotalPrice = x.TicketTotalPrice,
                    EventName = x.TicketSeat.TicketArea.Event.PageContent.Heading,
                    TicketDiscountID = x.TicketDiscountID,
                    DiscountConfirmationNumber = x.TicketDiscount?.SecurityConfirmationNumber,
                    Options = new Dictionary<int, int>(),
                    IsValid = true
                };

                foreach (var y in x.TicketOptionChoices)
                {
                    ticket.Options.Add(y.TicketOptionID, y.TicketOptionChoiceID);
                }
                response.Tickets.Add(ticket);
            }

            return Ok(response);
        }
コード例 #2
0
        public async Task<IHttpActionResult> Put(int id, SecureOrderApiModel model)
        {
            var order = await repository.RetrieveAsync(id);

            if (order != null && order.UserName == User.Identity.Name)
            {
                var apiContext = PaypalConfiguration.GetAPIContext();
                var payment = PayPal.Api.Payment.Get(apiContext, model.PaymentID);
                if (payment.state == "approved")
                {
                    var transaction = payment.transactions.ToArray()[0];
                    var sale = transaction.related_resources.ToArray()[0].sale;

                    if (order.Payments == null)
                    {
                        order.Payments = new List<DexCMS.Tickets.Orders.Models.Payment>();
                    }

                    order.Payments.Add(new DexCMS.Tickets.Orders.Models.Payment
                    {
                        GrossPaid = decimal.Parse(transaction.amount.total),
                        NetPaid = decimal.Parse(transaction.amount.total) - decimal.Parse(sale.transaction_fee.value),
                        OrderID = order.OrderID,
                        PaidOn = Convert.ToDateTime(payment.update_time),
                        PaymentDetails = payment.ConvertToJson(),
                        PaymentFee = decimal.Parse(sale.transaction_fee.value),
                        PaymentType = PaymentType.Paypal
                    });

                    order.OrderStatus =
                        order.OrderTotal == decimal.Parse(transaction.amount.total) ? OrderStatus.Complete : OrderStatus.Partial;

                    await repository.UpdateAsync(order, order.OrderID);

                    return Ok();
                }
                else
                {
                    return BadRequest();
                }
            }
            else
            {
                return BadRequest();
            }

        }