django - 在 Django 应用程序中实现 PayPal IPN

标签 django paypal paypal-ipn django-2.0

我正在用 Django 2.0 编写应用程序

这是一个多成员(member)应用程序。我必须实现 PayPal 付款方式并根据收到的付款激活成员(member)资格。

为此,我在 PayPal 中创建了一个按钮,生成代码为

升级.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 页面。

但是我如何收到付款确认,以便我可以处理成员(member)资格并将交易数据记录在数据库中?

我在 paypal 沙盒帐户 的设置中启用了即时付款通知,网址为 https://example.com/paypal-ipn/

由于某些限制,我不想使用 django-paypal 插件。

最佳答案

您可以创建自己的 IPN 处理页面来接收 PayPal IPN 消息。下面的 IPN 示例代码。

https://github.com/paypal/ipn-code-samples

关于django - 在 Django 应用程序中实现 PayPal IPN,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48066824/

相关文章:

python - 返回时Django聚合字段错误

django - 在 Django 中添加查询集中的所有值

rest - 为订阅调用 PayPal REST API 执行 URL 时到底发生了什么

php - Paypal Mass Payment Api 使用 Sandbox 获取非 paypal 电子邮件的通知

PayPal IPN 和买家地址

php - 地址中嵌入换行符的 Paypal IPN 错误

django - 使用 celery 在 Django 中实现 SOA

python - 在 HTML 模板中显示来自 sqlite 的数据时出现错误

rest - PayPal REST API - 如何获取在网络挂接中返回的电子邮件地址?

php - 为什么我从 PayPal 的 IPN 获得 2 次不同数据的匹配?