gpt4 book ai didi

python - Django,收不到paypal ipn通知

转载 作者:太空宇宙 更新时间:2023-11-04 04:46:53 25 4
gpt4 key购买 nike

我正在尝试将 django 应用程序与 paypal 支付网关集成,但我没有收到信号,而且我无法接收 paypal ipn 通知,

模型.py

class Pr_request(models.Model):
number = models.CharField(max_length=20)
subject = models.TextField(max_length=500)
date_posted = models.DateTimeField(auto_now_add=True)

class Purchase(models.Model):
resourse = models.ForeignKey(Pr_request, related_name='purchase')
purchaser = models.ForeignKey(User)
purchased_at = models.DateTimeField(auto_now_add=True)

views.py ti 创建 payment_dic

def payment_proccess(request, id):
pr = get_object_or_404(Pr_request, id=id)
host = request.get_host()

paypal_dict = {

'business': settings.PAYPAL_RECEIVER_EMAIL,
'amount': '%.2f' % pr.fees.quantize(Decimal('.01')),
'item_name': 'purchase Req {}'.format(pr.number),
'invoice': '2',
'currency_code': 'USD',
'notifiy_url' : 'http://da...879.ngrok.io',#also i tried
localhost
'return_url' : 'http://{}{}'.format(host, reverse('payment:done')),
'cancel_return': 'http://{}{}'.format(host, reverse('payment:canceled')),
}

form = PayPalPaymentsForm(initial=paypal_dict)
print (" iam pyament process function")
return render(request, 'payment/process.html', {'pr':pr, 'form':form})

信号.py

def payment_notification(request, sender, **kwargs):
ipn_obj = sender
if ipn_obj.payment_status == ST_PP_COMPLETED:
print ("successful payment was done Lol")
pr = get_object_or_404(Pr_request, id=ipn_obj.invoice)
pur = Purchase.objects.get_or_create(resourse=pr,
purchaser=request.user,
tx='some text')
pur.save()
#mark the pr as paid
else:
print (" not able to pay")
# payment was successful

valid_ipn_received.connect(payment_notification)
print ("signal is fired")

初始化.py

default_app_config = 'payment.apps.PaymentConfig'

请注意,每当我重新加载本地服务器时,都会触发我的信号,所以关于我的错误的任何想法,谢谢..

最佳答案

最后我发现了我的错误,这只是我的 views.py 中的错字

View .py

'notifiy_url'  : 'http://{}{}'.format(host, reverse('paypal-ipn')),
# should be changed to
'notify_url' : 'http://{}{}'.format(host, reverse('paypal-ipn')),
# also here i have set the logged in user
'payer': request.user,

关于python - Django,收不到paypal ipn通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49376263/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com