2

現在、djangoを使用してサイトを開発しています。サイトをペイパルと統合する際に、プラグ可能なアプリケーション " http://github.com/johnboxall/django-paypal " を使用しています。ドキュメントは「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)

Paypal サイトで「続行」ボタンをクリックすると、「returnurl」にリダイレクトされます。これが私の問題です。この returnurl を処理する方法がわかりません。私の意見では、confirmation.html をレンダリングする関数も作成する必要があります。私は正しいですか?もしそうなら、この関数を書く方法。ヘルプと指示に本当に感謝しています。

4

2 に答える 2

1

ドキュメントはdjango-paypalには適していません。手短に言えreturnurlば、URL がメソッドを指すものであれば何でもよいということbuy_my_itemです。これは、私が作業中の IRL から取ったいくつかの例です。PayPal の「useraction=commit」オプションを使用して、エクスプレス チェックアウトのステップ数を減らしていることに注意してください。

あなたの urls.py で:

url(r'^pay-now/', views.pay_now, name='pay_now'),
url(r'^purchase-thanks/$', views.purchase_thanks, name='pay_success'),
url(r'^purchase-cancelled/$', views.purchase_thanks, name='pay_cancel'),

あなたの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は悪くありませんが、特にテンプレートに追加の値を渡したい場合や、ドキュメンテーション (私が見たフォークでさえ) があまり良くない場合は、それを機能させるのにかなりイライラする可能性があります。

この例では、HTTPS URL ではなく HTTP を参照していることに注意してください。WPP を使用する運用環境では、ほぼ確実に HTTPS を使用する必要があります。また、製品の主要なディストリビューションは古く@csrf_exemptなっているため、動作させるには IPN エンドポイントにパッチを適用する必要があります。

于 2011-01-16T16:06:48.767 に答える
0

こんにちは、私は同じ問題を抱えています。このhttp://uswaretech.com/blog/2008/11/using-paypal-with-django/によると、ペイパルからの応答を処理するビューを作成する必要があるため、使用しますconfirm.html テンプレートですが、何もレンダリングされません...

于 2010-09-15T06:22:19.573 に答える