コード例 #1
0
        /// <summary>
        /// Creates the service topup.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns></returns>
        public async Task <APIResponse> CreateServiceTopup(CreateServiceTopupRequest request)
        {
            try
            {
                var vendorclient = httpClientFactory.CreateClient(VendorServiceOperation.serviceName);

                var         param       = JsonConvert.SerializeObject(request);
                HttpContent contentPost = new StringContent(param, Encoding.UTF8, "application/json");

                var response = await vendorclient.PostAsync(servicesConfig.Vendor + VendorServiceOperation.CreateServiceTopup(), contentPost);

                if (response.IsSuccessStatusCode)
                {
                    var branch = JsonConvert.DeserializeObject <List <ServiceTopupResponse> >(await response.Content.ReadAsStringAsync());
                    return(new APIResponse(branch, HttpStatusCode.Created));
                }

                return(new APIResponse(response.StatusCode));
            }
            catch (Exception ex)
            {
                logger.Error(ex, "Exception in method 'CreateServiceTopup()'");
                var exMessage = ex.InnerException != null ? ex.InnerException.Message : ex.Message;
                return(new APIResponse(exMessage, HttpStatusCode.InternalServerError));
            }
        }