Ejemplo n.º 1
0
def processUpgrade( ):
	user = current_user
	packageType = request.form['packageType']
	prevPackage = user.currentPackage

	taxRate = tax_service.getSalesTax(user.zipCode)
	taxRateString = '%2f'%taxRate
	app.logger.info('sales tax for zip' + user.zipCode + 'determined to be:' + taxRateString)


	chargePrice = None
	taxMultiplier = 1 + taxRate

	chargePrice = pricing_service.getPackagePrice(packageType)*100

	finalPrice = chargePrice * taxMultiplier
	stripePlanIdentifier = packageType + '-' + '%.2f'%chargePrice + '-' + '%.2f'%taxMultiplier +'-' + user.zipCode
	currentStripePlans = stripe.Plan.all()
	targetStripePlan = None
	for plan in currentStripePlans.data:
		if plan.name.strip() == stripePlanIdentifier.strip():
			app.logger.info("Found existing stripe plan:" + stripePlanIdentifier)
			targetStripePlan = plan
			break

	if targetStripePlan == None:
		app.logger.info("Creating new stripe plan for:"  + stripePlanIdentifier)
		try:
			stripe.Plan.create(
			amount='%.0f'%finalPrice,
			interval='month',
			name=stripePlanIdentifier,
			currency='usd',
			id=stripePlanIdentifier)
		except Exception:
			app.logger.info("The plan " + stripePlanIdentifier + " already exists in stripe")

	app.logger.info('package price upgrade is :' + '%.2f'%chargePrice)
	app.logger.info('with tax package upgrade  price is : ' + '%.2f'%finalPrice)

	customer =  stripe.Customer.retrieve(user.stripeCustomerId)
	customer.update_subscription(plan=stripePlanIdentifier)
	user.currentPackage = stripePlanIdentifier
	user.save()
	emailHtml = render_template("emails/upgradeConfirmationEmail.html",newPackage=pricing_service.getDisplayPackage(packageType),pricePerMonth=chargePrice/100,
								oldPackage=pricing_service.getDisplayPackage(prevPackage.split("-",1)[0]))
	email_service.send_mail(user.emailAddress, '*****@*****.**',
		'Resupply Upgrade Confirmation', 'html',
		emailHtml)
	email_service.send_mail('*****@*****.**', '*****@*****.**',
		'Resupply Upgrade Confirmation', 'html',
		emailHtml)
	return redirect('/account')
Ejemplo n.º 2
0
def charge():
	app.logger.info("starting charge")
	name = request.form['name']
	email = request.form['email']
	password = request.form['password']
	shippingAddress = request.form['shippingAddress']
	shippingAddress2 = request.form['shippingAddress2']
	zipcode = request.form['shippingZip']
	refferal = session.get('refferalCode')
	phone = request.form['shippingPhone']
	shippingState = request.form['shippingState']
	shippingPhone = request.form['shippingPhone']
	sourceRefferer = None


	taxRate = None
	if shippingState == 'VA':
		taxRate = 0.06
	else:
		taxRate = 0.0
