【问题标题】:Django, cannot receive paypal ipn notificationDjango,无法收到贝宝 ipn 通知
【发布时间】:2018-03-20 04:16:33
【问题描述】:

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

models.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 创建 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})

signals.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'

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

【问题讨论】:

    标签: python django


    【解决方案1】:

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

    views.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,
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-03-13
      • 2016-06-11
      • 1970-01-01
      • 2016-04-15
      • 2016-05-27
      • 2013-01-11
      • 2018-06-29
      • 2012-07-22
      相关资源
      最近更新 更多