Ejemplo n.º 1
0
        public async Task UpdatePaymentRequestStateIfNeeded(PaymentRequestData pr)
        {
            var blob          = pr.GetBlob();
            var currentStatus = pr.Status;

            if (blob.ExpiryDate.HasValue)
            {
                if (blob.ExpiryDate.Value <= DateTimeOffset.UtcNow)
                {
                    currentStatus = Client.Models.PaymentRequestData.PaymentRequestStatus.Expired;
                }
            }

            if (currentStatus == Client.Models.PaymentRequestData.PaymentRequestStatus.Pending)
            {
                var rateRules = pr.StoreData.GetStoreBlob().GetRateRules(_BtcPayNetworkProvider);
                var invoices  = await _PaymentRequestRepository.GetInvoicesForPaymentRequest(pr.Id);

                var contributions = _AppService.GetContributionsByPaymentMethodId(blob.Currency, invoices, true);
                if (contributions.TotalCurrency >= blob.Amount)
                {
                    currentStatus = Client.Models.PaymentRequestData.PaymentRequestStatus.Completed;
                }
            }

            if (currentStatus != pr.Status)
            {
                pr.Status = currentStatus;
                await _PaymentRequestRepository.UpdatePaymentRequestStatus(pr.Id, currentStatus);
            }
        }
        public async Task UpdatePaymentRequestStateIfNeeded(PaymentRequestData pr)
        {
            var blob          = pr.GetBlob();
            var currentStatus = pr.Status;

            if (blob.ExpiryDate.HasValue)
            {
                if (blob.ExpiryDate.Value <= DateTimeOffset.UtcNow)
                {
                    currentStatus = PaymentRequestData.PaymentRequestStatus.Expired;
                }
            }
            else if (pr.Status == PaymentRequestData.PaymentRequestStatus.Pending)
            {
                var rateRules = pr.StoreData.GetStoreBlob().GetRateRules(_BtcPayNetworkProvider);
                var invoices  = await _PaymentRequestRepository.GetInvoicesForPaymentRequest(pr.Id);

                var paymentStats    = _AppService.GetCurrentContributionAmountStats(invoices, true);
                var amountCollected =
                    await _AppService.GetCurrentContributionAmount(paymentStats, blob.Currency, rateRules);

                if (amountCollected >= blob.Amount)
                {
                    currentStatus = PaymentRequestData.PaymentRequestStatus.Completed;
                }
            }

            if (currentStatus != pr.Status)
            {
                pr.Status = currentStatus;
                await _PaymentRequestRepository.UpdatePaymentRequestStatus(pr.Id, currentStatus);
            }
        }