Skip to content

Commit

Permalink
Merge pull request #129 from birddevelper/fix/bmi-token
Browse files Browse the repository at this point in the history
fix: resolve bmi token issue
  • Loading branch information
ali-zahedi authored Oct 24, 2024
2 parents 89cfa7a + 0ed4530 commit 290fb12
Showing 1 changed file with 13 additions and 6 deletions.
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

0 comments on commit 290fb12

Please sign in to comment.