Skip to content

Commit

Permalink
fix: resolve pyav1 issue
Browse files Browse the repository at this point in the history
  • Loading branch information
birddevelper committed Sep 10, 2024
1 parent 461b427 commit 2dab51a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 22 deletions.
1 change: 1 addition & 0 deletions azbankgateways/banks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from .bmi import BMI # noqa
from .idpay import IDPay # noqa
from .mellat import Mellat # noqa
from .payV1 import PayV1 # noqa
from .sep import SEP # noqa
from .zarinpal import Zarinpal # noqa
from .zibal import Zibal # noqa
42 changes: 20 additions & 22 deletions azbankgateways/banks/payV1.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
import logging

import requests
from requests.exceptions import HTTPError, JSONDecodeError

from azbankgateways.banks import BaseBank
from azbankgateways.default_settings import TRACKING_CODE_QUERY_PARAM
from azbankgateways.exceptions import BankGatewayConnectionError, SettingDoesNotExist
from azbankgateways.exceptions.exceptions import (
BankGatewayRejectPayment,
Expand Down Expand Up @@ -87,8 +87,13 @@ def pay(self):

def prepare_verify_from_gateway(self):
super(PayV1, self).prepare_verify_from_gateway()
for method in ["GET", "POST", "data"]:
token = getattr(self.get_request(), method).get(TRACKING_CODE_QUERY_PARAM, None)
request = self.get_request()
for method in [
"GET",
"POST",
]:
token = getattr(request, method, {}).get("token")

if token:
self._set_reference_number(token)
self._set_bank_record()
Expand All @@ -105,37 +110,30 @@ def verify_from_gateway(self, request):

def get_verify_data(self):
super(PayV1, self).get_verify_data()
data = {
"api": self._merchant_code(),
"token": self.get_reference_number(),
}
data = {"api": self._merchant_code, "token": self.get_reference_number(), "status": self._bank.status}
return data

def prepare_verify(self, tracking_code):
super(PayV1, self).prepare_verify(tracking_code)

def verify(self, tracking_code):
super(PayV1, self).verify(tracking_code)

data = self.get_verify_data()
response = self._send_data(self._verify_api_url, data, timeout=10)
response_json = response.json()
status = PaymentStatus.COMPLETE
if int(response_json["status"]) != 1:
if int(response_json["errorCode"]) == -5:
status = PaymentStatus.ERROR
elif int(response_json["errorCode"]) == -9:
status = PaymentStatus.EXPIRE_VERIFY_PAYMENT
elif int(response_json["errorCode"]) == -15:
status = PaymentStatus.CANCEL_BY_USER
elif int(response_json["errorCode"]) == -27:
status = PaymentStatus.RETURN_FROM_BANK
try:
response = self._send_data(self._verify_api_url, data, timeout=10)
response.raise_for_status()
response_json = response.json()
status = str(response_json.get("status", 0))
if status == '1':
status = PaymentStatus.COMPLETE
extra_information = json.dumps(response_json)
self._bank.extra_information = extra_information
else:
status = PaymentStatus.ERROR
except (JSONDecodeError, HTTPError):
status = PaymentStatus.ERROR

self._set_payment_status(status)
extra_information = json.dumps(response_json)
self._bank.extra_information = extra_information
self._bank.save()

def _send_data(self, url, data, timeout=5) -> requests.post:
Expand Down

0 comments on commit 2dab51a

Please sign in to comment.