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); } }
public async Task <PaymentMethod> RemovePaymentMethod(string customerId, string paymentMethodId) { var service = new PaymentMethodService(); var paymentMethod = await service.GetAsync(paymentMethodId); if (paymentMethod.CustomerId != customerId) { return(null); } var response = await service.DetachAsync(paymentMethodId, new PaymentMethodDetachOptions { }); return(response); }
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); }
public async Task DeleteStripeCustomerPaymentMethod(int userId, string paymentMethodId) { var user = await _userService.GetUserDevicesAsync(userId); if (!string.IsNullOrEmpty(user.StripeCustomerId)) { var service = new PaymentMethodService(); var paymentMethod = await service.GetAsync(paymentMethodId); if (paymentMethod != null) { if (paymentMethod.CustomerId != user.StripeCustomerId) { throw new ForbiddenException("You dont have permission to remove this payment method"); } else { await service.DetachAsync(paymentMethodId); } } } }
public async Task <PaymentMethod> DetachPaymentMethodAsync(string paymentMethodId) { var service = new PaymentMethodService(); return(await service.DetachAsync(paymentMethodId)); }