0

Everything is working apart from notify url receiver call back is not working Following are the codes in my views.py

def view_that_asks_for_money(request):
# generating invoice id
total_invoices = 0
invoices_of_user = Invoice.objects.all().filter(user__username__exact=request.user.username)
if invoices_of_user:
    total_invoices = len(invoices_of_user)
total_invoices += 1
invoice_key = request.user.username + "-" + str(total_invoices)
Invoice.objects.create(user=request.user, invoice_no=invoice_key)
print(invoice_key, reverse('paypal-ipn'))
valid_ipn_received.connect(receiver=show_me_the_money)
print(valid_ipn_received.receivers)
# What you want the button to do.
paypal_dict = {
    "business": "osama.jameel.ahmad-facilitator@gmail.com",
    "amount": "14.99",
    "item_name": "One Month Premium Package",
    "invoice": invoice_key,
    "notify_url": "http://0.0.0.0:8000/" + reverse('paypal-ipn'),
    "return_url": "http://0.0.0.0:8000/app/dashboard",
    "cancel_return": "http://0.0.0.0:8000/app/change_password",
}
# Create the instance.
form = PayPalPaymentsForm(initial=paypal_dict)
context = {"form": form}

return render_to_response("core/payment.html", context)

@require_POST
@csrf_exempt
def ipn(request):
    print("ipn(request)")

also the receiver method in views.py

def show_me_the_money(sender, **kwargs):
print("show_me_the_money: ")
ipn_obj = sender
print("show_me_the_money: " + ipn_obj.payment_status)

and following are urls in in my urls.py

url(r'^paypal_ipn/', views.ipn, name="paypal-ipn"),
url(r'^something/paypal/', include('paypal.standard.ipn.urls')),
#patterns('paypal.standard.ipn.views',url(r'^paypal_notification/', 'ipn', name="paypal-ipn"),)
#url(r'^show_me_the_money/', core_views.show_me_the_money, name='show_me_the_money'),
url(r'^payment/', core_views.view_that_asks_for_money, name='paypal_page'),
Osama Jameel Ahmad
  • 119
  • 1
  • 1
  • 11
  • `0.0.0.0` isn't a valid IP address. You should use the actual IP address or domain name of your Django server. Using `http://localhost:8000` will work for `return_url` and `cancel_return`, but you can't use it for `notify_url` because PayPal's servers won't be able to access it. – Alasdair Oct 15 '18 at 10:10
  • Thanks, okay I have to finalize my development after pushing to live domain right? Do you see any issues in my code or is it good enough? – Osama Jameel Ahmad Oct 15 '18 at 10:46
  • I can’t review your code for you. Ideally you want a staging environment on a public IP that can test notifications from the PayPal sandbox, instead of pushing straight to the live domain. – Alasdair Oct 15 '18 at 11:47
  • okay thank you so much. – Osama Jameel Ahmad Oct 15 '18 at 15:24

0 Answers0