Esempio n. 1
0
        public async Task <IActionResult> CreateNewOrder([FromBody] OrderRequest request)
        {
            var isValid = await ValidateRequest();

            if ((isValid as OkResult)?.StatusCode != Ok().StatusCode)
            {
                return(isValid);
            }


            var store = request?.GetRequest(MerchantId);

            if (store == null)
            {
                return(BadRequest());
            }



            store.MerchantPayRequestStatus = MerchantPayRequestStatus.New.ToString();
            //store.MerchantPayRequestNotification = MerchantPayRequestNotification.InProgress.ToString();

            var resp = await _gaService.ApiGeneratePostWithHttpMessagesAsync(new GenerateAddressRequest
            {
                MerchantId = MerchantId,
                AssertId   = store.ExchangeAssetId
            });

            var result = await GenerateOrder(store, resp.Body.Address);

            if (result == null)
            {
                return(BadRequest());
            }

            await Log.WriteInfoAsync(nameof(OrderController), nameof(CreateNewOrder), OrderContext(MerchantId, result), "Created new order");

            return(Json(result));
        }
Esempio n. 2
0
        private async Task <OrderRequestResponse> GetOrder(string id)
        {
            var storeResponse = await _storeRequestClient.ApiStoreOrderByMerchantIdGetWithHttpMessagesAsync(MerchantId);

            var content = await storeResponse.Response.Content.ReadAsStringAsync();

            if (string.IsNullOrEmpty(content))
            {
                return(null);
            }

            var result = (from o in JsonConvert.DeserializeObject <List <Lykke.Pay.Service.StoreRequest.Client.Models.OrderRequest> >(content)
                          where
                          (id.Equals(o.RequestId, StringComparison.CurrentCultureIgnoreCase) || id.Equals(o.OrderId, StringComparison.CurrentCultureIgnoreCase) ||
                           !string.IsNullOrEmpty(o.TransactionId) && o.TransactionId.Equals(id, StringComparison.CurrentCultureIgnoreCase) ||
                           !string.IsNullOrEmpty(o.SourceAddress) && o.SourceAddress.Equals(id, StringComparison.CurrentCultureIgnoreCase)) &&
                          !string.IsNullOrEmpty(o.TransactionWaitingTime)
                          orderby o.TransactionWaitingTime.GetRepoDateTime()
                          select o).ToList();

            if (result.Count == 0)
            {
                return(null);
            }
            if (result.Count == 1 && result[0].TransactionWaitingTime.GetRepoDateTime() > DateTime.Now && result[0].MerchantPayRequestStatus != ((int)MerchantPayRequestStatus.New).ToString())
            {
                return(new OrderRequestResponse(result[0]));
            }

            var order = result.FirstOrDefault(
                o => o.MerchantPayRequestStatus != ((int)MerchantPayRequestStatus.New).ToString());

            if (order != null)
            {
                return(new OrderRequestResponse(order));
            }


            order = result.FirstOrDefault(o => o.TransactionWaitingTime.GetRepoDateTime() > DateTime.Now);
            if (order != null)
            {
                return(new OrderRequestResponse(order));
            }

            var oRequest = result.First();



            var request = new OrderRequest(Log)
            {
                Amount           = oRequest.OriginAmount.ToString(),
                Currency         = oRequest.AssetId,
                ExchangeCurrency = oRequest.ExchangeAssetId,
                ErrorUrl         = oRequest.ErrorUrl,
                ProgressUrl      = oRequest.ProgressUrl,
                SuccessUrl       = oRequest.SuccessUrl,
                Markup           = new Markup
                {
                    FixedFee = oRequest.Markup.FixedFee ?? 0,
                    Percent  = oRequest.Markup.Percent ?? 0,
                    Pips     = 0
                },
                OrderId = oRequest.OrderId,
            };

            var store = request.GetRequest(MerchantId);

            if (store == null)
            {
                return(null);
            }

            store.OriginAmount = oRequest.OriginAmount;
            return(await GenerateOrder(store, result.First().SourceAddress));
        }