Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/payv1 issue resolve #118

Merged
merged 3 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -499,8 +499,9 @@ pre-commit install
* [amirreza8002](https://github.com/amirreza8002) رفع مشکل ترجمه
* [ahmadrezanavaie](https://github.com/ahmadrezanavaie) رفع مشکل ترجمه
* [zamoosh](https://github.com/zamoosh) اضافه کردن وضعیت های تراکنش در بانک ملت
* [birddevelper](https://github.com/birddevelper) الزامی کردن وجود referrer برای درگاه بانک ملی
* [birddevelper](https://github.com/birddevelper) الزامی کردن وجود referrer برای درگاه های بانک ملی و سامان
* [apidemy](https://github.com/apidemy) ریفکتور _is_strict_origin_policy_enabled و پیروی از DRY
* [TinyPuff](https://github.com/TinyPuff) رفع مشکل Pay.ir
## License

The MIT License (MIT). Please see [License File](LICENSE) for more information.
Expand Down
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 import HTTPError, JSONDecodeError, Timeout

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, Timeout):
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
Loading