stripe.go 603 B

123456789101112131415161718192021222324252627282930
  1. package stripe
  2. import (
  3. "fmt"
  4. "os"
  5. "github.com/stripe/stripe-go/v81"
  6. "github.com/stripe/stripe-go/v81/account"
  7. )
  8. // Initialize sets up the Stripe client with the provided API key
  9. func Initialize() error {
  10. apiKey := os.Getenv("STRIPE_SECRET_KEY")
  11. if apiKey == "" {
  12. return fmt.Errorf("STRIPE_SECRET_KEY environment variable is not set")
  13. }
  14. // Set the API key for the Stripe client
  15. stripe.Key = apiKey
  16. // Test the connection
  17. acc, err := account.Get()
  18. if err != nil {
  19. return fmt.Errorf("failed to connect to Stripe: %v", err)
  20. }
  21. fmt.Printf("Stripe account: %+v\n", acc)
  22. return nil
  23. }