Exemplo n.º 1
0
        public static string Lithic_GetCardEmbedCode(bool fTestnet, string sCardGuid)
        {
            Chilkat.Rest rest = ConnectToLithic(fTestnet);
            embedRequest e    = new embedRequest();

            e.embed_request = sCardGuid;
            string          lithic_testnet = GetBMSConfigurationKeyValue("lithic_testnet");
            string          lithic_prod    = GetBMSConfigurationKeyValue("lithic_prod");
            string          myKey          = fTestnet ? lithic_testnet : lithic_prod;
            embedSubRequest esr            = new embedSubRequest();

            esr.token = sCardGuid;
            esr.css   = "";
            string embedRequestJson = JsonConvert.SerializeObject(esr);

            e.hmac = GetHMAC(embedRequestJson, myKey);
            string json      = JsonConvert.SerializeObject(e, Formatting.Indented);
            string sResponse = rest.FullRequestString("POST", "/v1/embed/card", json);

            if (rest.LastMethodSuccess != true)
            {
                Log(rest.LastErrorText);
                return("");
            }
            Chilkat.JsonObject jsonResponse = new Chilkat.JsonObject();
            jsonResponse.Load(sResponse);
            return("?");
        }
Exemplo n.º 2
0
        public static string ListCards1(bool fTestnet)
        {
            Chilkat.Rest rest = ConnectToLithic(fTestnet);
            string       s    = rest.FullRequestString("GET", "/v1/card", "");

            Chilkat.JsonObject jsonResponse = new Chilkat.JsonObject();
            dynamic            oJson        = JsonConvert.DeserializeObject <dynamic>(s);

            foreach (var card in oJson["data"])
            {
                string token = card["token"].Value;
                return(token);
            }
            return("");
        }
Exemplo n.º 3
0
        public static void SimulateAuth_Lithic(bool fTestnet)
        {
            Chilkat.Rest rest = ConnectToLithic(fTestnet);
            panObject    p    = new panObject();

            p.amount     = 500;
            p.descriptor = "AMAZON.COM";
            string json      = JsonConvert.SerializeObject(p, Formatting.Indented);
            string sResponse = rest.FullRequestString("POST", "/v1/simulate/authorize", json);

            if (rest.LastMethodSuccess != true)
            {
                Log(rest.LastErrorText);
                return;
            }
            Chilkat.JsonObject jsonResponse = new Chilkat.JsonObject();
            jsonResponse.Load(sResponse);
        }
Exemplo n.º 4
0
        public static void CreateCard_Lithic(bool fTestnet)
        {
            Chilkat.Rest     rest = ConnectToLithic(fTestnet);
            cardobjectlithic c    = new cardobjectlithic();

            c.memo                 = "Memo1";
            c.spend_limit          = 200 * 100;
            c.spend_limit_duration = "TRANSACTION";

            c.type = "MERCHANT_LOCKED";
            string json      = JsonConvert.SerializeObject(c, Formatting.Indented);
            string sResponse = rest.FullRequestString("POST", "/v1/card", json);

            if (rest.LastMethodSuccess != true)
            {
                Log(rest.LastErrorText);
                return;
            }
            Chilkat.JsonObject jsonResponse = new Chilkat.JsonObject();
            jsonResponse.Load(sResponse);
            string mytest = "";
        }
Exemplo n.º 5
0
        public static DACResult Zinc_RealTimeProductQuery(string myItem, string sCountry)
        {
            DACResult r = new DACResult();

            r.sError = "";
            try
            {
                Chilkat.Rest rest             = ConnectToZinc();
                string       jsonOrder        = "";
                string[]     q                = myItem.Split("/");
                string       sOriginalURL     = "";
                string       sSearchProductID = "";
                for (int i = 0; i < q.Length; i++)
                {
                    sOriginalURL += q[i] + "/";
                    if (q[i].Length == 10)
                    {
                        sSearchProductID = q[i];
                        break;
                    }
                }
                string sRetailer = "amazon";
                if (sCountry == "UK")
                {
                    sRetailer = "amazon_uk";
                }
                else
                {
                    sRetailer = "amazon";
                }
                string sResponse = rest.FullRequestString("GET", "/v1/search?query=" + HttpUtility.UrlEncode(sSearchProductID) + "&retailer=" + sRetailer, jsonOrder);
                if (rest.LastMethodSuccess != true)
                {
                    Log(rest.LastErrorText);
                    r.sError = "Unable to interface with AMAZON.";
                    return(r);
                }
                dynamic oJson = JsonConvert.DeserializeObject <dynamic>(sResponse);
                if (oJson["results"] == null)
                {
                    r.sError = "Unable to find item";
                    return(r);
                }

                foreach (var j in oJson["results"])
                {
                    // if its not prime or its pantry; give them a nice error
                    bool fFresh  = j["fresh"].Value;
                    bool fPrime  = j["prime"].Value;
                    bool fPantry = j["pantry"].Value;
                    if (fFresh || fPantry)
                    {
                        r.sError = "Sorry, we are not interfacing with Fresh or Pantry items yet. ";
                        return(r);
                    }
                    if (!fPrime)
                    {
                        r.sError = "Sorry, this item is not amazon prime.  Please, only add Amazon Prime items so we can offer free shipping. ";
                        return(r);
                    }
                    CacheProduct(j, sOriginalURL, sCountry);
                    r.sResult = sOriginalURL;
                    return(r);
                }
                r.sResult = sOriginalURL;
                return(r);
            }
            catch (Exception ex)
            {
                r.sError = "Unable to find product.";
                return(r);
            }
        }
