Esempio n. 1
0
        private string GetOptionName(Invoice invoice)
        {
            if (invoice.MidiID.HasValue) // MIDI Option
            {
                MidiFile crumbsmodel = crumbsRepository.FindMidiFile(invoice.MidiID.Value);
                if (crumbsmodel != null)
                {
                    return string.Format("MIDI file for {0}", crumbsmodel.Name);
                }
                return "MIDI file";
            }
            else if (invoice.PackageID.HasValue) // MIDI Package
            {
                Package package = crumbsRepository.FindPackage(invoice.PackageID.Value);
                if (package != null)
                {
                    return package.Name;
                }
                return "MIDI package";
            }
            else
            {
                PrepaidOption option = crumbsRepository.FindPrepaidOption(invoice.Type);
                if (option != null)
                {
                    return option.Name;
                }
            }

            return "";
        }
Esempio n. 2
0
 private string GetPriceAmount(Invoice invoice)
 {
     return invoice.Amount.ToString();
 }
Esempio n. 3
0
        private string BuildDECPRequest(string token, string payerID, Invoice invoice)
        {
            string name = GetOptionName(invoice);
            string price = GetPriceAmount(invoice);

            if (invoice.Type < 10 && isProvideTrialPeriod)
            {
                name = "2 Weeks Trial Period";
            }

            string strNVP = APICredentials +
                "&METHOD=DoExpressCheckoutPayment" +
                "&TOKEN=" + token +
                "&PAYERID=" + payerID +
                "&PAYMENTREQUEST_0_PAYMENTACTION=Sale" +
                "&PAYMENTREQUEST_0_AMT=" + price +
                "&L_PAYMENTREQUEST_0_ITEMCATEGORY0=Digital" +
                "&L_PAYMENTREQUEST_0_AMT0=" + price +
                "&L_PAYMENTREQUEST_0_NAME0=" + name +
                "&L_PAYMENTREQUEST_0_QTY0=1" +
                "&VERSION=" + APIVersion;

            return strNVP;
        }
