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);
            }
        }
Пример #2
0
        public ViewPaymentRequestViewModel(PaymentRequestData data)
        {
            Id = data.Id;
            var blob = data.GetBlob();

            Title                     = blob.Title;
            Amount                    = blob.Amount;
            Currency                  = blob.Currency;
            Description               = blob.Description;
            ExpiryDate                = blob.ExpiryDate;
            Email                     = blob.Email;
            EmbeddedCSS               = blob.EmbeddedCSS;
            CustomCSSLink             = blob.CustomCSSLink;
            AllowCustomPaymentAmounts = blob.AllowCustomPaymentAmounts;
            switch (data.Status)
            {
            case PaymentRequestData.PaymentRequestStatus.Pending:
                Status    = ExpiryDate.HasValue ? $"Expires on {ExpiryDate.Value:g}" : "Pendiente";
                IsPending = true;
                break;

            case PaymentRequestData.PaymentRequestStatus.Completed:
                Status = "Aceptado";
                break;

            case PaymentRequestData.PaymentRequestStatus.Expired:
                Status = "Expirado";
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
        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);
            }
        }
        public UpdatePaymentRequestViewModel(PaymentRequestData data)
        {
            if (data == null)
            {
                return;
            }

            Id      = data.Id;
            StoreId = data.StoreDataId;

            var blob = data.GetBlob();

            Title                     = blob.Title;
            Amount                    = blob.Amount;
            Currency                  = blob.Currency;
            Description               = blob.Description;
            ExpiryDate                = blob.ExpiryDate;
            Email                     = blob.Email;
            CustomCSSLink             = blob.CustomCSSLink;
            EmbeddedCSS               = blob.EmbeddedCSS;
            AllowCustomPaymentAmounts = blob.AllowCustomPaymentAmounts;
        }
Пример #5
0
        public ViewPaymentRequestViewModel(PaymentRequestData data)
        {
            Id = data.Id;
            var blob = data.GetBlob();

            Archived                  = data.Archived;
            Title                     = blob.Title;
            Amount                    = blob.Amount;
            Currency                  = blob.Currency;
            Description               = blob.Description;
            ExpiryDate                = blob.ExpiryDate;
            Email                     = blob.Email;
            EmbeddedCSS               = blob.EmbeddedCSS;
            CustomCSSLink             = blob.CustomCSSLink;
            AllowCustomPaymentAmounts = blob.AllowCustomPaymentAmounts;
            if (!string.IsNullOrEmpty(EmbeddedCSS))
            {
                EmbeddedCSS = $"<style>{EmbeddedCSS}</style>";
            }
            switch (data.Status)
            {
            case PaymentRequestData.PaymentRequestStatus.Pending:
                Status    = ExpiryDate.HasValue ? $"Expires on {ExpiryDate.Value:g}" : "Pending";
                IsPending = true;
                break;

            case PaymentRequestData.PaymentRequestStatus.Completed:
                Status = "Settled";
                break;

            case PaymentRequestData.PaymentRequestStatus.Expired:
                Status = "Expired";
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }