JourneyJoker/payment/demo/models.py

30 lines
824 B
Python
Raw Normal View History

from payment.models import InvoicePayment, Invoice
2021-04-18 14:46:57 +00:00
from payment.signals import initiate_payment
from django.db import models
from django.urls import reverse_lazy
2021-04-18 14:46:57 +00:00
from django.dispatch import receiver
import uuid
class DemoInvoicePayment(InvoicePayment):
@property
def gateway(self):
2021-04-18 14:46:57 +00:00
return "Demo"
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())
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 {}