From 2f70418f4d6f9b6393611a563ccc339f4abc1838 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Floure?= Date: Thu, 5 Mar 2020 11:13:04 +0100 Subject: [PATCH] Fix dumb logic errors/typo from last commit --- uncloud/uncloud_pay/models.py | 13 +++++++------ uncloud/uncloud_pay/serializers.py | 2 +- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/uncloud/uncloud_pay/models.py b/uncloud/uncloud_pay/models.py index c8aba99..0ac4107 100644 --- a/uncloud/uncloud_pay/models.py +++ b/uncloud/uncloud_pay/models.py @@ -142,20 +142,21 @@ class PaymentMethod(models.Model): if not self.active: raise Exception('This payment method is inactive.') - if amount > 0: # Make sure we don't charge negative amount by errors... + if amount < 0: # Make sure we don't charge negative amount by errors... raise Exception('Cannot charge negative amount.') if self.source == 'stripe': stripe_customer = StripeCustomer.objects.get(owner=self.owner).stripe_id stripe_payment = uncloud_pay.stripe.charge_customer( amount, stripe_customer, self.stripe_payment_method_id) - if stripe_payment['paid']: - payment = Payment(owner=self.owner, source=self.source, amount=amount) - payment.save() # TODO: Check return status + print(stripe_payment) + if 'paid' in stripe_payment and stripe_payment['paid'] == False: + raise Exception(stripe_payment['error']) + else: + payment = Payment.objects.create( + owner=self.owner, source=self.source, amount=amount) return payment - else: - raise Exception(stripe_payment['error']) else: raise Exception('This payment method is unsupported/cannot be charged.') diff --git a/uncloud/uncloud_pay/serializers.py b/uncloud/uncloud_pay/serializers.py index d406493..bfbe0da 100644 --- a/uncloud/uncloud_pay/serializers.py +++ b/uncloud/uncloud_pay/serializers.py @@ -22,7 +22,7 @@ class UserSerializer(serializers.ModelSerializer): class PaymentSerializer(serializers.ModelSerializer): class Meta: model = Payment - fields = ['owner', 'amount', 'source', 'timestamp'] + fields = '__all__' class PaymentMethodSerializer(serializers.ModelSerializer): stripe_card_last4 = serializers.IntegerField()