{"id":27941804,"url":"https://github.com/techwithty/fast_stripe_python_template","last_synced_at":"2025-07-04T03:05:48.665Z","repository":{"id":291386347,"uuid":"972367036","full_name":"TechWithTy/fast_stripe_python_template","owner":"TechWithTy","description":"Stripe payment processing integration utilities for sass","archived":false,"fork":false,"pushed_at":"2025-05-26T23:43:58.000Z","size":92,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-04T03:04:21.080Z","etag":null,"topics":["fastapi","integration","payments","sass","stripe"],"latest_commit_sha":null,"homepage":"https://www.cybershoptech.com","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/TechWithTy.png","metadata":{"files":{"readme":"ReadMe.md","changelog":null,"contributing":null,"funding":null,"license":null,"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,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-04-25T00:58:01.000Z","updated_at":"2025-05-09T02:47:42.000Z","dependencies_parsed_at":"2025-07-04T03:04:22.222Z","dependency_job_id":null,"html_url":"https://github.com/TechWithTy/fast_stripe_python_template","commit_stats":null,"previous_names":["techwithty/fast_stripe_python_template"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/TechWithTy/fast_stripe_python_template","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TechWithTy%2Ffast_stripe_python_template","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TechWithTy%2Ffast_stripe_python_template/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TechWithTy%2Ffast_stripe_python_template/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TechWithTy%2Ffast_stripe_python_template/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/TechWithTy","download_url":"https://codeload.github.com/TechWithTy/fast_stripe_python_template/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TechWithTy%2Ffast_stripe_python_template/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263437343,"owners_count":23466367,"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","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":["fastapi","integration","payments","sass","stripe"],"created_at":"2025-05-07T11:23:50.089Z","updated_at":"2025-07-04T03:05:48.637Z","avatar_url":"https://github.com/TechWithTy.png","language":"Python","readme":"# Stripe Python SaaS Template\n\nA complete Python template for building SaaS applications with Stripe integration. This template includes all essential functionality for subscription management, payment processing, customer management, and more.\n\n## Features\n\n### Core Stripe Integration\n- **Customers**: Create, retrieve, update and delete Stripe customers\n- **Products \u0026 Prices**: Manage your product catalog and pricing tiers\n- **Subscriptions**: Handle subscription creation, updates, cancellations and renewals\n- **Invoices \u0026 Billing**: Manage invoices, payment methods, and billing cycles\n- **Customer Portal**: Allow customers to manage their own subscriptions\n- **Connect**: Support for Stripe Connect for marketplace or platform businesses\n\n### SaaS-Specific Features\n- **Credit System**: Flexible credit/usage-based billing models\n- **Metered Billing**: Support for metered subscriptions and usage tracking\n- **Tiered Pricing**: Implementation of tiered pricing models\n- **Trial Management**: Free trial setup and conversion\n\n### Admin Functionality\n- **Admin Dashboard**: Ready-to-customize admin interface\n- **Reporting**: Revenue, customer, and subscription analytics\n- **User Management**: Admin tools for managing users and permissions\n- **Subscription Management**: Tools to manually adjust subscriptions\n\n### Testing\n- **Unit Tests**: Comprehensive test suite for all Stripe interactions\n- **Mock Responses**: Pre-configured mock responses for Stripe API calls\n- **Integration Tests**: End-to-end testing of payment flows\n\n## Installation\n\n```bash\n# Clone the repository\ngit clone https://github.com/yourusername/stripe-python-saas.git\ncd stripe-python-saas\n\n# Install required dependencies manually\npip install stripe\npip install django  # If using Django\n```\n\n## Configuration\n\nAdd your Stripe API keys to your environment or configuration file:\n\n```python\n# In your settings file\nSTRIPE_SECRET_KEY = \"sk_test_...\"\nSTRIPE_PUBLISHABLE_KEY = \"pk_test_...\"\n```\n\n## Quick Start\n\n```python\n# Initialize the Stripe client\nfrom stripe_saas import StripeClient\n\nclient = StripeClient()\n\n# Create a new customer\ncustomer = client.customers.create(\n    email=\"customer@example.com\",\n    name=\"Example Customer\"\n)\n\n# Create a subscription\nsubscription = client.subscriptions.create(\n    customer=customer.id,\n    items=[{\"price\": \"price_12345\"}]\n)\n```\n\n## Customer Portal Integration\n\nThe template includes ready-to-use integration with Stripe Customer Portal, allowing your users to manage their subscriptions directly:\n\n```python\n# Create a customer portal session\nfrom stripe_saas.portal import create_portal_session\n\nportal_session = create_portal_session(\n    customer_id=customer.stripe_id,\n    return_url=\"https://yourdomain.com/account\"\n)\n\n# Redirect your customer to the portal URL\nportal_url = portal_session.url\n```\n\n### Configuring the Customer Portal\n\n```python\n# Configure what customers can do in the portal\nclient.customer_portal.configurations.create(\n    business_profile={\n        \"headline\": \"Your Company Subscription Management\",\n    },\n    features={\n        \"subscription_update\": {\n            \"enabled\": True,\n            \"products\": [\"prod_12345\", \"prod_67890\"],\n        },\n        \"payment_method_update\": {\"enabled\": True},\n        \"invoice_history\": {\"enabled\": True},\n    },\n)\n```\n\n## Models\n\n### Customer Model\n\n```python\nfrom stripe_saas.models import Customer\n\n# Get or create a customer\ncustomer, created = Customer.objects.get_or_create(\n    email=\"customer@example.com\",\n    defaults={\n        \"name\": \"Example Customer\"\n    }\n)\n\n# Get the Stripe customer ID\nstripe_customer_id = customer.stripe_id\n```\n\n### Subscription Model\n\n```python\nfrom stripe_saas.models import Subscription\n\n# Get active subscriptions for a customer\nactive_subscriptions = Subscription.objects.filter(\n    customer=customer,\n    status='active'\n)\n\n# Check if customer has access to a feature\nhas_access = customer.has_feature_access('advanced_reporting')\n```\n\n### Credit Model\n\n```python\nfrom stripe_saas.models import CreditBalance\n\n# Add credits to a customer account\nCreditBalance.objects.add_credits(\n    customer=customer,\n    amount=100,\n    description=\"Referral bonus\"\n)\n\n# Use credits\nCreditBalance.objects.use_credits(\n    customer=customer,\n    amount=10,\n    feature=\"api_calls\"\n)\n```\n\n## Event Handling\n\nThis template provides event handler functions for important Stripe events. You can integrate these with your webhook endpoint implementation:\n\n```python\nfrom stripe_saas.events import handle_event\n\n# Example usage in your webhook view\ndef webhook_endpoint(request):\n    payload = request.body\n    signature = request.headers.get('stripe-signature')\n    \n    try:\n        event = stripe.Webhook.construct_event(\n            payload, signature, 'your_webhook_secret'\n        )\n        \n        # Process the event using the template's handlers\n        handle_event(event)\n        \n        return HttpResponse(status=200)\n    except Exception as e:\n        return HttpResponse(status=400)\n```\n\nThe `handle_event` function processes events including:\n\n- `customer.subscription.created`\n- `customer.subscription.updated`\n- `customer.subscription.deleted`\n- `invoice.paid`\n- `invoice.payment_failed`\n- `charge.succeeded`\n- `charge.failed`\n\n## Signals\n\nThe template includes Django signals for key events:\n\n```python\nfrom stripe_saas.signals import subscription_created, subscription_updated\n\n# Connect to the signals\n@receiver(subscription_created)\ndef handle_new_subscription(sender, subscription, **kwargs):\n    # Your custom logic here\n    pass\n\n@receiver(subscription_updated)\ndef handle_subscription_change(sender, subscription, **kwargs):\n    # Your custom logic here\n    pass\n```\n\n## Usage-Based Billing\n\n```python\nfrom stripe_saas.usage import report_usage\n\n# Report usage for a metered subscription\nreport_usage(\n    subscription_item_id=\"si_12345\",\n    quantity=1,\n    timestamp=int(time.time())\n)\n```\n\n## Tax Management\n\n```python\n# Set tax rates for a customer\nclient.customers.modify(\n    customer.stripe_id,\n    tax_id_data=[{\"type\": \"eu_vat\", \"value\": \"DE123456789\"}]\n)\n\n# Apply tax rates to a subscription\nsubscription = client.subscriptions.create(\n    customer=customer.stripe_id,\n    items=[{\"price\": \"price_12345\"}],\n    default_tax_rates=[\"txr_12345\"]\n)\n```\n\n## Handling Failed Payments\n\n```python\n# Retrieve invoices with failed payments\nfailed_invoices = client.invoices.list(\n    customer=customer.stripe_id,\n    status=\"open\"\n)\n\n# Attempt to pay a failed invoice\nclient.invoices.pay(failed_invoices[0].id)\n```\n\n## Refunds\n\n```python\n# Process a full refund\nrefund = client.refunds.create(\n    charge=\"ch_12345\"\n)\n\n# Process a partial refund\nrefund = client.refunds.create(\n    charge=\"ch_12345\",\n    amount=1000  # $10.00\n)\n```\n\n## Testing\n\nThe template includes a comprehensive testing suite:\n\n```python\n# Example test for subscription creation\ndef test_create_subscription(self):\n    customer = self.create_test_customer()\n    subscription = self.client.subscriptions.create(\n        customer=customer.stripe_id,\n        items=[{\"price\": self.test_price_id}]\n    )\n    self.assertEqual(subscription.status, \"active\")\n```\n\nFor event handling testing:\n\n```python\n# Test event handling\ndef test_subscription_deleted_event(self):\n    event_data = {\n        \"id\": \"evt_12345\",\n        \"type\": \"customer.subscription.deleted\",\n        \"data\": {\n            \"object\": {\n                \"id\": \"sub_12345\",\n                \"customer\": \"cus_12345\",\n                \"status\": \"canceled\"\n            }\n        }\n    }\n    event = stripe.Event.construct_from(event_data, 'test_key')\n    result = handle_event(event)\n    self.assertTrue(result)\n```\n\n## Resources\n\n- [Stripe API Documentation](https://docs.stripe.com/api)\n- [Stripe Customer Portal](https://docs.stripe.com/billing/subscriptions/customer-portal)\n- [Stripe Python Library](https://github.com/stripe/stripe-python)\n- [Event Types Reference](https://docs.stripe.com/webhooks/webhook-events)\n\n## License\n\nMIT","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftechwithty%2Ffast_stripe_python_template","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftechwithty%2Ffast_stripe_python_template","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftechwithty%2Ffast_stripe_python_template/lists"}