public static string ScalablePressAPICall(string URL, string Method, string Body)
        {
            try
            {
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URL);
                request.Method      = Method;
                request.ContentType = "application/x-www-form-urlencoded";
                request.Accept      = "*/*";
                CredentialCache mycache = new CredentialCache();
                mycache.Add(new Uri(URL), "Basic", new NetworkCredential("", APIKEY));
                request.Credentials = mycache;
                request.Headers.Add("Authorization", "Basic " + Convert.ToBase64String(new ASCIIEncoding().GetBytes(":" + APIKEY)));

                if (!string.IsNullOrWhiteSpace(Body))
                {
                    byte[] myShinyMetalAss = System.Text.ASCIIEncoding.Default.GetBytes(Body);
                    request.ContentLength = myShinyMetalAss.Length;

                    using (Stream postStream = request.GetRequestStream())
                        postStream.Write(myShinyMetalAss, 0, myShinyMetalAss.Length);
                }

                HttpWebResponse response       = (HttpWebResponse)request.GetResponse();
                Stream          responseStream = response.GetResponseStream();
                var             reader         = new StreamReader(responseStream);

                string result = reader.ReadToEnd();

                reader.Close();
                responseStream.Close();
                return(result);
            }
            catch (WebException ex)
            {
                LoggingUtil.InsertError(ex);

                StreamReader sr   = new StreamReader(ex.Response.GetResponseStream());
                string       body = sr.ReadToEnd();
                sr.Close();

                throw new Exception(body);
            }
        }
        public static Status GetOrderStatus(Order orderObject)
        {
            Status OrderStatus = Status.Error;

            try
            {
                Event eventObject = orderObject.Events.OrderByDescending(x => x.CreatedAt).FirstOrDefault();
                if (eventObject != null)
                {
                    switch (eventObject.Name.ToUpper())
                    {
                    case "QUOTE":
                        OrderStatus = Status.Pending;
                        break;

                    case "ORDER":
                    case "PAID":
                    case "UNPAID":
                    case "HOLD":
                        OrderStatus = Status.Paid;
                        break;

                    case "PRINTING":
                        OrderStatus = Status.Printing;
                        break;

                    case "SHIPPED":
                        OrderStatus = Status.Shipped;
                        break;

                    case "CANCELLED":
                        OrderStatus = Status.Canceled;
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                LoggingUtil.InsertError(ex);
            }

            return(OrderStatus);
        }
예제 #3
0
        public static bool IsCartAlive(Guid CacheKey)
        {
            bool exist = false;

            try
            {
                DataTable dtCart = DB.GetWithQuery("SELECT TOP 1 1 FROM Cart WITH(NOLOCK) WHERE CacheID = '" + CacheKey + "'");
                if (dtCart != null && dtCart.Rows.Count > 0)
                {
                    exist = true;
                }
            }
            catch (Exception ex)
            {
                ex.Data.Add("CacheKey", CacheKey);
                LoggingUtil.InsertError(ex);
            }

            return(exist);
        }
예제 #4
0
        public static bool ApplyDiscountToCart(int DiscountID, Guid CartKey)
        {
            bool added = false;

            try
            {
                List <SqlParameter> p = new List <SqlParameter>();
                p.Add(new SqlParameter("@CartKey", CartKey));
                p.Add(new SqlParameter("@DiscountID", DiscountID));

                int iAffected = DB.SetWithRowsAffected("DiscountCartApply", p.ToArray());
                added = iAffected > 0;
            }
            catch (Exception ex)
            {
                ex.Data.Add("DiscountID", DiscountID);
                ex.Data.Add("CartKey", CartKey);
                LoggingUtil.InsertError(ex);
            }

            return(added);
        }
예제 #5
0
        public static bool IsValidDiscount(string DiscountCode, out int DiscountID)
        {
            bool valid = false;

            DiscountID = 0;

            try
            {
                Discount d = new Discount();
                using (SqlConnection conn = DB.GetConnection())
                    d = conn.Query <Discount>("DiscountSelect", new { DiscountCode = DiscountCode }, commandType: CommandType.StoredProcedure).FirstOrDefault();

                if (d != null)
                {
                    if (d.DiscountUsage != null && d.DiscountLimit != null && d.DiscountUsage >= d.DiscountLimit)
                    {
                        return(false);
                    }

                    if (d.ExpirationDate != null && d.ExpirationDate < DateTime.UtcNow)
                    {
                        return(false);
                    }

                    DiscountID = d.DiscountID;
                    valid      = true;
                }
            }
            catch (Exception ex)
            {
                ex.Data.Add("DiscountCode", DiscountCode);
                LoggingUtil.InsertError(ex);
            }

            return(valid);
        }
        public static decimal GetShippingQuote(Guid CacheID)
        {
            string BulkQuoteURL = "https://api.scalablepress.com/v2/quote/bulk";
            string Method       = "POST";
            string Body         = string.Empty;

            decimal ShipTotal = 0M;

            try
            {
                List <SqlParameter> p = new List <SqlParameter>();
                p.Add(new SqlParameter("@CacheID", CacheID));

                DataTable dtCartAddress = DB.Get("CartAddressSelect", p.ToArray());
                DataTable dtCart        = DB.Get("CartDetailedSelect", p.ToArray());
                DataRow   drAddress     = dtCartAddress.Rows[0];

                int i = 0;
                foreach (DataRow drCart in dtCart.Rows)
                {
                    if (i > 0)
                    {
                        Body += "&";
                    }

                    string DesignID = drCart["DesignID"].ToString();

                    if (string.IsNullOrWhiteSpace(DesignID))
                    {
                        DesignID = GetDesignID(drCart["VariationID"].ToString());
                    }

                    Body += "items[" + i + "][type]=dtg";
                    Body += "&items[" + i + "][designId]=" + DesignID;

                    Body += "&items[" + i + "][address][name]=" + drAddress["ShipFirstName"].ToString() + " " + drAddress["ShipLastName"].ToString();
                    Body += "&items[" + i + "][address][address1]=" + drAddress["ShipAddress1"].ToString();
                    if (!string.IsNullOrWhiteSpace(drAddress["ShipAddress2"].ToString()))
                    {
                        Body += "&items[" + i + "][address][address2]=" + drAddress["ShipAddress2"].ToString();
                    }
                    Body += "&items[" + i + "][address][city]=" + drAddress["ShipCity"].ToString();
                    Body += "&items[" + i + "][address][state]=" + drAddress["ShipState"].ToString();
                    Body += "&items[" + i + "][address][country]=" + drAddress["ShipCountryCode"].ToString();
                    Body += "&items[" + i + "][address][zip]=" + drAddress["ShipZip"].ToString();

                    Body += "&items[" + i + "][products][0][id]=" + drCart["Type"].ToString();
                    Body += "&items[" + i + "][products][0][color]=" + drCart["Color"].ToString();
                    Body += "&items[" + i + "][products][0][quantity]=" + drCart["Quantity"].ToString();
                    Body += "&items[" + i + "][products][0][size]=" + drCart["Size"].ToString();

                    i++;
                }

                string result = ScalablePressAPICall(BulkQuoteURL, Method, Body);

                Quote quoteObject = JsonConvert.DeserializeObject <Quote>(result);

                string OrderToken = quoteObject.OrderToken;

                p.Add(new SqlParameter("@OrderToken", OrderToken));
                int RowsAffected = DB.SetWithRowsAffected("CartOrderTokenPost", p.ToArray());
                if (RowsAffected <= 0)
                {
                    throw new Exception("Order token not saved");
                }

                ShipTotal = quoteObject.Shipping;
            }
            catch (Exception ex)
            {
                ex.Data.Add("CacheID", CacheID);
                LoggingUtil.InsertError(ex);
            }

            return(ShipTotal);
        }
예제 #7
0
        public static string ProcessSale(string firstName, string lastName, string billAddress1, string billAddress2, string billCity, string billState, string billCountry, string billZip,
                                         List <SaleProduct> CartItems, string CardNo, string cvv2, int expYear, int expMonth, decimal shippingCharge)
        {
            string  PaymentID  = "";
            decimal totalPrice = 0M;
            Dictionary <string, string> payPalConfig = new Dictionary <string, string>();

            payPalConfig.Add("mode", mode);

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

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

                PayPal.Api.Address billingAddress = new PayPal.Api.Address();
                billingAddress.city  = billCity;
                billingAddress.line1 = billAddress1;
                if (!string.IsNullOrWhiteSpace(billAddress2))
                {
                    billingAddress.line2 = billAddress2;
                }
                billingAddress.state        = billState;
                billingAddress.country_code = billCountry;
                billingAddress.postal_code  = billZip;

                CreditCard cc = new CreditCard();
                cc.billing_address = billingAddress;
                cc.number          = CardNo;
                cc.cvv2            = cvv2;
                cc.type            = CCUtils.CreditCardType(CardNo).ToLower();
                cc.first_name      = firstName;
                cc.last_name       = lastName;
                cc.expire_month    = expMonth;
                cc.expire_year     = expYear;

                FundingInstrument fi = new FundingInstrument();
                fi.credit_card = cc;

                Payer py = new Payer();
                py.payment_method      = "credit_card";
                py.funding_instruments = new List <FundingInstrument>()
                {
                    fi
                };

                Transaction t = new Transaction();
                t.amount = new Amount();

                foreach (SaleProduct item in CartItems)
                {
                    totalPrice = Math.Round(totalPrice + (item.UnitPrice * item.Quantity), 2, MidpointRounding.AwayFromZero);
                }

                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 Store Purchase";

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

                Payment pResp = p.Create(AC);

                if (pResp.state.Equals("approved", StringComparison.OrdinalIgnoreCase))
                {
                    PaymentID = pResp.id;
                }
            }
            catch (PayPal.PayPalException ppex)
            {
                LoggingUtil.InsertError(ppex);
            }
            catch (WebException ex)
            {
                LoggingUtil.InsertError(ex);
                WebResponse wr = ex.Response;
                if (wr != null)
                {
                    StreamReader sr = new StreamReader(wr.GetResponseStream());
                    string       ss = sr.ReadToEnd();
                    throw new Exception(ss);
                }
            }
            catch (Exception ex)
            {
                LoggingUtil.InsertError(ex);
            }

            return(PaymentID);
        }