|
|
@@ -29,8 +29,7 @@ func NewStripeClient(secretKey string, publishableKey string) *StripeClient {
|
|
|
}
|
|
|
|
|
|
// CreateCustomer will create a customer in Stripe only if the project doesn't have a BillingID
|
|
|
-<<<<<<< HEAD
|
|
|
-func (s *StripeBillingManager) CreateCustomer(ctx context.Context, userEmail string, projectID uint, projectName string) (customerID string, err error) {
|
|
|
+func (s *StripeClient) CreateCustomer(ctx context.Context, userEmail string, projectID uint, projectName string) (customerID string, err error) {
|
|
|
ctx, span := telemetry.NewSpan(ctx, "create-stripe-customer")
|
|
|
defer span.End()
|
|
|
|
|
|
@@ -38,14 +37,7 @@ func (s *StripeBillingManager) CreateCustomer(ctx context.Context, userEmail str
|
|
|
return "", fmt.Errorf("invalid project id or name")
|
|
|
}
|
|
|
|
|
|
- stripe.Key = s.StripeSecretKey
|
|
|
-=======
|
|
|
-func (s *StripeClient) CreateCustomer(ctx context.Context, userEmail string, proj *models.Project) (customerID string, err error) {
|
|
|
- ctx, span := telemetry.NewSpan(ctx, "create-stripe-customer")
|
|
|
- defer span.End()
|
|
|
-
|
|
|
stripe.Key = s.SecretKey
|
|
|
->>>>>>> b8c4273a5 (Add Metronome business logic)
|
|
|
|
|
|
// Create customer if not exists
|
|
|
customerName := fmt.Sprintf("project_%s", projectName)
|
|
|
@@ -76,8 +68,7 @@ func (s *StripeClient) CreateCustomer(ctx context.Context, userEmail string, pro
|
|
|
}
|
|
|
|
|
|
// DeleteCustomer will delete the customer from the billing provider
|
|
|
-<<<<<<< HEAD
|
|
|
-func (s *StripeBillingManager) DeleteCustomer(ctx context.Context, customerID string) (err error) {
|
|
|
+func (s *StripeClient) DeleteCustomer(ctx context.Context, customerID string) (err error) {
|
|
|
ctx, span := telemetry.NewSpan(ctx, "delete-stripe-customer")
|
|
|
defer span.End()
|
|
|
|
|
|
@@ -85,14 +76,7 @@ func (s *StripeBillingManager) DeleteCustomer(ctx context.Context, customerID st
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
- stripe.Key = s.StripeSecretKey
|
|
|
-=======
|
|
|
-func (s *StripeClient) DeleteCustomer(ctx context.Context, proj *models.Project) (err error) {
|
|
|
- ctx, span := telemetry.NewSpan(ctx, "delete-stripe-customer")
|
|
|
- defer span.End()
|
|
|
-
|
|
|
stripe.Key = s.SecretKey
|
|
|
->>>>>>> b8c4273a5 (Add Metronome business logic)
|
|
|
|
|
|
telemetry.WithAttributes(span,
|
|
|
telemetry.AttributeKV{Key: "billing-id", Value: customerID},
|
|
|
@@ -108,8 +92,7 @@ func (s *StripeClient) DeleteCustomer(ctx context.Context, proj *models.Project)
|
|
|
}
|
|
|
|
|
|
// CheckPaymentEnabled will return true if the project has a payment method added, false otherwise
|
|
|
-<<<<<<< HEAD
|
|
|
-func (s *StripeBillingManager) CheckPaymentEnabled(ctx context.Context, customerID string) (paymentEnabled bool, err error) {
|
|
|
+func (s *StripeClient) CheckPaymentEnabled(ctx context.Context, customerID string) (paymentEnabled bool, err error) {
|
|
|
_, span := telemetry.NewSpan(ctx, "check-stripe-payment-enabled")
|
|
|
defer span.End()
|
|
|
|
|
|
@@ -117,14 +100,7 @@ func (s *StripeBillingManager) CheckPaymentEnabled(ctx context.Context, customer
|
|
|
return false, fmt.Errorf("customer id cannot be empty")
|
|
|
}
|
|
|
|
|
|
- stripe.Key = s.StripeSecretKey
|
|
|
-=======
|
|
|
-func (s *StripeClient) CheckPaymentEnabled(ctx context.Context, proj *models.Project) (paymentEnabled bool, err error) {
|
|
|
- _, span := telemetry.NewSpan(ctx, "check-stripe-payment-enabled")
|
|
|
- defer span.End()
|
|
|
-
|
|
|
stripe.Key = s.SecretKey
|
|
|
->>>>>>> b8c4273a5 (Add Metronome business logic)
|
|
|
|
|
|
params := &stripe.PaymentMethodListParams{
|
|
|
Customer: stripe.String(customerID),
|
|
|
@@ -136,8 +112,7 @@ func (s *StripeClient) CheckPaymentEnabled(ctx context.Context, proj *models.Pro
|
|
|
}
|
|
|
|
|
|
// ListPaymentMethod will return all payment methods for the project
|
|
|
-<<<<<<< HEAD
|
|
|
-func (s *StripeBillingManager) ListPaymentMethod(ctx context.Context, customerID string) (paymentMethods []types.PaymentMethod, err error) {
|
|
|
+func (s *StripeClient) ListPaymentMethod(ctx context.Context, customerID string) (paymentMethods []types.PaymentMethod, err error) {
|
|
|
ctx, span := telemetry.NewSpan(ctx, "list-stripe-payment-method")
|
|
|
defer span.End()
|
|
|
|
|
|
@@ -145,14 +120,7 @@ func (s *StripeBillingManager) ListPaymentMethod(ctx context.Context, customerID
|
|
|
return paymentMethods, fmt.Errorf("customer id cannot be empty")
|
|
|
}
|
|
|
|
|
|
- stripe.Key = s.StripeSecretKey
|
|
|
-=======
|
|
|
-func (s *StripeClient) ListPaymentMethod(ctx context.Context, proj *models.Project) (paymentMethods []types.PaymentMethod, err error) {
|
|
|
- ctx, span := telemetry.NewSpan(ctx, "list-stripe-payment-method")
|
|
|
- defer span.End()
|
|
|
-
|
|
|
stripe.Key = s.SecretKey
|
|
|
->>>>>>> b8c4273a5 (Add Metronome business logic)
|
|
|
|
|
|
// Get configured payment methods
|
|
|
params := &stripe.PaymentMethodListParams{
|
|
|
@@ -197,8 +165,7 @@ func (s *StripeClient) ListPaymentMethod(ctx context.Context, proj *models.Proje
|
|
|
}
|
|
|
|
|
|
// CreatePaymentMethod will add a new payment method to the project in Stripe
|
|
|
-<<<<<<< HEAD
|
|
|
-func (s *StripeBillingManager) CreatePaymentMethod(ctx context.Context, customerID string) (clientSecret string, err error) {
|
|
|
+func (s *StripeClient) CreatePaymentMethod(ctx context.Context, customerID string) (clientSecret string, err error) {
|
|
|
ctx, span := telemetry.NewSpan(ctx, "create-stripe-payment-method")
|
|
|
defer span.End()
|
|
|
|
|
|
@@ -206,14 +173,7 @@ func (s *StripeBillingManager) CreatePaymentMethod(ctx context.Context, customer
|
|
|
return "", fmt.Errorf("customer id cannot be empty")
|
|
|
}
|
|
|
|
|
|
- stripe.Key = s.StripeSecretKey
|
|
|
-=======
|
|
|
-func (s *StripeClient) CreatePaymentMethod(ctx context.Context, proj *models.Project) (clientSecret string, err error) {
|
|
|
- ctx, span := telemetry.NewSpan(ctx, "create-stripe-payment-method")
|
|
|
- defer span.End()
|
|
|
-
|
|
|
stripe.Key = s.SecretKey
|
|
|
->>>>>>> b8c4273a5 (Add Metronome business logic)
|
|
|
|
|
|
params := &stripe.SetupIntentParams{
|
|
|
Customer: stripe.String(customerID),
|
|
|
@@ -232,8 +192,7 @@ func (s *StripeClient) CreatePaymentMethod(ctx context.Context, proj *models.Pro
|
|
|
}
|
|
|
|
|
|
// SetDefaultPaymentMethod will add a new payment method to the project in Stripe
|
|
|
-<<<<<<< HEAD
|
|
|
-func (s *StripeBillingManager) SetDefaultPaymentMethod(ctx context.Context, paymentMethodID string, customerID string) (err error) {
|
|
|
+func (s *StripeClient) SetDefaultPaymentMethod(ctx context.Context, paymentMethodID string, customerID string) (err error) {
|
|
|
ctx, span := telemetry.NewSpan(ctx, "set-default-stripe-payment-method")
|
|
|
defer span.End()
|
|
|
|
|
|
@@ -241,14 +200,7 @@ func (s *StripeBillingManager) SetDefaultPaymentMethod(ctx context.Context, paym
|
|
|
return fmt.Errorf("empty customer id or payment method id")
|
|
|
}
|
|
|
|
|
|
- stripe.Key = s.StripeSecretKey
|
|
|
-=======
|
|
|
-func (s *StripeClient) SetDefaultPaymentMethod(ctx context.Context, paymentMethodID string, proj *models.Project) (err error) {
|
|
|
- ctx, span := telemetry.NewSpan(ctx, "set-default-stripe-payment-method")
|
|
|
- defer span.End()
|
|
|
-
|
|
|
stripe.Key = s.SecretKey
|
|
|
->>>>>>> b8c4273a5 (Add Metronome business logic)
|
|
|
|
|
|
params := &stripe.CustomerParams{
|
|
|
InvoiceSettings: &stripe.CustomerInvoiceSettingsParams{
|
|
|
@@ -269,15 +221,11 @@ func (s *StripeClient) DeletePaymentMethod(ctx context.Context, paymentMethodID
|
|
|
ctx, span := telemetry.NewSpan(ctx, "delete-stripe-payment-method")
|
|
|
defer span.End()
|
|
|
|
|
|
-<<<<<<< HEAD
|
|
|
if paymentMethodID == "" {
|
|
|
return fmt.Errorf("payment method id cannot be empty")
|
|
|
}
|
|
|
|
|
|
- stripe.Key = s.StripeSecretKey
|
|
|
-=======
|
|
|
stripe.Key = s.SecretKey
|
|
|
->>>>>>> b8c4273a5 (Add Metronome business logic)
|
|
|
|
|
|
_, err = paymentmethod.Detach(paymentMethodID, nil)
|
|
|
if err != nil {
|