Exemplo n.º 6
0
        public static DACResult Zinc_QueryOrderStatus(string sZincID)
        {
            DACResult r = new DACResult();

            r.sError = "";
            try
            {
                Chilkat.Rest rest      = ConnectToZinc();
                string       jsonOrder = "";
                string       sResponse = rest.FullRequestString("GET", "/v1/orders/" + sZincID, jsonOrder);
                if (rest.LastMethodSuccess != true)
                {
                    Log(rest.LastErrorText);
                    r.sError = "Unable to interface with AMAZON.";
                    return(r);
                }
                dynamic oJson = JsonConvert.DeserializeObject <dynamic>(sResponse);
                // Tracking
                string sDeliveryDate = GetJsonValue(oJson, "delivery_dates", "date");
                string sTrackingURL  = GetJsonValue(oJson, "merchant_order_ids", "tracking_url");
                if (sTrackingURL != "")
                {
                    sTrackingURL = sZincID;
                }


                string sCode = GetJsonValue(oJson, "code", "");

                string msg = GetJsonValue(oJson, "message", "");
                msg = msg.Replace("'", "");

                string sStatus = "";

                if (sCode == "aborted_request")
                {
                    sStatus      = "COMPLETED";
                    sTrackingURL = sCode;
                }
                else if (msg == "One of the products you selected is unavailable.")
                {
                    sStatus      = "COMPLETED";
                    sTrackingURL = "CUSTOMER REFUNDED";
                    // Credit the user the amount
                    string    sMySql     = "Select * from Orders where ZincID = '" + BMS.PurifySQL(sZincID, 40) + "'";
                    DataTable dtRefunded = gData.GetDataTable2(sMySql);
                    if (dtRefunded.Rows.Count > 0)
                    {
                        double nPriceBBP = GetDouble(dtRefunded.Rows[0]["bbpprice"]);
                        string sSql2     = "Select product_id from products where id='" + dtRefunded.Rows[0]["productid"].ToString() + "'";
                        string sProdID   = gData.GetScalarString2(sSql2, "product_id");
                        string sNotes    = "Full refund for unavailable product for product id " + sProdID;
                        DataOps.AdjBalance(1 * nPriceBBP, DataOps.GetUserRecord(dtRefunded.Rows[0]["UserId"].ToString()).UserId.ToString(), sNotes);
                        NotifyOfMissingProduct(DataOps.GetUserRecord(dtRefunded.Rows[0]["UserId"].ToString()).EmailAddress, sProdID);
                    }
                }
                else if (sTrackingURL != "")
                {
                    sStatus = "OUT_FOR_DELIVERY";
                    if (sDeliveryDate != "")
                    {
                        System.TimeSpan diffResult = System.DateTime.Now - Convert.ToDateTime(sDeliveryDate);
                        if (diffResult.TotalHours > 1)
                        {
                            sStatus = "COMPLETED";
                        }
                    }
                }


                if (r.sResult != "" || true)
                {
                    string sql = "Update Orders Set Updated=getdate(),DeliveryDate='" + sDeliveryDate + "', TrackingNumber='" + sTrackingURL + "',Message='"
                                 + msg + "',Status = '" + sStatus + "' where ZincID = '" + sZincID + "' and status <> 'COMPLETED'";
                    gData.Exec(sql);
                }

                return(r);
            }
            catch (Exception ex)
            {
                r.sError = "Unable to find product.";
                return(r);
            }
        }