Ejemplo n.º 1
0
        public async Task <Tuple <IInvoice, IOrder> > GetOrderDetails(string invoiceId)
        {
            IInvoice invoice = await _invoiceRepository.GetAsync(invoiceId);

            if (invoice.DueDate.GetRepoDateTime() < DateTime.Now)
            {
                throw new InvalidOperationException("Invoice expired.");
            }

            if (invoice.Status == InvoiceStatus.Draft.ToString() || invoice.Status == InvoiceStatus.Removed.ToString())
            {
                throw new InvalidOperationException("Invoice status is invalid.");
            }

            Core.Clients.OrderResponse response =
                await _lykkePayServiceClient.ReCreateOrder(invoice.WalletAddress, invoice.MerchantId);

            await _log.WriteInfoAsync(nameof(InvoiceService), nameof(GetOrderDetails),
                                      invoiceId, "Order re-created");

            return(new Tuple <IInvoice, IOrder>(invoice, new Order
            {
                OrderId = response.OrderId,
                Currency = response.Currency,
                Amount = response.Amount,
                ExchangeRate = response.ExchangeRate,
                TotalAmount = response.TotalAmount,
                // Seconds from 01.01.1970
                TransactionWaitingTime = response.TransactionWaitingTime
            }));
        }
Ejemplo n.º 2
0
        private async Task <string> CreateOrder(IInvoice invoice)
        {
            try
            {
                var orderRequest = new OrderRequest
                {
                    Currency         = invoice.Currency,
                    Amount           = invoice.Amount.ToString(CultureInfo.InvariantCulture),
                    ExchangeCurrency = "BTC",
                    OrderId          = invoice.InvoiceNumber,
                    Markup           = new Markup //TODO Needs to set Merchant Markup here
                    {
                        Percent = 0,
                        Pips    = 0
                    },
                    SuccessUrl  = _callbackUrlFormatter.GetSuccessUrl(invoice.InvoiceId),
                    ErrorUrl    = _callbackUrlFormatter.GetErrorUrl(invoice.InvoiceId),
                    ProgressUrl = _callbackUrlFormatter.GetProgressUrl(invoice.InvoiceId)
                };

                Core.Clients.OrderResponse response =
                    await _lykkePayServiceClient.CreateOrder(orderRequest, invoice.MerchantId);

                await _log.WriteInfoAsync(nameof(InvoiceService), nameof(CreateOrder),
                                          invoice.InvoiceId, "Order created.");

                return(response.Address);
            }
            catch (Exception exception)
            {
                await _log.WriteErrorAsync(nameof(InvoiceService), nameof(CreateOrder),
                                           invoice.InvoiceId, exception);

                throw;
            }
        }