forked from uncloud/uncloud
Create payment on strip charging
This commit is contained in:
parent
4bed53c8a8
commit
37ed126bc1
1 changed files with 23 additions and 4 deletions
|
@ -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)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue