2010-06-27 4 views
2

이제 django를 사용하여 내 사이트를 개발 중입니다. 내 사이트를 페이팔과 통합 할 때, 나는 플러그 형 응용 프로그램 "http://github.com/johnboxall/django-paypal"을 사용합니다. 이 문서는 "PayPal Payments Pro (WPP) 사용"에 대해 매우 명확하지만, "returnurl"과 "confirm_template"사이의 관계에 대해서는 여전히 몇 가지 질문이 있습니다.django-paypal에서 returnurl을 처리하는 방법 WPP

#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"로 다시 리디렉션됩니다. 여기, 내 문제는, 나는이 퇴거를 다루는 방법을 모른다. 필자는 confirm.html을 렌더링하는 함수를 작성해야한다고 생각합니다. 내가 맞습니까? 그렇다면이 함수를 작성하는 방법. 도움과 지침에 대해 정말 감사드립니다. ...

답변

1

설명서는 django-paypal에 적합하지 않습니다. 짧은 대답은 귀하의 returnurl이 귀하의 방법 인 buy_my_item을 가리키는 URL이어야한다는 것입니다. 다음은 IRL 작업에서 얻은 몇 가지 예입니다. Express Checkout의 단계 수를 줄이기 위해 PayPal의 "useraction = commit"옵션을 사용합니다. 당신의 views.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'), 

: 어떻게이 EC의 차이를 알 수 있습니다 "와 같은

""" 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) 

당신은 다른 질문에 무리가있을 수 있습니다 당신의 urls.py에서

WPP 지불을 지불 확인 페이지에 올리면 되겠습니까? "라고 물을 때까지 저장합니다! django-paypal은 나쁘지는 않지만, 특히 템플릿에 추가 값을 전달할 때 매우 실망 스러울 수 있으며 문서 (심지어 본 포크에서도)는 그리 좋지 않습니다.

이 예제는 HTTPS URL 대신 HTTP를 참조합니다. 프로덕션 환경에서 WPP를 사용하면 거의 확실하게 HTTPS를 사용하려고합니다. 또한 제품의 주요 배포본이 오래되었으므로 IPN 끝점을 패치하려면 @csrf_exempt으로 패치해야합니다.

+0

나는 앞으로 가서 물어볼 것이다. EC와 WPP 지불의 차이를 어떻게 알 수 있습니까? 또한 여기에 ipn 끝점을 설정할 필요가 있습니까? – joshcartme

+0

아, 사용자가 내 사이트에서 확인한 후 지불이 접수되었음을 확신합니까? – joshcartme

+1

request.POST.has_key [ 'email'] 그러면 WPP이고, 그렇지 않으면 EC입니다. EC 지불을 사용하여 사용자의 이메일 주소를 전달하는 다른 방법을 찾아야하며, 이는 어려울 수 있습니다. 그래, 지불이 이렇게 완료되었다고 확신 할 수 있습니다. 그러나 나는 IPN 콜백을 기다리는 경향이있다. 그리고 아니오, IPN 주소는 PayPal 구성에서 설정됩니다. 이것은 정말 짜증나게하고, IPN 끝점을 동적으로 변경할 수 없다는 것을 의미합니다. PayPal의 웹 폼을 사용하여 지불을 처리 할 수 ​​있지만 누가 사용하고 싶습니까? – afit

관련 문제