예제 #1
0
        public ActionResult Create(PaymentDetail paymentdetail, int reqno, decimal price)
        {
            try
            {
                int Ref = 0;

                // Get relevent request details
                PassRequestHed passReq = new PassRequestHed();
                passReq = db.PassRequestHeds.Find(reqno);

                PassIssueController PIC = new PassIssueController();
                using (TransactionScope Scope = new TransactionScope(TransactionScopeOption.Required))
                {
                    Ref = PIC.SavePassIssueHed(PassIssueFacade.MapModelToHed(passReq));
                    if (Ref > 0)
                    {
                        PIC.SavePassIssueDet(PassIssueFacade.MapModelToDet(passReq), Ref);
                        PIC.SavePassIssueVehi(PassIssueFacade.MapModelToVehi(passReq), Ref);

                        // Save Payment details
                        paymentdetail.PassNo      = Ref;
                        paymentdetail.PassTotal   = price;
                        paymentdetail.AddDate     = DateTime.Now;
                        paymentdetail.PaymentDate = DateTime.Now.Date;
                        paymentdetail.AddUser     = WebSecurity.CurrentUserName;
                        db.PaymentDetails.Add(paymentdetail);

                        // Update Pass request (Paid & Issued flags)
                        passReq = PassIssueFacade.UpdatePassReq(passReq);
                        db.Entry(passReq).State = System.Data.EntityState.Modified;
                        db.SaveChanges();

                        Scope.Complete();
                    }
                }

                return(RedirectToAction("Complete"));
            }

            catch (DbEntityValidationException ex)
            {
                // Retrieve the error messages as a list of strings.
                var errorMessages = ex.EntityValidationErrors
                                    .SelectMany(x => x.ValidationErrors)
                                    .Select(x => x.ErrorMessage);

                // Join the list to a single string.
                var fullErrorMessage = string.Join("; ", errorMessages);

                // Combine the original exception message with the new one.
                var exceptionMessage = string.Concat(ex.Message, " The validation errors are: ", fullErrorMessage);

                // Throw a new DbEntityValidationException with the improved exception message.
                throw new DbEntityValidationException(exceptionMessage, ex.EntityValidationErrors);
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
        /// <summary>
        /// Captures the specified authorization identifier.
        /// </summary>
        /// <param name="authorizationId">The authorization identifier.</param>
        /// <returns></returns>
        public ActionResult Capture(string authorizationId)
        {
            var viewData = new PayPalViewData();

            try
            {
                var accessToken   = new OAuthTokenCredential(ConfigManager.Instance.GetProperties()["ClientID"], ConfigManager.Instance.GetProperties()["ClientSecret"]).GetAccessToken();
                var apiContext    = new APIContext(accessToken);
                var authorization = Authorization.Get(apiContext, authorizationId);

                if (authorization != null)
                {
                    var total = Convert.ToDecimal(authorization.amount.total);

                    var capture = authorization.Capture(apiContext, new Capture
                    {
                        is_final_capture = true,
                        amount           = new Amount
                        {
                            currency = "USD",
                            total    = (total + (total * .05m)).ToString("f2")
                        },
                    });

                    viewData.JsonResponse = JObject.Parse(capture.ConvertToJson()).ToString(Formatting.Indented);

                    // Newly added
                    // Sends the Sms
                    var smsId            = HttpContext.Application["smsId"].ToString();
                    PaymentController PC = new PaymentController();
                    TempData["SMS"] = PC.SendSms(smsId);

                    // Get relevent request details
                    PassRequestHed passReq = new PassRequestHed();
                    passReq = db.PassRequestHeds.Find(Convert.ToInt16(smsId));

                    // Update Pass request (Paid & Issued flags)
                    passReq = PassIssueFacade.UpdatePassReq(passReq);
                    db.Entry(passReq).State = System.Data.EntityState.Modified;
                    db.SaveChanges();

                    return(View("Success"));
                }

                viewData.ErrorMessage = "Could not find previous authorization.";

                return(View("Error", viewData));
            }
            catch (PayPalException ex)
            {
                viewData.ErrorMessage = ex.Message;

                return(View("Error", viewData));
            }
        }