2021-04-15 08:34:31 +00:00
|
|
|
from payment.models import InvoicePayment, Invoice
|
2021-04-18 14:46:57 +00:00
|
|
|
from payment.signals import initiate_payment
|
2021-04-15 08:34:31 +00:00
|
|
|
|
|
|
|
from django.db import models
|
|
|
|
from django.urls import reverse_lazy
|
2021-04-18 14:46:57 +00:00
|
|
|
from django.dispatch import receiver
|
2021-04-15 08:34:31 +00:00
|
|
|
|
2021-04-18 10:02:17 +00:00
|
|
|
import uuid
|
2021-04-15 08:34:31 +00:00
|
|
|
|
2021-04-18 10:02:17 +00:00
|
|
|
class DemoInvoicePayment(InvoicePayment):
|
2021-04-15 08:34:31 +00:00
|
|
|
@property
|
|
|
|
def gateway(self):
|
2021-04-18 14:46:57 +00:00
|
|
|
return "Demo"
|
2021-04-15 08:34:31 +00:00
|
|
|
|
2021-04-18 14:46:57 +00:00
|
|
|
@classmethod
|
|
|
|
def initiate(cls, invoice):
|
|
|
|
payment = cls.objects.create(invoice=invoice, amount=invoice.balance * -1, gateway_id=uuid.uuid4())
|
2021-04-20 11:37:36 +00:00
|
|
|
invoice.finalize()
|
2021-04-18 14:46:57 +00:00
|
|
|
return reverse_lazy("payment:status", args=[payment.uuid])
|
|
|
|
|
|
|
|
@property
|
|
|
|
def status(self):
|
|
|
|
return 0
|
|
|
|
|
|
|
|
@receiver(initiate_payment)
|
|
|
|
def from_signal(sender, **kwargs):
|
|
|
|
if kwargs["gateway"] == "demo":
|
|
|
|
return {"redirect": DemoInvoicePayment.initiate(kwargs["invoice"])}
|
|
|
|
else:
|
|
|
|
return {}
|