{"id":28557288,"url":"https://github.com/ydaniels/django-saas-billing","last_synced_at":"2025-09-04T01:38:49.239Z","repository":{"id":63831815,"uuid":"253944403","full_name":"ydaniels/django-saas-billing","owner":"ydaniels","description":"Fastest django app you'll ever user that provides paypal, stripe and cryptocurrency ( bitcoin) payment for your django drf saas app mvps subscription and billings. supports normal, Flat rate: Good-better-best, usage billing","archived":false,"fork":false,"pushed_at":"2024-02-12T01:09:11.000Z","size":103,"stargazers_count":13,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-10T21:41:28.063Z","etag":null,"topics":["billingsystem","bitcoin","django","django-rest-framework","drf","mvp","payment-gateway","paypal","saas","stripe","subscribe","subscriber","subscription","subscriptions"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ydaniels.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2020-04-08T00:28:26.000Z","updated_at":"2025-06-07T19:54:08.000Z","dependencies_parsed_at":"2023-12-01T14:12:29.096Z","dependency_job_id":"896492bd-04af-4777-be60-284a2aaf5020","html_url":"https://github.com/ydaniels/django-saas-billing","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ydaniels/django-saas-billing","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ydaniels%2Fdjango-saas-billing","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ydaniels%2Fdjango-saas-billing/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ydaniels%2Fdjango-saas-billing/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ydaniels%2Fdjango-saas-billing/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ydaniels","download_url":"https://codeload.github.com/ydaniels/django-saas-billing/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ydaniels%2Fdjango-saas-billing/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273539293,"owners_count":25123499,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-03T02:00:09.631Z","response_time":76,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["billingsystem","bitcoin","django","django-rest-framework","drf","mvp","payment-gateway","paypal","saas","stripe","subscribe","subscriber","subscription","subscriptions"],"created_at":"2025-06-10T07:09:31.494Z","updated_at":"2025-09-04T01:38:49.229Z","avatar_url":"https://github.com/ydaniels.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"drf-saas-billing\n======================================\n\n|build-status-image| |pypi-version|\n\nOverview\n--------\n\nFastest django app you'll ever user that provides paypal, stripe and cryptocurrency ( bitcoin) payment for your  django drf saas app subscription and billings. supports normal, Flat rate: Good-better-best, usage billing\nbased on https://github.com/ydaniels/drf-django-flexible-subscriptions\n\n\nRequirements\n------------\n\n-  Python (2.7, 3.3, 3.4+)\n-  Django (1.6, 1.7, 1.8+)\n-  Django REST Framework (2.4, 3.0, 3.1+)\n\nInstallation\n------------\n\nInstall using ``pip``\\ …\n\n.. code:: bash\n\n    $ pip install django-saas-billing\n\nSetup\n-------\n\n.. code:: python\n\n    #    settings.py\n    INSTALLED_APPS = [\n                        ...,\n                        'rest_framework',\n                        'subscriptions_api',\n                        'cryptocurrency_payment', #for crypto payments\n                        'saas_billing'\n                        ]\n    SUBSCRIPTIONS_API_SUBSCRIPTIONTRANSACTION_MODEL = 'saas_billing.SubscriptionTransaction'\n    SAAS_BILLING_MODELS = {\n            'stripe': {\n                'plan': 'saas_billing.StripeSubscriptionPlan',\n                'cost': 'saas_billing.StripeSubscriptionPlanCost',\n                'subscription': 'saas_billing.StripeSubscription'\n            },\n            'paypal': {\n                'plan': 'saas_billing.PaypalSubscriptionPlan',\n                'cost': 'saas_billing.PaypalSubscriptionPlanCost',\n                'subscription': 'saas_billing.PaypalSubscription'\n            }\n        }\n    SAAS_BILLING_AUTH = {\n            'stripe': {\n                'PUBLISHABLE_KEY': 'Your Publishable Key',\n                'LIVE_KEY': 'You Live key can be test or live',\n                'CANCEL_URL': 'Where you want to redirect to if user cancels payment',\n                'SUCCESS_URL': ' Where to redirect to if subscription is successful'\n            },\n            'paypal': {\n                'CLIENT_ID': 'Your paypal rest client id',\n                'CLIENT_SECRET': 'Your paypal rest secret id',\n                'TOKEN': None,\n                'ENV': 'live|development',\n                'CANCEL_URL':  'Where to redirect to if subscription fails',\n                'SUCCESS_URL':  'Where to redirect to if subscription is successful',\n                'WEB_HOOK_ID': 'Your paypal rest webhook id'\n            }\n    }\n\n    CRYPTOCURRENCY_PAYMENT = {\n    \"BITCOIN\": {\n        \"CODE\": \"btc\",\n        \"BACKEND\": \"merchant_wallet.backends.btc.BitcoinBackend\",\n        \"FEE\": 0.00,\n        \"REFRESH_PRICE_AFTER_MINUTE\": 15,\n        \"REUSE_ADDRESS\": False,\n        \"ACTIVE\": True,\n        \"MASTER_PUBLIC_KEY\": 'PUT_YOUR_WALLET_MASTER_PUBLIC_KEY',\n        \"CANCEL_UNPAID_PAYMENT_HRS\": 24,\n        \"CREATE_NEW_UNDERPAID_PAYMENT\": True,\n        \"IGNORE_UNDERPAYMENT_AMOUNT\": 10,\n        \"IGNORE_CONFIRMED_BALANCE_WITHOUT_SAVED_HASH_MINS\": 20,\n        \"BALANCE_CONFIRMATION_NUM\": 1,\n        \"ALLOW_ANONYMOUS_PAYMENT\": False,\n         \"DERIVATION_PATH\": \"m/0\",\n        \"ADDRESS_TYPE\": \"p2wpkh\"\n    }\n }\n    DFS_DEFAULT_PLAN_COST_ID = 'Optional Put plan cost id here for new user to be automatically subscribed to this plan or subscription to be downgraded here'\n.. code-block:: python\n\n    path('', include('saas_billing.webhook_urls')) #Compulsory for webhook register url webhook on paypal and stripe\n    #create webhook url https://yourdomain.com/billing/stripe/webhook/\n    #https://yourdomain.com/billing/paypal/webhook/\n    path('api/subscriptions/', include('subscriptions_api.urls')),\n    path('api/', include('saas_billing.urls')), \n    \n\nUsage\n-----\n\nStep 1\n------\n\n- Regsiter webhook urls on paypal and stripe\n\n.. code-block:: bash\n\n    https://yourdomain/billing/stripe/webhook/ #Please use ngrok on  localhost\n    https://yourdomain/billing/paypal/webhook/\n\n- Register signal in apps.py for crypto payments to activate subscription when crypto payment gets paid\n\n.. code-block:: python\n\n    #apps.py\n    class MyAppConfig(AppConfig):\n\n        def ready(self):\n            import saas_billing.signals\n\nStep 2\n-------\n\n.. code-block:: python\n\n        python manage.py migrate\n        \n- Create Your Plans and PlanCost  from django admin \n\n.. code-block:: python\n\n        from subscription_api.models import SubscriptionPlan, PlanCost, MONTH\n        free_plan = SubscriptionPlan(plan_name='Free Plan', features='{\"can_perform_action\": false, \"token_limit\": 3}', group=optional_already_created_group_obj_user_will_be_added_to)\n        free_plan.save()\n\n        pro_plan = SubscriptionPlan(plan_name='Pro Plan', features='{\"can_perform_action\": true, \"token_limit\": 10}', group=already_created_group_obj).save()\n        pro_plan.save()\n        PlanCost(plan=pro_plan, recurrence_unit=MONTH, cost=30, min_subscription_quantity=20).save() #30$/month #min_subscription_quantity user must subscribe upto quantity to use this cost\n \nTips\n----\n.. code-block:: python\n\n    #In your code or views you can use\n    if not user.subscription.plan.can_perform_action:\n               print('I am a free user')\n          else:\n               print('I am a pro user')\n     # features is a json dict that can be accessed from plan and group is normal django group that user will belong to\n\n\n     # You should be able to implement most subscriptions access and permissions with the feautures and django groups\n\n\nStep 3\n------\n\n\n- Generate Paypal and Stripe Plans and Pricing by using  command below\n\n.. code-block:: python\n\n   python manage.py billing gateway all # Create all plans on stripe.com and paypal.com\n   python manage.py billing gateway \u003cpaypal|stripe\u003e # Create   only on paypal.com or Stripe.com\n   python manage.py billing gateway \u003cpaypal|stripe\u003e --action \u003cactivate|deactivate\u003e # Activate or Deactivate plans\n\nTips\n-----\n\n\nGetting Active Subscriptions Of a User\n------------------------------------------\n\n.. code-block:: python\n\n    subscription = request.user.subscriptions.filter(active=True).first() #if you only allow a subscription per user\n    subscription.transactions.all() #returns all transaction payment of this subscriptions\n    request.user.subscriptions.filter(active=True).all() #for all subscriptions if you allow multiple subscription per user\n\n.. code-block:: python\n\n    transactions = request.user.subscription_transactions.all() #Returns all payment trasnsaction for this user\n\nBuilding A  Payment And Active Subscription View\n------------------------------------------------\n\n.. code-block:: python\n\n    from saas_billing.models import SubscriptionTransaction #import this to show crypto payments\n    from subscriptions_api.base_models import BaseSubscriptionTransaction # use this to only show paypal \u0026 stripe payment\n\n    class BillingView(ListView):\n        model = BaseSubscriptionTransaction\n        context_object_name = 'payment_transactions'\n        template_name = 'transactions.html'\n\n        def get_queryset(self):\n              return self.request.user.subscription_transactions.order_by('-date_transaction')\n\n        def get_context_data(self, **kwargs):\n              context = super().get_context_data(**kwargs)\n              context['active_subscription'] = self.request.user.subscriptions.filter(active=True).first()\n              return context\n\n.. code-block:: html\n\n     \u003c!-- transactions.html --\u003e\n      \u003ctable class=\"table table-bordernone display\" id=\"basic-1\"\u003e\n                \u003cthead\u003e\n                  \u003ctr\u003e\n                    \u003cth scope=\"col\"\u003eDate\u003c/th\u003e\n                    \u003cth scope=\"col\"\u003eSubscription\u003c/th\u003e\n                    \u003cth scope=\"col\"\u003eAmount\u003c/th\u003e\n                    \u003cth scope=\"col\"\u003eStatus\u003c/th\u003e\n                  \u003c/tr\u003e\n                \u003c/thead\u003e\n                \u003ctbody\u003e\n                {% for tran in payment_transactions %}\n                  \u003ctr\u003e\n                    \u003ctd\u003e{{ tran.payment_transactions }}\u003c/td\u003e\n                    \u003ctd\u003e\n                      \u003cdiv class=\"product-name\"\u003e{{ tran.subscription_name }}\n                      \u003c/div\u003e\n                    \u003c/td\u003e\n                    \u003ctd\u003e${{ tran.amount }}\u003c/td\u003e\n                    \u003ctd\u003ePaid\u003c/td\u003e\n                  \u003c/tr\u003e\n                {% endfor %}\n                \u003c/tbody\u003e\n              \u003c/table\u003e\n\n\nStep 4\n--------\n\nHow To Subscribe A User to a Plan Cost\n---------------------------------------\n-Send a post request using ajax or axios with data { gateway: \u003cstripe|paypal|bitcoin\u003e, quantity: 1 } to url below where ${id} is the  plan cost id under subscriptions plans and  quantity is optional for usage pricing\n\n.. code-block:: javascript\n     // post data { gateway: \u003cstripe|paypal|bitcoin\u003e, quantity: 1 } quantity allows use to use usage biling\n    '/api/plan-costs/${id}/init_gateway_subscription/'\n\n- For paypal redirect user to payment_link value from returned data\n.. code-block:: javascript\n\n   $.ajax({url: '/api/plan-costs/${id-of-cost}/init_gateway_subscription/', { gateway: 'paypal', quantity: 1 }}).then((post_return_data) =\u003e {\n    window.open(post_return_data.payment_link, '_blank').focus();\n    })\n    \n    \n- For stripe start session with session id returned from post requsest using stripe javascript sdk\n\n.. code-block:: javascript\n\n   (post_return_data) =\u003e {\n    var stripe = window.Stripe(YOUR_STRIPE_PUBLIC_KEY)\n    return stripe.redirectToCheckout({ sessionId: post_return_data.session_id })\n    }\n    \n    \n**Thats all you need to start accepting subscriptions, subscriptions are activated or deactivated automatically and notification are sent to users automatically**\n\nTips Api URL To use in frontend app for drf users\n------------------------------------------------\n\n.. code-block:: python\n\n    '/api/subscriptions/subscription-plans/'  #Get all plans to display in frontend\n    '/api/subscriptions/get_active_subscription/' # Returns active UserSubscription Object for the current logged in user\n    '/api/subscriptions/${id}/unsubscribe_user/' # Unsubscribe user from subscription with ${id}\n    '/api/transactions/' # Get payment transactions\n    '/api/transactions/${id}/' # Get single payment transaction with ${id}\n-\n\nTesting\n-------\n\nInstall testing requirements.\n\n.. code:: bash\n\n    $ pip install -r requirements.txt\n\nRun with runtests.\n\n.. code:: bash\n\n    $ ./runtests.py\n\nYou can also use the excellent `tox`_ testing tool to run the tests\nagainst all supported versions of Python and Django. Install tox\nglobally, and then simply run:\n\n.. code:: bash\n\n    $ tox\n\nDocumentation\n-------------\n\nTo build the documentation, you’ll need to install ``mkdocs``.\n\n.. code:: bash\n\n    $ pip install mkdocs\n\nTo preview the documentation:\n\n.. code:: bash\n\n    $ mkdocs serve\n    Running at: http://127.0.0.1:8000/\n\nTo build the documentation:\n\n.. code:: bash\n\n    $ mkdocs build\n\n.. _tox: http://tox.readthedocs.org/en/latest/\n\n.. |build-status-image| image:: https://secure.travis-ci.org/ydaniels/drf-saas-billing.svg?branch=master\n   :target: http://travis-ci.org/ydaniels/drf-saas-billing?branch=master\n.. |pypi-version| image:: https://img.shields.io/pypi/v/drf-saas-billing.svg\n   :target: https://pypi.python.org/pypi/drf-saas-billing\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fydaniels%2Fdjango-saas-billing","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fydaniels%2Fdjango-saas-billing","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fydaniels%2Fdjango-saas-billing/lists"}