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 6, 2024
1 parent 461b427 commit 2a1a6d7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 19 deletions.
1 change: 1 addition & 0 deletions azbankgateways/banks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
from .sep import SEP # noqa
from .zarinpal import Zarinpal # noqa
from .zibal import Zibal # noqa
from .payV1 import PayV1 #noqa
32 changes: 13 additions & 19 deletions azbankgateways/banks/payV1.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,10 @@ 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', None)

if token:
self._set_reference_number(token)
self._set_bank_record()
Expand All @@ -104,10 +106,10 @@ def verify_from_gateway(self, request):
"""

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

Expand All @@ -119,23 +121,15 @@ def verify(self, 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
else:
status = PaymentStatus.ERROR

if response.status_code == 200 and int((response_json:=response.json())["status"]) == 1:
status = PaymentStatus.COMPLETE
extra_information = json.dumps(response_json)
self._bank.extra_information = extra_information
else:
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 2a1a6d7

Please sign in to comment.