Esempio n. 4
0
        private string BuildSECRequest(Invoice invoice)
        {
            string strNVP = "";
            string price = GetPriceAmount(invoice);
            string name = GetOptionName(invoice);

            if (invoice.Type < 10)
            {
                if (isProvideTrialPeriod)
                {
                    name = "2 Weeks Trial Period";
                }

                PrepaidOption option = crumbsRepository.FindPrepaidOption(invoice.Type);

                strNVP = APICredentials +
                   "&METHOD=SetExpressCheckout" +
                   "&RETURNURL=" + Server.UrlEncode(Url.Action("Success", "Order", null, "http")) +
                   "&CANCELURL=" + Server.UrlEncode(Url.Action("Cancel", "Order", null, "http")) +
                   "&PAYMENTREQUEST_0_INVNUM=" + invoice.InvoiceID.ToString() +
                   "&PAYMENTREQUEST_0_CUSTOM=" + invoice.UserID.ToString() +
                   "&PAYMENTREQUEST_0_CURRENCYCODE=USD" +
                   "&PAYMENTREQUEST_0_AMT=" + price +
                   "&PAYMENTREQUEST_0_ITEMAMT=" + price +
                   "&PAYMENTREQUEST_0_TAXAMT=0.00" +
                   "&PAYMENTREQUEST_0_DESC=Interactive Piano Tutorials" +
                   "&PAYMENTREQUEST_0_PAYMENTACTION=Sale" +
                   "&L_PAYMENTREQUEST_0_ITEMCATEGORY0=Digital" +
                   "&L_PAYMENTREQUEST_0_NAME0=" + name +
                   "&REQCONFIRMSHIPPING=0" +
                   "&NOSHIPPING=1" +
                   "&L_PAYMENTREQUEST_0_QTY0=1" +
                   "&L_PAYMENTREQUEST_0_TAXAMT0=0.00" +
                   "&L_PAYMENTREQUEST_0_AMT0=" + price +
                   "&L_PAYMENTREQUEST_0_DESC0=" + option.SubName +
                   "&L_BILLINGAGREEMENTDESCRIPTION0=" + option.SubName +
                   "&L_BILLINGTYPE0=RecurringPayments" +
                   "&LOGOIMG=" + "http://www.pianocrumbs.com/piano/Content/html/css/images/logo_small.jpg" +
                   "&VERSION=" + APIVersion;
            }
            else {
                strNVP = APICredentials +
                   "&METHOD=SetExpressCheckout" +
                   "&RETURNURL=" + Server.UrlEncode(Url.Action("Success", "Order", null, "http")) +
                   "&CANCELURL=" + Server.UrlEncode(Url.Action("Cancel", "Order", null, "http")) +
                   "&PAYMENTREQUEST_0_INVNUM=" + invoice.InvoiceID.ToString() +
                   "&PAYMENTREQUEST_0_CUSTOM=" + invoice.UserID.ToString() +
                   "&PAYMENTREQUEST_0_CURRENCYCODE=USD" +
                   "&PAYMENTREQUEST_0_AMT=" + price +
                   "&PAYMENTREQUEST_0_ITEMAMT=" + price +
                   "&PAYMENTREQUEST_0_TAXAMT=0.00" +
                   "&PAYMENTREQUEST_0_DESC=Interactive Piano Tutorials" +
                   "&PAYMENTREQUEST_0_PAYMENTACTION=Sale" +
                   "&L_PAYMENTREQUEST_0_ITEMCATEGORY0=Digital" +
                   "&L_PAYMENTREQUEST_0_NAME0=" + name +
                   "&REQCONFIRMSHIPPING=0" +
                   "&NOSHIPPING=1" +
                   "&L_PAYMENTREQUEST_0_QTY0=1" +
                   "&L_PAYMENTREQUEST_0_TAXAMT0=0.00" +
                   "&L_PAYMENTREQUEST_0_AMT0=" + price +
                   "&LOGOIMG=" + "http://www.pianocrumbs.com/piano/Content/html/css/images/logo_small.jpg" +
                   "&VERSION=" + APIVersion +
                   "&SOLUTIONTYPE=Sole";
            }

            return strNVP;
        }
Esempio n. 5
0
        private string BuildCRPRequest(string token, Invoice invoice)
        {
            DateTime startDate = DateTime.Now;
            PrepaidOption option = crumbsRepository.FindPrepaidOption(invoice.Type);

            if (isProvideTrialPeriod)
            {
                startDate = startDate.AddDays(14);
            }
            else
            {
                if (option.Months == 12)
                {
                    startDate = startDate.AddYears(1);
                }
                else
                {
                    startDate = startDate.AddMonths(option.Months);
                }
            }

            Decimal price = GetPriceAmount(invoice.Type, null);
            string strNVP = APICredentials +
                "&METHOD=CreateRecurringPaymentsProfile" +
                "&AMT=" + price +
                "&DESC=" + option.SubName +
                "&CURRENCYCODE=USD" +
                "&BILLINGPERIOD=Month" +
                "&BILLINGFREQUENCY=" + option.Months.ToString() +
                "&PROFILESTARTDATE=" + startDate.ToString("s") +
                "&PROFILEREFERENCE=" + invoice.UserID.ToString() +
                "&L_PAYMENTREQUEST_0_ITEMCATEGORY0=Digital" +
                "&L_PAYMENTREQUEST_0_NAME0=Interactive Piano Tutorials" +
                "&L_PAYMENTREQUEST_0_AMT0=" + price.ToString() +
                "&L_PAYMENTREQUEST_0_QTY0=1" +
                //"&TRIALBILLINGPERIOD=Week" + //Period of time in one trial period
                //"&TRIALBILLINGFREQUENCY=2" + //Frequency of charges, if any, during the trial period
                //"&TRIALTOTALBILLINGCYCLES=1" + // Length of trial period
                //"&TRIALAMT=1" +    // Payment amount (can be 0) during the trial period
                "&TOKEN=" + token +
                "&VERSION=" + APIVersion;

            return strNVP;
        }
