Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix stripe disabled functions for organization creation #502

Merged
merged 1 commit into from
May 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading