【发布时间】:2018-08-18 18:58:30
【问题描述】:
我正在使用 Django-Paypal 包将 Paypal 集成到我的 Django 项目中。我已经成功配置了所有内容并且它正在工作,但突然间来自 PayPal 的信号停止了。
会出现什么问题?
这是我所做的:
来自 view.py:
def payment_process(request):
minutes = int(request.user.tagging.count()) * 5
testhours = minutes / 60
hours = str(round(testhours, 3))
# pdb.set_trace()
# What you want the button to do.
invoice = generate_cid()
userInfo = {
"name": str(request.user.first_name + ' ' + request.user.last_name),
"hours": str(hours),
"taggedArticles": str(request.user.tagging.count())
}
paypal_dict = {
"business": settings.PAYPAL_RECEIVER_EMAIL,
"item_name": "Certificate of Completion from Nami Montana",
"custom": userInfo,
"invoice": str(invoice),
"amount": "5.00",
"notify_url": "https://6fd5e31b.ngrok.io/users/paypal/",
# "return_url": "https://6fd5e31b.ngrok.io/users/profile/",
"cancel_return": "https://6fd5e31b.ngrok.io/users/cancel/",
}
print(paypal_dict)
# Create the instance.
form = PayPalPaymentsForm(initial=paypal_dict)
context = {"form": form}
return render(request, "users/generateCert.html", context)
来自 urls.py:
urlpatterns = [
url('^paypal/', include('paypal.standard.ipn.urls')),
url('^profile/buildCertificate/$', views.CertificateProcess.as_view(), name='certificate'),
url('^cancel/$', views.payment_canceled, name='cancel'),
url('^done/$', views.payment_done, name='done'),
url('^process/$', views.payment_process, name='payment'),
]
来自 signals.py:
def show_me_the_money(sender, **kwargs):
ipn_obj = sender
custom = ipn_obj.custom
# Undertake some action depending upon `ipn_obj`.
if ipn_obj.payment_status == ST_PP_COMPLETED:
print('Get success signal')
user_info = ast.literal_eval(ipn_obj.custom)
if int(user_info['taggedArticles']) > 11:
# here i need to generate and send a pdf file to the user in a new tab
pass
else:
print('Get fail signal')
payment_was_successful.connect(show_me_the_money)
更新:当我用实时 IPN 沙箱测试它时,它返回
IPN was sent and the handshake was verified
付款成功存入PayPal沙盒商户账户,只是信号出现问题。
请帮帮我!
提前致谢!
【问题讨论】:
-
根据我的经验,paypal 沙箱有时会很慢。你等了多久的信号?另外,如果您不知道,您还可以在 django admin 中检查收到的 ipn 调用,这非常有用
-
嗨@hwhite4,即使在 Django 管理员中,PayPal IPN 也不会出现。
-
好的,你等了多久?沙箱有时发送 ipn 很慢
-
嗨@hwhite4,如果你的意思是等待回复,那么我想我已经通过等待2-3分钟来测试它!
-
好的,我还使用 ngrok 在沙盒上完成了测试,有时需要 20 多分钟才能获得 ipn,但有时会非常快。
标签: python django python-3.x paypal