如何处理 django-paypal 中的 returnurl for paypal WPP

发布于 2024-09-07 09:31:35 字数 1242 浏览 1 评论 0原文

我现在正在使用 django 开发我的网站。在将我的网站与 paypal 集成时,我使用可插入应用程序“http://github.com/johnboxall/django-贝宝”。虽然文档对于“Using PayPal Payments Pro (WPP)”说得很清楚,但我仍然有一些疑问,特别是“returnurl”和“confirm_template”之间的关系。

#views.py
from paypal.pro.views import PayPalPro

def buy_my_item(request):
   item = {"amt": "10.00",             # amount to charge for item
           "inv": "inventory",         # unique tracking variable paypal
           "custom": "tracking",       # custom tracking variable for you
           "cancelurl": "http://...",  # Express checkout cancel url
           "returnurl": "http://..."}  # Express checkout return url

   kw = {"item": item,                            # what you're selling
         "payment_template": "payment.html",      # template name for payment
         "confirm_template": "confirmation.html", # template name for confirmation
         "success_url": "/success/"}              # redirect location after success

   ppp = PayPalPro(**kw)
   return ppp(request)

当点击贝宝网站上的“继续”按钮时,它会将我重定向回“returnurl”。这是我的问题,我不知道如何处理这个 returnurl。在我看来,我还应该编写一个函数来使其呈现confirmation.html。我说得对吗?如果可以的话这个函数怎么写。 非常感谢任何帮助和指示。

I am now developing my site using django. In integrating my site with paypal, I use pluggable application "http://github.com/johnboxall/django-paypal". Although the document is very clear for "Using PayPal Payments Pro (WPP)", but I still have some questions, especially the relationship between "returnurl" and "confirm_template".

#views.py
from paypal.pro.views import PayPalPro

def buy_my_item(request):
   item = {"amt": "10.00",             # amount to charge for item
           "inv": "inventory",         # unique tracking variable paypal
           "custom": "tracking",       # custom tracking variable for you
           "cancelurl": "http://...",  # Express checkout cancel url
           "returnurl": "http://..."}  # Express checkout return url

   kw = {"item": item,                            # what you're selling
         "payment_template": "payment.html",      # template name for payment
         "confirm_template": "confirmation.html", # template name for confirmation
         "success_url": "/success/"}              # redirect location after success

   ppp = PayPalPro(**kw)
   return ppp(request)

When clicking the "continue" button on paypal site, it redirects me back to "returnurl". Here, is my problem, I don't know how to deal with this returnurl. In my opinion, I should also write a function to make it render confirmation.html. Am I right? If so, how to write this function.
Really grateful for any help and instructions.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

静待花开 2024-09-14 09:31:35

该文档对于 django-paypal 来说不太好。简而言之,您的 returnurl 应该是指向您的方法 buy_my_item 的任何 URL。以下是我在现实生活中工作的一些例子。请注意,我使用 PayPal 的“useraction=commit”选项来减少其快速结帐中的步骤数。

在你的urls.py中:

url(r'^pay-now/', views.pay_now, name='pay_now'),
url(r'^purchase-thanks/

在你的views.py中:

""" User payment method endpoint for rendering and processing forms. """
@csrf_exempt
def pay_now( request ):
    # Override django-paypal library endpoints to include 'useraction=commit'
    # which changed PayPal's review page to be a 'pay now' page.
    # This is ugly but I didn't want to subclass.
    from paypal.pro import views as pro_views
    pro_views.EXPRESS_ENDPOINT = "https://www.paypal.com/webscr?cmd=_express-checkout&useraction=commit&%s"
    pro_views.SANDBOX_EXPRESS_ENDPOINT = "https://www.sandbox.paypal.com/webscr?cmd=_express-checkout&useraction=commit&%s"

    # ...because we use 'useraction=commit', there's no need to show the confirm page.
    # So let's change the request to show the confirmation form into a request to
    # approve it. It just so happens that the arguments are the same -- the difference
    # is between the GET and the POST.
    # <input type="hidden" name="token" value="EC-485941126E653491T" id="id_token"/>
    # <input type="hidden" name="PayerID" value="78W69D3FEVWJBC" id="id_PayerID"/>
    if request.method == 'GET' and 'token' in request.GET and 'PayerID' in request.GET:
        request.method = 'POST'
        request.POST = request.GET # Crudely convert GET to POST

    item = {
        'amt':           99.99, # Amount to charge for item
        'currencycode':  'usd',
        #'inv':           1, # Unique tracking variable paypal - must be a number.
        #'desc':          'Your product name', # Deprecated by PayPal, don't bother
                                               # (you'll get the name twice in your statement otherwise)
        'custom':        'custom1', # Custom tracking variable for you. Realistically you have to pass
                                    # this if you're specifying basket contents to PayPal as django-paypal
                                    # won't be given `item_name` in the IPN, only `item_name1` etc.
                                    # which it cannot interpret.
        'cancelurl':     'http://%s%s' % DYNAMIC_URL, reverse('pay_cancel')), # Express checkout cancel url
        'returnurl':     'http://%s%s' % (DYNAMIC_URL, reverse('pay_now')), # Express checkout return url
        'allownote':     0, # Disable "special instructions for seller"
        'l_name0':       'Your product name',
        #'l_number0':    1234,
        #'l_desc0':      'longer description',
        'l_amt0':        99.99,
        'l_qty0':        1,
        'itemamt':       99.99,
        #'taxamt':       0.00,
        #'shippingamt':  0.00,
        #'handlingamt':  0.00,
        #'shipdiscamt':  0.00,
        #'insuranceamt': 0.00,
    }

    kw = {
        'item': item,
        'payment_template': 'cms/register.html', # Template name for payment
        'confirm_template': 'cms/paypal-confirmation.html', # Template name for confirmation
        'success_url':      reverse('pay_success'), # Ultimate return URL
    }

    ppp = PayPalPro(**kw)
    return ppp(request)

