|
|
@@ -81,21 +81,11 @@ func (s *StripeBillingManager) ListPaymentMethod(proj *models.Project) (paymentM
|
|
|
}
|
|
|
result := paymentmethod.List(params)
|
|
|
|
|
|
- // Get customer to check default payment method
|
|
|
- customer, err := customer.Get(proj.BillingID, nil)
|
|
|
+ defaultPaymentExists, defaultPaymentID, err := s.checkDefaultPaymentMethod(proj.BillingID)
|
|
|
if err != nil {
|
|
|
return paymentMethods, err
|
|
|
}
|
|
|
|
|
|
- var (
|
|
|
- defaultPaymentExists bool
|
|
|
- defaultPaymentID string
|
|
|
- )
|
|
|
- if customer.InvoiceSettings != nil && customer.InvoiceSettings.DefaultPaymentMethod != nil {
|
|
|
- defaultPaymentExists = true
|
|
|
- defaultPaymentID = customer.InvoiceSettings.DefaultPaymentMethod.ID
|
|
|
- }
|
|
|
-
|
|
|
for result.Next() {
|
|
|
stripePaymentMethod := result.PaymentMethod()
|
|
|
|
|
|
@@ -146,7 +136,7 @@ func (s *StripeBillingManager) CreatePaymentMethod(proj *models.Project) (client
|
|
|
return intent.ClientSecret, nil
|
|
|
}
|
|
|
|
|
|
-// CreatePaymentMethod will add a new payment method to the project in Stripe
|
|
|
+// SetDefaultPaymentMethod will add a new payment method to the project in Stripe
|
|
|
func (s *StripeBillingManager) SetDefaultPaymentMethod(paymentMethodID string, proj *models.Project) (err error) {
|
|
|
stripe.Key = s.StripeSecretKey
|
|
|
|
|
|
@@ -180,3 +170,18 @@ func (s *StripeBillingManager) DeletePaymentMethod(paymentMethodID string) (err
|
|
|
func (s *StripeBillingManager) GetPublishableKey() (key string) {
|
|
|
return s.StripePublishableKey
|
|
|
}
|
|
|
+
|
|
|
+func (s *StripeBillingManager) checkDefaultPaymentMethod(customerID string) (defaultPaymentExists bool, defaultPaymentID string, err error) {
|
|
|
+ // Get customer to check default payment method
|
|
|
+ customer, err := customer.Get(customerID, nil)
|
|
|
+ if err != nil {
|
|
|
+ return defaultPaymentExists, defaultPaymentID, err
|
|
|
+ }
|
|
|
+
|
|
|
+ if customer.InvoiceSettings != nil && customer.InvoiceSettings.DefaultPaymentMethod != nil {
|
|
|
+ defaultPaymentExists = true
|
|
|
+ defaultPaymentID = customer.InvoiceSettings.DefaultPaymentMethod.ID
|
|
|
+ }
|
|
|
+
|
|
|
+ return defaultPaymentExists, defaultPaymentID, err
|
|
|
+}
|