Skip to content

Commit

Permalink
Implement Multi-Subscriptions (#364)
Browse files Browse the repository at this point in the history
Co-authored-by: mnida <33556500+mnida@users.noreply.github.com>
Co-authored-by: Hardik-uselotus <116748720+Hardik-uselotus@users.noreply.github.com>
Co-authored-by: Hardik Agarwal <hardikagarwal@192.168.1.7>
Co-authored-by: mnida <mikaelnida@gmail.com>
Co-authored-by: Hardik Agarwal <hardikagarwal@192.168.1.4>
Co-authored-by: deepsource-autofix[bot] <62050782+deepsource-autofix[bot]@users.noreply.github.com>
7 people authored Dec 7, 2022
1 parent 11bdb78 commit 052cb52
Showing 90 changed files with 8,513 additions and 4,558 deletions.
17 changes: 10 additions & 7 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
{
"python.linting.pylintEnabled": true,
"python.linting.enabled": false,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.defaultFormatter": null,
"[typescript]": {
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[python]": {
"editor.formatOnSave": true,
"editor.defaultFormatter": "ms-python.python"
},
"editor.formatOnSave": true,
"isort.args": ["--profile", "black", "--filter-files"],
"python.formatting.provider": "black",
"python.testing.pytestArgs": ["${workspaceFolder}/metering_billing"],
"python.unitTest.unittestEnabled": false,
"python.unitTest.nosetestsEnabled": false,
"python.unitTest.pyTestEnabled": true,
"[properties]": {
"editor.defaultFormatter": "foxundermoon.shell-format"
}
"python.linting.pylintEnabled": false,
"python.linting.enabled": false,
"[typescriptreact]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
}
1 change: 1 addition & 0 deletions backend/Pipfile
Original file line number Diff line number Diff line change
@@ -49,6 +49,7 @@ kafka-python = "*"
kafka-helper = "*"
cronitor = "*"
svix = "*"
drf-nested-routers = "*"

[dev-packages]
platformdirs = "*"
166 changes: 87 additions & 79 deletions backend/Pipfile.lock

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions backend/lotus/settings.py
Original file line number Diff line number Diff line change
@@ -465,6 +465,8 @@ def key_deserializer(key):
"EXCEPTION_HANDLER": "metering_billing.custom_exception_handler.custom_exception_handler",
"COERCE_DECIMAL_TO_STRING": False,
}


SPECTACULAR_SETTINGS = {
"TITLE": "Lotus API",
"DESCRIPTION": (
@@ -488,6 +490,9 @@ def key_deserializer(key):
"TokenAuth": [],
}
],
"PREPROCESSING_HOOKS": [
"metering_billing.openapi_hooks.remove_subscription_delete"
],
"ENUM_NAME_OVERRIDES": {
"PaymentProvidersEnum": "metering_billing.utils.enums.PAYMENT_PROVIDERS.choices",
"FlatFeeBillingTypeEnum": "metering_billing.utils.enums.FLAT_FEE_BILLING_TYPE.choices",
@@ -506,6 +511,7 @@ def key_deserializer(key):
"OrganizationUserStatus": "metering_billing.utils.enums.ORGANIZATION_STATUS.choices",
},
}

