Beispiel #1
0
        public ViewPullPaymentModel(PullPaymentData data, DateTimeOffset now)
        {
            Id      = data.Id;
            StoreId = data.StoreId;
            var blob = data.GetBlob();

            PaymentMethods        = blob.SupportedPaymentMethods;
            SelectedPaymentMethod = PaymentMethods.First().ToString();
            Archived      = data.Archived;
            AutoApprove   = blob.AutoApproveClaims;
            Title         = blob.View.Title;
            Description   = blob.View.Description;
            Amount        = blob.Limit;
            Currency      = blob.Currency;
            Description   = blob.View.Description;
            ExpiryDate    = data.EndDate is DateTimeOffset dt ? (DateTime?)dt.UtcDateTime : null;
            Email         = blob.View.Email;
            MinimumClaim  = blob.MinimumClaim;
            EmbeddedCSS   = blob.View.EmbeddedCSS;
            CustomCSSLink = blob.View.CustomCSSLink;
            if (!string.IsNullOrEmpty(EmbeddedCSS))
            {
                EmbeddedCSS = $"<style>{EmbeddedCSS}</style>";
            }
            IsPending = !data.IsExpired();
            var period = data.GetPeriod(now);

            if (data.Archived)
            {
                Status = "Archived";
            }
            else if (data.IsExpired())
            {
                Status = "Expired";
            }
            else if (period is null)
            {
                Status = "Not yet started";
            }
            else
            {
                Status = string.Empty;
            }

            ResetIn = string.Empty;
            if (period?.End is DateTimeOffset pe)
            {
                var resetIn = (pe - DateTimeOffset.UtcNow);
                if (resetIn < TimeSpan.Zero)
                {
                    resetIn = TimeSpan.Zero;
                }
                ResetIn = resetIn.TimeString();
            }
        }
        public async Task Refresh()
        {
            var selectedPaymentMethodId = PaymentMethods.FirstOrDefault(p => p.Selected)?.PaymentMethod.Id;

            PaymentMethods.Clear();
            try {
                var stripeClient = await EphemeralService.Instance.GetClient();

                var customerId = await EphemeralService.Instance.GetCustomerId();

                var customerService = new CustomerService(stripeClient);
                _customer = await customerService.GetAsync(customerId);


                var paymentMethodService     = new PaymentMethodService(stripeClient);
                var paymentMethodListOptions = new PaymentMethodListOptions {
                    Customer = _customer.Id,
                    Type     = "card"
                };
                var methods = await paymentMethodService.ListAsync(paymentMethodListOptions);

                foreach (var paymentMethod in methods)
                {
                    PaymentMethods.Add(new PaymentMethodViewModel(paymentMethod, PaymentMethodSelected));
                }

                if (PaymentMethods.Any())
                {
                    var toSelect = PaymentMethods.FirstOrDefault(pm => pm.PaymentMethod.Id == selectedPaymentMethodId) ??
                                   PaymentMethods.First();
                    SelectPaymentMethod(toSelect);
                }
            }
            catch (Exception ex) {
                await Navigator.ShowMessage("Error", ex.Message);
            }
        }