你可能还有很多其他问题,比如“当我进入付款确认页面时,如何区分EC和WPP付款?”,但我'会保存它直到有人询问为止! django-paypal 还不错,但是让它工作起来可能会非常令人沮丧,特别是当你想要将附加值传递给您的模板,而文档(即使是我见过的分叉)也不是很好。

请注意,此示例指的是 HTTP 而不是 HTTPS URL。在生产中,使用 WPP,您几乎肯定会希望使用 HTTPS。此外,该产品的主要发行版已过时,您需要使用 @csrf_exempt 修补 IPN 端点才能使其正常工作。

, views.purchase_thanks, name='pay_success'), url(r'^purchase-cancelled/

在你的views.py中:


你可能还有很多其他问题,比如“当我进入付款确认页面时,如何区分EC和WPP付款?”,但我'会保存它直到有人询问为止! django-paypal 还不错,但是让它工作起来可能会非常令人沮丧,特别是当你想要将附加值传递给您的模板,而文档(即使是我见过的分叉)也不是很好。

请注意,此示例指的是 HTTP 而不是 HTTPS URL。在生产中,使用 WPP,您几乎肯定会希望使用 HTTPS。此外,该产品的主要发行版已过时,您需要使用 @csrf_exempt 修补 IPN 端点才能使其正常工作。

, views.purchase_thanks, name='pay_cancel'),

在你的views.py中:

你可能还有很多其他问题,比如“当我进入付款确认页面时,如何区分EC和WPP付款?”,但我'会保存它直到有人询问为止! django-paypal 还不错,但是让它工作起来可能会非常令人沮丧,特别是当你想要将附加值传递给您的模板,而文档(即使是我见过的分叉)也不是很好。

请注意,此示例指的是 HTTP 而不是 HTTPS URL。在生产中,使用 WPP,您几乎肯定会希望使用 HTTPS。此外,该产品的主要发行版已过时,您需要使用 @csrf_exempt 修补 IPN 端点才能使其正常工作。

The documentation isn't great for django-paypal. The short answer is that your returnurl should be whatever URL points to your method buy_my_item. Here's a few examples taken from something I have working IRL. Note that I use PayPal's "useraction=commit" option to reduce the number of steps in their Express Checkout.

In your urls.py:

