Exemple #1
0
        static async Task <return_object> add_customer_info(string cart_id, booking this_booking)
        {
            string        ret          = "";
            return_object returnObject = new return_object();

            string flight_num = get_flight(this_booking.res_comments);//extract flight number
            // flight_num = "AA875";
            dynamic    jsonObj   = "";
            string     json_body = @"{""email"":""*****@*****.**"",""firstName"":""" + this_booking.firstname + @""",""lastName"":""" + this_booking.lastname + @""",""title"":""title"",""phone"":""8777688370"",""organization"":""book it"",""postalCode"":""00000"",""state"":""FL"",""country"":""USA"",""Arrival Flight Number"":""" + flight_num + @""",""Departure Airline and Flight Number"":""0000""}";
            string     _url      = "https://app.resmarksystems.com/public/api/cart/" + cart_id + "/customer";
            HttpClient _client   = new HttpClient();

            _client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", token);
            _client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
            var response = await _client.PutAsync(_url, new StringContent(json_body, Encoding.UTF8, "application/json"));

            try
            {
                // response.EnsureSuccessStatusCode();

                ret = await response.Content.ReadAsStringAsync();

                JavaScriptSerializer serializer = new JavaScriptSerializer();
                jsonObj = serializer.Deserialize <dynamic>(ret);
                JObject jObject = JObject.Parse(ret);
                // jObject.

                returnObject.return_message = (string)jObject["errorMessage"];
                returnObject.return_obj     = (JObject)jObject["data"];

                //ret = (string)data["id"];
                // var t = cart_id["id"];
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception: " + ex.Message);
            }

            return(returnObject);
        }
Exemple #2
0
        static async Task <return_object> create_order(string cart_id, booking this_booking)
        {
            string        ret          = "";
            return_object returnObject = new return_object();

            dynamic    jsonObj   = "";
            string     json_body = @"{""id"":""" + cart_id + @""",""billing"":{},""orderId"":null,""referenceId"":""test comment""}";
            string     _url      = "https://app.resmarksystems.com/public/api/order";
            HttpClient _client   = new HttpClient();

            _client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", token);
            _client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
            var response = await _client.PostAsync(_url, new StringContent(json_body, Encoding.UTF8, "application/json"));

            try
            {
                // response.EnsureSuccessStatusCode();

                ret = await response.Content.ReadAsStringAsync();

                JavaScriptSerializer serializer = new JavaScriptSerializer();
                jsonObj = serializer.Deserialize <dynamic>(ret);
                JObject jObject = JObject.Parse(ret);
                // jObject.

                returnObject.return_message = (string)jObject["errorMessage"];
                returnObject.return_obj     = (JObject)jObject["data"];

                //ret = (string)data["id"];
                // var t = cart_id["id"];
            }
            catch (Exception ex)
            {
                Console.WriteLine("Create Order Exception: " + ex.Message);
            }

            return(returnObject);
        }
Exemple #3
0
        static async Task begin_integrate(bool ignore_fail)
        {
            //build product matching table
            product   prod           = new product();
            Hashtable product_lookup = prod.product_lookup();

            //build pickup matching table
            pickup_lookup = prod.pickup_lookup();

            //load products to be imported
            booking        bookclass = new booking();
            List <booking> bookings = bookclass.get_bookings(ignore_fail); int x = 1;

            foreach (booking mbook in bookings)
            {
                Console.Write(x + ". Migrating Resmark#: " + mbook.res_num + " -> "); x++;
                if (mbook.available_item().Length > 0)
                {
                    //item available
                    //assign activity ID
                    string activity_id = mbook.available_item();

                    //get pickup ID
                    pickup this_pickup = await get_pickup_details(mbook);

                    //does pick up location match??
                    if (this_pickup != null)
                    {
                        //pickup location found
                        //create cart item
                        string cart_id = await create_cart();

                        if (cart_id.Length > 0)
                        {
                            //add item to cart
                            return_object cart_return = await add_item_to_cart(activity_id, cart_id, mbook, this_pickup);

                            mbook.update_status(cart_return.return_message, false); //update booking record with response after add item to cart
                            if (cart_return.return_obj != null)                     //no errors. next step
                            {
                                //Lets add customer details
                                JObject       jObject            = (JObject)cart_return.return_obj;
                                return_object cart_update_return = await add_customer_info(cart_id, mbook);

                                mbook.update_status(cart_return.return_message, false);                     //update booking record with response after add customer

                                if (cart_update_return.return_obj != null)                                  //no errors from add customer. next step
                                {
                                    return_object create_order_return = await create_order(cart_id, mbook); // create order

                                    if (create_order_return.return_obj != null)                             //no errors from add customer. next step
                                    {
                                        JObject jobject = (JObject)create_order_return.return_obj;
                                        Console.WriteLine("Migration completed > Confirmation: " + (string)(jobject["confirmation"]));
                                        mbook.update_status(create_order_return.return_message, true, (string)jobject["id"], Convert.ToInt32(jobject["confirmation"])); //update booking record with response after successful create order
                                    }
                                    else
                                    {
                                        Console.WriteLine("Error : " + create_order_return.return_message);
                                        mbook.update_status(create_order_return.return_message, false); //update booking record with response after failed create order
                                    }
                                }
                                else
                                {
                                    //error adding customer to cart
                                    Console.WriteLine("Error adding customer info to cart");
                                    mbook.update_status("Error adding customer info to cart", false);
                                }
                            }
                            else
                            {
                                // error adding item to cart
                                Console.WriteLine("Error adding item to cart ");
                                //  mbook.update_status("Error adding item to cart", false);
                            }
                        }
                        else
                        {
                            //no cart id returned
                            Console.WriteLine("No cart id returned");
                            mbook.update_status("No cart id", false);
                        }
                    } //no pickup options found.. what to do next?
                }     //no date available, update booking record
                else
                {
                    Console.WriteLine("No available dates found");
                    mbook.update_status("No available dates", false);
                }
            }
        }
Exemple #4
0
        static async Task <return_object> add_item_to_cart(string activity_id, string cart_id, booking this_booking, pickup pickup_d)
        {
            string        ret          = "";
            return_object returnObject = new return_object();

            //string flight_num = get_flight(this_booking.res_comments);

            dynamic jsonObj = "";

            List <string> price_tiers = new List <string>();

            try
            {
                price_tiers = new product().get_tiers(activity_id);
            }
            catch (Exception e)
            {
            }

            string json_body = "";



            try
            {
                if (price_tiers.Count > 1)
                {
                    //probably aduly/child
                    json_body = @"{""itemId"":""" + activity_id + @""",""participants"":{""All"":""" + 1 + @""",""" + price_tiers[0] + @""":""" + this_booking.res_a + @""",""" + price_tiers[1] + @""":""" + this_booking.res_y + @"""},""locationId"":""" + pickup_d.location_id + @""",""pickupDetailId"":""" + pickup_d.pickup_detail_id + @"""}";
                }
                else
                {
                    if (price_tiers[0] == "Adult") //use Adult
                    {
                        json_body = @"{""itemId"":""" + activity_id + @""",""participants"":{""All"":""" + 1 + @""",""" + price_tiers[0] + @""":""" + this_booking.res_a + @"""},""locationId"":""" + pickup_d.location_id + @""",""pickupDetailId"":""" + pickup_d.pickup_detail_id + @"""}";
                    }
                    else
                    {
                        //single tier,, use Unit
                        json_body = @"{""itemId"":""" + activity_id + @""",""participants"":{""All"":""" + 1 + @""",""" + price_tiers[0] + @""":""" + this_booking.res_u + @"""},""locationId"":""" + pickup_d.location_id + @""",""pickupDetailId"":""" + pickup_d.pickup_detail_id + @"""}";
                    }
                }


                string     _url    = "https://app.resmarksystems.com/public/api/cart/" + cart_id + "/item";
                HttpClient _client = new HttpClient();
                _client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", token);
                _client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
                var response = await _client.PostAsync(_url, new StringContent(json_body, Encoding.UTF8, "application/json"));

                // response.EnsureSuccessStatusCode();

                ret = await response.Content.ReadAsStringAsync();

                JavaScriptSerializer serializer = new JavaScriptSerializer();
                jsonObj = serializer.Deserialize <dynamic>(ret);
                JObject jObject = JObject.Parse(ret);
                // jObject.

                returnObject.return_message = (string)jObject["errorMessage"];
                returnObject.return_obj     = (JObject)jObject["data"];
            }
            catch (Exception ex)
            {
                // Console.WriteLine("Add to Cart Exception: " + ex.Message);
            }

            return(returnObject);
        }