コード例 #1
0
        public async Task <ActionResult> AddOrEditMarkup(AddOrEditMarkupDialogViewModel vm)
        {
            if (string.IsNullOrEmpty(vm.AssetPairId))
            {
                return(this.JsonFailResult("AssetPairId required", ErrorMessageAnchor));
            }
            if (!vm.IsEditMode)
            {
                var markup = new MarkupResponse();
                try
                {
                    if (!string.IsNullOrEmpty(vm.AssetPairId) && vm.SelectedMerchant == "Default")
                    {
                        markup = await _payInternalClient.GetDefaultMarkupAsync(vm.AssetPairId);
                    }
                    else if (!string.IsNullOrEmpty(vm.AssetPairId))
                    {
                        markup = await _payInternalClient.GetMarkupForMerchantAsync(vm.SelectedMerchant, vm.AssetPairId);
                    }
                }
                catch (DefaultErrorResponseException ex)
                {
                    markup = null;
                }
                if (markup != null)
                {
                    return(this.JsonFailResult("Markup exist: " + markup.AssetPairId, ErrorMessageAnchor));
                }
            }
            var request = new UpdateMarkupRequest();

            request.DeltaSpread      = vm.DeltaSpread;
            request.FixedFee         = vm.FixedFee;
            request.Percent          = vm.Percent;
            request.Pips             = vm.Pips;
            request.PriceAssetPairId = vm.PriceAssetPairId;
            var pricemethod = PriceMethod.None;

            Enum.TryParse <PriceMethod>(vm.SelectedPriceMethod, out pricemethod);
            request.PriceMethod = pricemethod;
            try
            {
                if (string.IsNullOrEmpty(vm.SelectedMerchant) || vm.SelectedMerchant == "Default")
                {
                    await _payInternalClient.SetDefaultMarkupAsync(vm.AssetPairId, request);
                }
                else
                {
                    await _payInternalClient.SetMarkupForMerchantAsync(vm.SelectedMerchant, vm.AssetPairId, request);
                }
                return(this.JsonRequestResult("#markupsList", Url.Action("MarkupsList"), new StaffsPageViewModel()
                {
                    SelectedMerchant = vm.SelectedMerchant
                }));
            }
            catch (DefaultErrorResponseException ex)
            {
                return(this.JsonFailResult("Error: " + ex.Error.ErrorMessage, ErrorMessageAnchor));
            }
        }
コード例 #2
0
        public async Task <ActionResult> AddOrEditMarkupDialog(AddOrEditMarkupDialogViewModel vm)
        {
            var markup = new MarkupResponse();

            if (!string.IsNullOrEmpty(vm.AssetPairId) && vm.SelectedMerchant == "Default")
            {
                markup = await _payInternalClient.GetDefaultMarkupAsync(vm.AssetPairId);
            }
            else if (!string.IsNullOrEmpty(vm.AssetPairId))
            {
                markup = await _payInternalClient.GetMarkupForMerchantAsync(vm.SelectedMerchant, vm.AssetPairId);
            }
            var viewmodel = new AddOrEditMarkupDialogViewModel()
            {
                SelectedMerchant    = vm.SelectedMerchant,
                AssetPairId         = vm.AssetPairId,
                DeltaSpread         = markup.DeltaSpread,
                FixedFee            = markup.FixedFee,
                Percent             = markup.Percent,
                Pips                = markup.Pips,
                PriceAssetPairId    = markup.PriceAssetPairId,
                PriceMethod         = Enum.GetValues(typeof(PriceMethod)).Cast <PriceMethod>().ToList(),
                SelectedPriceMethod = markup.PriceMethod.ToString(),
                IsEditMode          = !string.IsNullOrEmpty(vm.AssetPairId)
            };

            return(View(viewmodel));
        }