#    taxRate = tax_service.getSalesTax(zipcode)
	taxRateString = '%2f'%taxRate
	app.logger.info('sales tax for zip' + zipcode + 'determined to be:' + taxRateString)


	chargePrice = None
	taxMultiplier = 1 + taxRate

	packageType = session.get('packageType')
	app.logger.info('packageType is:' + packageType)
	chargePrice = pricing_service.getPackagePrice(packageType)*100
	finalPrice = chargePrice * taxMultiplier
	stripePlanIdentifier = packageType + '-' + '%.2f'%chargePrice + '-' + '%.2f'%taxMultiplier +'-' + zipcode + '-' + shippingState
	currentStripePlans = stripe.Plan.all()
	targetStripePlan = None
	for plan in currentStripePlans.data:
		if stripePlanIdentifier.strip() == plan.name.strip():
			app.logger.info("Found existing stripe plan:" + stripePlanIdentifier)
			targetStripePlan = plan
			break

	if targetStripePlan == None:
		app.logger.info("Creating new stripe plan for:"  + stripePlanIdentifier)
		try:
			stripe.Plan.create(
			amount='%.0f' % finalPrice,
			interval='month',
			name=stripePlanIdentifier,
			currency='usd',
			id=stripePlanIdentifier)
		except Exception:
			app.logger.info("The plan " + stripePlanIdentifier + " already exists in stripe")

	app.logger.info('package price is :' + '%.2f'%chargePrice)
	app.logger.info('with tax package price is : ' + '%.2f'%finalPrice)

	session['stripePlanIdentifier'] = stripePlanIdentifier
	session['finalPricePerMonth'] = round(finalPrice,2)




	if(refferal):
		refferalCode = refferal.split('-')[1]
		refferalObject = Refferal.objects.get(refferalCode=refferalCode)
		if(refferalObject):
			sourceRefferer = refferalObject.originatorEmailAddress
			refferUser = User.objects.get(emailAddress=refferalObject.originatorEmailAddress)
			if(refferUser):
				if(refferUser.reducedPrice==False):
					refferStripeCustomer = stripe.Customer.retrieve(refferUser.stripeCustomerId)
					if(refferStripeCustomer):
						refferStripeCustomer.coupon = "3month25PCTOff"
						refferStripeCustomer.save()
						refferUser.reducedPrice = True
						refferrUser.save()
						couponAppliedHtml = render_template('emails/couponApplied.html',amount=25)
						email_service.send_mail(refferalObject.originatorEmailAddress, '*****@*****.**','We\'ve reduced your subscription amount!', 'html',couponAppliedHtml)
						email_service.send_mail('*****@*****.**', '*****@*****.**','We\'ve reduced your subscription amount!', 'html',couponAppliedHtml)

	packageType = stripePlanIdentifier
	chargePrice = finalPrice

	description = "Charging customer with email : " + email + " for " + packageType + " at address :" + shippingAddress + " " + shippingAddress2  + " " + zipcode
	fullAddress = shippingAddress + ',' 
	if shippingAddress2 != None :
		fullAddress = fullAddress + shippingAddress2
  

	fullAddress = ',' + fullAddress  + ',' + zipcode

	customer = stripe.Customer.create(
		email=request.form['email'],
		card=request.form['stripeToken'],
		plan=stripePlanIdentifier,
		description=description)

	createdUser = user_service.createUser(email, password, shippingAddress, shippingAddress2, shippingState,shippingPhone,zipcode,request.form['stripeToken'], stripePlanIdentifier, customer.id,sourceRefferer)

	refferal_service.createRefferal(createdUser.emailAddress)
	login_user(createdUser)
	emailHtml = render_template('emails/signupConfirmationEmailTemplate.html',package=pricing_service.getDisplayPackage(stripePlanIdentifier),pricePerMonth=chargePrice/100,shippingAddress=fullAddress)
	email_service.send_mail(createdUser.emailAddress, '*****@*****.**',
			  'Confirmation of subscription to Resupp.ly', 'html',
			  emailHtml)
	email_service.send_mail('*****@*****.**', '*****@*****.**',
			  'Confirmation of subscription to Resupp.ly', 'html',
			  emailHtml)

	return redirect('account')
Ejemplo n.º 3
0
def step1():
	packageType = request.form['packageType']
	app.logger.info('in step1 the package selected is:' + packageType)
	session['packageType'] = packageType

	return render_template('signup/signupStep2.html',name=session.get('name'),package=session.get('packageType'),email=session.get('email'),password=session.get('password'),shippingAddress=session.get('shippingAddress'),
	shippingAddress2=session.get('shippingAddress2'),zipcode=session.get('targetZipCode'),finalPricePerMonth=session.get('finalPricePerMonth'),city=session.get('city'),packageType=pricing_service.getDisplayPackage(packageType),packagePrice=pricing_service.getPackagePrice(packageType),stripePublishableKey=app.config["STRIPE_PUBLISHABLE_KEY"])
Ejemplo n.º 4
0
def upgradeConfirmation( ):
    user = current_user
    currentPackage = user.currentPackage
    upgradePackage = request.form['packageType']
    familySize = request.form['familySize']
    return render_template('product/upgradeConfirmation.html',currentPackage=pricing_service.getDisplayPackage(currentPackage),upgradePackageDisplay=pricing_service.getDisplayPackage(upgradePackage),upgradePackage=upgradePackage,currentPrice=pricing_service.getPackagePrice(currentPackage),upgradePrice=pricing_service.getPackagePrice(upgradePackage),familySize=familySize)