コード例 #1
0
        /// <summary>
        /// Create billogram
        /// </summary>
        /// <param name="billogramHelper"></param>
        /// <returns>BillogramStructure instance</returns>
        public async Task <BillogramStructure> CreateBillogram(BillogramHelper billogramHelper)
        {
            Exception catchedException = null;
            var       data             = new
            {
                customer = new
                {
                    customer_no = billogramHelper.CustomerStructure.CustomerNo
                },
                items = new[]
                {
                    new {
                        count    = billogramHelper.Subscriptions.Count,
                        discount = billogramHelper.Subscriptions.Discount,
                        item_no  = billogramHelper.Subscriptions.ItemNo
                    }
                }
            };

            try
            {
                HttpResponseMessage response = await _client.PostAsJsonAsync(_baseUrl + "billogram/", data);

                if (!response.IsSuccessStatusCode)
                {
                    return(null);
                }
                response.EnsureSuccessStatusCode();
                var responseBody = await response.Content.ReadAsStringAsync();

                JObject jObject       = JObject.Parse(responseBody);
                JToken  billogramData = jObject["data"];
                _billogram = billogramData.ToObject <BillogramStructure>();
            }
            catch (Exception e)
            {
                catchedException = e;
            }

            if (catchedException == null)
            {
                return(_billogram);
            }
            throw catchedException;
        }
コード例 #2
0
        public void CreateBillogram_Test()
        {
            BillogramHelper billogramHelper = new BillogramHelper()
            {
                CustomerStructure = new CustomerStructure()
                {
                    CustomerNo = CustomerNo
                },
                Subscriptions = new BillogramItems()
                {
                    ItemNo   = SubscriptionId.ToString(),
                    Discount = 0,
                    Count    = 2
                }
            };

            var result = _billogramUtility.CreateBillogram(billogramHelper).Result;

            Console.WriteLine(result.ID);
            Assert.IsNotNull(result.ID);
        }