2017-10-07 28 views
0

私は自分のウェブサイトにオンライン決済ポータルを設定しています。 私はコードの下に使用します。404 suds要求でエラーが見つかりませんでした。 - python - django

ZARINPAL_WEBSERVICE ='https://www.zarinpal.com/pg/services/WebGate/wsdl' # Required 
MERCHANT_ID = 'blah-blah-blah' # Required 
amount = 0 

@method_decorator(login_required, name='dispatch') 
class Upgrade(View): 
    def get(self, request): 
     current_plan = UserPlan.objects.filter(user=request.user).first() 
     all_plans = Plans.objects.all() 
     old_plans = None 
     if current_plan: 
      new_plans = all_plans.filter(no__gt=current_plan.no) 
      old_plans = all_plans.filter(no__lte=current_plan.no) 
     else: 
      new_plans = all_plans 

     return render(request, 'business/upgrade.html', {'current_plan': current_plan, 
                'new_plans': new_plans, 
                'old_plans': old_plans}) 

    def post(self, request): 
     current_plan = UserPlan.objects.filter(user=request.user).first() 
     form = UpgradeForm(request.POST) 
     if form.is_valid(): 
      new_plan = form.cleaned_data.get('requested_plan') 
      requested_plan = Plans.objects.filter(no=new_plan).first() 
      global amount 
      if current_plan: 
       amount = requested_plan.price - current_plan.price 
      else: 
       amount = requested_plan.price 

      # redirect to ZarinPal page and send data to it 
      description = u'TEST DESCRIPTION' # Required 
      email = form.cleaned_data.get('email') # Optional 
      mobile = form.cleaned_data.get('phone') # Optional 
      CallbackURL = 'http://127.0.0.1:8000/business/verify/' 
      client = Client(ZARINPAL_WEBSERVICE) 
      result = client.service.PaymentRequest(MERCHANT_ID, amount, description, email, mobile, CallbackURL) 
      if result.Status == 100: 
       return redirect('https://www.zarinpal.com/pg/StartPay/' + result.Authority) 
      else: 
       return HttpResponse('Error') 
     else: 
      messages.error(request, form.errors) 
      print(form.errors) 
      return redirect('upgrade_plan') 


@login_required 
def verify(request): 
    client = Client(ZARINPAL_WEBSERVICE) 
    if request.GET.get('Status') == 'OK': 
     result = client.service.PaymentVerification(MMERCHANT_ID, 
               request.GET['Authority'], 
               amount) 
     if result.Status == 100: 
      # in this step, it must create or update UserPlan row in DB. 
     # also, it should be create a row in Sells table and save transaction defatils. 

      return HttpResponse('Transaction was successfull. RefID: ' + str(result.RefID)) 
     elif result.Status == 101: 
      return HttpResponse('Transaction submitted : ' + str(result.Status)) 
     else: 
      return HttpResponse('Transaction failed. Status: ' + str(result.Status)) 
    else: 
     return HttpResponse('Transaction failed or canceled by user') 

しかし、それは私の支払いゲートを示し前に、それはエラーが発生します。

Exception at /business/upgrade/
(404, 'Not Found')
Request Method: POST
Request URL: http://localhost:8000/business/upgrade/ Django Version: 1.11.4 Exception Type: Exception Exception Value:
(404, 'Not Found')

とエラーコードのこの行のためである:

result = client.service.PaymentRequest(MERCHANT_ID, amount, description, email, mobile, CallbackURL) 

どうしたの?それをどうすれば解決できますか?どんな意味がありません。ここでかなりの数のものがあります

from django.conf.urls import url 
from . import views 
urlpatterns = [ 
    # for explicit urls 
    url(r'^upgrade/$', views.Upgrade.as_view(), name='upgrade_plan'), 
    url(r'^verify/$', views.verify, name='verify'), 
] 
+0

実際の表示とURLを表示してください。 –

+0

@DanielRosemanコメントありがとうございました。私は問題のコードを更新し、views.pyファイル全体を追加しました。 – msln

答えて

0

: 感謝

* UPDATE *
以下のスニペットは、私のurls.pyファイルです。

まず、127.0.0.1アドレスのサイトにコールバックを行うように決済プロバイダに指示することはできません。それはちょうどあなたのローカルホストです。明らかにゲートウェイはインターネット上の他の場所にあります。それはあなたが呼び出すことができるあなたのサイトの実際のアドレスを持っている必要があります。

第2に、あなたの質問には関係ないが、依然として非常に深刻な問題です。このようなグローバル変数は絶対に使用しないでください。それらはサイトのすべてのユーザーによって共有されるため、金額はすべて混在します。私はこの支払いプロバイダについて何も知らないが、私はそれがコールバックのパラメータの量を提供することは絶対に確信している。

+0

ゲートプロバイダーのウェブサイトにlocalhostで作業していることを示すいくつかのコード例は問題ありませんでしたが、私のコードをサーバーにアップロードすると問題が解決するかどうかわかりません。 – msln

+0

問題はsudsライブラリの問題でした。私は "zeep"ライブラリを使い、問題は解決しました。しかし私は質問があります、あなたは自分のコードで 'global amount'を使うべきではないと言ったので、どうすれば2番目の関数で使うことができますか? 'verify'関数で使用されます。どのように2番目の関数( 'verify')に送るのですか? – msln

+0

私が言ったように、その量はコールバック関数のパラメータで提供されていることは間違いありません。 –

関連する問題