Merge pull request 'FEATURE/payment-commission' (#6) from FEATURE/payment-commission into master
Reviewed-on: addwin/pg#6 Reviewed-by: Sayyid Hamid Mahdavi <sahama@noreply.localhost>
This commit is contained in:
commit
a2b1e83f69
4 changed files with 35 additions and 3 deletions
18
apps/pg/migrations/0007_paymentrequest_commission.py
Normal file
18
apps/pg/migrations/0007_paymentrequest_commission.py
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
# Generated by Django 5.1.4 on 2025-11-10 15:10
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('pg', '0006_paymentrequest_is_registered'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='paymentrequest',
|
||||||
|
name='commission',
|
||||||
|
field=models.PositiveBigIntegerField(null=True),
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
@ -14,8 +14,8 @@ from apps.core.models import BaseModel, BasePGModel
|
||||||
from apps.pg.constans import StateChoices
|
from apps.pg.constans import StateChoices
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
from utils.wallet_client import deposit_to_user_wallet_submit, \
|
from utils.wallet_client import deposit_to_user_wallet_submit, deposit_to_user_wallet_verify
|
||||||
deposit_to_user_wallet_verify
|
from main import settings
|
||||||
|
|
||||||
from utils.pna import PNAClient
|
from utils.pna import PNAClient
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
|
@ -39,6 +39,7 @@ class PaymentRequest(models.Model):
|
||||||
state = models.IntegerField(choices=StateChoices.choices, default=StateChoices.CREATED)
|
state = models.IntegerField(choices=StateChoices.choices, default=StateChoices.CREATED)
|
||||||
user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.PROTECT)
|
user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.PROTECT)
|
||||||
amount = models.PositiveBigIntegerField(null=True, blank=True)
|
amount = models.PositiveBigIntegerField(null=True, blank=True)
|
||||||
|
commission = models.PositiveBigIntegerField(null=True)
|
||||||
phone_number = models.CharField(max_length=255, null=True, blank=True)
|
phone_number = models.CharField(max_length=255, null=True, blank=True)
|
||||||
callback_url = models.CharField(max_length=255, null=True, blank=True)
|
callback_url = models.CharField(max_length=255, null=True, blank=True)
|
||||||
|
|
||||||
|
|
@ -68,6 +69,13 @@ class PaymentRequest(models.Model):
|
||||||
|
|
||||||
return to_jalali(self.created_at)
|
return to_jalali(self.created_at)
|
||||||
|
|
||||||
|
def calculate_commission(self):
|
||||||
|
self.commission = settings.COMMISSION_LEVEL1
|
||||||
|
if settings.COMMISSION_LEVEL2_MIN_AMOUNT <= self.amount <= settings.COMMISSION_LEVEL2_MAX_AMOUNT:
|
||||||
|
self.commission = settings.COMMISSION_LEVEL2_RATE * self.amount
|
||||||
|
elif settings.COMMISSION_LEVEL2_MAX_AMOUNT < self.amount:
|
||||||
|
self.commission = settings.COMMISSION_LEVEL3
|
||||||
|
self.save(update_fields=['commission'])
|
||||||
|
|
||||||
def get_gateway_tools(self):
|
def get_gateway_tools(self):
|
||||||
if self.gateway == GatewayChoise.PNA:
|
if self.gateway == GatewayChoise.PNA:
|
||||||
|
|
@ -225,7 +233,7 @@ class PNA(BasePGModel):
|
||||||
|
|
||||||
def make_request(self):
|
def make_request(self):
|
||||||
self.payment_request.change_state(StateChoices.CREATED, StateChoices.IPG_PENDING, 'can not change state')
|
self.payment_request.change_state(StateChoices.CREATED, StateChoices.IPG_PENDING, 'can not change state')
|
||||||
amount = self.payment_request.amount
|
amount = self.payment_request.amount + self.payment_request.commission
|
||||||
description = 'from addwin ipg'
|
description = 'from addwin ipg'
|
||||||
callback_url = urllib.parse.urljoin(
|
callback_url = urllib.parse.urljoin(
|
||||||
settings.IPG_BASE_PUBLIC_URL,
|
settings.IPG_BASE_PUBLIC_URL,
|
||||||
|
|
|
||||||
|
|
@ -59,6 +59,7 @@ class PaymentRequestView(UpdateView):
|
||||||
def get(self, request, *args, **kwargs):
|
def get(self, request, *args, **kwargs):
|
||||||
charge_request: PaymentRequest = self.get_object()
|
charge_request: PaymentRequest = self.get_object()
|
||||||
charge_request.set_gateway({'pna': True})
|
charge_request.set_gateway({'pna': True})
|
||||||
|
charge_request.calculate_commission()
|
||||||
tool = charge_request.get_gateway_tools()
|
tool = charge_request.get_gateway_tools()
|
||||||
tool.make_request()
|
tool.make_request()
|
||||||
redirect_url = tool.get_pg_page_url()
|
redirect_url = tool.get_pg_page_url()
|
||||||
|
|
|
||||||
|
|
@ -257,3 +257,8 @@ PNA_CORPORATION_PIN = config('PNA_CORPORATION_PIN')
|
||||||
WALLET_BASE_PUBLIC_URL = config('WALLET_BASE_PUBLIC_URL')
|
WALLET_BASE_PUBLIC_URL = config('WALLET_BASE_PUBLIC_URL')
|
||||||
WALLET_RIAL = config('WALLET_RIAL')
|
WALLET_RIAL = config('WALLET_RIAL')
|
||||||
IPG_BASE_PUBLIC_URL = config('IPG_BASE_PUBLIC_URL')
|
IPG_BASE_PUBLIC_URL = config('IPG_BASE_PUBLIC_URL')
|
||||||
|
COMMISSION_LEVEL1 = config('COMMISSION_LEVEL1', cast=int)
|
||||||
|
COMMISSION_LEVEL2_MIN_AMOUNT = config('COMMISSION_LEVEL2_MIN_AMOUNT', cast=int)
|
||||||
|
COMMISSION_LEVEL2_MAX_AMOUNT = config('COMMISSION_LEVEL2_MAX_AMOUNT', cast=int)
|
||||||
|
COMMISSION_LEVEL2_RATE = config('COMMISSION_LEVEL2_RATE', cast=float)
|
||||||
|
COMMISSION_LEVEL3 = config('COMMISSION_LEVEL3', cast=int)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue