Ejemplo n.º 1
0
        public ActionResult InvoicePayment(string k)
        {
            if (string.IsNullOrEmpty(k))
            {
                return(InvokeHttp400());
            }

            string encodedKey = k.ToLower();

            var emailInvoice = _orderService.GetEmailInvoiceByEncodedKey(encodedKey);

            // Not found
            // Expired
            if (emailInvoice == null || emailInvoice.EndDate.CompareTo(DateTime.Now) < 0)
            {
                return(InvokeHttp400());
            }

            // Paid
            if (emailInvoice.Paid)
            {
                return(InvokeHttp410());
            }

            var paymentModel = new CheckoutPaymentModel
            {
                CardTypes    = PrepareCardTypes(),
                ExpireYears  = PrepareCardYears(),
                ExpireMonths = PrepareCardMonths(),
                OrderTotal   = _priceFormatter.FormatValue(emailInvoice.Amount * emailInvoice.ExchangeRate, emailInvoice.CurrencyCode)
            };

            if (string.IsNullOrEmpty(_session["PaymentErrorMessage"] as string) == false)
            {
                ViewBag.ErrorMessage            = _session["PaymentErrorMessage"].ToString();
                _session["PaymentErrorMessage"] = null;
            }

            var model = new InvoicePaymentModel
            {
                EmailInvoiceId = emailInvoice.Id,
                Payment        = paymentModel
            };

            // countries and states
            var countries = _shippingService.GetActiveCountries();
            var states    = _shippingService.GetUSStates();

            model.BillingAddress.AvailableCountries = countries.PrepareCountries();
            model.BillingAddress.AvailableStates    = states.PrepareStates();

            return(View(model));
        }
Ejemplo n.º 2
0
 public IHttpActionResult PayInvoice([FromUri] int id, [FromBody] InvoicePaymentModel invoicePaymentModel)
 {
     try
     {
         _service.Pay(id, invoicePaymentModel);
         return(Ok());
     }
     catch (ApplicationException e)
     {
         return(BadRequest(e.Message));
     }
 }
Ejemplo n.º 3
0
        public ActionResult ConfirmInvoicePayment(InvoicePaymentModel model)
        {
            var address = model.BillingAddress.PrepareAddressEntity();
            var card    = new Card
            {
                CardType     = model.Payment.CardType,
                CardNumber   = model.Payment.CardNumber,
                HolderName   = model.Payment.CardHolderName,
                SecurityCode = model.Payment.CardCode,
                ExpiryMonth  = model.Payment.ExpireMonth,
                ExpiryYear   = model.Payment.ExpireYear,
                StartMonth   = string.Empty,
                StartYear    = string.Empty,
                IssueNumber  = string.Empty
            };

            var output = _paymentService.ProcessPaymentFromEmailInvoice(
                model.EmailInvoiceId,
                address,
                card,
                _httpContext.Request.UserAgent,
                _httpContext.Request.UserHostAddress == "::1" ? "45.1.1.1" : _httpContext.Request.UserHostAddress,
                true);

            if (output.Status)
            {
                // 3D Secure redirect?
                if (output.Has3DSecure)
                {
                    RedirectToSecuredCardPage(output.RedirectUrl, output.PaReq, output.MD);
                }
                else
                {
                    return(RedirectToRoute("Checkout Completed", new { orderid = 0, emailinvoiceid = model.EmailInvoiceId, hasnhs = 0 }));
                }
            }
            else
            {
                var invoice = _orderService.GetEmailInvoiceById(model.EmailInvoiceId);

                _session["PaymentErrorMessage"] = output.Message;
                return(RedirectToAction("InvoicePayment", new { k = invoice.EncodedKey }));
            }

            return(Content(string.Empty));
        }
Ejemplo n.º 4
0
        public void Pay(int invoiceId, InvoicePaymentModel invoicePaymentModel)
        {
            var invoice = Get(invoiceId);

            if (invoice.InvoiceStatus.Equals(InvoiceStatus.Pending))
            {
                var _movementService     = new MovementService();
                var paymentCategory      = _categoryService.GetPaymentCategory();
                var paymentSubcategories = _categoryService.GetSubcategories(paymentCategory.Id);

                invoice.PaymentDate   = invoicePaymentModel.AccountingDate;
                invoice.InvoiceStatus = InvoiceStatus.Paid;

                var movement = new Movement
                {
                    Type                = "D",
                    Description         = $"Payment of credit card invoice #{invoiceId} - credit card: {invoice.CreditCard.Name}",
                    AccountingDate      = invoicePaymentModel.AccountingDate,
                    AccountId           = invoicePaymentModel.AccountId,
                    Value               = invoicePaymentModel.Value,
                    MovementStatus      = invoicePaymentModel.MovementStatus,
                    AutomaticallyLaunch = invoicePaymentModel.AutomaticallyLaunch,
                    Observation         = invoicePaymentModel.Observation,
                    CategoryId          = paymentCategory.Id,
                    SubcategoryId       = paymentSubcategories.FirstOrDefault(s => s.Name.Equals("Credit card")).Id
                };

                _repository.Update(invoice);
                _movementService.Insert(movement);
                _movementService.LaunchMovement(GetMovements(invoice.Id), false);
            }
            else
            {
                throw new Exceptions.InvalidOperationException("This invoice alright is paid or is not closed yet");
            }
        }