2015-10-06 16 views
0

我使用django-paypalpaypalrestsdk整合Paypal付款 & 訂閱到我的網站。如何才能在Django應用程序使用網絡掛接貝寶

我看過django-paypal和其他模塊,但我無法完全理解處理webhook的過程。

當我完成付款時,我在控制檯中收到405 Error

我已成功創建了一個用於測試目的的PayPal沙盒帳戶(爲其進行測試時自動創建了兩個用戶帳戶)。

在我settings.py

PAYPAL_RECEIVER_EMAIL = "the email" 
PAYPAL_IDENTITY_TOKEN = "_BB3dqp-crOrUo2uh84g0zN2alX0LwWPAT85r0g-2Eo0" 

在我index.html

<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post"> 
    <input type="hidden" name="business" value="my_email" id="id_business" /> 
    <input type="hidden" name="amount" value="1" id="id_amount" /> 
    <input type="hidden" name="item_name" value="Subscription Package" id="id_item_name" /> 
    <input type="hidden" name="notify_url" value="website/page" id="id_notify_url" /> 
    <input type="hidden" name="cancel_return" value="website/page" id="id_cancel_return" /> 
    <input type="hidden" name="return" value="website/page" id="id_return_url" /> 
    <input type="hidden" name="invoice" value="UID" id="id_invoice" /> 
    <input type="hidden" name="cmd" value="_xclick" id="id_cmd" /> 
    <input type="hidden" name="charset" value="utf-8" id="id_charset" /> 
    <input type="hidden" name="currency_code" value="USD" id="id_currency_code" /> 
    <input type="hidden" name="no_shipping" value="1" id="id_no_shipping" /> 
    <input type="image" src="https://www.sandbox.paypal.com/en_US/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" alt="Buy it Now" /> 
</form> 

而且我views.py

class PayPalWebhook(View): 
    @staticmethod 
    def post(request): 
     event_json = json.loads(request.body) 

     print '==========' 
     print event_json.type 
     print '==========' 
     print event_json 

     return HttpResponse(status=200) 

class PaypalAPI(View): 
    @staticmethod 
    def post(request): 
     pass 
  • 要我在PaypalAPI類的東西傳遞爲了讓我的表單能夠正常工作? (目前它正確發送付款,但它使用表單參數內的值,這不是我想要的)
  • 我該如何擺脫405錯誤?我做錯了什麼?(如提到的,我在儀表板中創建了一個webhook)

我只想在我的控制檯中看到webhooks,就這樣。

+0

你可能想看看dj-webhooks:https://dj-webhooks.readthedocs.org/en/latest/很多繁重的工作已經完成了。 – FlipperPA

回答

1

希望這有助於:405通常當您調用的API /端點使用了不正確的方法。例如,對於只支持GET或不使用正確端點的HTTP調用使用POST。

Python的軟件開發工具包是一個好點的開始以及https://github.com/paypal/PayPal-Python-SDK

此外,它的一個很好的做法,在論壇/ QNA網站不共享任何標記。 :)