Fix dumb logic errors/typo from last commit
This commit is contained in:
		
					parent
					
						
							
								21e1a3d220
							
						
					
				
			
			
				commit
				
					
						2f70418f4d
					
				
			
		
					 2 changed files with 8 additions and 7 deletions
				
			
		| 
						 | 
				
			
			@ -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.')
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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()
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue