Example #1
0
        public async Task <ActionResult> Download(string id)
        {
            //This is a copy of Pay, changes there should be reflected here
            var invoice = await _dbContext.Invoices
                          .Include(i => i.Items)
                          .Include(i => i.Team)
                          .Include(i => i.Attachments)
                          .Include(i => i.Coupon)
                          .FirstOrDefaultAsync(i => i.LinkId == id);

            if (invoice == null)
            {
                // check expired link id
                var link = await _dbContext.InvoiceLinks
                           .Include(l => l.Invoice)
                           .ThenInclude(i => i.Team)
                           .FirstOrDefaultAsync(l => l.LinkId == id);

                // still not found
                if (link == null)
                {
                    return(PublicNotFound());
                }

                // if the invoice has a new link id,
                // just forward them to the corrected invoice
                if (!string.IsNullOrWhiteSpace(link.Invoice.LinkId))
                {
                    Message = "Your link was expired/old. We've forwarded you to the new link. Please review the invoice for any changes before proceeding.";
                    return(RedirectToAction("Download", new { id = link.Invoice.LinkId }));
                }

                // otherwise, the invoice is probably back in draft
                var expiredModel = new ExpiredInvoiceViewModel()
                {
                    Team = new PaymentInvoiceTeamViewModel(link.Invoice.Team)
                };
                return(View("Expired", expiredModel));
            }

            // the customer isn't allowed access to draft or cancelled invoices
            if (invoice.Status == Invoice.StatusCodes.Draft || invoice.Status == Invoice.StatusCodes.Cancelled)
            {
                return(PublicNotFound());
            }

            invoice.UpdateCalculatedValues();

            var model = CreateInvoicePaymentViewModel(invoice);

            return(View(model));
        }
Example #2
0
        public async Task <ActionResult> Pay(string id)
        {
            //Changes here should be made to Download too
            var invoice = await _dbContext.Invoices
                          .Include(i => i.Items)
                          .Include(i => i.Team)
                          .Include(i => i.Attachments)
                          .Include(i => i.Coupon)
                          .FirstOrDefaultAsync(i => i.LinkId == id);

            if (invoice == null)
            {
                // check expired link id
                var link = await _dbContext.InvoiceLinks
                           .Include(l => l.Invoice)
                           .ThenInclude(i => i.Team)
                           .FirstOrDefaultAsync(l => l.LinkId == id);

                // still not found
                if (link == null)
                {
                    return(PublicNotFound());
                }

                // if the invoice has a new link id,
                // just forward them to the corrected invoice
                if (!string.IsNullOrWhiteSpace(link.Invoice.LinkId))
                {
                    Message = "Your link was expired/old. We've forwarded you to the new link. Please review the invoice for any changes before proceeding.";
                    return(RedirectToAction("Pay", new { id = link.Invoice.LinkId }));
                }

                // otherwise, the invoice is probably back in draft
                var expiredModel = new ExpiredInvoiceViewModel()
                {
                    Team = new PaymentInvoiceTeamViewModel(link.Invoice.Team)
                };
                return(View("Expired", expiredModel));
            }

            // the customer isn't allowed access to draft or cancelled invoices
            if (invoice.Status == Invoice.StatusCodes.Draft || invoice.Status == Invoice.StatusCodes.Cancelled)
            {
                return(PublicNotFound());
            }

            invoice.UpdateCalculatedValues();

            var model = CreateInvoicePaymentViewModel(invoice);

            if (invoice.Status == Invoice.StatusCodes.Sent)
            {
                // prepare dictionary
                var dictionary = invoice.GetPaymentDictionary();
                dictionary.Add("access_key", _cyberSourceSettings.AccessKey);
                dictionary.Add("profile_id", _cyberSourceSettings.ProfileId);

                var fieldNames = string.Join(",", dictionary.Keys);
                dictionary.Add("signed_field_names", "signed_field_names," + fieldNames);

                ViewBag.Signature = _dataSigningService.Sign(dictionary);

                ViewBag.CyberSourceUrl = _cyberSourceSettings.BaseUrl;

                model.PaymentDictionary = dictionary;
            }

            return(View(model));
        }