Ejemplo n.º 1
0
        public static void SendConfirmation(string OrderID)
        {
            List <SqlParameter> op = new List <SqlParameter>();

            op.Add(new SqlParameter("@OrderID", OrderID));
            DataTable dtOrder    = DB.Get("OrderSummarySelect", op.ToArray());
            DataTable dtCustomer = DB.GetWithQuery("SELECT * FROM Orders WITH(NOLOCK) WHERE OrderID = " + OrderID);

            if (dtOrder != null && dtOrder.Rows.Count > 0 && dtCustomer != null && dtCustomer.Rows.Count > 0)
            {
                DataRow drCustomer = dtCustomer.Rows[0];

                string address = "";
                address += "<b>" + drCustomer["ShipName"].ToString() + "</b><br />";
                address += drCustomer["ShipAddress1"].ToString() + "<br />";
                if (!string.IsNullOrWhiteSpace(drCustomer["ShipAddress2"].ToString()))
                {
                    address += drCustomer["ShipAddress2"].ToString() + "<br />";
                }
                address += drCustomer["ShipCity"].ToString() + ", " + drCustomer["ShipState"].ToString() + " "
                           + drCustomer["ShipZip"].ToString() + " " + drCustomer["ShipCountryCode"].ToString();

                decimal       subtotal = 0M;
                StringBuilder itemrows = new StringBuilder();
                foreach (DataRow dr in dtOrder.Rows)
                {
                    decimal tryDec;
                    int     tryInt;

                    decimal price = 0M, linetotal = 0M;
                    int     quantity = 0;

                    if (decimal.TryParse(dr["Price"].ToString(), out tryDec))
                    {
                        price = tryDec;
                    }
                    if (int.TryParse(dr["Quantity"].ToString(), out tryInt))
                    {
                        quantity = tryInt;
                    }

                    linetotal = Math.Round(price * quantity, 2, MidpointRounding.AwayFromZero);

                    itemrows.AppendLine("<tr>");
                    itemrows.AppendLine("<td style=\"padding-right:8px;\">" + dr["Title"].ToString() + "</td>");
                    itemrows.AppendLine("<td style=\"padding-right:8px;\">" + dr["Color"].ToString() + "</td>");
                    itemrows.AppendLine("<td style=\"padding-right:8px;\">" + dr["Size"].ToString() + "</td>");
                    itemrows.AppendLine("<td style=\"padding-right:8px;\">$" + price.ToString("0.00") + "</td>");
                    itemrows.AppendLine("<td style=\"padding-right:8px;\">" + quantity + "</td>");
                    itemrows.AppendLine("<td style=\"padding-right:8px;\">$" + linetotal.ToString("0.00") + "</td>");
                    itemrows.AppendLine("</tr>");

                    subtotal = Math.Round(subtotal + linetotal, 2, MidpointRounding.AwayFromZero);
                }

                decimal Discount   = 0M;
                int     DiscountID = 0;
                if (!string.IsNullOrEmpty(drCustomer["DiscountID"].ToString()) && int.TryParse(drCustomer["DiscountID"].ToString(), out DiscountID))
                {
                    Discount = DiscountUtils.CalculateOrderDiscount(DiscountID, dtOrder);
                }

                string body = Properties.Resources.OrderConfirmation;

                body = body.Replace("$$USER$$", drCustomer["ShipName"].ToString());
                body = body.Replace("$$ORDER$$", OrderID);
                body = body.Replace("$$ADDRESS$$", address);
                body = body.Replace("$$ITEMROWS$$", itemrows.ToString());
                body = body.Replace("$$SUBTOTAL$$", "$" + subtotal.ToString("0.00"));
                body = body.Replace("$$DISCOUNT$$", "$" + (subtotal - Discount).ToString("0.00"));
                decimal shipping = 0M;
                if (decimal.TryParse(drCustomer["ShippingPaid"].ToString(), out shipping))
                {
                    body = body.Replace("$$SHIPPING$$", "$" + shipping.ToString("0.00"));
                }
                body = body.Replace("$$TOTAL$$", "$" + Math.Round((subtotal - (subtotal - Discount)) + shipping, 2, MidpointRounding.AwayFromZero).ToString("0.00"));

                SendEmail(drCustomer["ShipEmail"].ToString(), "Your Order #" + OrderID, body);
            }
            else
            {
                return;
            }
        }
Ejemplo n.º 2
0
        public static string ConfirmSale(Guid cartKey, decimal ShippingCharge)
        {
            try
            {
                string payment_url = "";

                decimal totalPrice = 0M;
                Dictionary <string, string> payPalConfig = new Dictionary <string, string>();
                payPalConfig.Add("mode", mode);

                string     AccessToken = GetPayPalAccessToken();
                APIContext AC          = new APIContext(AccessToken);
                AC.Config = payPalConfig;

                Payee pe = new Payee();
                pe.merchant_id = "Q4A2XY37JY7VW";

                RedirectUrls ru = new RedirectUrls();
                ru.return_url = "https://www.chimaeraconspiracy.com/shop/approved.aspx";
                ru.cancel_url = "https://www.chimaeraconspiracy.com/shop/cancelled.aspx";

                Payer pyr = new Payer();
                pyr.payment_method = "paypal";

                List <Transaction> transactions = new List <Transaction>();
                Transaction        t            = new Transaction();
                t.amount = new Amount();

                List <SqlParameter> sqlp = new List <SqlParameter>();
                sqlp.Add(new SqlParameter("@CacheID", cartKey));

                DataTable dtDiscount = DB.Get("CartDiscountSelect", sqlp.ToArray());
                if (dtDiscount != null && dtDiscount.Rows.Count > 0)
                {
                    int DiscountID = (int)(dtDiscount.Rows[0][0]);
                    totalPrice = DiscountUtils.CalculateDiscountTotal(DiscountID, cartKey);
                }
                else
                {
                    DataTable dtSub = DB.Get("CartSubtotalGet", sqlp.ToArray());
                    if (dtSub != null && dtSub.Rows.Count > 0)
                    {
                        string  strSub     = dtSub.Rows[0][0].ToString();
                        decimal tryDecimal = 0M;
                        if (decimal.TryParse(strSub, out tryDecimal))
                        {
                            totalPrice = tryDecimal;
                        }
                        else
                        {
                            throw new Exception("You done mucked up good");
                        }
                    }
                    else
                    {
                        throw new Exception("Subtotal could not be gathered");
                    }
                }

                t.amount.currency         = "USD";
                t.amount.details          = new Details();
                t.amount.details.subtotal = totalPrice.ToString("0.00");
                t.amount.details.tax      = "0.00";
                t.amount.details.shipping = ShippingCharge.ToString("0.00");
                t.amount.total            = Math.Round(totalPrice + ShippingCharge, 2, MidpointRounding.AwayFromZero).ToString("0.00");
                t.description             = "Chimaera Conspiracy Shop Purchase";

                Payment p = new Payment();
                p.intent        = "sale";
                p.payer         = pyr;
                p.redirect_urls = ru;
                p.transactions  = new List <Transaction>()
                {
                    t
                };

                Payment pResp = p.Create(AC);

                if (pResp.state.Equals("created", StringComparison.OrdinalIgnoreCase))
                {
                    payment_url = pResp.links.Where(x => x.rel.Equals("approval_url", StringComparison.OrdinalIgnoreCase)).Select(y => y.href).FirstOrDefault();
                }

                return(payment_url);
            }
            catch (PayPal.PayPalException ppe)
            {
                throw ppe;
            }
            catch (Exception e)
            {
                throw e;
            }
        }