Complete Implemenation of tenancy
This commit is contained in:
@@ -267,10 +267,19 @@ class RegisterSerializer(serializers.Serializer):
|
||||
)
|
||||
plan_slug = serializers.CharField(max_length=50, required=False)
|
||||
payment_method = serializers.ChoiceField(
|
||||
choices=['stripe', 'paypal', 'bank_transfer'],
|
||||
choices=['stripe', 'paypal', 'bank_transfer', 'local_wallet'],
|
||||
default='bank_transfer',
|
||||
required=False
|
||||
)
|
||||
# Billing information fields
|
||||
billing_email = serializers.EmailField(required=False, allow_blank=True)
|
||||
billing_address_line1 = serializers.CharField(max_length=255, required=False, allow_blank=True)
|
||||
billing_address_line2 = serializers.CharField(max_length=255, required=False, allow_blank=True)
|
||||
billing_city = serializers.CharField(max_length=100, required=False, allow_blank=True)
|
||||
billing_state = serializers.CharField(max_length=100, required=False, allow_blank=True)
|
||||
billing_postal_code = serializers.CharField(max_length=20, required=False, allow_blank=True)
|
||||
billing_country = serializers.CharField(max_length=2, required=False, allow_blank=True)
|
||||
tax_id = serializers.CharField(max_length=100, required=False, allow_blank=True)
|
||||
|
||||
def validate(self, attrs):
|
||||
if attrs['password'] != attrs['password_confirm']:
|
||||
@@ -287,7 +296,7 @@ class RegisterSerializer(serializers.Serializer):
|
||||
def create(self, validated_data):
|
||||
from django.db import transaction
|
||||
from igny8_core.business.billing.models import CreditTransaction
|
||||
from igny8_core.business.billing.models import Subscription
|
||||
from igny8_core.auth.models import Subscription
|
||||
from igny8_core.business.billing.models import AccountPaymentMethod
|
||||
from igny8_core.business.billing.services.invoice_service import InvoiceService
|
||||
from django.utils import timezone
|
||||
@@ -371,6 +380,15 @@ class RegisterSerializer(serializers.Serializer):
|
||||
credits=initial_credits,
|
||||
status=account_status,
|
||||
payment_method=validated_data.get('payment_method') or 'bank_transfer',
|
||||
# Save billing information
|
||||
billing_email=validated_data.get('billing_email', '') or validated_data.get('email', ''),
|
||||
billing_address_line1=validated_data.get('billing_address_line1', ''),
|
||||
billing_address_line2=validated_data.get('billing_address_line2', ''),
|
||||
billing_city=validated_data.get('billing_city', ''),
|
||||
billing_state=validated_data.get('billing_state', ''),
|
||||
billing_postal_code=validated_data.get('billing_postal_code', ''),
|
||||
billing_country=validated_data.get('billing_country', ''),
|
||||
tax_id=validated_data.get('tax_id', ''),
|
||||
)
|
||||
|
||||
# Log initial credit transaction only for free/trial accounts with credits
|
||||
@@ -392,13 +410,14 @@ class RegisterSerializer(serializers.Serializer):
|
||||
user.account = account
|
||||
user.save()
|
||||
|
||||
# For paid plans, create subscription, invoice, and default bank transfer method
|
||||
# For paid plans, create subscription, invoice, and default payment method
|
||||
if plan_slug and plan_slug in paid_plans:
|
||||
payment_method = validated_data.get('payment_method', 'bank_transfer')
|
||||
|
||||
subscription = Subscription.objects.create(
|
||||
account=account,
|
||||
plan=plan,
|
||||
status='pending_payment',
|
||||
payment_method='bank_transfer',
|
||||
external_payment_id=None,
|
||||
current_period_start=billing_period_start,
|
||||
current_period_end=billing_period_end,
|
||||
@@ -410,15 +429,21 @@ class RegisterSerializer(serializers.Serializer):
|
||||
billing_period_start=billing_period_start,
|
||||
billing_period_end=billing_period_end,
|
||||
)
|
||||
# Seed a default bank transfer payment method for the account
|
||||
# Create AccountPaymentMethod with selected payment method
|
||||
payment_method_display_names = {
|
||||
'stripe': 'Credit/Debit Card (Stripe)',
|
||||
'paypal': 'PayPal',
|
||||
'bank_transfer': 'Bank Transfer (Manual)',
|
||||
'local_wallet': 'Mobile Wallet (Manual)',
|
||||
}
|
||||
AccountPaymentMethod.objects.create(
|
||||
account=account,
|
||||
type='bank_transfer',
|
||||
display_name='Bank Transfer (Manual)',
|
||||
type=payment_method,
|
||||
display_name=payment_method_display_names.get(payment_method, payment_method.title()),
|
||||
is_default=True,
|
||||
is_enabled=True,
|
||||
is_verified=False,
|
||||
instructions='Please complete bank transfer and add your reference in Payments.',
|
||||
instructions='Please complete payment and confirm with your transaction reference.',
|
||||
)
|
||||
|
||||
return user
|
||||
|
||||
Reference in New Issue
Block a user