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)