PayPal IPN 信号来注册用户



我正在尝试让两个第三方应用程序相互通信:Django-PayPal和django-registration。付款成功后,PayPal向提供的 URL 发送 IPN 信号。我希望这个信号来验证注册了django注册的用户。

成功付款后,似乎 IPN 不是由沙箱发送PayPal但我不确定它只是我的信号代码设置方式没有问题。

signals.py 在 init 中导入.py

import signals 

我正在使用 ngrok 允许PayPal沙盒访问我的本地主机。

views.py:

def payment(request):
    """
    This is the view for the page a new user is redirected
    to after registering (not activating) a new account.
    """
    paypal_dict = {
        "cmd": "_xclick-subscriptions",
        "business": settings.PAYPAL_RECEIVER_EMAIL,
        "a3": "7.99",
        "p3": "1",
        "t3": "M",
        "src": "1",
        "sra": "1",
        "no_note": "1",
        "item_name": "My Item",
        "notify_url": "http://localhost:8000/accounts/register/account_activated/",
        "return_url": "http://localhost:8000/",
        "cancel_return": "http//www.example.com/cancel-location/",

    }
    form = PayPalPaymentsForm(initial=paypal_dict, button_type="subscribe")
    context = {"form": form}
    return render_to_response("registration/registration_complete.html", context)

signlas.py:

from paypal.standard.models import ST_PP_COMPLETED
from paypal.standard.ipn.signals import valid_ipn_received, payment_was_flagged
from registration.models import RegistrationProfile
from registration.views import ActivationView
def payment_signal(sender, **kwargs):
    ipn_object = sender
    if ipn_object.payment_status == ST_PP_COMPLETED:
        print "payment_status == ST_PP_COMPLETED"
        """
        Here use django-registration to authenticate
        the User
        """
        activate_user(activation_key)
        activation_key = ACTIVATED
        #ActivationView.activate()
    else:
        print str(ipn_object.payment_status)
        print "error"
valid_ipn_received.connect(payment_signal)  
payment_was_flagged.connect(payment_signal)
print "SIGNALS MODULE IMPORTED"

urls.py:

url(r'^accounts/register/account_activated/$', include('paypal.standard.ipn.urls')),

可能是因为您使用的是测试端口(如 8000 )而不是标准端口80

当我切换到端口 80 时,我能够接收 IPN 通知、触发信号并适当地处理信号。

这个问题引导我走上了这条道路:我如何允许 django-merchant 接收PayPal IPN 构象?

相关内容

  • 没有找到相关文章

最新更新