Beispiel #1
0
        public static Chilkat.Rest ConnectToLithic(bool fTestnet)
        {
            Chilkat.Rest rest = new Chilkat.Rest();
            bool         success;
            bool         bTls           = true;
            int          port           = 443;
            bool         bAutoReconnect = true;
            string       sURL           = fTestnet ? "sandbox.lithic.com" : "api.lithic.com";

            success = rest.Connect(sURL, port, bTls, bAutoReconnect);
            if (success != true)
            {
                Log("ConnectFailReason: " + Convert.ToString(rest.ConnectFailReason));
                Log(rest.LastErrorText);
                return(null);
            }
            string lithic_testnet = GetBMSConfigurationKeyValue("lithic_testnet");
            string lithic_prod    = GetBMSConfigurationKeyValue("lithic_prod");

            string auth = "Authorization: api-key " + lithic_testnet;
            string sKey = fTestnet ? "api-key " + lithic_testnet : "api-key " + lithic_prod;

            rest.AddHeader("Authorization", sKey);
            rest.AddHeader("Content-Type", "application/json");
            return(rest);
        }
Beispiel #2
0
        public static void ListAllCardholders()
        {
            Chilkat.Rest rest = new Chilkat.Rest();
            bool         success;
            //  URL: https://api.stripe.com/v1/balance
            bool bTls           = true;
            int  port           = 443;
            bool bAutoReconnect = true;

            success = rest.Connect("api.stripe.com", port, bTls, bAutoReconnect);
            if (success != true)
            {
                Log("ConnectFailReason: " + Convert.ToString(rest.ConnectFailReason));
                Log(rest.LastErrorText);
                return;
            }
            Chilkat.StringBuilder sbResponseBody = new Chilkat.StringBuilder();
            success = rest.FullRequestNoBodySb("GET", "/v1/issuing/cardholders", sbResponseBody);
            if (success != true)
            {
                Log(rest.LastErrorText);
                return;
            }
            Chilkat.JsonObject jsonResponse = new Chilkat.JsonObject();
            jsonResponse.LoadSb(sbResponseBody);
            var o        = jsonResponse.StringOf("object");
            var livemode = jsonResponse.BoolOf("livemode");
        }
Beispiel #3
0
        public static void CreateCardholder()
        {
            Chilkat.Rest rest = new Chilkat.Rest();
            bool         success;
            //  URL: https://api.stripe.com/v1/balance
            bool bTls           = true;
            int  port           = 443;
            bool bAutoReconnect = true;

            success = rest.Connect("api.stripe.com", port, bTls, bAutoReconnect);
            if (success != true)
            {
                Log("ConnectFailReason: " + Convert.ToString(rest.ConnectFailReason));
                Log(rest.LastErrorText);
                return;
            }
            //rest.SetAuthBasic(stripe_testnet, "");
            rest.AddQueryParam("type", "individual");
            rest.AddQueryParam("name", "John Doe");
            rest.AddQueryParam("billing[address][line1]", "1008 Their Address St.");
            rest.AddQueryParam("billing[address][city]", "City");
            rest.AddQueryParam("billing[address][state]", "St");
            rest.AddQueryParam("billing[address][country]", "US");
            rest.AddQueryParam("billing[address][postal_code]", "Zip");
            string strResponseBody = rest.FullRequestFormUrlEncoded("POST", "/v1/issuing/cardholders");

            if (rest.LastMethodSuccess != true)
            {
                Log(rest.LastErrorText);
                return;
            }

            Chilkat.JsonObject jsonResponse = new Chilkat.JsonObject();
            jsonResponse.Load(strResponseBody);
        }
Beispiel #4
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("?");
        }
Beispiel #5
0
        public static void Main(string[] args)
        {
            Chilkat.Rest rest = new Chilkat.Rest();
            Console.WriteLine(rest.Version);

            BuildWebHost(args).Run();
        }
