2
0

billing.go 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package billing
  2. import (
  3. "fmt"
  4. "github.com/porter-dev/porter/api/types"
  5. "github.com/porter-dev/porter/internal/models"
  6. )
  7. // BillingManager contains methods for managing billing for a project
  8. type BillingManager interface {
  9. // CreateTeam creates the concept of a billing "team". This is currently a one-to-one
  10. // mapping with projects, but this may change in the future (i.e. multiple projects
  11. // per same team)
  12. CreateTeam(user *models.User, proj *models.Project) (teamID string, err error)
  13. // DeleteTeam deletes a billing team.
  14. DeleteTeam(user *models.User, proj *models.Project) (err error)
  15. // GetRedirectURI gets the redirect URI to send the user to the billing portal
  16. GetRedirectURI(user *models.User, proj *models.Project) (url string, err error)
  17. // ParseProjectUsageFromWebhook parses the project usage from a webhook payload sent
  18. // from a billing agent
  19. ParseProjectUsageFromWebhook(payload []byte) (*models.ProjectUsage, *types.FeatureFlags, error)
  20. // VerifySignature verifies the signature for a webhook
  21. VerifySignature(signature string, body []byte) bool
  22. }
  23. // NoopBillingManager performs no billing operations
  24. type NoopBillingManager struct{}
  25. func (n *NoopBillingManager) CreateTeam(user *models.User, proj *models.Project) (teamID string, err error) {
  26. return fmt.Sprintf("%d", proj.ID), nil
  27. }
  28. func (n *NoopBillingManager) DeleteTeam(user *models.User, proj *models.Project) (err error) {
  29. return nil
  30. }
  31. func (n *NoopBillingManager) GetRedirectURI(user *models.User, proj *models.Project) (url string, err error) {
  32. return "", nil
  33. }
  34. func (n *NoopBillingManager) ParseProjectUsageFromWebhook(payload []byte) (*models.ProjectUsage, *types.FeatureFlags, error) {
  35. return nil, nil, nil
  36. }
  37. func (n *NoopBillingManager) VerifySignature(signature string, body []byte) bool {
  38. return false
  39. }