Skip to content

Commit

Permalink
Fix stripe disabled functions for organization creation (#502)
Browse files Browse the repository at this point in the history
  • Loading branch information
DishenWang2023 authored May 27, 2024
1 parent e3ef091 commit d1617e3
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from utils.auth import Authorize, User, authenticate_user


def check_stripe_disabled(request: Request):
def is_stripe_disabled(request: Request):
if invoice_settings.stripe_disabled:
raise StripeDisabledError()
return request
Expand All @@ -28,7 +28,7 @@ def check_stripe_disabled(request: Request):
router = APIRouter(
prefix="/organizations",
responses={404: {"description": "Not found"}},
dependencies=[Depends(check_stripe_disabled)],
dependencies=[Depends(is_stripe_disabled)],
)

authorize = Authorize()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,14 @@ class UsageInvoice(BaseModel):
sql_generation_cost: int = 0
finetuning_gpt_35_cost: int = 0
finetuning_gpt_4_cost: int = 0


class MockStripeCustomer(BaseModel):
id: str | None = None
name: str | None = None


class MockStripeSubscription(BaseModel):
id: str | None = None
status: str | None = None
billing_cycle_anchor: int | None = None
18 changes: 14 additions & 4 deletions services/enterprise/modules/organization/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from modules.organization.invoice.models.entities import (
Credit,
InvoiceDetails,
MockStripeCustomer,
MockStripeSubscription,
PaymentPlan,
RecordStatus,
)
Expand Down Expand Up @@ -62,8 +64,12 @@ def add_organization(
)
organization = Organization(**org_request.dict())

customer = self.billing.create_customer(organization.name)
subscription = self.billing.create_subscription(customer.id)
if invoice_settings.stripe_disabled:
customer = MockStripeCustomer()
subscription = MockStripeSubscription()
else:
customer = self.billing.create_customer(organization.name)
subscription = self.billing.create_subscription(customer.id)
# default organization plan is CREDIT_ONLY
organization.invoice_details = InvoiceDetails(
plan=PaymentPlan.CREDIT_ONLY,
Expand Down Expand Up @@ -161,8 +167,12 @@ def add_organization_by_slack_installation(
owner=slack_installation_request.user.id,
)

customer = self.billing.create_customer(organization.name)
subscription = self.billing.create_subscription(customer.id)
if invoice_settings.stripe_disabled:
customer = MockStripeCustomer()
subscription = MockStripeSubscription()
else:
customer = self.billing.create_customer(organization.name)
subscription = self.billing.create_subscription(customer.id)
organization.invoice_details = InvoiceDetails(
plan=PaymentPlan.CREDIT_ONLY,
stripe_customer_id=customer.id,
Expand Down

0 comments on commit d1617e3

Please sign in to comment.