コード例 #3
0
        /// <summary>
        /// Get payment details from Invoice, PaymentRequest and Order
        /// </summary>
        /// <param name="invoiceId">Invoice Id</param>
        /// <param name="force">Will force to create new order if the actual order is expired but can be considered
        //     as actual till extended due date</param>
        /// <returns></returns>
        public async Task <PaymentDetails> GetPaymentDetailsAsync(string invoiceId, bool force)
        {
            InvoiceModel invoice = await _payInvoiceClient.GetInvoiceAsync(invoiceId);

            if (invoice.DueDate <= DateTime.UtcNow || invoice.Status == InvoiceStatus.Removed)
            {
                return(null);
            }

            Task <MerchantModel> merchantTask = _payMerchantClient.Api.GetByIdAsync(invoice.MerchantId);

            Task <MarkupResponse> markupForMerchantTask =
                _payInternalClient.ResolveMarkupByMerchantAsync(invoice.MerchantId, $"{invoice.PaymentAssetId}{invoice.SettlementAssetId}");

            // now it is important to wait order checkout before making GetPaymentRequest
            // as WalletAddress will be only after that
            Task <OrderModel> orderTask = _payInternalClient.ChechoutOrderAsync(new ChechoutRequestModel
            {
                MerchantId       = invoice.MerchantId,
                PaymentRequestId = invoice.PaymentRequestId,
                Force            = force
            });

            try
            {
                await Task.WhenAll(merchantTask, markupForMerchantTask, orderTask);
            }
            catch (Exception ex)
            {
                _log.ErrorWithDetails(ex, invoice.Sanitize());
                throw;
            }

            OrderModel     order             = orderTask.Result;
            MerchantModel  merchant          = merchantTask.Result;
            MarkupResponse markupForMerchant = markupForMerchantTask.Result;

            PaymentRequestModel paymentRequest =
                await _payInternalClient.GetPaymentRequestAsync(invoice.MerchantId, invoice.PaymentRequestId);

            Asset settlementAsset = await _lykkeAssetsResolver.TryGetAssetAsync(invoice.SettlementAssetId);

            Asset paymentAsset = await _lykkeAssetsResolver.TryGetAssetAsync(invoice.PaymentAssetId);

            int totalSeconds             = 0;
            int remainingSeconds         = 0;
            int extendedTotalSeconds     = 0;
            int extendedRemainingSeconds = 0;

            if (invoice.Status == InvoiceStatus.Unpaid)
            {
                totalSeconds     = (int)(order.DueDate - order.CreatedDate).TotalSeconds;
                remainingSeconds = (int)(order.DueDate - DateTime.UtcNow).TotalSeconds;

                if (remainingSeconds > totalSeconds)
                {
                    remainingSeconds = totalSeconds;
                }

                extendedTotalSeconds     = (int)(order.ExtendedDueDate - order.DueDate).TotalSeconds;
                extendedRemainingSeconds = (int)(order.ExtendedDueDate - DateTime.UtcNow).TotalSeconds;

                if (extendedRemainingSeconds > extendedTotalSeconds)
                {
                    extendedRemainingSeconds = extendedTotalSeconds;
                }
            }

            return(new PaymentDetails
            {
                Id = invoice.Id,
                Number = invoice.Number,
                Status = invoice.Status,
                Merchant = merchant,
                PaymentAmount = order.PaymentAmount,
                SettlementAmount = invoice.Amount,
                PaymentAssetId = invoice.PaymentAssetId,
                PaymentAsset = paymentAsset,
                SettlementAssetId = invoice.SettlementAssetId,
                SettlementAsset = settlementAsset,
                ExchangeRate = order.ExchangeRate,
                DeltaSpread = markupForMerchant.DeltaSpread > 0,
                Pips = markupForMerchant.Pips + paymentRequest.MarkupPips,
                Percents = markupForMerchant.DeltaSpread + markupForMerchant.Percent + paymentRequest.MarkupPercent,
                Fee = markupForMerchant.FixedFee + paymentRequest.MarkupFixedFee,
                DueDate = invoice.DueDate,
                Note = invoice.Note,
                WalletAddress = paymentRequest.WalletAddress,
                PaymentRequestId = invoice.PaymentRequestId,
                TotalSeconds = totalSeconds,
                RemainingSeconds = remainingSeconds,
                ExtendedTotalSeconds = extendedTotalSeconds,
                ExtendedRemainingSeconds = extendedRemainingSeconds,
                PaidAmount = paymentRequest.PaidAmount,
                PaidDate = paymentRequest.PaidDate
            });
        }