当前位置: 动力学知识库 > 问答 > 编程问答 >

python - Django-paypal doesn't receive signals

问题描述:

I'm trying to create a simple Paypal pay in my project, just to see if it works and then make it more custom. The problem is that it doesn't work as I expected. When I make a payment (using sandbox), [email protected]gmail.com sents money succesfully but myemail-facilitator doesn't have any notifications there (but recieved money). Moreover, no signal is being recieved and no Paypal IPNS rows are in Django-admin Paypal IPNs.

It can be probably many things and since I'm new in django-paypal I can't figure out what's the problem.

I'm using developlment server but it is accessible from outside.

VIEW

def payment(request):

items = Job.get_unpaid_orders_for_user(request.user)

table = PaymentTable(items)

total_price = 0

payment = Payment.objects.create()

for item in items:

if item.invoice.final_price:

payment.invoices.add(item.invoice)

total_price += item.invoice.final_price

payment.total_price = total_price

payment.save()

context = {}

context['items'] = items

context['table'] = table

context['total_price'] = total_price

paypal_dict = {

"business": "[email protected]",

"currency_code":"EUR",

"amount": total_price,

"item_name": payment.get_desc(),

"invoice": payment.payment_identifier,

"notify_url": "http://my_public_ip:8000/" + reverse('paypal-ipn'),

"return_url": "http://my_public_ip:8000/return",

"cancel_return": "http://my_public_ip:8000/cancel",

"custom": "Upgrade all users!", # Custom command to correlate to some function later (optional)

}

form = PayPalPaymentsForm(initial=paypal_dict)

context["form"]=form

return render(request, "ordersapp/payment/payment.html", context=context)

BOTTOM OF MODELS.PY OF ORDERSAPP

from paypal.standard.models import ST_PP_COMPLETED

from paypal.standard.ipn.signals import valid_ipn_received

def show_me_the_money(sender, **kwargs):

ipn_obj = sender

print ipn_obj

try:

print ipn_obj.__dict__

except: print ipn_obj.__dict__()

if ipn_obj.payment_status == ST_PP_COMPLETED:

# WARNING !

# Check that the receiver email is the same we previously

# set on the business field request. (The user could tamper

# with those fields on payment form before send it to PayPal)

if ipn_obj.receiver_email != "[email protected]":

# Not a valid payment

return

# ALSO: for the same reason, you need to check the amount

# received etc. are all what you expect.

# Undertake some action depending upon `ipn_obj`.

if ipn_obj.custom == "Upgrade all users!":

# Users.objects.update(paid=True)

print 'PAYMENT OK'

else:

print 'BAD'

#...

valid_ipn_received.connect(show_me_the_money)

SETTINGS.PY

INSTALLED_APPS = (

'django.contrib.auth',

'mainapp',

'django.contrib.admin',

'django.contrib.contenttypes',

'django.contrib.sessions',

'django.contrib.messages',

'django.contrib.sites',

'django.contrib.staticfiles',

....

....

'paypal',

'paypal.standard.ipn'

)

PAYPAL_RECEIVER_EMAIL = "[email protected]"

PAYPAL_TEST = True

分享给朋友:
您可能感兴趣的文章:
随机阅读: