Przelewy24 payment getway transaction notification not getting?

Viewed 48

I have implemented the Payment method and I had to provide URL_STATUS to get the payment status notification but when trying to catch the notification on my backend and I could not catch it "https://developers.przelewy24.pl/index.php?en#section/Payment-system/Transaction-process" this is their a document to get status.

here is my code in python.

class PaymentVerify(APIView):
def post(self, request):

    try:
        data = request.data
        data.get
    except (KeyError, ValueError, AttributeError):
        return Response(
            "Need valid JSON dictionary.", 404)

    if data:
        print(data)
        return Response(
            {'message': 'Payment successful!'},
            status=status.HTTP_200_OK)
    else:
        return Response(
            {'message': 'Payment unsuccessful!'},
            status=status.HTTP_400_OK)

I am not able to catch anything, can you please help me to catch this error. thanks

1 Answers

You have a few problems with your code.

In case of any error (except KeyError, ValueError, AttributeError) your data variable will not be set. So if data: part will raise another error. Move if/else part inside try/catch block unless you have a better option.

    ...
    try:
        data = request.data
        data.get
        if data:
            print(data)
            return Response({'message': 'Payment successful!'}, status=status.HTTP_200_OK)
        else:
            return Response({'message': 'Payment unsuccessful!'}, status=status.HTTP_400_OK)
    except (KeyError, ValueError, AttributeError):
        return Response(
            "Need valid JSON dictionary.", 404)

you can make those a bit better by using walrus operator (if your python version lets you so).

if data := some_result:
    do_something_with_data

The second problem is, you have just thrown away a documentation and two lines of code,

data = request.data
data.get

and asking where to set/get URL_STATUS and complaining about transaction notifications.

Please define your problem accurately and post your solution attempts too if any.

Related