mirror of
https://github.com/i701/sarlink-portal-api.git
synced 2025-10-05 01:15:23 +00:00
feat(topup): add payment_type field and update AdminTopupCreateView to handle payment type ✨
All checks were successful
Build and Push Docker Images / Build and Push Docker Images (push) Successful in 4m26s
All checks were successful
Build and Push Docker Images / Build and Push Docker Images (push) Successful in 4m26s
This commit is contained in:
21
billing/migrations/0015_topup_payment_type.py
Normal file
21
billing/migrations/0015_topup_payment_type.py
Normal file
@@ -0,0 +1,21 @@
|
||||
# Generated by Django 5.2 on 2025-07-27 07:08
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
("billing", "0014_wallettransaction"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name="topup",
|
||||
name="payment_type",
|
||||
field=models.CharField(
|
||||
choices=[("CASH", "Cash"), ("TRANSFER", "Transfer")],
|
||||
default="TRANSFER",
|
||||
max_length=20,
|
||||
),
|
||||
),
|
||||
]
|
@@ -66,6 +66,14 @@ class Topup(models.Model):
|
||||
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
|
||||
amount = models.FloatField()
|
||||
user = models.ForeignKey(user, on_delete=models.CASCADE, related_name="topups")
|
||||
payment_type = models.CharField(
|
||||
max_length=20,
|
||||
choices=[
|
||||
("CASH", "Cash"),
|
||||
("TRANSFER", "Transfer"),
|
||||
],
|
||||
default="TRANSFER",
|
||||
)
|
||||
paid = models.BooleanField(default=False)
|
||||
paid_at = models.DateTimeField(null=True, blank=True)
|
||||
status = models.CharField(
|
||||
|
@@ -624,14 +624,16 @@ class AdminTopupCreateView(StaffEditorPermissionMixin, generics.CreateAPIView):
|
||||
{"message": "User not found."},
|
||||
status=status.HTTP_404_NOT_FOUND,
|
||||
)
|
||||
topup = Topup.objects.create(amount=amount, user=user)
|
||||
description = f"Topup of {amount} MVR (Cash)"
|
||||
WalletTransaction.objects.create(
|
||||
user=user,
|
||||
topup = Topup.objects.create(
|
||||
amount=amount,
|
||||
transaction_type="TOPUP",
|
||||
description=description,
|
||||
user=user,
|
||||
paid=True,
|
||||
paid_at=timezone.now(),
|
||||
payment_type="CASH",
|
||||
status="PAID",
|
||||
)
|
||||
description = f"Topup of {amount} MVR (Cash)"
|
||||
user.add_wallet_funds(amount, description, topup.id)
|
||||
serializer = TopupSerializer(topup)
|
||||
return Response(serializer.data, status=status.HTTP_201_CREATED)
|
||||
|
||||
|
Reference in New Issue
Block a user