payment app
This commit is contained in:
		
					parent
					
						
							
								3ca9ef5900
							
						
					
				
			
			
				commit
				
					
						e5d2d74450
					
				
			
		
					 15 changed files with 379 additions and 101 deletions
				
			
		
							
								
								
									
										46
									
								
								membership/payment.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										46
									
								
								membership/payment.py
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,46 @@
 | 
			
		|||
__author__ = 'tomislav'
 | 
			
		||||
from django.conf import settings
 | 
			
		||||
from .models import CreditCards
 | 
			
		||||
import stripe
 | 
			
		||||
stripe.api_key = settings.STRIPE_API_PRIVATE_KEY
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class StripePayment(object):
 | 
			
		||||
 | 
			
		||||
    @classmethod
 | 
			
		||||
    def make_payment(cls,user,amount,token,time):
 | 
			
		||||
        try:
 | 
			
		||||
            # Use Stripe's library to make requests...
 | 
			
		||||
            charge = stripe.Charge.create(
 | 
			
		||||
                amount=amount,
 | 
			
		||||
                currency='chf',
 | 
			
		||||
                source=token,
 | 
			
		||||
                description=settings.STRIPE_DESCRIPTION_ON_PAYMENT
 | 
			
		||||
            )
 | 
			
		||||
            if charge['status'] =='succeeded':
 | 
			
		||||
                obj = CreditCards.objects.filter(user_id=user.id).first()
 | 
			
		||||
                obj.payment_type = time
 | 
			
		||||
                obj.save()
 | 
			
		||||
            return charge['status']
 | 
			
		||||
 | 
			
		||||
        except stripe.error.CardError as e:
 | 
			
		||||
            # Since it's a decline, stripe.error.CardError will be caught
 | 
			
		||||
            body = e.json_body
 | 
			
		||||
            err = body['error']
 | 
			
		||||
            return err['message']
 | 
			
		||||
        except stripe.error.RateLimitError as e:
 | 
			
		||||
            return "Too many requests made to the API too quickly"
 | 
			
		||||
        except stripe.error.InvalidRequestError as e:
 | 
			
		||||
            return "Invalid parameters"
 | 
			
		||||
        except stripe.error.AuthenticationError as e:
 | 
			
		||||
            # Authentication with Stripe's API failed
 | 
			
		||||
            # (maybe you changed API keys recently)
 | 
			
		||||
            pass
 | 
			
		||||
        except stripe.error.APIConnectionError as e:
 | 
			
		||||
            return "Currently its not possible to make payments."
 | 
			
		||||
        except stripe.error.StripeError as e:
 | 
			
		||||
            return "Currently its not possible to make payments."
 | 
			
		||||
            #maybe send email
 | 
			
		||||
        except Exception as e:
 | 
			
		||||
            return "Currently its not possible to make payments."
 | 
			
		||||
            #maybe send email
 | 
			
		||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue