public InvoiceControllerAPI(InvoiceController invoiceController,
                             InvoiceRepository invoceRepository,
                             TokenRepository tokenRepository,
                             StoreRepository storeRepository)
 {
     this._InvoiceController = invoiceController;
     this._InvoiceRepository = invoceRepository;
     this._TokenRepository   = tokenRepository;
     this._StoreRepository   = storeRepository;
 }
 public AppsPublicController(AppService AppService,
                             BTCPayServerOptions btcPayServerOptions,
                             InvoiceController invoiceController,
                             UserManager <ApplicationUser> userManager)
 {
     _AppService          = AppService;
     _BtcPayServerOptions = btcPayServerOptions;
     _InvoiceController   = invoiceController;
     _UserManager         = userManager;
 }
Ejemplo n.º 3
0
 public AppsController(
     UserManager <ApplicationUser> userManager,
     ApplicationDbContextFactory contextFactory,
     CurrencyNameTable currencies,
     InvoiceController invoiceController)
 {
     _InvoiceController = invoiceController;
     _UserManager       = userManager;
     _ContextFactory    = contextFactory;
     _Currencies        = currencies;
 }
Ejemplo n.º 4
0
 public InvoiceControllerAPI(InvoiceController invoiceController,
                             InvoiceRepository invoceRepository,
                             TokenRepository tokenRepository,
                             StoreRepository storeRepository,
                             BTCPayNetworkProvider networkProvider)
 {
     this._InvoiceController = invoiceController;
     this._InvoiceRepository = invoceRepository;
     this._TokenRepository   = tokenRepository;
     this._StoreRepository   = storeRepository;
     this._NetworkProvider   = networkProvider;
 }
 public PaymentRequestController(
     InvoiceController invoiceController,
     UserManager <ApplicationUser> userManager,
     StoreRepository storeRepository,
     PaymentRequestRepository paymentRequestRepository,
     PaymentRequestService paymentRequestService,
     EventAggregator eventAggregator,
     CurrencyNameTable currencies,
     InvoiceRepository invoiceRepository)
 {
     _InvoiceController        = invoiceController;
     _UserManager              = userManager;
     _StoreRepository          = storeRepository;
     _PaymentRequestRepository = paymentRequestRepository;
     _PaymentRequestService    = paymentRequestService;
     _EventAggregator          = eventAggregator;
     _Currencies        = currencies;
     _InvoiceRepository = invoiceRepository;
 }
Ejemplo n.º 6
0
 public PublicController(InvoiceController invoiceController,
                         StoreRepository storeRepository)
 {
     _InvoiceController = invoiceController;
     _StoreRepository   = storeRepository;
 }
        public async Task <IActionResult> ShopifyInvoiceEndpoint(
            [FromServices] InvoiceRepository invoiceRepository,
            [FromServices] InvoiceController invoiceController,
            [FromServices] IHttpClientFactory httpClientFactory,
            string storeId, string orderId, decimal amount, bool checkOnly = false)
        {
            var invoiceOrderId          = $"{ShopifyOrderMarkerHostedService.SHOPIFY_ORDER_ID_PREFIX}{orderId}";
            var matchedExistingInvoices = await invoiceRepository.GetInvoices(new InvoiceQuery()
            {
                OrderId = new[] { invoiceOrderId }, StoreId = new[] { storeId }
            });

            matchedExistingInvoices = matchedExistingInvoices.Where(entity =>
                                                                    entity.GetInternalTags(ShopifyOrderMarkerHostedService.SHOPIFY_ORDER_ID_PREFIX)
                                                                    .Any(s => s == orderId))
                                      .ToArray();

            var firstInvoiceStillPending =
                matchedExistingInvoices.FirstOrDefault(entity => entity.GetInvoiceState().Status == InvoiceStatus.New);

            if (firstInvoiceStillPending != null)
            {
                return(Ok(new
                {
                    invoiceId = firstInvoiceStillPending.Id,
                    status = firstInvoiceStillPending.Status.ToString().ToLowerInvariant()
                }));
            }

            var firstInvoiceSettled =
                matchedExistingInvoices.LastOrDefault(entity =>
                                                      new[] { InvoiceStatus.Paid, InvoiceStatus.Complete, InvoiceStatus.Confirmed }.Contains(
                                                          entity.GetInvoiceState().Status));

            var store = await _Repo.FindStore(storeId);

            var shopify             = store?.GetStoreBlob()?.Shopify;
            ShopifyApiClient client = null;
            ShopifyOrder     order  = null;

            if (shopify?.IntegratedAt.HasValue is true)
            {
                client = new ShopifyApiClient(httpClientFactory, shopify.CreateShopifyApiCredentials());
                order  = await client.GetOrder(orderId);

                if (string.IsNullOrEmpty(order?.Id))
                {
                    return(NotFound());
                }
            }

            if (firstInvoiceSettled != null)
            {
                //if BTCPay was shut down before the tx managed to get registered on shopify, this will fix it on the next UI load in shopify
                if (client != null && order?.FinancialStatus == "pending" &&
                    firstInvoiceSettled.Status != InvoiceStatus.Paid)
                {
                    await new OrderTransactionRegisterLogic(client).Process(orderId, firstInvoiceSettled.Id,
                                                                            firstInvoiceSettled.Currency,
                                                                            firstInvoiceSettled.Price.ToString(CultureInfo.InvariantCulture), true);
                    order = await client.GetOrder(orderId);
                }

                if (order?.FinancialStatus != "pending" && order?.FinancialStatus != "partially_paid")
                {
                    return(Ok(new
                    {
                        invoiceId = firstInvoiceSettled.Id,
                        status = firstInvoiceSettled.Status.ToString().ToLowerInvariant()
                    }));
                }
            }

            if (checkOnly)
            {
                return(Ok());
            }

            if (shopify?.IntegratedAt.HasValue is true)
            {
                if (string.IsNullOrEmpty(order?.Id) ||
                    !new[] { "pending", "partially_paid" }.Contains(order.FinancialStatus))
                {
                    return(NotFound());
                }

                //we create the invoice at due amount provided from order page or full amount if due amount is bigger than order amount
                var invoice = await invoiceController.CreateInvoiceCoreRaw(
                    new CreateInvoiceRequest()
                {
                    Amount   = amount < order.TotalPrice ? amount : order.TotalPrice,
                    Currency = order.Currency,
                    Metadata = new JObject {
                        ["orderId"] = invoiceOrderId
                    }
                }, store,
                    Request.GetAbsoluteUri(""), new List <string>() { invoiceOrderId });

                return(Ok(new { invoiceId = invoice.Id, status = invoice.Status.ToString().ToLowerInvariant() }));
            }

            return(NotFound());
        }
Ejemplo n.º 8
0
 public InvoiceControllerAPI(InvoiceController invoiceController,
                             InvoiceRepository invoiceRepository)
 {
     _InvoiceController = invoiceController;
     _InvoiceRepository = invoiceRepository;
 }
Ejemplo n.º 9
0
 public AppsPublicController(AppsHelper appsHelper, InvoiceController invoiceController)
 {
     _AppsHelper        = appsHelper;
     _InvoiceController = invoiceController;
 }