該文檔不適用於django-paypal。簡短的回答是你的returnurl
應該是任何URL指向你的方法buy_my_item
。以下是我從事IRL工作的幾個例子。請注意,我使用PayPal的「useraction = commit」選項來減少Express Checkout中的步驟數。
在你的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並不差,但它可能會讓你感覺很沮喪,特別是當你想向你的模板傳遞額外的值時,文檔(甚至在我見過的叉子上)都不太好。
請注意,此示例引用HTTP而不是HTTPS URL。在生產中,使用WPP,你幾乎肯定會想要使用HTTPS。此外,該產品的主要分發版已過時,您需要使用@csrf_exempt
修補IPN端點才能使其工作。
我要繼續提問。我如何分辨EC和WPP付款之間的差異?另外,我是否需要在這裏設置ipn端點? – joshcartme 2011-05-19 16:50:41
哦,並且在用戶在我的網站上確認我確定已收到付款? – joshcartme 2011-05-19 16:56:53
如果request.POST.has_key ['email']那麼它是一個WPP,否則它是EC。你需要找到另一種方式來通過用戶的電子郵件地址與EC付款,這可能是一個痛苦。是的,你可以確定付款已經完成了這種方式。不過,我傾向於等待IPN回撥。不,IPN地址在您的PayPal配置中設置。這真是令人煩惱,並且意味着您不能動態更改IPN端點。如果您使用PayPal的webforms處理付款,您可以,但是誰想要使用它們? – afit 2011-06-04 11:35:06