implement credit card listing

This commit is contained in:
Nico Schottelius 2020-12-28 23:35:34 +01:00
commit e225bf1cc0
12 changed files with 183 additions and 63 deletions

View file

@ -6,7 +6,7 @@ from django.contrib.auth import get_user_model
from django.core.validators import MinValueValidator, MaxValueValidator
from django.core.exceptions import FieldError, ValidationError
from uncloud_pay.models import Order
from uncloud_pay.models import Order, Product
class WireGuardVPNPool(models.Model):
"""
@ -123,6 +123,19 @@ class WireGuardVPN(models.Model):
def __str__(self):
return f"{self.address} ({self.pool_index})"
def create_product(self):
"""
Ensure we have a product for the WireguardVPN
"""
pass
# Product.objects.get_or_create(
# name="WireGuardVPN",
# description="Wireguard VPN",
# currency=Currency.CHF,
# config=
class WireGuardVPNFreeLeases(models.Model):
"""

View file

@ -4,9 +4,24 @@ from .models import *
from .selectors import *
from .tasks import *
@transaction.atomic
def create_wireguard_vpn(owner, public_key, network_mask):
# Check if the user has a membership.
#------------------------------------
# If yes, user is eligible for API access and 2 VPNs
# If user already has 2 VPNs, we deduct from the credit
# If deduction is higher than the allowed credit, we fail
#
# Check if the user has suitable balance
# Create order
#
return create_wireguard_vpn_tech(owner, public_key, network_mask)
@transaction.atomic
def create_wireguard_vpn_tech(owner, public_key, network_mask):
pool = get_suitable_pools(network_mask)[0]
count = pool.wireguardvpn_set.count()