public async Task <IActionResult> PostOrderAsync([FromBody] PostOrderRequest request)
        {
            Logger?.LogDebug("{0} has been invoked", nameof(PostOrderAsync));

            var token = await RothschildHouseIdentityClient.GetRothschildHouseTokenAsync();

            if (token.IsError)
            {
                return(Unauthorized());
            }

            var paymentRequest = request.GetPostPaymentRequest();

            var paymentHttpResponse = await RothschildHousePaymentClient.PostPaymentAsync(token, paymentRequest);

            if (!paymentHttpResponse.IsSuccessStatusCode)
            {
                return(BadRequest());
            }

            var paymentResponse = await paymentHttpResponse.GetPaymentResponseAsync();

            var entity = request.GetOrderHeader();

            entity.CreationUser = UserInfo.UserName;

            // Get response from business logic
            var response = await SalesService.CreateOrderAsync(entity, request.GetOrderDetails().ToArray());

            // Return as http response
            return(response.ToHttpResponse());
        }
        public async Task TestPostOrderAsync()
        {
            // Arrange
            var controller = ControllerMocker.GetSalesController(nameof(TestPostOrderAsync));
            var request    = new PostOrderRequest
            {
                CustomerID      = 1,
                PaymentMethodID = new Guid("7671A4F7-A735-4CB7-AAB4-CF47AE20171D"),
                CurrencyID      = "USD",
                Comments        = "Order from unit tests",
                Details         = new List <OrderDetailRequest>
                {
                    new OrderDetailRequest
                    {
                        ProductID = 1,
                        Quantity  = 1
                    }
                }
            };

            // Act
            var response = await controller.PostOrderAsync(request) as ObjectResult;

            var value = response.Value as ISingleResponse <OrderHeader>;

            // Assert
            Assert.False(value.DidError);
            Assert.True(value.Model.OrderHeaderID.HasValue);
        }
Exemplo n.º 3
0
        public PostOrderResponse PostOrder(PostOrderRequest apor_por)
        {
            PostOrderResponse lpor_response;

            lpor_response        = new PostOrderResponse();
            lpor_response.status = new Status();

            try
            {
                IOrderServiceBusiness liosb_iosb;

                liosb_iosb    = new OrderServiceBusiness();
                lpor_response = liosb_iosb.PostOrder(apor_por);
            }
            catch (Exception ae_e)
            {
                Exception le_e;

                le_e = ae_e.InnerException != null ? ae_e.InnerException : ae_e;
                lpor_response.status.CodeResp    = "01";
                lpor_response.status.MessageResp = ae_e.InnerException != null ? "Error en la ejecucion del servicio" : ae_e.Message;
                lpor_response.result             = null;
                Common.CreateTrace.WriteLog(Common.CreateTrace.LogLevel.Error, "ERROR EN LA CAPA DE SERVICIO OrderService:PostOrder");
                Common.CreateTrace.WriteLog(Common.CreateTrace.LogLevel.Error, " :: " + le_e.Message);
            }

            return(lpor_response);
        }
Exemplo n.º 4
0
        public async Task PostOrderAsync()
        {
            // Arrange
            var userInfo       = IdentityMocker.GetCustomerIdentity().GetUserInfo();
            var service        = ServiceMocker.GetSalesService(userInfo, nameof(PostOrderAsync), true);
            var identityClient = new MockedRothschildHouseIdentityClient();
            var paymentClient  = new MockedRothschildHousePaymentClient();
            var controller     = new SalesController(null, identityClient, paymentClient, service);
            var request        = new PostOrderRequest
            {
                ID              = 2,
                CustomerID      = 1,
                PaymentMethodID = new Guid("7671A4F7-A735-4CB7-AAB4-CF47AE20171D"),
                CurrencyID      = "USD",
                Comments        = "Order from unit tests",
                Details         = new List <OrderDetailRequest>
                {
                    new OrderDetailRequest
                    {
                        ID        = 2,
                        ProductID = 1,
                        Quantity  = 1
                    }
                }
            };

            // Act
            var response = await controller.PostOrderAsync(request) as ObjectResult;

            var value = response.Value as ISingleResponse <OrderHeader>;

            // Assert
            Assert.False(value.DidError);
            Assert.True(value.Model.ID.HasValue);
        }
        public async Task <IActionResult> PostOrder([FromBody] PostOrderRequest postOrderRequest)
        {
            if (postOrderRequest == null)
            {
                throw new RequestNullException();
            }

            IOrderStateMachine orderStateMachine = await _orderStateMachineFactory.CreateOrderStateMachineAsync(postOrderRequest.BuyerName, postOrderRequest.BuyerAddress, postOrderRequest.TotalAmount);

            orderStateMachine.SubmitOrder();

            return(StatusCode((int)HttpStatusCode.Created, orderStateMachine.OrderResponse));
        }
        public void CheckPostOrderResponseCode()
        {
            var expectedStatusCode            = HttpStatusCode.OK;
            PostOrderRequest postOrderRequest = new PostOrderRequest();
            OrderEntity      orderEntity      = new OrderEntity()
            {
                petId    = 15,
                quantity = 25,
                shipDate = DateTime.Now
            };
            var actualStatusCode = postOrderRequest.PostOrderResponseCode(orderEntity);

            Assert.AreEqual(expectedStatusCode, actualStatusCode, "Status code 200 olarak dönmemiştir.Dönen code: {0}", actualStatusCode);
        }
