Not getting Django paypal IPN handshake
Asked Answered
S

0

0

I am trying to implement Django- PayPal in my project , now it has been 3 days , I am still stuck on this , I don't understand how we perform IPN handshake, I am receiving a signal from PayPal after payment but what is the next step after this , really frustrated there are no clear docs about this process help needed , thanks in advance

Signals.py

def show_me_the_money(sender, **kwargs):
    ipn_obj = sender
    if ipn_obj.payment_status == ST_PP_COMPLETED:
      

        

        # WARNING !
        # Check that the receiver email is the same we previously
        # set on the `business` field. (The user could tamper with
        # that fields on the payment form before it goes to PayPal)

        if ipn_obj.receiver_email != settings.PAYPAL_RECEIVER_EMAIL:
        # Not a valid payment
            print('reciever mail is diff')
            print(ipn_obj.receiver_email)
            

        # ALSO: for the same reason, you need to check the amount
        # received, `custom` etc. are all what you expect or what
        # is allowed.

        # Undertake some action depending upon `ipn_obj`.
        if ipn_obj.custom == "premium_plan":
            price = ...
        else:
            price = ...

        if ipn_obj.mc_gross == price and ipn_obj.mc_currency == 'USD':
            ...
        else:
            pass
            #...
            



valid_ipn_received.connect(show_me_the_money)

Urls.py

path('payment/',PaymentProcess.as_view(),name='payment-process'),  
path('payment_redirect/',Payment.as_view(),name='payment-redirect'),  
path('createorder/',CreateOrderView.as_view(),name='create-order'),  
#  Paypal IPN url ------------------

re_path(r'^paypal/', include('paypal.standard.ipn.urls')),
path('payment_done', payment_done,name='payment_done'),

I mean where should the below code reside or do I even need to process it, as I see other resources doing it , they are sending Response back to Paypal as confirming the payment https://github.com/paypal/ipn-code-samples/blob/master/python/paypal_ipn.py

verify_url = settings.VERIFY_URL_TEST
            print ('content-type: text/plain')
            print ()
            print('SIgnal form paypal')
    
            param_str = sys.stdin.readline().strip()
            print(param_str)
            params = urllib.parse.parse_qsl(param_str)
    
            params.append(('cmd', '_notify-validate'))
    
            print(params)
    
            headers = {'content-type': 'application/x-www-form-urlencoded',
               'user-agent': 'Python-IPN-Verification-Script'}
    
    
            r = requests.post(verify_url, params=params, headers=headers, verify=True)
            r.raise_for_status()
            print(r)
Sleet answered 13/11, 2021 at 14:4 Comment(5)
Why are you using IPN?Wooster
I believe we have to respond to the signal sent by Paypal , once the payment happens , but what I am confused about is, After receiving the signal what is the further process! i have also updated my questionSleet
The only response you must send for an IPN to be acknowledged as received, is an HTTP 200 status. However the question is why you are using IPN at all, since in 2021 you should be doing something else.Wooster
So what am I supposed to not send a response at all ,?Sleet
As mentioned, a response status of HTTP 200 is the only thing required for an IPN to be received. What you are supposed to do beyond that, including verifying it, depends on whether you will actually be making use of the IPN message for anything, And for that to be a factor you first need to have an answer to the question of why you are using IPN. And it should be a good answer. If you don't have one, don't use IPN.Wooster

© 2022 - 2024 — McMap. All rights reserved.