Beispiel #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 static bool SetBlob(this PaymentRequestData paymentRequestData, PaymentRequestBaseData blob)
        {
            var original = new Serializer(null).ToString(paymentRequestData.GetBlob());
            var newBlob  = new Serializer(null).ToString(blob);

            if (original == newBlob)
            {
                return(false);
            }
            paymentRequestData.Blob = ZipUtils.Zip(newBlob);
            return(true);
        }
        private static Client.Models.PaymentRequestData FromModel(PaymentRequestData data)
        {
            var blob = data.GetBlob();

            return(new Client.Models.PaymentRequestData()
            {
                Created = data.Created,
                Id = data.Id,
                Status = data.Status,
                Archived = data.Archived,
                Amount = blob.Amount,
                Currency = blob.Currency,
                Description = blob.Description,
                Title = blob.Title,
                ExpiryDate = blob.ExpiryDate,
                Email = blob.Email,
                AllowCustomPaymentAmounts = blob.AllowCustomPaymentAmounts,
                EmbeddedCSS = blob.EmbeddedCSS,
                CustomCSSLink = blob.CustomCSSLink
            });
        }
        public UpdatePaymentRequestViewModel(PaymentRequestData data)
        {
            if (data == null)
            {
                return;
            }

            Id       = data.Id;
            StoreId  = data.StoreDataId;
            Archived = data.Archived;
            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;
        }
Beispiel #5
0
        public ViewPaymentRequestViewModel(PaymentRequestData data)
        {
            Id      = data.Id;
            StoreId = data.StoreDataId;
            var blob = data.GetBlob();

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

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

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

            default:
                throw new ArgumentOutOfRangeException();
            }
        }