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); }
private async Task <OrchardCore.TenantBilling.Models.PaymentMethod> GetPaymentInformation(Invoice invoice) { //Get Customer var stripeCustomerId = invoice.CustomerId; var customerService = new CustomerService(); var customer = await customerService.GetAsync(stripeCustomerId); //User Customer to extract subscription payment var paymentMethodId = customer.Subscriptions.Data[0].DefaultPaymentMethodId; var paymentService = new PaymentMethodService(); var paymentMethod = await paymentService.GetAsync(paymentMethodId); //Get card info var card = paymentMethod.Card; var cardType = (CardType)Enum.Parse(typeof(CardType), card.Brand.ToLower()); var creditCardInformation = new CreditCardInformation(cardType, Int32.Parse(card.Last4), Convert.ToInt32(card.ExpMonth), Convert.ToInt32(card.ExpYear)); var paymentInformation = new OrchardCore.TenantBilling.Models.PaymentMethod(true, creditCardInformation); return(paymentInformation); }
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 SavePaymentMethodsAsync(string nativePaymentMethodId, TKey userId) { var service = new PaymentMethodService(); var stripePaymentMethod = await service.GetAsync(nativePaymentMethodId); var paymentMethod = await _paymentMethodManager.FindByNativeIdAsync(nativePaymentMethodId); if (paymentMethod == null) { paymentMethod = new TPaymentMethod(); paymentMethod.NativePaymentMethodId = stripePaymentMethod.Id; if (stripePaymentMethod.Card != null) { if (stripePaymentMethod.Card.Wallet != null) { paymentMethod.PaymentGateway = stripePaymentMethod.Card.Wallet.ToString(); } paymentMethod.Name = stripePaymentMethod.Card.Last4; } else { paymentMethod.Name = stripePaymentMethod.Type; } paymentMethod.PaymentMethodType = PaymentMethodType.Card; paymentMethod.OwnerUserId = userId; paymentMethod.IsActive = true; paymentMethod.CreatedDateUtc = DateTime.UtcNow; paymentMethod.LastUpdatedDateUtc = DateTime.UtcNow; await _paymentMethodManager.CreateAsync(paymentMethod); } }
public async Task <PaymentMethod> GetPaymentMethodAsync(string paymentMethodId) { var service = new PaymentMethodService(); return(await service.GetAsync(paymentMethodId)); }
async public Task <PaymentMethod> GetPaymnetMethodAsync(string id) { return(await _paymentMethodService.GetAsync(id, null, _requestOptions)); }