url(r'^pay-now/', views.pay_now, name='pay_now'),
url(r'^purchase-thanks/

In your views.py:

""" User payment method endpoint for rendering and processing forms. """
@csrf_exempt
def pay_now( request ):
    # Override django-paypal library endpoints to include 'useraction=commit'
    # which changed PayPal's review page to be a 'pay now' page.
    # This is ugly but I didn't want to subclass.
    from paypal.pro import views as pro_views
    pro_views.EXPRESS_ENDPOINT = "https://www.paypal.com/webscr?cmd=_express-checkout&useraction=commit&%s"
    pro_views.SANDBOX_EXPRESS_ENDPOINT = "https://www.sandbox.paypal.com/webscr?cmd=_express-checkout&useraction=commit&%s"

    # ...because we use 'useraction=commit', there's no need to show the confirm page.
    # So let's change the request to show the confirmation form into a request to
    # approve it. It just so happens that the arguments are the same -- the difference
    # is between the GET and the POST.
    # <input type="hidden" name="token" value="EC-485941126E653491T" id="id_token"/>
    # <input type="hidden" name="PayerID" value="78W69D3FEVWJBC" id="id_PayerID"/>
    if request.method == 'GET' and 'token' in request.GET and 'PayerID' in request.GET:
        request.method = 'POST'
        request.POST = request.GET # Crudely convert GET to POST

    item = {
        'amt':           99.99, # Amount to charge for item
        'currencycode':  'usd',
        #'inv':           1, # Unique tracking variable paypal - must be a number.
        #'desc':          'Your product name', # Deprecated by PayPal, don't bother
                                               # (you'll get the name twice in your statement otherwise)
        'custom':        'custom1', # Custom tracking variable for you. Realistically you have to pass
                                    # this if you're specifying basket contents to PayPal as django-paypal
                                    # won't be given `item_name` in the IPN, only `item_name1` etc.
                                    # which it cannot interpret.
        'cancelurl':     'http://%s%s' % DYNAMIC_URL, reverse('pay_cancel')), # Express checkout cancel url
        'returnurl':     'http://%s%s' % (DYNAMIC_URL, reverse('pay_now')), # Express checkout return url
        'allownote':     0, # Disable "special instructions for seller"
        'l_name0':       'Your product name',
        #'l_number0':    1234,
        #'l_desc0':      'longer description',
        'l_amt0':        99.99,
        'l_qty0':        1,
        'itemamt':       99.99,
        #'taxamt':       0.00,
        #'shippingamt':  0.00,
        #'handlingamt':  0.00,
        #'shipdiscamt':  0.00,
        #'insuranceamt': 0.00,
    }

    kw = {
        'item': item,
        'payment_template': 'cms/register.html', # Template name for payment
        'confirm_template': 'cms/paypal-confirmation.html', # Template name for confirmation
        'success_url':      reverse('pay_success'), # Ultimate return URL
    }

    ppp = PayPalPro(**kw)
    return ppp(request)

You may have a bunch of other questions, like "how can I tell the difference between an EC and a WPP payment when I get to the payment confirmation page?", but I'll save that until it's asked! django-paypal isn't bad, but it can be pretty frustrating making it work, particularly when you want to pass additional values to your templates, and the documentation (even on the forks I've seen) isn't much good.

Note that this example refers to HTTP rather than HTTPS URLs. In production, using WPP, you'll almost certainly want to be using HTTPS. Also, the main distribution of the product is out of date, and you'll need to patch the IPN endpoint with @csrf_exempt to make it work.

, views.purchase_thanks, name='pay_success'), url(r'^purchase-cancelled/

In your views.py:


You may have a bunch of other questions, like "how can I tell the difference between an EC and a WPP payment when I get to the payment confirmation page?", but I'll save that until it's asked! django-paypal isn't bad, but it can be pretty frustrating making it work, particularly when you want to pass additional values to your templates, and the documentation (even on the forks I've seen) isn't much good.

Note that this example refers to HTTP rather than HTTPS URLs. In production, using WPP, you'll almost certainly want to be using HTTPS. Also, the main distribution of the product is out of date, and you'll need to patch the IPN endpoint with @csrf_exempt to make it work.

, views.purchase_thanks, name='pay_cancel'),

In your views.py:

You may have a bunch of other questions, like "how can I tell the difference between an EC and a WPP payment when I get to the payment confirmation page?", but I'll save that until it's asked! django-paypal isn't bad, but it can be pretty frustrating making it work, particularly when you want to pass additional values to your templates, and the documentation (even on the forks I've seen) isn't much good.

Note that this example refers to HTTP rather than HTTPS URLs. In production, using WPP, you'll almost certainly want to be using HTTPS. Also, the main distribution of the product is out of date, and you'll need to patch the IPN endpoint with @csrf_exempt to make it work.

旧人 2024-09-14 09:31:35

大家好,我遇到了同样的问题,根据这个http: //uswaretech.com/blog/2008/11/using-paypal-with-django/我们需要编写一个视图来处理来自paypal的响应,所以我使用confirm.html模板,但它不渲染任何东西...

Hi guys i'm with the same problem, according to this http://uswaretech.com/blog/2008/11/using-paypal-with-django/ we need to write a view that handle response from paypal, so i use confirm.html template but it doesn't render anything...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文