Exemplo n.º 7
0
        public async Task <IHttpActionResult> Post(PostOrderRequest postOrderRequest)
        {
            var claimsIdentity = User.Identity as ClaimsIdentity;

            if (claimsIdentity == null)
            {
                return(InternalServerError());
            }

            var fullName = claimsIdentity.GetFullNameFromClaims();

            await _orderControllerService.Add(User.Identity.GetUserId(), User.Identity.GetUserName(), fullName, postOrderRequest.MenuOrders);

            return(Ok());
        }
Exemplo n.º 8
0
        // POST api/values
        public StatusResponse Post(int id, [FromBody] PostOrderRequest request)
        {
            if (Request.Headers.Contains("SessionKey"))
            {
                var db     = new Database();
                var header = Request.Headers.GetValues("SessionKey").First();
                var user   = db.databaseModel.Users.SingleOrDefault(x => x.SessionKey == header);
                if (user != null && user.SessionKey == header)
                {
                    var cart = db.databaseModel.Carts.SingleOrDefault(x => x.ID == id && user.ID == x.User && x.Ordered == false);
                    cart.Ordered = true;
                    Order order = new Order()
                    {
                        Cart           = cart.ID,
                        Cart1          = cart,
                        FirstName      = request.FirstName,
                        LastName       = request.LastName,
                        Email          = request.Email,
                        Address        = request.Address,
                        State          = request.State,
                        City           = request.City,
                        Zip            = request.Zip,
                        CardName       = request.CardName,
                        CardNumber     = request.CardNumber,
                        ExpirationDate = request.ExpirationDate,
                        CVV            = request.CVV,
                        User           = user.ID,
                        User1          = user,
                        OrderedTime    = DateTime.Now
                    };

                    db.databaseModel.Orders.Add(order);

                    user.LastSeen = DateTime.Now;
                    db.databaseModel.SaveChanges();
                    return(new StatusResponse()
                    {
                        Status = "Success", Message = ""
                    });
                }
            }
            return(new StatusResponse()
            {
                Status = "Failed", Message = "Not authenticated"
            });
        }
Exemplo n.º 9
0
        public ActionResult <Order> Create(PostOrderRequest request)
        {
            var results = new List <String>();
            var tokens  = this._tokenService.GetTokens();

            String userId = tokens.FirstOrDefault(x => x.Value == request.UserToken).Key;

            request.Order.UserId = userId;

            if (userId != null)
            {
                _orderService.Create(request.Order);
                return(CreatedAtRoute("GetOrder", new { id = request.Order.Id.ToString() }, request.Order));
            }
            else
            {
                return(Unauthorized());
            }
        }
Exemplo n.º 10
0
        public string PostOrder(PostOrderRequest data)
        {
            if (IO.Container.Resolve <ICMSApplication>().IsBackendUserAuthenticated)
            {
                var order = OrderHelper.GetOrder(data.id);

                OrderStatus status;
                Enum.TryParse(data.status, out status);

                order.SetStatus(status, data.emails);

                order.Fulfilled = data.fulfilled;
                order.Paid      = data.paid;

                order.Save();

                return(data.status);
            }

            return(null);
        }
