46 lines
1.3 KiB
Python
Executable File
46 lines
1.3 KiB
Python
Executable File
from rest_framework import serializers
|
|
from mnfapp.models import PaymentData
|
|
from .models import Refund, privilegedUser1
|
|
from django.contrib.auth import get_user_model
|
|
import razorpay
|
|
from django.conf import settings
|
|
from mnfapp.models import centralDatabase
|
|
|
|
# authorize razorpay client with API Keys.
|
|
razorpay_client = razorpay.Client(
|
|
auth=(settings.RAZORPAY_KEY_ID, settings.RAZORPAY_KEY_SECRET))
|
|
|
|
class PaymentDataSerializer(serializers.ModelSerializer):
|
|
isRefund = serializers.SerializerMethodField()
|
|
|
|
class Meta:
|
|
model = PaymentData
|
|
fields = '__all__'
|
|
|
|
def get_isRefund(self,obj):
|
|
payment = razorpay_client.payment.fetch(obj.payment_id)
|
|
if payment['status'] == 'captured':
|
|
return True
|
|
else:
|
|
return False
|
|
|
|
class RefundSerializer(serializers.ModelSerializer):
|
|
class Meta:
|
|
model= Refund
|
|
fields = "__all__"
|
|
|
|
User = get_user_model()
|
|
|
|
class UserSerializer(serializers.ModelSerializer):
|
|
class Meta:
|
|
model = User
|
|
fields = '__all__'
|
|
|
|
class privilegedUser1Serializer(serializers.ModelSerializer):
|
|
# user = UserSerializer()
|
|
class Meta:
|
|
model= privilegedUser1
|
|
fields = ['user', 'city', 'country', 'postal_code', 'state', 'email', 'phone', 'name']
|
|
|
|
|
|
|