示例#1
0
        public string Post([FromBody] string value)
        {
            if (string.IsNullOrWhiteSpace(value))
            {
                Response.StatusCode = (int)HttpStatusCode.BadRequest;
                return("{'error':'Bad Request'}");
            }
            var payData = JsonConvert.DeserializeObject <PaymentData>(value);

            if (payData == null)
            {
                Response.StatusCode = (int)HttpStatusCode.BadRequest;
                return("{'error':'Bad Request'}");
            }

            try
            {
                payData             = PaymentManagement.ProcessPayment(payData);
                Response.StatusCode = (int)HttpStatusCode.OK;
                return(payData.ToString());
            }
            catch
            {
                Response.StatusCode = (int)HttpStatusCode.InternalServerError;
                return("{'error':'Server couldn't process payment'}");
            }
        }
示例#2
0
        public async Task <ActionResult> Buy(IFormCollection collection)
        {
            try
            {
                var buyModel = await PrepareTicketBuyViewModel(Guid.Parse(collection["evnt.Id"]));

                if (buyModel.evnt == null || buyModel.evnt.TotalAvailableTickets < 1)
                {
                    return(View("Error"));
                }
                var paymentData = new PaymentData()
                {
                    CardNumber   = collection["paymentData.CardNumber"],
                    NameOnCard   = collection["paymentData.NameOnCard"],
                    ValidMonth   = Int32.Parse(collection["paymentData.ValidMonth"]),
                    ValidYear    = Int32.Parse(collection["paymentData.ValidYear"]),
                    SecurityCode = collection["paymentData.SecurityCode"],
                    Value        = buyModel.evnt.Price
                };
                paymentData          = PaymentManagement.ProcessPayment(paymentData);
                buyModel.paymentData = paymentData;
                if (buyModel.user.Id == Guid.Empty)
                {
                    buyModel.user = await UserManager.GetOrCreateUserByAuthId(buyModel.user);
                }
                if (paymentData.TransactionSuccessful)
                {
                    var ticket = await TicketManager.IssueEventTicket(buyModel.evnt, buyModel.user, paymentData.ToString());

                    return(RedirectToAction("ViewTicket", new { id = ticket.Id }));
                }
                return(View("Error"));
            }
            catch
            {
                return(View("Error"));
            }
        }