REST_KNOX = {
"TOKEN_TTL": timedelta(hours=2),
"AUTO_REFRESH": True,
28 changes: 23 additions & 5 deletions backend/lotus/urls.py
Original file line number Diff line number Diff line change
@@ -43,13 +43,15 @@
from metering_billing.views.payment_provider_views import PaymentProviderView
from metering_billing.views.views import ( # MergeCustomersView,
APIKeyCreate,
ConfirmIdemsReceivedView,
CostAnalysisView,
CustomerBatchCreateView,
CustomersSummaryView,
CustomersWithRevenueView,
DraftInvoiceView,
ExperimentalToActiveView,
GetCustomerAccessView,
GetCustomerEventAccessView,
GetCustomerFeatureAccessView,
ImportCustomersView,
ImportPaymentObjectsView,
PeriodMetricRevenueView,
@@ -59,6 +61,7 @@
TransferSubscriptionsView,
)
from rest_framework import routers
from rest_framework_nested import routers

DEBUG = settings.DEBUG
ON_HEROKU = settings.ON_HEROKU
@@ -67,6 +70,12 @@
router = routers.DefaultRouter()
router.register(r"users", UserViewSet, basename="user")
router.register(r"customers", CustomerViewSet, basename="customer")

# customers_router = routers.NestedSimpleRouter(router, r"customers", lookup="")
# customers_router.register(
# r"plans", SubscriptionRecordViewSet, basename="customer-plans"
# )

router.register(r"metrics", MetricViewSet, basename="metric")
router.register(r"subscriptions", SubscriptionViewSet, basename="subscription")
router.register(r"invoices", InvoiceViewSet, basename="invoice")
@@ -94,7 +103,6 @@
basename="balance_adjustment",
)


urlpatterns = [
path("admin/", admin.site.urls),
path("api/", include(router.urls)),
@@ -137,9 +145,14 @@
path("api/new_api_key/", APIKeyCreate.as_view(), name="new_api_key"),
path("api/draft_invoice/", DraftInvoiceView.as_view(), name="draft_invoice"),
path(
"api/customer_access/",
GetCustomerAccessView.as_view(),
name="customer_access",
"api/customer_metric_access/",
GetCustomerEventAccessView.as_view(),
name="customer_metric_access",
),
path(
"api/customer_feature_access/",
GetCustomerFeatureAccessView.as_view(),
name="customer_feature_access",
),
path(
"api/batch_create_customers/",
@@ -175,6 +188,11 @@
path("api/logout/", auth_views.LogoutView.as_view(), name="api-logout"),
path("api/session/", auth_views.SessionView.as_view(), name="api-session"),
path("api/register/", auth_views.RegisterView.as_view(), name="register"),
path(
"api/verify_idems_received/",
ConfirmIdemsReceivedView.as_view(),
name="verify_idems_received",
),
path(
"api/demo_register/",
auth_views.DemoRegisterView.as_view(),
6 changes: 4 additions & 2 deletions backend/metering_billing/admin.py
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@
from rest_framework_api_key.models import APIKey
from simple_history.admin import SimpleHistoryAdmin

from .models import (
from .models import ( # Subscription,
APIToken,
Backtest,
BacktestSubstitution,
@@ -21,6 +21,7 @@
PlanComponent,
PlanVersion,
Subscription,
SubscriptionRecord,
User,
WebhookEndpoint,
)
@@ -36,13 +37,14 @@ class CustomAdmin(UserAdmin, SimpleHistoryAdmin):
admin.site.register(User, CustomAdmin)
admin.site.register(Customer, SimpleHistoryAdmin)
admin.site.register(Event)
admin.site.register(Subscription)
admin.site.register(SubscriptionRecord)
admin.site.register(Plan, SimpleHistoryAdmin)
admin.site.register(Backtest)
admin.site.register(Metric, SimpleHistoryAdmin)
admin.site.register(PlanComponent)
admin.site.register(Feature, SimpleHistoryAdmin)
admin.site.register(PlanVersion, SimpleHistoryAdmin)
admin.site.register(Subscription, SimpleHistoryAdmin)
admin.site.register(Invoice, SimpleHistoryAdmin)
admin.site.register(OrganizationInviteToken)
admin.site.unregister(APIKey)
2 changes: 1 addition & 1 deletion backend/metering_billing/apps.py
Original file line number Diff line number Diff line change
@@ -12,5 +12,5 @@ def ready(self):
registry.register(self.get_model("PlanVersion"))
registry.register(self.get_model("Customer"))
registry.register(self.get_model("Plan"))
registry.register(self.get_model("Subscription"))
registry.register(self.get_model("SubscriptionRecord"))
registry.register(self.get_model("Metric"))
Loading

0 comments on commit 052cb52

Please sign in to comment.