我试图在我的项目中创建一个简单的Paypal支付,只是为了看它是否有效,然后让它更加自定义。问题是它没有像我预期的那样工作。当我付款(使用沙盒)时,myemail-buyer @ gmail.com成功地获得了金钱,但myemail-facilitator在那里没有任何通知(但收到了钱)。此外,没有收到任何信号,Django-admin Paypal IPNS
中没有Paypal IPNs
行。
这可能是很多事情,因为我是django-paypal的新手,我无法弄清楚问题是什么。
我使用的是开发服务器,但可以从外部访问。
查看
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": "myemail-facilitator@gmail.com",
"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)
模型的底部。订购数量
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 != "receiver_email@example.com":
# 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 = "myemail-facilitator@gmail.com"
PAYPAL_TEST = True