Esempio n. 6
0
        public ActionResult SetEC(Invoice newInvoice)
        {
            // Send SetExpressCheckout request
            string strSECRequest = BuildSECRequest(newInvoice);
            Hashtable htSECResponse = SendRequest(strSECRequest);
            string strAck = htSECResponse["ACK"].ToString();
            if (strAck == "Success" || strAck == "SuccessWithWarning")
            {
                string token = htSECResponse["TOKEN"].ToString();
                return Redirect("https://www.paypal.com/incontext?token=" + token);
            }
            else
            {
                string strErr = "Error: " + htSECResponse["L_LONGMESSAGE0"].ToString();
                string strErrcode = "Error code: " + htSECResponse["L_ERRORCODE0"].ToString();

                return View("Failed", (object)strErr);
            }
        }
Esempio n. 7
0
        //
        // POST: /Order/SetEC
        public ActionResult SetEC(short optionID, int? midiID)
        {
            Invoice newInvoice = new Invoice();
            newInvoice.UserID = CurrentUser != null ? CurrentUser.UserID : 20;
            newInvoice.Type = optionID;

            if (optionID == 10)
            {
                newInvoice.MidiID = midiID;
            }
            else if (optionID >= 20)
            {
                newInvoice.PackageID = (short?)midiID;
            }

            if (optionID < 10)
            {
                if (isProvideTrialPeriod)
                {
                    newInvoice.Amount = 0.01M;
                }

                // Don't allow unregistered users to buy subscriptions
                if (newInvoice.UserID == 20)
                {
                    return View("SessionExpired", newInvoice);
                }
            }
            else
            {
                newInvoice.Amount = GetPriceAmount(optionID, midiID);
            }

            newInvoice.Date = DateTime.Now;
            crumbsRepository.InsertOrUpdateInvoice(newInvoice);
            crumbsRepository.Save();

            newInvoice.Message = GetOptionName(newInvoice);

            return View(newInvoice);
        }
Esempio n. 8
0
        public ActionResult CreateInvoice(string userKey, short optionID, int? midiID)
        {
            Invoice newInvoice = null;
            User user = usersRepository.FindUser(userKey);
            if (user != null)
            {
                newInvoice = new Invoice();
                newInvoice.UserID = user.UserID;
                newInvoice.Type = optionID;

                if (optionID == 10)
                {
                    newInvoice.MidiID = midiID;
                }
                else if (optionID >= 20)
                {
                    newInvoice.PackageID = (short?)midiID;
                }

                if (optionID < 10 && isProvideTrialPeriod)
                {
                    newInvoice.Amount = 0.01M;
                }
                else
                {
                    newInvoice.Amount = GetPriceAmount(optionID, midiID);
                }

                newInvoice.Date = DateTime.Now;
                crumbsRepository.InsertOrUpdateInvoice(newInvoice);
                crumbsRepository.Save();

                newInvoice.Message = GetOptionName(newInvoice);
            }

            return new JsonResult
            {
                Data = newInvoice,
                JsonRequestBehavior = JsonRequestBehavior.AllowGet
            };
        }
