30 lines
No EOL
824 B
Python
30 lines
No EOL
824 B
Python
from payment.models import InvoicePayment, Invoice
|
|
from payment.signals import initiate_payment
|
|
|
|
from django.db import models
|
|
from django.urls import reverse_lazy
|
|
from django.dispatch import receiver
|
|
|
|
import uuid
|
|
|
|
class DemoInvoicePayment(InvoicePayment):
|
|
@property
|
|
def gateway(self):
|
|
return "Demo"
|
|
|
|
@classmethod
|
|
def initiate(cls, invoice):
|
|
payment = cls.objects.create(invoice=invoice, amount=invoice.balance * -1, gateway_id=uuid.uuid4())
|
|
invoice.finalize()
|
|
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 {} |