コード例 #1
0
        public async Task<IHttpActionResult> Get(int id)
        {
            var order = await repository.RetrieveAsync(id);
            Orders.Models.Payment payment = null;

            if (order.Payments != null && order.Payments.Count > 0)
            {
                payment = order.Payments.First();
            }
            InvoiceDetails details = null;
            var response = new CashierOrderApiModel
            {
                OrderID = order.OrderID,
                EnteredOn = order.EnteredOn,
                OrderStatus = order.OrderStatus,
                OrderTotal = order.OrderTotal,
                Notes = order.Notes
            };

            if (payment != null)
            {
                if (payment.PaymentType == PaymentType.PendingInvoice)
                {
                    details = JsonConvert.DeserializeObject<InvoiceDetails>(payment.PaymentDetails);

                    var invoice = Invoice.Get(PaypalConfiguration.GetAPIContext(), details.id);
                    if (invoice.status == "PAID")
                    {
                        payment.GrossPaid = decimal.Parse(invoice.total_amount.value);
                        payment.PaidOn = Convert.ToDateTime(invoice.invoice_date.Substring(0, 10));
                        payment.PaymentType = PaymentType.Paypal;
                        order.OrderStatus = OrderStatus.Complete;
                        await repository.UpdateAsync(order, order.OrderID);
                    }
                }
                else
                {
                    response.PaymentDetails = payment.PaymentDetails;
                    response.PaymentID = payment.PaymentID;
                    response.PaymentType = payment.PaymentType;
                    response.GrossPaid = payment.GrossPaid;
                }
            } 
            else
            {
                response.PaymentType = PaymentType.Pending;
            }


            if (details != null)
            {
                response.InvoiceEmail = details.email;
                response.InvoiceID = details.id;
            }

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

            if (order == null || order.OrderID != model.OrderID)
            {
                return NotFound();
            }

            if (model.GrossPaid.HasValue)
            {
                Orders.Models.Payment payment = null;

                if (model.PaymentID.HasValue)
                {
                    payment = order.Payments.Where(x => x.PaymentID == model.PaymentID).SingleOrDefault();
                    payment.GrossPaid = model.GrossPaid.Value;
                    payment.PaymentType = model.PaymentType;
                    payment.PaymentDetails = model.PaymentDetails;
                }

                if (payment == null)
                {
                    payment = new Orders.Models.Payment
                    {
                        GrossPaid = model.GrossPaid.Value,
                        PaidOn = cstTime,
                        PaymentType = model.PaymentType,
                        PaymentDetails = model.PaymentDetails,
                        OrderID = model.OrderID
                    };
                }

                if (order.Payments == null || order.Payments.Count == 0)
                {
                    order.Payments = new List<Orders.Models.Payment>
                    {
                        payment
                    };
                }

            }
            order.OrderStatus = model.OrderStatus;
            order.Notes = model.Notes;

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

            return Ok();
    }
コード例 #3
0
        public async Task<IHttpActionResult> Post(CashierOrderApiModel model)
        {
            if (model == null || model.Tickets.Length == 0)
            {
                return Ok();
            }

            //Create Order
            DexCMS.Tickets.Orders.Models.Order order = new DexCMS.Tickets.Orders.Models.Order
            {
                EnteredOn = cstTime,
                OrderStatus = OrderStatus.Pending,
                OrderTicketReferences = new List<OrderTicketReference>(),
                UserName = User.Identity.Name
            };

            foreach (var item in model.Tickets)
            {
                OrderTicketReference ticketRef = new OrderTicketReference
                {
                    TicketSeatID = item.TicketSeatID,
                    PendingPurchaseConfirmation = item.ConfirmationNumber,
                    EventAgeGroupID = item.AgeID,
                    TicketDiscountID = item.TicketDiscountID,
                    SecurityConfirmationNumber = item.DiscountConfirmationNumber,
                    TotalPrice = item.TotalPrice
                };

                if (item.Options != null && item.Options.Count > 0)
                {
                    ticketRef.TicketOptionChoices = new List<int>();
                    foreach (KeyValuePair<int, int> optionChoice in item.Options)
                    {
                        ticketRef.TicketOptionChoices.Add(optionChoice.Value);
                    }
                }

                order.OrderTicketReferences.Add(ticketRef);
            }

            //save
            await repository.AddAsync(order);


            //! CHANGING HERE
            switch (model.CashierOrderType)
            {
                case CashierOrderType.CashOrCheck:
                    return Ok(new { OrderID = order.OrderID });

                case CashierOrderType.Paypal:
                     Invoice invoice = CreateInvoice(model.InvoiceEmail, order);
                    invoice.id = order.OrderID.ToString();

                    try
                    {
                        var apiContext = PaypalConfiguration.GetAPIContext();
                        var createdInvoice = invoice.Create(apiContext);
                        createdInvoice.Send(apiContext, true);

                        var invoiceDetails = new
                        {
                            id = createdInvoice.id,
                            email = model.InvoiceEmail
                        };

                        order.Payments = new List<Orders.Models.Payment>
                        {
                            new Orders.Models.Payment
                            {
                                OrderID = order.OrderID,
                                PaymentDetails = JsonConvert.SerializeObject(invoiceDetails),
                                PaymentType = PaymentType.PendingInvoice
                            }
                        };
                        order.OrderStatus = OrderStatus.Pending;

                        await repository.UpdateAsync(order, order.OrderID);
                        return Ok(new { OrderID = order.OrderID });
                    }
                    catch (Exception ex)
                    {
                        await Logger.WriteLog(LogType.Error, ex.ToString());
                        throw ex;
                    }
  
                default:
                    return Ok();
            }          
        }