Exemplo n.º 1
0
        private static DisplayInvoice DisplayInvoice(DataModels.PaymentGateway.Invoices.Invoice voice)
        {
            DisplayInvoice v = new DisplayInvoice();
            try
            {
                v.UserId = voice.UserId;
                v.AdminNote = voice.AdminNote;
                if (voice.CurrencyRate != null)
                {
                    v.Currency = voice.CurrencyRate.CurrencyAbbrName;
                    v.CurrencyCost = voice.CurrencyRate.CurrencyExchangePerUSD;
                }
                else
                {
                    v.Currency = "USD";
                    v.CurrencyCost = 1;
                }

                v.InvoiceId = voice.InvoiceId;
                v.TotalIncludingTax = voice.BasePriceForItems;
                v.RefundAmount = voice.BasePriceForItems;
                v.ShoppingCartId = voice.ShoppingCartId;
                v.ShippingCost = voice.Shipping;
                v.RDNDeductedFee = voice.RDNDeductedFee;
                v.CreditCardCompanyProcessorDeductedFee = voice.CreditCardCompanyProcessorDeductedFee;
                v.PaymentProvider = (PaymentProvider)voice.PaymentProvider;
                v.Note = voice.Note;
                v.InvoiceStatus = (InvoiceStatus)voice.InvoiceStatus;
                v.Created = voice.Created;
                v.CustomerId = voice.PaymentProviderCustomerId;
                if (!String.IsNullOrEmpty(v.CustomerId) && v.PaymentProvider == PaymentProvider.Stripe)
                    v.CanRefundCustomer = true;

                v.TotalItemsBeingSold = 0;
                foreach (var refund in voice.Refunds)
                {
                    InvoiceRefund r = new InvoiceRefund();
                    r.RefundAmount = refund.PriceRefunded;
                    r.RefundId = refund.InvoiceRefundId;
                    v.Refunds.Add(r);
                }
                v.RefundAmount -= v.Refunds.Sum(x => x.RefundAmount);
                if (voice.InvoiceBilling != null)
                {
                    try
                    {
                        v.InvoiceBilling.City = voice.InvoiceBilling.City;
                        if (!String.IsNullOrEmpty(voice.InvoiceBilling.Country))
                        {
                            var count = SiteCache.GetCountries().Where(x => x.CountryId == Convert.ToInt32(voice.InvoiceBilling.Country)).FirstOrDefault();
                            v.InvoiceBilling.Country = count.Name;
                        }
                        v.InvoiceBilling.Email = voice.InvoiceBilling.Email;
                        v.InvoiceBilling.FirstName = voice.InvoiceBilling.FirstName;
                        v.InvoiceBilling.LastName = voice.InvoiceBilling.LastName;
                        v.InvoiceBilling.State = voice.InvoiceBilling.State;
                        v.InvoiceBilling.Street = voice.InvoiceBilling.Street;
                        v.InvoiceBilling.Street2 = voice.InvoiceBilling.Street2;
                        v.InvoiceBilling.Zip = voice.InvoiceBilling.Zip;
                    }
                    catch (Exception exception)
                    {
                        ErrorDatabaseManager.AddException(exception, exception.GetType());
                    }
                }
                if (voice.Paywall != null)
                {
                    InvoicePaywall i = new InvoicePaywall();
                    i.Price = voice.Paywall.BasePrice;
                    i.Description = voice.Paywall.Description;
                    i.PaywallPassword = voice.Paywall.GeneratedPassword;
                    i.PaywallId = voice.Paywall.InvoicePaywallId;
                    i.MemberPaidId = voice.Paywall.MemberPaidId;
                    i.ValidUntil = voice.Paywall.ValidUntil;
                    i.ValidUntilDisplay = voice.Paywall.ValidUntil.ToShortDateString() + " " + voice.Paywall.ValidUntil.ToShortTimeString();
                    i.PriceType = (PaywallPriceTypeEnum)voice.Paywall.PaywallPriceTypeEnum;
                    i.SecondsViewedPaywall = voice.Paywall.SecondsViewedPaywall;
                    i.TimesUsedPassword = voice.Paywall.TimesUsedPassword;
                    i.LastViewedPaywall = voice.Paywall.LastViewedPaywall;
                    v.Paywall = i;
                }

                v.Merchant.MerchantId = voice.Merchant.MerchantId;
                v.Merchant.PrivateManagerId = voice.Merchant.PrivateManagerId;
                v.Merchant.ShopName = voice.Merchant.ShopName;
            }
            catch (Exception exception)
            {
                ErrorDatabaseManager.AddException(exception, exception.GetType());
            }
            return v;
        }
        public InvoiceFactory SetPaywall(InvoicePaywall paywall)
        {
            if (string.IsNullOrEmpty(paywall.Description))
                throw new Exception("Invalid paywall description");
            if (string.IsNullOrEmpty(paywall.Name))
                throw new Exception("Invalid paywall name");
            if (paywall.Price < 0)
                throw new Exception("Item price can not be negative");
            if (paywall.PaywallLengthOfDays < 1)
                paywall.PaywallLengthOfDays *= -1;

            invoice.Paywall = paywall;
            //gets the league subscriptio date.
            //if the league date is in the fiture, then we use that date, otherwise we use todas date.

            //checks the last subscription to see if one exists.  
            //invoice.Paywall.ValidUntil = DateTime.UtcNow.AddDays(paywall.PaywallLengthOfDays);
            invoice.FinancialData.BasePriceForItems += paywall.Price;
            invoice.FinancialData.TotalIncludingTax += paywall.Price;
            return this;
        }