From 37ed126bc17ebe387b63c21c052bb5a5b9217340 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Floure?= Date: Fri, 28 Feb 2020 09:26:18 +0100 Subject: [PATCH] Create payment on strip charging --- uncloud/uncloud_pay/models.py | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/uncloud/uncloud_pay/models.py b/uncloud/uncloud_pay/models.py index f3de8c4..8e41e24 100644 --- a/uncloud/uncloud_pay/models.py +++ b/uncloud/uncloud_pay/models.py @@ -57,8 +57,16 @@ class Order(models.Model): blank=True) - recurring_price = models.FloatField(editable=False) - one_time_price = models.FloatField(editable=False) + recurring_price = models.DecimalField( + 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, choices = RecurringPeriod.choices, @@ -86,7 +94,18 @@ class PaymentMethod(models.Model): primary = models.BooleanField(default=True) 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: unique_together = [['owner', 'primary']] @@ -112,7 +131,7 @@ class Payment(models.Model): ('unknown', 'Unknown') ), default='unknown') - timestamp = models.DateTimeField(editable=False) + timestamp = models.DateTimeField(editable=False, auto_now_add=True)