public async Task <DomainValidationResult <PaymentMethod> > AttachPaymentMethodAsync( string paymentMethodId, string customerId, bool defaultPaymentMethod = false ) { var result = new DomainValidationResult <PaymentMethod>(); var paymentMethodCardLimit = Options.PaymentMethod.Card.Limit; if (await this.PaymentMethodCountAsync(customerId) >= paymentMethodCardLimit) { result.AddFailedPreconditionError( $"You can have a maximum of {paymentMethodCardLimit} card{(paymentMethodCardLimit > 1 ? "s" : string.Empty)} as a payment method"); } if (result.IsValid) { var options = new PaymentMethodAttachOptions { Customer = customerId }; var paymentMethod = await this.AttachAsync(paymentMethodId, options); if (defaultPaymentMethod || !await _stripeCustomerService.HasDefaultPaymentMethodAsync(customerId)) { await _stripeCustomerService.SetDefaultPaymentMethodAsync(customerId, paymentMethodId); } return(paymentMethod); } return(result); }
public async Task <IActionResult> SetDefaultPaymentMethodAsync(string paymentMethodId) { var customerId = HttpContext.GetStripeCustomerId(); var customer = await _stripeCustomerService.SetDefaultPaymentMethodAsync(customerId, paymentMethodId); return(this.Ok(_mapper.Map <StripeCustomerDto>(customer))); }