Beispiel #6
0
        static void Main(string[] args)
        {
            Chilkat.Rest rest    = new Chilkat.Rest();
            Chilkat.Xmp  xmp     = new Chilkat.Xmp();
            bool         success = xmp.UnlockComponent("Anything for 30-day trial.");

            if (success != true)
            {
                Console.WriteLine(xmp.LastErrorText);
                return;
            }

            success = xmp.LoadAppFile(@"C:\eInvoicePdf\Invoice.pdf");

            Console.WriteLine("Num embedded XMP docs: " + Convert.ToString(xmp.NumEmbedded));

            //  Assuming there is at least one, get the 1st.
            //  (There is typically never more than one, but theoretically it's possible.)
            Chilkat.Xml xml = null;
            xml = xmp.GetEmbedded(0);
            if (!(xml == null))
            {
                string propVal = xmp.GetSimpleStr(xml, "Iptc4xmpCore:Location");
                if (xmp.LastMethodSuccess != true)
                {
                    Console.WriteLine("Not found.");
                }
                else
                {
                    Console.WriteLine(propVal);
                }
            }
            else
            {
                Console.WriteLine(xmp.LastErrorText);
            }


            /*
             * PdfReader reader = new PdfReader(@"C:\eInvoicePdf\Invoice.pdf");
             * byte[] metadata = reader.Metadata;
             * XmpCore.XmpMetaFactory.
             * XmpCore.IXmpMeta meta = XmpCore.XmpMetaFactory.ParseFromBuffer(reader.Metadata);
             * string content = meta.GetPropertyString("http://www.CraneSoftwrights.com/ns/XMP/", "c:file");
             * System.Xml.Serialization.XmlSerializer ser = new System.Xml.Serialization.XmlSerializer(typeof(InvoiceType));
             * System.IO.StringReader rdr = new System.IO.StringReader(content);
             * InvoiceType invoice = (InvoiceType)ser.Deserialize(rdr);
             */
        }
Beispiel #7
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("");
        }
Beispiel #8
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);
        }
Beispiel #9
0
        public static Chilkat.Rest ConnectToZinc()
        {
            Chilkat.Rest rest = new Chilkat.Rest();
            bool         success;
            bool         bTls           = true;
            int          port           = 443;
            bool         bAutoReconnect = true;
            string       sURL           = "api.zinc.io";

            success = rest.Connect(sURL, port, bTls, bAutoReconnect);
            if (success != true)
            {
                Log("ConnectFailReason: " + Convert.ToString(rest.ConnectFailReason));
                Log(rest.LastErrorText);
                return(null);
            }

            string sKey = GetBMSConfigurationKeyValue("zincprod");

            rest.SetAuthBasic(sKey, "");
            return(rest);
        }
Beispiel #10
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 = "";
        }
Beispiel #11
0
        private void googleDriveListFiles()
        {
            bool success = true;

            Chilkat.AuthGoogle gAuth = new Chilkat.AuthGoogle();
            //  This is our previously obtained access token...
            gAuth.AccessToken = getSavedAccessToken();
            if (gAuth.AccessToken.Length == 0)
            {
                popupError("No previously obtained access token is available.");
                return;
            }

            Chilkat.Rest rest = new Chilkat.Rest();

            //  Connect using TLS.
            bool bAutoReconnect = true;

            success = rest.Connect("www.googleapis.com", 443, true, bAutoReconnect);

            //  Provide the authentication credentials (i.e. the access key)
            rest.SetAuthGoogle(gAuth);

            //  Add a search query parameter to only return files having names matching our criteria
            //  See https://developers.google.com/drive/v3/web/search-parameters
            // ignore = rest.AddQueryParam("q","name contains 'starfish'");
            // ignore = rest.AddQueryParam("maxResults","2");

            //  We are using the Google Drive V3 API... (not V2)
            string jsonResponse = rest.FullRequestNoBody("GET", "/drive/v3/files");

            if (rest.LastMethodSuccess != true)
            {
                fgAppendToErrorLog(rest.LastErrorText);
                popupError("REST request failed.");
                return;
            }

            // A successful JSON response looks like this:
            //{
            //  "kind": "drive#fileList",
            //  "files": [
            //    {
            //      "kind": "drive#file",
            //      "id": "0B53Q6OSTWYolenpjTEU4ekJlQUU",
            //      "name": "test",
            //      "mimeType": "application/vnd.google-apps.folder"
            //    },
            //    {
            //      "kind": "drive#file",
            //      "id": "0B53Q6OSTWYolRm4ycjZtdXhRaEE",
            //      "name": "starfish4.jpg",
            //      "mimeType": "image/jpeg"
            //    },
            //    {
            //      "kind": "drive#file",
            //      "id": "0B53Q6OSTWYolMWt2VzN0Qlo1UjA",
            //      "name": "hamlet2.xml",
            //      "mimeType": "text/xml"
            //    },
            // ...
            //    {
            //      "kind": "drive#file",
            //      "id": "0B53Q6OSTWYolc3RhcnRlcl9maWxlX2Rhc2hlclYw",
            //      "name": "Getting started",
            //      "mimeType": "application/pdf"
            //    }
            //  ]
            //}

            // Iterate over the files and show the name and mimeType of each.
            Chilkat.JsonObject json = new Chilkat.JsonObject();
            json.Load(jsonResponse);
            int numFiles = json.SizeOfArray("files");
            int i        = 0;

            while (i < numFiles)
            {
                json.I = i;
                fgAppendToErrorLog("name: " + json.StringOf("files[i].name") + "\r\n");
                fgAppendToErrorLog("mimeType: " + json.StringOf("files[i].mimeType") + "\r\n");
                i++;
            }
        }
