Exemple #1
0
        private async Task <OrderRegistrationResponse> RegisterOrderInPaymentSystem(Order order)
        {
            var httpRequest = httpContext.HttpContext.Request;
            var returnUrl   = httpRequest.Scheme + "://" + httpRequest.Host.Value + "/Home/Status";
            var server      = _configuration["Urls:Server"];
            var userName    = _configuration["Position:Name"];

            var client = new HttpClient();

            var request = new OrderRegistrationRequest
            {
                UserName    = userName,
                Password    = Convert.ToString(PasswordASCIIDecoder.ASCIIDecoder(userName)),
                OrderNumber = Convert.ToString(Guid.NewGuid()),
                ReturnUrl   = returnUrl,
                Amount      = order.Amount,
                Description = order.Description
            };


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

            var url = server + "/payment/rest/register.do";

            var response = await client.PostAsync(url, data);

            var result = await response.Content.ReadAsStringAsync();

            return(SimpleJson.DeserializeObject <OrderRegistrationResponse>(result));
        }
Exemple #2
0
        //------------------------------------------------------------------------------RequestOrderStatus----------------------------------------------------------------------


        public async Task <OrderStatusResponse> RequestOrderStatus(string orderId)
        {
            var client = new HttpClient();

            var server   = _configuration["Urls:Server"];
            var userName = _configuration["Position:Name"];


            var getIDForOrderRequest = GetDonationer(orderId);

            var request = new OrderRequest
            {
                UserName = _configuration["Position:Name"],
                Password = Convert.ToString(PasswordASCIIDecoder.ASCIIDecoder(userName)),
                orderId  = getIDForOrderRequest.PaymentSystemOrderId
            };

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

            var url = server + "/payment/rest/getOrderStatus.do";

            var response = await client.PostAsync(url, data);

            var result = await response.Content.ReadAsStringAsync();

            var status = SimpleJson.DeserializeObject <OrderStatusResponse>(result);

            var getIDForStatusPosition = Database.Orders.Get(request.orderId);

            if (status.orderStatus == 2)
            {
                getIDForStatusPosition.Paid = true;

                Database.Orders.Update(getIDForStatusPosition);
                await Database.SaveAsync();
            }

            return(status);
        }