forked from uncloud/uncloud
72 lines
2.5 KiB
Python
72 lines
2.5 KiB
Python
from django.contrib.auth import get_user_model
|
|
from rest_framework import serializers
|
|
from .models import *
|
|
|
|
###
|
|
# Payments and Payment Methods.
|
|
|
|
class PaymentSerializer(serializers.ModelSerializer):
|
|
class Meta:
|
|
model = Payment
|
|
fields = '__all__'
|
|
|
|
class PaymentMethodSerializer(serializers.ModelSerializer):
|
|
stripe_card_last4 = serializers.IntegerField()
|
|
|
|
class Meta:
|
|
model = PaymentMethod
|
|
fields = ['uuid', 'source', 'description', 'primary', 'stripe_card_last4', 'active']
|
|
|
|
class UpdatePaymentMethodSerializer(serializers.ModelSerializer):
|
|
class Meta:
|
|
model = PaymentMethod
|
|
fields = ['description']
|
|
|
|
class ChargePaymentMethodSerializer(serializers.Serializer):
|
|
amount = serializers.DecimalField(max_digits=10, decimal_places=2)
|
|
|
|
class CreatePaymentMethodSerializer(serializers.ModelSerializer):
|
|
please_visit = serializers.CharField(read_only=True)
|
|
class Meta:
|
|
model = PaymentMethod
|
|
fields = ['uuid', 'primary', 'source', 'description', 'please_visit']
|
|
read_only_field = ['uuid', 'primary']
|
|
|
|
###
|
|
# Orders & Products.
|
|
|
|
class OrderRecordSerializer(serializers.ModelSerializer):
|
|
class Meta:
|
|
model = OrderRecord
|
|
fields = ['one_time_price', 'recurring_price', 'description']
|
|
|
|
|
|
class OrderSerializer(serializers.ModelSerializer):
|
|
records = OrderRecordSerializer(many=True, read_only=True)
|
|
class Meta:
|
|
model = Order
|
|
fields = ['uuid', 'creation_date', 'starting_date', 'ending_date',
|
|
'bill', 'recurring_period', 'records', 'recurring_price', 'one_time_price']
|
|
|
|
|
|
###
|
|
# Bills
|
|
|
|
# TODO: remove magic numbers for decimal fields
|
|
class BillRecordSerializer(serializers.Serializer):
|
|
order = serializers.HyperlinkedRelatedField(
|
|
view_name='order-detail',
|
|
read_only=True)
|
|
description = serializers.CharField()
|
|
recurring_period = serializers.CharField()
|
|
recurring_price = serializers.DecimalField(max_digits=10, decimal_places=2)
|
|
recurring_count = serializers.DecimalField(max_digits=10, decimal_places=2)
|
|
one_time_price = serializers.DecimalField(max_digits=10, decimal_places=2)
|
|
amount = serializers.DecimalField(max_digits=10, decimal_places=2)
|
|
|
|
class BillSerializer(serializers.ModelSerializer):
|
|
records = BillRecordSerializer(many=True, read_only=True)
|
|
class Meta:
|
|
model = Bill
|
|
fields = ['reference', 'owner', 'total', 'due_date', 'creation_date',
|
|
'starting_date', 'ending_date', 'records', 'final']
|