Ejemplo n.º 1
0
        public virtual TblInvoiceBillingAddress PrepareTblInvoiceBillingAddress(InvoiceBillingAddressModel address)
        {
            var result = address.Adapt <TblInvoiceBillingAddress>();

            result.Country   = null;
            result.CountryId = address.CountryId;
            return(result);
        }
Ejemplo n.º 2
0
        public virtual async Task <ActionResult> Index(Guid Id, string paymentMethod, InvoiceBillingAddressModel address)
        {
            var invoice = await _invoiceService.FindByIdAsync(Id);

            if (invoice == null)
            {
                return(View("PageNotFound"));
            }

            if (invoice.InvoiceDetails.Count == 0)
            {
                ViewBag.Message = _localizationService.GetResource("ShoppingCartEmpty");
                return(View(await _invoiceModelFactory.PrepareInvoiceModelAsync(invoice)));
            }

            if (CurrentSettings.GetBillingAddressForInvoice)
            {
                if (!ModelState.IsValid)
                {
                    return(View(await _invoiceModelFactory.PrepareInvoiceModelAsync(invoice)));
                }
            }
            else
            {
                if (!ModelState.IsValidField("Id") || !ModelState.IsValidField("paymentMethod"))
                {
                    return(View(await _invoiceModelFactory.PrepareInvoiceModelAsync(invoice)));
                }
            }

            if (CurrentSettings.GetBillingAddressForInvoice)
            {
                await _invoiceService.AddUpdateBillingAddressAsync(Id, _invoiceModelFactory.PrepareTblInvoiceBillingAddress(address));
            }

            var paymentGateway = _paymentGatewayManager.FindPaymentMethodBySystemName(paymentMethod);

            if (invoice.ComputeInvoiceTotalAmount() <= 0)
            {
                await _invoiceService.SetGatewayNameAndTokenAsync(Id, paymentGateway.PaymentGatewayName,
                                                                  paymentGateway.PaymentGatewaySystemName, "-", WorkContext.CurrentCurrency.Id);

                return(RedirectToAction("VerifyPayment", new { id = Id }));
            }

            var result =
                await paymentGateway.RequestForPaymentUrl(
                    Url.Action("VerifyPayment", "Invoice", new { id = Id }, Request.Url.Scheme),
                    invoice);

            if (result.IsSuccess)
            {
                await _invoiceService.SetGatewayNameAndTokenAsync(Id, paymentGateway.PaymentGatewayName,
                                                                  paymentGateway.PaymentGatewaySystemName, result.Token, WorkContext.CurrentCurrency.Id);

                if (result.PostDate != null)
                {
                    return(new RedirectAndPostActionResult(result.RedirectUrl, result.PostDate));
                }

                return(Redirect(result.RedirectUrl));
            }

            ViewBag.Message = result.ErrorMessage;
            return(View(await _invoiceModelFactory.PrepareInvoiceModelAsync(invoice)));
        }
Ejemplo n.º 3
0
        public virtual async Task <ActionResult> UpdateInvoiceBillingAddress(Guid invoiceId, InvoiceBillingAddressModel model)
        {
            if (!ModelState.IsValid)
            {
                return(Json(new
                {
                    response = ModelState.Values.FirstOrDefault(p => p.Errors.Any()).Errors.FirstOrDefault()
                               .ErrorMessage
                }));
            }

            var record = _invoiceModelFactory.PrepareTblInvoiceBillingAddress(model);
            await _invoiceService.AddUpdateBillingAddressAsync(invoiceId, record);

            return(Json(new { response = "OK" }));
        }