Skip to content

Commit d1617e3

Browse files
Fix stripe disabled functions for organization creation (#502)
1 parent e3ef091 commit d1617e3

File tree

3 files changed

+27
-6
lines changed

3 files changed

+27
-6
lines changed

services/enterprise/modules/organization/invoice/controller.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from utils.auth import Authorize, User, authenticate_user
2020

2121

22-
def check_stripe_disabled(request: Request):
22+
def is_stripe_disabled(request: Request):
2323
if invoice_settings.stripe_disabled:
2424
raise StripeDisabledError()
2525
return request
@@ -28,7 +28,7 @@ def check_stripe_disabled(request: Request):
2828
router = APIRouter(
2929
prefix="/organizations",
3030
responses={404: {"description": "Not found"}},
31-
dependencies=[Depends(check_stripe_disabled)],
31+
dependencies=[Depends(is_stripe_disabled)],
3232
)
3333

3434
authorize = Authorize()

services/enterprise/modules/organization/invoice/models/entities.py

+11
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,14 @@ class UsageInvoice(BaseModel):
7070
sql_generation_cost: int = 0
7171
finetuning_gpt_35_cost: int = 0
7272
finetuning_gpt_4_cost: int = 0
73+
74+
75+
class MockStripeCustomer(BaseModel):
76+
id: str | None = None
77+
name: str | None = None
78+
79+
80+
class MockStripeSubscription(BaseModel):
81+
id: str | None = None
82+
status: str | None = None
83+
billing_cycle_anchor: int | None = None

services/enterprise/modules/organization/service.py

+14-4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
from modules.organization.invoice.models.entities import (
55
Credit,
66
InvoiceDetails,
7+
MockStripeCustomer,
8+
MockStripeSubscription,
79
PaymentPlan,
810
RecordStatus,
911
)
@@ -62,8 +64,12 @@ def add_organization(
6264
)
6365
organization = Organization(**org_request.dict())
6466

65-
customer = self.billing.create_customer(organization.name)
66-
subscription = self.billing.create_subscription(customer.id)
67+
if invoice_settings.stripe_disabled:
68+
customer = MockStripeCustomer()
69+
subscription = MockStripeSubscription()
70+
else:
71+
customer = self.billing.create_customer(organization.name)
72+
subscription = self.billing.create_subscription(customer.id)
6773
# default organization plan is CREDIT_ONLY
6874
organization.invoice_details = InvoiceDetails(
6975
plan=PaymentPlan.CREDIT_ONLY,
@@ -161,8 +167,12 @@ def add_organization_by_slack_installation(
161167
owner=slack_installation_request.user.id,
162168
)
163169

164-
customer = self.billing.create_customer(organization.name)
165-
subscription = self.billing.create_subscription(customer.id)
170+
if invoice_settings.stripe_disabled:
171+
customer = MockStripeCustomer()
172+
subscription = MockStripeSubscription()
173+
else:
174+
customer = self.billing.create_customer(organization.name)
175+
subscription = self.billing.create_subscription(customer.id)
166176
organization.invoice_details = InvoiceDetails(
167177
plan=PaymentPlan.CREDIT_ONLY,
168178
stripe_customer_id=customer.id,

0 commit comments

Comments
 (0)