using System; using Newtonsoft.Json; // ******************************************************************************** // Import 'TSNETApiModels.dll' and 'Newtonsoft.Json.dll'(Version: 11.0.1 or later) into your project first.( .Net Framework 4.6 or later) // Then can use model classes with namespace 'TSNETDataInterface.Models'. // ******************************************************************************** namespace TSNETDataInterface.Models { internal static class DemoClass { internal static string HowToMakeRequest() { // Make a request: Example for creating a sales order // Type 'OrderSubmission' can be changed to 'PostData', 'PostData1', 'Product' etc. according to different businesses. var oRqt = new ApiRequest(0L /* Fill in your Startnet user ID here */, "Fill in your 'AppKey' here") { data = new OrderSubmission() { branch_id = 1, customer_id = 2, warehouse_id = 3, invoice_type = 3003, consignee_name = "Consignee name", consignee_mobile = "Consignee mobile", shipping_address = "Shipping address", /* You can continue to set other fields as needed ... */ carts = new ShopCart[] { new ShopCart() { product_id = 1234, quantity = 10 }, new ShopCart() { product_id = 23456, quantity = 9 }, new ShopCart() { product_id = 56789, quantity = 8 }, /* You can continue to add more items as needed ... */ }, }, }; // **************************************** // Example for getting paged data resources // **************************************** //var oRqt_Exp1 = new ApiRequest(0L /* Fill in your Startnet user ID here */, "Fill in your 'AppKey' here") //{ // data = new PostData1() // { // page_number = 1, // page_size = 15, // include_details = false, // timestamp = DateTime.Now.Ticks, // }, //}; // **************************************** // Example for add a product // **************************************** //var oRqt_Exp2 = new ApiRequest(0L /* Fill in your Startnet user ID here */, "Fill in your 'AppKey' here") //{ // data = new Product() // { // name = "Product name", // code = "Product code", // barcode = "Product barcode", // category_id = 1, // brand_id = 2, // retail_price = 100.000000m, // wholesale_price = 87.654321m, // /* You can continue to set other fields as needed ... */ // }, //}; // Sign the requested data. oRqt.PSign(); // The serialized string is put into the request body and sent to the server. string request_body = JsonConvert.SerializeObject(oRqt, Formatting.None); return request_body; } internal static void HowToHandleResponse(string responseBody) { if (string.IsNullOrWhiteSpace(responseBody)) { return; } ApiResponse oRsp = null; try { // Example for handle the response after created a sales order // Type 'SalesOrder' can be changed to 'Customer', 'Product', 'Inventory[]' etc. according to different businesses. oRsp = JsonConvert.DeserializeObject>(responseBody); // **************************************** // More examples. // **************************************** //var oRsp_Exp1 = JsonConvert.DeserializeObject>(responseBody); //var oRsp_Exp2 = JsonConvert.DeserializeObject>(responseBody); //var oRsp_Exp3 = JsonConvert.DeserializeObject>(responseBody); //var oRsp_Exp4 = JsonConvert.DeserializeObject>>(responseBody); } // Capture conversion error. catch (Exception ex) { // Log ex ? throw ex; } // Conversion succeeded. if (oRsp != null) { oRsp.PInit(0L /* Fill in your Startnet user ID here */, "Fill in your 'AppKey' here"); // Validation succeeded. if (oRsp.PVerifySignatureOnClient()) { // Put your business code here ... } // Validation failed. else { } } // Convert JSON string to object failed. else { } } } }