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 fe0ed82
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 23 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
38 changes: 15 additions & 23 deletions azbankgateways/banks/payV1.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import requests

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 +86,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 @@ -104,11 +108,7 @@ 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):
Expand All @@ -119,23 +119,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 fe0ed82

Please sign in to comment.