Exemplo n.º 11
0
        public async Task <IActionResult> PostOrderAsync([FromBody] PostOrderRequest request)
        {
            Logger?.LogDebug("{0} has been invoked", nameof(PostOrderAsync));

            var paymentRequest = request.GetPostPaymentRequest();

            var paymentResponse = await RothschildHouseClient.PostPaymentAsync(paymentRequest);

            if (paymentResponse.StatusCode == HttpStatusCode.BadRequest)
            {
                return(BadRequest());
            }

            var entity = request.GetOrderHeader();

            entity.CreationUser = UserInfo.UserName;

            // Get response from business logic
            var response = await SalesService.CreateOrderAsync(entity, request.GetOrderDetails().ToArray());

            // Return as http response
            return(response.ToHttpResponse());
        }
 public async Task <IActionResult> PostOrder([FromBody] PostOrderRequest request) =>
 await this.orderActorRef.Ask <OrderActor.IResponse>(
Exemplo n.º 13
0
 public async Task <IActionResult> PostOrder([FromBody] PostOrderRequest request) =>
 await this.printerActorRef.Ask(
Exemplo n.º 14
0
        /// <summary>
        /// Create a new order.
        /// </summary>
        /// <param name="apiKey">Your apiKey.</param>
        /// <param name="apiSecret">Your apiSecretKey.</param>
        /// <param name="sendingAddressPrivateKey">The privateKey of the sending address.</param>
        /// <param name="receivingAddressPrivateKey">The privateKey of the receiving address.</param>
        /// <param name="orderRequest">Request body.</param>
        /// <response code="201">Newly created order.</response>
        /// <response code="400_InvalidUrlParameters">Invalid URL parameters.</response>
        /// <response code="400_MissingBody">Request body is missing.</response>
        /// <response code="400_InvalidBody">Request validation errors. See InnerErrors.</response>
        /// <response code="400_ValidationError">Request validation errors. See InnerErrors.</response>
        /// <response code="403_Forbidden">Not authorized to use this endpoint.</response>
        /// <response code="403_WebhookNotFound">Webhook URL to send exchange request is unavailable.</response>
        /// <response code="500">Server error.</response>
        /// <response code="503">Service unavailable for the specified conversion.</response>
        /// <returns></returns>
        public async Task <Result <CreateOrderResponse, ErrorResponse> > CreateOrderAsync(
            string apiKey,
            string apiSecret,
            string sendingAddressPrivateKey,
            string receivingAddressPrivateKey,
            CreateOrderRequest orderRequest)
        {
            #region
            IEnumerable <ValidationResult> validation = orderRequest.Validate();

            if (validation.Any())
            {
                foreach (var item in validation)
                {
                    throw new ArgumentNullException(item.ErrorMessage);
                }
            }

            if (string.IsNullOrWhiteSpace(sendingAddressPrivateKey))
            {
                throw new ArgumentNullException(nameof(sendingAddressPrivateKey));
            }
            else if (string.IsNullOrWhiteSpace(receivingAddressPrivateKey))
            {
                throw new ArgumentNullException(nameof(receivingAddressPrivateKey));
            }
            #endregion

            string token = getAuthToken(apiKey, apiSecret);

            var    result     = new Result <CreateOrderResponse, ErrorResponse>();
            string requestUri = $"{mEnv.BaseUrl}/v1/Orders";

            string btcpublicKey = null;

            if (orderRequest.Conversion.Value.IsSourceCurrencyBtc())
            {
                btcpublicKey = Key.Parse(sendingAddressPrivateKey, mEnv.Network).PubKey.ToString();
            }

            PostOrderRequest bodyParams = new PostOrderRequest()
            {
                Conversion                = orderRequest.Conversion.ToString(),
                SendingAddress            = orderRequest.SendingAddress,
                SendingAddressSignature   = GluwaService.GetAddressSignature(sendingAddressPrivateKey, orderRequest.Conversion.Value.ToSourceCurrency(), mEnv),
                ReceivingAddress          = orderRequest.ReceivingAddress,
                ReceivingAddressSignature = GluwaService.GetAddressSignature(receivingAddressPrivateKey, orderRequest.Conversion.Value.ToTargetCurrency(), mEnv),
                SourceAmount              = orderRequest.SourceAmount,
                Price        = orderRequest.Price,
                BtcPublicKey = btcpublicKey
            };

            string        json    = bodyParams.ToJson();
            StringContent content = new StringContent(json, Encoding.UTF8, "application/json");

            try
            {
                using (HttpClient httpClient = new HttpClient())
                {
                    httpClient.DefaultRequestHeaders.Add(AUTHORIZATION, $"{BASIC} {token}");

                    using (HttpResponseMessage response = await httpClient.PostAsync(requestUri, content))
                    {
                        if (response.IsSuccessStatusCode)
                        {
                            CreateOrderResponse orderResponse = await response.Content.ReadAsAsync <CreateOrderResponse>();

                            result.IsSuccess = true;
                            result.Data      = orderResponse;

                            return(result);
                        }

                        string contentString = await response.Content.ReadAsStringAsync();

                        result.Error = ResponseHandler.GetError(response.StatusCode, requestUri, contentString);
                    }
                }
            }
            catch (HttpRequestException)
            {
                result.IsSuccess = false;
                result.Error     = ResponseHandler.GetExceptionError();
            }

            return(result);
        }