FEAT(pg): ipg commission
ipg commission
This commit is contained in:
parent
63c43f597e
commit
9d79f30518
3 changed files with 29 additions and 1 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),
|
||||
),
|
||||
]
|
||||
|
|
@ -39,6 +39,7 @@ class PaymentRequest(models.Model):
|
|||
state = models.IntegerField(choices=StateChoices.choices, default=StateChoices.CREATED)
|
||||
user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.PROTECT)
|
||||
amount = models.PositiveBigIntegerField(null=True, blank=True)
|
||||
commission = models.PositiveBigIntegerField(null=True)
|
||||
phone_number = models.CharField(max_length=255, null=True, blank=True)
|
||||
callback_url = models.CharField(max_length=255, null=True, blank=True)
|
||||
|
||||
|
|
@ -68,6 +69,14 @@ class PaymentRequest(models.Model):
|
|||
|
||||
return to_jalali(self.created_at)
|
||||
|
||||
def calculate_commission(self):
|
||||
self.commission = 1200
|
||||
if 6000000 <= self.amount <= 400000000:
|
||||
self.commission = 0.0002 * self.amount
|
||||
elif 400000000 < self.amount:
|
||||
self.commission = 80000
|
||||
self.save(update_fields=['commission'])
|
||||
|
||||
|
||||
def get_gateway_tools(self):
|
||||
if self.gateway == GatewayChoise.PNA:
|
||||
|
|
@ -225,7 +234,7 @@ class PNA(BasePGModel):
|
|||
|
||||
def make_request(self):
|
||||
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'
|
||||
callback_url = urllib.parse.urljoin(
|
||||
settings.IPG_BASE_PUBLIC_URL,
|
||||
|
|
|
|||
|
|
@ -59,6 +59,7 @@ class PaymentRequestView(UpdateView):
|
|||
def get(self, request, *args, **kwargs):
|
||||
charge_request: PaymentRequest = self.get_object()
|
||||
charge_request.set_gateway({'pna': True})
|
||||
charge_request.calculate_commission()
|
||||
tool = charge_request.get_gateway_tools()
|
||||
tool.make_request()
|
||||
redirect_url = tool.get_pg_page_url()
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue