Coverage for polar/enums.py: 59%
57 statements
« prev ^ index » next coverage.py v7.10.6, created at 2025-12-05 17:15 +0000
« prev ^ index » next coverage.py v7.10.6, created at 2025-12-05 17:15 +0000
1from datetime import datetime 1ab
2from enum import StrEnum 1ab
3from typing import Literal 1ab
5from dateutil.relativedelta import relativedelta 1ab
8class Platforms(StrEnum): 1ab
9 github = "github" 1ab
12class PaymentProcessor(StrEnum): 1ab
13 stripe = "stripe" 1ab
16class AccountType(StrEnum): 1ab
17 stripe = "stripe" 1ab
18 manual = "manual" 1ab
19 open_collective = "open_collective" 1ab
21 def get_display_name(self) -> str: 1ab
22 return {
23 AccountType.stripe: "Stripe Connect Express",
24 AccountType.open_collective: "Open Collective",
25 AccountType.manual: "Manual",
26 }[self]
29class SubscriptionRecurringInterval(StrEnum): 1ab
30 day = "day" 1ab
31 week = "week" 1ab
32 month = "month" 1ab
33 year = "year" 1ab
35 def as_literal(self) -> Literal["day", "week", "month", "year"]: 1ab
36 return self.value
38 def get_next_period(self, d: datetime, leap: int = 1) -> datetime: 1ab
39 match self:
40 case SubscriptionRecurringInterval.day:
41 return d + relativedelta(days=leap)
42 case SubscriptionRecurringInterval.week:
43 return d + relativedelta(weeks=leap)
44 case SubscriptionRecurringInterval.month:
45 return d + relativedelta(months=leap)
46 case SubscriptionRecurringInterval.year:
47 return d + relativedelta(years=leap)
50class SubscriptionProrationBehavior(StrEnum): 1ab
51 invoice = "invoice" # Invoice immediately 1ab
52 prorate = "prorate" # Add prorations to next invoice 1ab
54 def to_stripe(self) -> Literal["always_invoice", "create_prorations"]: 1ab
55 if self == SubscriptionProrationBehavior.invoice:
56 return "always_invoice"
57 if self == SubscriptionProrationBehavior.prorate:
58 return "create_prorations"
59 raise ValueError(f"Invalid proration behavior: {self}")
62class InvoiceNumbering(StrEnum): 1ab
63 organization = "organization" 1ab
64 customer = "customer" 1ab
67class TokenType(StrEnum): 1ab
68 client_secret = "polar_client_secret" 1ab
69 client_registration_token = "polar_client_registration_token" 1ab
70 authorization_code = "polar_authorization_code" 1ab
71 access_token = "polar_access_token" 1ab
72 refresh_token = "polar_refresh_token" 1ab
73 personal_access_token = "polar_personal_access_token" 1ab
74 organization_access_token = "polar_organization_access_token" 1ab
75 customer_session_token = "polar_customer_session_token" 1ab
76 user_session_token = "polar_user_session_token" 1ab
79class RateLimitGroup(StrEnum): 1ab
80 web = "web" 1ab
81 default = "default" 1ab
82 elevated = "elevated" 1ab