Exemplo n.º 1
0
        public ActionResult paypal(PayPalDTO input)
        {
            input.isPayment = false;
            input.isSendEmail = false;
            DateTime currentDay = DateTime.Now;
            string transactionID = System.Guid.NewGuid().ToString();
            string localhost = ConfigurationManager.AppSettings["localhost"];
            string paypal_success_url = ConfigurationManager.AppSettings["paypal_success_url"] + "?d=" + currentDay.ToString("yyyyMMdd") + transactionID;
            string paypal_cancel_url = ConfigurationManager.AppSettings["paypal_cancel_url"];
            string paypal_sandbox_account = ConfigurationManager.AppSettings["paypal_sandbox_account"];
            string paypal = ConfigurationManager.AppSettings["paypal"];
            string deploy_mode = ConfigurationManager.AppSettings["deploy_mode"];
            string amount = "0";
            bool isValid = false;
            switch (input.packageName)
            {
                case "Basic":
                    amount = ConfigurationManager.AppSettings["packageBasicprice"];
                    isValid = true;
                    break;
                case "Standard":
                    amount = ConfigurationManager.AppSettings["packageStandardprice"];
                    isValid = true;
                    break;
                case "Premium":
                    amount = ConfigurationManager.AppSettings["packagePremiumprice"];
                    isValid = true;
                    break;
                case "Super":
                    isValid = false;
                    // package 4: 5000 designs is not ready now
                    break;
                default:
                    break;
            }
            if (isValid)
            {
                input.transactionID = transactionID;
                string queryString = string.Format("cmd={0}&business={1}&amount={2}&shopping_url={3}&return={4}&cancel_return={5}&item_name={6}&currency_code=USD", "_xclick", paypal_sandbox_account, amount, localhost, paypal_success_url, paypal_cancel_url, input.email + "|" + input.packageName+"|"+amount);
                this.save_log(input);
                if (deploy_mode=="test")
                {
                    return Redirect(paypal_success_url);
                }

                return Redirect(paypal + "?" + queryString);
            }

            return View();
        }
Exemplo n.º 2
0
        private void send_email(PayPalDTO input)
        {
            try
            {

                string template = "~\\App_Start\\Email\\package" + input.packageName + ".html";
                string templateDir = Server.MapPath(template);
                string templateContent = System.IO.File.ReadAllText(templateDir);
                StringBuilder v_sb = new StringBuilder(templateContent);
                v_sb.Replace("{{FirstName}}", input.firstName);

                BLL.Email email = new BLL.Email();

                email.sendSubject = string.Format("3000 Design TShirt - package {0}", input.packageName);
                email.sendBody = v_sb.ToString();
                email.sendTo = input.email;
                email.SendEmail();

                input.isSendEmail = true;
            }
            catch (Exception ex)
            {
                // write log
                input.isSendEmail = false;
            }
        }
Exemplo n.º 3
0
 private void save_log(PayPalDTO input)
 {
     string TransactionLogFolder = Server.MapPath(ConfigurationManager.AppSettings["TransactionLogFolder"]);
     string SubFolder = TransactionLogFolder + "\\" + DateTime.Now.ToString("yyyyMMdd");
     string FileDirectory = SubFolder + "\\" + input.transactionID + ".json";
     if (!Directory.Exists(TransactionLogFolder))
     {
         Directory.CreateDirectory(TransactionLogFolder);
     }
     if (!Directory.Exists(SubFolder))
     {
         Directory.CreateDirectory(SubFolder);
     }
     string jsonString = JsonConvert.SerializeObject(input);
     System.IO.File.WriteAllText(FileDirectory, jsonString);
 }