Exemplo n.º 1
0
 def post(self, request, id):
     try:
         order = filter_query('order', {'id': id}).first()
         payment = filter_query('payment', {'order__id': order.id}).first()
         return SerializeResponse(request.data,
                                  self.serializer,
                                  save=True,
                                  id=payment)
     except AttributeError as e:
         print("-------------", e)
         return Response({
             "status": False,
             "code": 200,
             "message": "Please make you sure pass right order id",
             "data": {}
         })
Exemplo n.º 2
0
    def get_is_done(self, obj):
        artist = filter_query('artist', {'active': True})
        obj.order.artist = artist.order_by('?').first()
        obj.order.is_complete = True
        obj.order.status = 'CONFIRM'
        obj.order.save()
        obj.is_done = True
        obj.save()

        send_email_artist(obj.order)
        return True
Exemplo n.º 3
0
    def post(self, request, id):

        id = filter_query('book_service', {
            'order__id': id,
            'order__book_by': request.user
        })

        id.delete()

        return SerializeResponse(request.data,
                                 self.serializer,
                                 save=True,
                                 many=True)
Exemplo n.º 4
0
    def get_card(self, obj):

        query = filter_query('card_management', {'user__id': obj.book_by.id})
        data = query.last()
        data = query.first()

        if data:
            try:
                customer = stripe.Customer.retrieve(data.stripe_customer_id)
                return {
                    "card_id": data.id,
                    "last4": f"**** **** **** {customer.sources.data[0].last4}"
                }
            except Exception:
                return None

        return None
Exemplo n.º 5
0
    def post(self, request, id):

        data = filter_query('card_management', {
            'user__id': request.user.id
        }).update(default=False)

        id = get_object(model_app['payment'], {
            'id': id,
            'user__id': request.user.id
        })
        id.default = True
        id.save()

        return SerializeResponse(request.data,
                                 self.serializer,
                                 save=True,
                                 id=id,
                                 partial=True)
Exemplo n.º 6
0
    def post(self, request, id):

        data = self.payment_api().post(request)

        order = get_object(model_app['order'], {'id': id})
        order.pk = None
        order.is_reorder = True
        order.unique_id = str(uuid.uuid4())
        order.status = 'CONFIRM'
        order.save()

        book_services = filter_query('book_service', {'order__id': id})

        for service in book_services:
            obj = service
            obj.order = order
            obj.pk = None
            obj.save()

        return FetchSerializeResponse(order, self.serializer)
Exemplo n.º 7
0
class TipSerializer(serializers.ModelSerializer):

    tip = serializers.CharField(required=True,
                                allow_blank=False,
                                allow_null=False)
    tip_price = serializers.FloatField(required=True)

    card = serializers.PrimaryKeyRelatedField(
        queryset=filter_query('card_management', {}))

    class Meta:
        model = Payment
        fields = ['id', 'tip', 'tip_price', 'card']

    def validate(self, data):

        charge = stripe.Charge.create(
            customer=data['card'].stripe_customer_id,
            amount=int(data['tip_price'] * 100),
            currency="usd",
            description="Payment By Card for tips",
        )

        return data
Exemplo n.º 8
0
    def get_book_services(self, obj):

        query = filter_query('book_service', {'order__pk': obj.pk})
        return BookServiceDetailsSerializer(query, many=True).data
Exemplo n.º 9
0
    def get(self, request):

        data = filter_query('card_management', {'user__id': request.user.id})
        return FetchSerializeResponse(data, self.serializer, many=True)
Exemplo n.º 10
0
 def post(self, request):
     filter_query('card_management', {'user': request.user}).delete()
     return SerializeResponse(request.data, self.serializer, save=True)
Exemplo n.º 11
0
    def post(self, request):

        serializer = self.serializer(data=request.data)

        if serializer.is_valid():
            email = serializer.data.get('email')
            password = serializer.data.get('password')
            account_type = serializer.data.get('account_type')
            social_id = serializer.data.get('social_id')

            if account_type == 'A' or account_type == 'F':

                user_exist = filter_query('account',
                                          query={
                                              'email': email,
                                              "account_type": account_type
                                          }).exists()

                if not user_exist:

                    return ReturnResponse(
                        message='User is not register with this account',
                        code=ResponseStatus.HTTP_202_ACCEPTED)

                obj = get_object(model=self.model,
                                 query={
                                     'email': email,
                                     'social_id': social_id
                                 })

                if obj:

                    return ReturnResponse(message='Login successfully',
                                          data=self.userserializer(obj).data,
                                          status=True)
                else:

                    return ReturnResponse(
                        message='User is not register with this account')

            auth = authenticate(email=email, password=password)

            # ----check user is authenticated or not----
            if auth is not None:

                # ----check user in verified or not----
                if not auth.verify:
                    return ReturnResponse(message='This account is unverified',
                                          code=ResponseStatus.HTTP_201_CREATED,
                                          data=self.unverified_user(auth).data)

                login(request, auth)

                return ReturnResponse(message='Login successfully',
                                      data=self.userserializer(auth).data,
                                      status=True)

            else:
                return ReturnResponse(message='Invalid email or password',
                                      data=serializer.errors)

        return ReturnResponse(data=serializer.errors)
Exemplo n.º 12
0
    def get(self, request):

        query = filter_query('service', {'active': True})

        return FetchSerializeResponse(query, self.serializer, many=True)