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: resolve bmi token issue #129

Merged
merged 1 commit into from
Oct 24, 2024
Merged
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
19 changes: 13 additions & 6 deletions azbankgateways/banks/bmi.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import requests
from Crypto.Cipher import DES3
from django.conf import settings

from azbankgateways.banks import BaseBank
from azbankgateways.exceptions import BankGatewayConnectionError, SettingDoesNotExist
from azbankgateways.exceptions.exceptions import (
Expand All @@ -23,7 +23,10 @@ class BMI(BaseBank):
def __init__(self, **kwargs):
super(BMI, self).__init__(**kwargs)
if not self._is_strict_origin_policy_enabled():
raise SettingDoesNotExist("SECURE_REFERRER_POLICY is not set to 'strict-origin-when-cross-origin' in django setting, it's mandatory for BMI gateway")
raise SettingDoesNotExist(
"SECURE_REFERRER_POLICY is not set to 'strict-origin-when-cross-origin'"
" in django setting, it's mandatory for BMI gateway"
)

self.set_gateway_currency(CurrencyEnum.IRR)
self._token_api_url = "https://sadad.shaparak.ir/vpg/api/v0/Request/PaymentRequest"
Expand Down Expand Up @@ -105,7 +108,8 @@ def verify(self, transaction_code):
if str(response_json["ResCode"]) == "0":
self._set_payment_status(PaymentStatus.COMPLETE)
extra_information = (
f"RetrivalRefNo={response_json['RetrivalRefNo']},SystemTraceNo={response_json['SystemTraceNo']}"
f"RetrivalRefNo={response_json['RetrivalRefNo']}"
",SystemTraceNo={response_json['SystemTraceNo']}"
)
self._bank.extra_information = extra_information
self._bank.save()
Expand All @@ -116,10 +120,13 @@ def verify(self, transaction_code):
def prepare_verify_from_gateway(self):
super(BMI, self).prepare_verify_from_gateway()
request = self.get_request()
for method in ["POST", "GET", "data", "PUT"]:
token = getattr(request, method, {}).get("token", None)
if token:
method_data = getattr(request, "POST", {})
token = None
for key, value in method_data.items():
if key.lower() == "token":
token = value
break

if not token:
raise BankGatewayStateInvalid
self._set_reference_number(token)
Expand Down
Loading