【发布时间】:2018-06-12 12:06:50
【问题描述】:
我正在Django 2.0写一个应用程序
这是一个多会员应用程序。我必须执行PayPal 付款方式并根据收到的付款激活会员。
为此,我在 PayPal 中创建了一个按钮,生成代码为
upgrade.html
<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post" target="_top">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="<button-id>">
<input type="image" src="https://www.sandbox.paypal.com/en_US/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
<img alt="" border="0" src="https://www.sandbox.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>
而 views.py 是
class Pricing(TemplateView):
template_name = 'membership/pricing.html'
class Upgrade(TemplateView):
template_name = 'membership/upgrade.html'
class PaymentSuccess(TemplateView):
template_name = 'membership/payment-success.html'
class PaymentFailed(TemplateView):
template_name = 'membership/payment-failed.html'
def paypal_ipn(request):
# IPN response goes here
和 urls.py
urlpatterns = [
path('pricing/', Pricing.as_view(), name='pricing'),
path('upgrade/', Upgrade.as_view(), name='upgrade'),
path('payment-success/', PaymentSuccess.as_view(), name='payment-success'),
path('payment-failed/', PaymentFailed.as_view(), name='payment-failed'),
path('paypal-ipn/', paypal_ipn, name='paypal-ipn'),
]
付款时一切正常,用户被重定向到payment-success页面。
但是我如何收到付款确认,以便处理会员资格并将交易数据记录在数据库中?
我已经在paypal sandbox accoun 的设置中启用了instant payment notification https://example.com/paypal-ipn/
由于某些限制,我不想使用django-paypal 插件。
【问题讨论】:
标签: django paypal paypal-ipn django-2.0