import stripe
from django.conf import settings
import random
import string


def generate_strip_id():
	try:
		stripe.api_key = settings.STRIPE_SECRET_KEY
		customer = stripe.Customer.create(
			description='Customer stripe card',
		)
		if customer:
			strip_id = customer['id']
		else:
			strip_id = ''
	except Exception as e:
		print(e)
	return strip_id


def paymentWithExistingCard(customerStripeId,cardId,totalAmount,capture_value):
	response = {}
	try:
		totalAmount = str(totalAmount)
		totalAmount = float(totalAmount)
		totalAmount = int(totalAmount)
		totalAmount  = totalAmount
		totalAmount = int(totalAmount)
		stripe.api_key=settings.STRIPE_SECRET_KEY
		#stripe.api_key = getStripeKey()
		stripeAmountCharges = stripe.Charge.create(
			currency="USD",
			customer=customerStripeId,
			card=cardId,
			amount=totalAmount*100,
			description = "charge from seer user",
			capture = capture_value,
		)
		if stripeAmountCharges:
			response['status'] = True
			response['data'] = stripeAmountCharges
			# return Response({'status_code':status.HTTP_200_OK,'status_message':'success','data':stripeAmountCharges})
			
	except Exception as e:
		response['status'] = False
		response['message'] = str(e)
	return response





def generate_referral_code(length=8):
    characters = string.ascii_uppercase + string.ascii_lowercase + string.digits
    referral_code = ''.join(random.choice(characters) for _ in range(length))
    return 'SEER'+referral_code