Esempio n. 9
0
        public static bool ProcessOrder(ICrumbsRepository crumbsRepository, Invoice invoice, string serverPath, string email, bool updateCopies)
        {
            List<MidiFile> files = new List<MidiFile>();
            User user = (crumbsRepository as IUserRepository).FindUserByID(invoice.UserID);
            Mailing mail = crumbsRepository.AllMailings.SingleOrDefault(item => item.Name == "Send_MIDI");

            if (user.UserID == 20)
            {
                User newUser = (crumbsRepository as IUserRepository).FindUserByEmail(email);
                if (newUser == null)
                {
                    newUser = new User()
                    {
                        Type = 3,
                        UserKey = email,
                        UserName = email,
                        Email = email,
                        CreateDate = DateTime.Now,
                        LastLoginDate = DateTime.Now
                    };
                    (crumbsRepository as IUserRepository).InsertOrUpdateUser(newUser);
                    crumbsRepository.Save();
                }
                user = newUser;
            }

            if (user == null || mail == null)
                return false;

            string userEmail = user.Email;
            if (string.IsNullOrEmpty(userEmail))
                userEmail = email;

            if (string.IsNullOrEmpty(userEmail))
                return false;

            SmtpClient client = null;
            try
            {
                bool useGMailForOrders = false;
                string s = ConfigurationManager.AppSettings["UseGMailForOrders"];
                if (string.IsNullOrEmpty(s) == false)
                {
                    useGMailForOrders = Convert.ToBoolean(s);
                }

                if (useGMailForOrders == true)
                {
                    client = new SmtpClient("smtp.gmail.com", 587);
                    client.EnableSsl = true;
                    client.Timeout = 10000;
                    client.DeliveryMethod = SmtpDeliveryMethod.Network;
                    client.UseDefaultCredentials = false;
                    client.Credentials = new NetworkCredential("*****@*****.**", "Crumbs123");
                }
                else
                {
                    client = new SmtpClient("m02.internetmailserver.net", 587);
                    client.EnableSsl = false;
                    client.Credentials = new NetworkCredential("*****@*****.**", "Crumbs123", "");
                }

                MailAddress from = new MailAddress("*****@*****.**", "PianoCrumbs.com");
                MailAddress to = new MailAddress(userEmail, "");
                MailMessage message = new MailMessage(from, to);

                message.Subject = mail.Subject;
                message.IsBodyHtml = true;
                message.CC.Add(new MailAddress("*****@*****.**", "PianoCrumbs.com"));

                if (invoice.MidiID.HasValue)
                {
                    MidiFile file = crumbsRepository.FindMidiFile(invoice.MidiID.Value);
                    if (file != null)
                    {
                        string path = MidiFileHelper.getMidiPath(file);
                        string FullPath = serverPath + path;

                        Attachment attachment = new Attachment(FullPath);
                        attachment.Name = file.FileName;
                        message.Attachments.Add(attachment);

                        files.Add(file);
                    }
                }
                else if (invoice.PackageID.HasValue)
                {
                    Package package = crumbsRepository.FindPackage(invoice.PackageID.Value);
                    if (package != null)
                    {
                        foreach (MidiFile file in package.MidiFiles)
                        {
                            string path = MidiFileHelper.getMidiPath(file);
                            string FullPath = serverPath + path;

                            Attachment attachment = new Attachment(FullPath);
                            attachment.Name = file.FileName;
                            message.Attachments.Add(attachment);

                            files.Add(file);
                        }
                    }
                }
                message.Body = string.Format(mail.Text, user.UserName, "", "", "");

                client.Send(message);
            }
            catch (Exception ex)
            {
                if (ex.InnerException != null)
                {
                    invoice.Comment = ex.InnerException.Message + " | " + DateTime.Now.ToString("s");
                }
                else
                {
                    invoice.Comment = ex.Message + " | " + DateTime.Now.ToString("s");
                }
                crumbsRepository.InsertOrUpdateInvoice(invoice);
                crumbsRepository.Save();

                return false;
            }

            // Create new SentMail record
            SentMail sent = new SentMail();
            sent.UserID = user.UserID;
            sent.MailID = mail.ID;
            sent.Date = DateTime.Now;
            crumbsRepository.InsertOrUpdateSentMail(sent);

            if (user.Role == null && updateCopies == true)
            {
                // Update MidiFile record - substruct one copy
                foreach (MidiFile file in files)
                {
                    file.CopiesLeft -= 1;
                    crumbsRepository.InsertOrUpdateMidiFile(file);
                }
            }

            // Update Invoice with SentMail ID
            invoice.Comment = userEmail + " | " + DateTime.Now.ToString("s");
            invoice.UserID = user.UserID;
            crumbsRepository.InsertOrUpdateInvoice(invoice);

            crumbsRepository.Save();
            return true;
        }