Fix dumb logic errors/typo from last commit

This commit is contained in:
fnux 2020-03-05 11:13:04 +01:00
parent 80fe28588e
commit a4fa0def4b
2 changed files with 8 additions and 7 deletions

View file

@ -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.')

View file

@ -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()