Ejemplo n.º 1
0
        public async Task RemoveAllCreditCards(string customerId)
        {
            var paymentMethodService = new PaymentMethodService();

            var cards = await paymentMethodService.ListAsync(new PaymentMethodListOptions { Customer = customerId, Type = "card" });

            foreach (var card in cards)
            {
                await paymentMethodService.DetachAsync(card.Id);
            }
        }
        private Task <StripeList <PaymentMethod> > GetStripePaymentMethodsAsync(string customerId)
        {
            var options = new PaymentMethodListOptions
            {
                Customer = customerId,
                Type     = "card",
            };

            var service = new PaymentMethodService();

            return(service.ListAsync(options));
        }
        private static async Task <PaymentMethod> GetPaymentMethodForCustomerAsync(
            PaymentMethodService paymentMethodService,
            string stripeCustomerId,
            string paymentMethodId)
        {
            var list = await paymentMethodService.ListAsync(new PaymentMethodListOptions()
            {
                Customer = stripeCustomerId,
                Type     = "card"
            });

            return(list.Data.SingleOrDefault(x => x.Id == paymentMethodId));
        }
Ejemplo n.º 4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="customerId"></param>
        /// <param name="type">
        /// afterpay_clearpay, alipay, au_becs_debit,
        //     bacs_debit, bancontact, card, card_present, eps, fpx, giropay, grabpay, ideal,
        //     interac_present, oxxo, p24, sepa_debit, or sofort.
        //  </param>
        /// <param name="startingAfter"></param>
        /// <returns></returns>
        public async Task <StripeList <PaymentMethod> > GetPaymentMethods(string customerId, string type, string startingAfter = null)
        {
            var service = new PaymentMethodService();
            var items   = await service.ListAsync(new PaymentMethodListOptions
            {
                Customer      = customerId,
                Type          = type,
                Limit         = 100,
                StartingAfter = startingAfter
            });

            return(items);
        }
Ejemplo n.º 5
0
        public async Task <PaymentMethodDao> GetCustomerPaymentMethod(string paymentCustomerId, CancellationToken cancellationToken)
        {
            Guard.Argument(paymentCustomerId, nameof(paymentCustomerId)).NotNull().NotEmpty().NotWhiteSpace();

            var options = new PaymentMethodListOptions
            {
                Customer = paymentCustomerId,
                Type     = "card"
            };

            var customerCards = await _paymentMethodService.ListAsync(options : options, cancellationToken : cancellationToken);

            return(customerCards.FirstOrDefault().ToPaymentMethodDao());
        }
Ejemplo n.º 6
0
        public async Task <PaymentMethod> GetDefaultCreditCardAsync(string customerId)
        {
            var options = new PaymentMethodListOptions
            {
                Customer = customerId,
                Type     = "card",
            };

            var service = new PaymentMethodService();

            var paymentMethods = await service.ListAsync(options);

            return(paymentMethods.FirstOrDefault());
        }
Ejemplo n.º 7
0
        public async Task AddCreditCardAsync(string customerId, string cardholderName, string number, string cvc, long expMonth, long expYear, string zipCode)
        {
            var paymentMethodCreateOptions = new PaymentMethodCreateOptions
            {
                Type = "card",
                Card = new PaymentMethodCardOptions
                {
                    Number   = number,
                    Cvc      = cvc,
                    ExpMonth = expMonth,
                    ExpYear  = expYear
                },

                BillingDetails = new PaymentMethodBillingDetailsOptions
                {
                    Name    = cardholderName,
                    Address = new AddressOptions
                    {
                        PostalCode = zipCode
                    }
                }
            };

            var paymentMethodService = new PaymentMethodService();

            var paymentMethod = await paymentMethodService.CreateAsync(paymentMethodCreateOptions);

            var cards = await paymentMethodService.ListAsync(new PaymentMethodListOptions { Customer = customerId, Type = "card" });

            foreach (var card in cards)
            {
                await paymentMethodService.DetachAsync(card.Id);
            }

            var paymentMethodAttachOptions = new PaymentMethodAttachOptions
            {
                Customer = customerId
            };

            await paymentMethodService.AttachAsync(paymentMethod.Id, paymentMethodAttachOptions);
        }
Ejemplo n.º 8
0
        public async Task <IEnumerable <StripePaymentMethodResponse> > GetStripeCustomerPaymentMethods(int userId)
        {
            var user = await _userService.GetUserDevicesAsync(userId);

            var result = new List <StripePaymentMethodResponse>();

            if (!string.IsNullOrEmpty(user.StripeCustomerId))
            {
                var options = new PaymentMethodListOptions
                {
                    Customer = user.StripeCustomerId,
                    Type     = "card"
                };

                var service        = new PaymentMethodService();
                var paymentMethods = await service.ListAsync(options);

                foreach (var method in paymentMethods)
                {
                    if (method.Type == "card" && method.Card != null)
                    {
                        var card   = method.Card;
                        var mapped = new StripePaymentMethodResponse
                        {
                            PaymentMethodId = method.Id,
                            Last4           = card.Last4,
                            Country         = card.Country,
                            Description     = card.Description,
                            ExpMonth        = card.ExpMonth,
                            ExpYear         = card.ExpYear,
                            Funding         = card.Funding,
                            Issuer          = card.Issuer
                        };

                        result.Add(mapped);
                    }
                }
            }

            return(result);
        }
        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);
            }
        }
Ejemplo n.º 10
0
 async public Task <StripeList <PaymentMethod> > GetPaymentMethodsAsync([FromBody] PaymentMethodListOptions paymentMethodListOptions)
 {
     return(await _paymentMethodService.ListAsync(paymentMethodListOptions, _requestOptions));
 }