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

add bank factory interface duo to make creation of bank factory cleaner and shorter #116

Merged
merged 5 commits into from
Oct 24, 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
55 changes: 55 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,61 @@ SECURE_REFERRER_POLICY = "strict-origin-when-cross-origin"

`set_mobile_number` متدی است که پارامتر شماره موبایل کاربری که قصد خرید دارد را به آن پاس میدهیم. این شماره موبایل جهت پرداخت و پیگیری آسان تر به درگاه ارسال می شود

هم‌چنین می‌توانید عملیات auto create کردن factory را از طریق interface انجام دهید:

```python
from azbankgateways.bankfactories_interface import BankFactory
from azbankgateways.exceptions import AZBankGatewaysException


def go_to_gateway_view(request):
try :
factory = BankFactory()
bank = factory.auto_create(
request=request,
amount=amount,
callback_url=callback_url,
mobile_number=mobile_number,
)

# در صورت تمایل اتصال این رکورد به رکورد فاکتور یا هر چیزی که بعدا بتوانید ارتباط بین محصول یا خدمات را با این
# پرداخت برقرار کنید.
bank_record = bank.ready()

# هدایت کاربر به درگاه بانک
return bank.redirect_gateway()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

لطفا در مثالتون قبل از فراخوانی redirect_gateway متد ready رو هم اضافه کنید تا اگر کسی از مثال شما استفاده کرد به مشکل بر نخوره.

# ...
bank_record = bank.ready()
return bank.redirect_gateway()
# ...

except AZBankGatewaysException as e :
raise e

```

عملیات create کردن factory از طریق interface :

```python
from azbankgateways.bankfactories_interface import BankFactory
from azbankgateways.exceptions import AZBankGatewaysException


def go_to_gateway_view(request):
try :
factory = BankFactory()
bank = factory.create(
request=request,
amount=amount,
callback_url=callback_url,
mobile_number=mobile_number,
bank_type=bank_type,
)

# در صورت تمایل اتصال این رکورد به رکورد فاکتور یا هر چیزی که بعدا بتوانید ارتباط بین محصول یا خدمات را با این
# پرداخت برقرار کنید.
bank_record = bank.ready()

# هدایت کاربر به درگاه بانک
return bank.redirect_gateway()
except AZBankGatewaysException as e :
raise e

<h2 dir="rtl">ساخت صفحه redirect_to_bank.html </h2>
<p dir="rtl">
این صفحه درصورتی کارمیکند که IS_SAFE_GET_GATEWAY_PAYMENT': True' و view مربوطه تنظیم شود.<br> برای این کار در پوشه templates پروژه فایل redirect_to_bank.html را ایجاد کرده و محتوای زیر را در آن قرار میدیم (میتونید با سلیقه خودتون سفاریشی کنید)
Expand Down
60 changes: 60 additions & 0 deletions azbankgateways/bankfactories_interface.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
from django.http import request
from azbankgateways.banks import BaseBank
from azbankgateways.models import BankType
from azbankgateways.bankfactories import BankFactory as BaseBankFactory


class BankFactory(BaseBankFactory):
def create(
self,
request: request,
amount: int,
callback_url : str,
mobile_number: str = None,
bank_type: BankType = None,
identifier: str = "1",
) -> BaseBank:
bank = super().create(bank_type, identifier)

bank = self.set_payment_info(
bank=bank,
request=request,
amount=amount,
callback_url=callback_url,
mobile_number=mobile_number,
)
return bank

def auto_create(
self,
request: request,
amount: int,
callback_url : str,
mobile_number: str = None,
identifier: str = "1",
) -> BaseBank:

bank = super().auto_create(identifier, amount)

bank = self.set_payment_info(
bank=bank,
request=request,
amount=amount,
callback_url=callback_url,
mobile_number=mobile_number,
)
return bank

def set_payment_info(
self,
bank: BaseBank,
request: request,
amount: int,
callback_url : str,
mobile_number: str = None,
):
bank.set_request(request=request)
bank.set_amount(amount=amount)
bank.set_client_callback_url(callback_url=callback_url)
bank.set_mobile_number(mobile_number=mobile_number)
return bank
Loading