forked from uncloud/uncloud
Fix dumb logic errors/typo from last commit
This commit is contained in:
parent
80fe28588e
commit
a4fa0def4b
2 changed files with 8 additions and 7 deletions
|
@ -142,20 +142,21 @@ class PaymentMethod(models.Model):
|
||||||
if not self.active:
|
if not self.active:
|
||||||
raise Exception('This payment method is inactive.')
|
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.')
|
raise Exception('Cannot charge negative amount.')
|
||||||
|
|
||||||
if self.source == 'stripe':
|
if self.source == 'stripe':
|
||||||
stripe_customer = StripeCustomer.objects.get(owner=self.owner).stripe_id
|
stripe_customer = StripeCustomer.objects.get(owner=self.owner).stripe_id
|
||||||
stripe_payment = uncloud_pay.stripe.charge_customer(
|
stripe_payment = uncloud_pay.stripe.charge_customer(
|
||||||
amount, stripe_customer, self.stripe_payment_method_id)
|
amount, stripe_customer, self.stripe_payment_method_id)
|
||||||
if stripe_payment['paid']:
|
print(stripe_payment)
|
||||||
payment = Payment(owner=self.owner, source=self.source, amount=amount)
|
if 'paid' in stripe_payment and stripe_payment['paid'] == False:
|
||||||
payment.save() # TODO: Check return status
|
raise Exception(stripe_payment['error'])
|
||||||
|
else:
|
||||||
|
payment = Payment.objects.create(
|
||||||
|
owner=self.owner, source=self.source, amount=amount)
|
||||||
|
|
||||||
return payment
|
return payment
|
||||||
else:
|
|
||||||
raise Exception(stripe_payment['error'])
|
|
||||||
else:
|
else:
|
||||||
raise Exception('This payment method is unsupported/cannot be charged.')
|
raise Exception('This payment method is unsupported/cannot be charged.')
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@ class UserSerializer(serializers.ModelSerializer):
|
||||||
class PaymentSerializer(serializers.ModelSerializer):
|
class PaymentSerializer(serializers.ModelSerializer):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Payment
|
model = Payment
|
||||||
fields = ['owner', 'amount', 'source', 'timestamp']
|
fields = '__all__'
|
||||||
|
|
||||||
class PaymentMethodSerializer(serializers.ModelSerializer):
|
class PaymentMethodSerializer(serializers.ModelSerializer):
|
||||||
stripe_card_last4 = serializers.IntegerField()
|
stripe_card_last4 = serializers.IntegerField()
|
||||||
|
|
Loading…
Reference in a new issue