Beispiel #12
0
        // (for Google authorization)
        // Exchange the code for an access token and refresh token.

        // REMEMBER -- this code is running in a background thread because it is called
        // from listenSocket_OnTaskCompleted.
        private bool googleExchangeCodeForToken(string code, string taskUserData)
        {
            // The taskUserData contains JSON information.
            Chilkat.JsonObject taskData = new Chilkat.JsonObject();
            taskData.Load(taskUserData);
            string redirect_uri  = taskData.StringOf("redirect_uri");
            string code_verifier = taskData.StringOf("code_verifier");

            Chilkat.Rest rest = new Chilkat.Rest();

            bool bTls           = true;
            int  port           = 443;
            bool bAutoReconnect = true;
            bool success        = rest.Connect("www.googleapis.com", port, bTls, bAutoReconnect);

            if (success != true)
            {
                fgAppendToErrorLog(rest.LastErrorText);
                return(false);
            }

            success = rest.AddQueryParam("code", code);
            success = rest.AddQueryParam("client_id", googleAppClientId);
            success = rest.AddQueryParam("client_secret", googleAppClientSecret);
            success = rest.AddQueryParam("redirect_uri", redirect_uri);
            success = rest.AddQueryParam("code_verifier", code_verifier);
            success = rest.AddQueryParam("scope", "");
            success = rest.AddQueryParam("grant_type", "authorization_code");

            rest.VerboseLogging = true;
            string responseJson = rest.FullRequestFormUrlEncoded("POST", "/oauth2/v4/token");

            if (rest.LastMethodSuccess != true)
            {
                fgAppendToErrorLog(rest.LastErrorText);
                return(false);
            }

            //  When successful, the response status code will equal 200.
            if (rest.ResponseStatusCode != 200)
            {
                //  Examine the request/response to see what happened.
                StringBuilder sb = new StringBuilder();
                sb.AppendLine("LastErrorText: " + rest.LastErrorText);
                sb.AppendLine("response status code = " + Convert.ToString(rest.ResponseStatusCode));
                sb.AppendLine("response status text = " + rest.ResponseStatusText);
                sb.AppendLine("response header: " + rest.ResponseHeader);
                sb.AppendLine("response body (if any): " + responseJson);
                sb.AppendLine("---");
                sb.AppendLine("LastRequestStartLine: " + rest.LastRequestStartLine);
                sb.AppendLine("LastRequestHeader: " + rest.LastRequestHeader);
                fgAppendToErrorLog(sb.ToString());
                return(false);
            }

            // A successful response JSON will look like this:
            //{
            // "access_token": "ya29.Ci9ZA-Z0Q7vtnch8xxxxxxxxxxxxxxgDVOOV97-IBvTt958xxxxxx1sasw",
            // "token_type": "Bearer",
            // "expires_in": 3600,
            // "refresh_token": "1/fYjEVR-3Oq9xxxxxxxxxxxxxxLzPtlNOeQ"
            //}
            m_googleAccessJson = responseJson;

            fgAppendToErrorLog(responseJson);

            return(true);
        }
Beispiel #13
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);
            }
        }
Beispiel #14
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);
            }
        }