Create payment on strip charging

This commit is contained in:
fnux 2020-02-28 09:26:18 +01:00
parent 4bed53c8a8
commit 37ed126bc1

View file

@ -57,8 +57,16 @@ class Order(models.Model):
blank=True) blank=True)
recurring_price = models.FloatField(editable=False) recurring_price = models.DecimalField(
one_time_price = models.FloatField(editable=False) max_digits=AMOUNT_MAX_DIGITS,
decimal_places=AMOUNT_DECIMALS,
validators=[MinValueValidator(0)],
editable=False)
one_time_price = models.DecimalField(
max_digits=AMOUNT_MAX_DIGITS,
decimal_places=AMOUNT_DECIMALS,
validators=[MinValueValidator(0)],
editable=False)
recurring_period = models.CharField(max_length=32, recurring_period = models.CharField(max_length=32,
choices = RecurringPeriod.choices, choices = RecurringPeriod.choices,
@ -86,7 +94,18 @@ class PaymentMethod(models.Model):
primary = models.BooleanField(default=True) primary = models.BooleanField(default=True)
def charge(self, amount): def charge(self, amount):
pass if amount > 0: # Make sure we don't charge negative amount by errors...
if self.source == 'stripe':
# TODO: wire to strip, see meooow-payv1/strip_utils.py
payment = Payment(owner=self.owner, source=self.source, amount=amount)
payment.save() # TODO: Check return status
return True
else:
# We do not handle that source yet.
return False
else:
return False
class Meta: class Meta:
unique_together = [['owner', 'primary']] unique_together = [['owner', 'primary']]
@ -112,7 +131,7 @@ class Payment(models.Model):
('unknown', 'Unknown') ('unknown', 'Unknown')
), ),
default='unknown') default='unknown')
timestamp = models.DateTimeField(editable=False) timestamp = models.DateTimeField(editable=False, auto_now_add=True)