def contactSubmit(): name = request.form['name'] email = request.form['email'] message = request.form['message'] contents = "From:" + name + ' email:' + email + ' message:' + message email_service.send_mail('*****@*****.**', '*****@*****.**','Contact Submission!', 'html',contents) resp = None resp = jsonify({'submitted': True}) resp.status_code = 200 return resp
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')
def cancelAccountSubmit( ): user = current_user user_service.cancelAccount(user) email = render_template ("emails/cancelAccountConfirmationEmail.html") email_service.send_mail(user.emailAddress,'*****@*****.**','Resupply Account Cancellation Confirmation', 'html',email) email_service.send_mail('*****@*****.**', '*****@*****.**','Resupply Account Cancellation Confirmation', 'html',email) user.delete() logout_user() res = jsonify({'canceled':True}) res.status_code = 202 app.logger.info("closed the account for :" + user.emailAddress) return res
def forgotPasswordSubmit( ): email=request.form['email'] try: user = User.objects.get(emailAddress=email) except DoesNotExist: return render_template ("user/forgotPassword.html",userNotFound=True,emailSent=False) else: linkRef = str(user.id)[5:10] now = datetime.datetime.now().microsecond linkRef = linkRef + str(now) link = app.config["passwordResetPrefix"] + '?linkRef=' + linkRef; password_change_service.createPasswordChangeRequest(user.emailAddress,linkRef) email = render_template ("emails/passwordResetEmail.html",link=link) email_service.send_mail(user.emailAddress,'*****@*****.**','Resupply Password Reset', 'html',email) email_service.send_mail('*****@*****.**', '*****@*****.**','Resupply Password Reset', 'html',email) return render_template ("user/forgotPassword.html",userNotFound=False,emailSent=True)
def requestPasswordChangeSubmit( ): user = current_user linkRef = str(user.id)[5:10] now = datetime.datetime.now().microsecond linkRef = linkRef + str(now) link = app.config["passwordResetPrefix"] + '?linkRef=' + linkRef; password_change_service.createPasswordChangeRequest(user.emailAddress,linkRef) email_service.send_mail(user.emailAddress, '*****@*****.**', 'Resupply Password Link', 'plaintext', 'Click the folowing link to reset your password ' + link) email_service.send_mail('*****@*****.**', '*****@*****.**', 'Resupply Password Link', 'plaintext', 'Click the folowing link to reset your password ' + link) data = {'link':link} resp = jsonify(data) resp.status_code = 202 return resp
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')
def testEmail(): emailHtml = render_template('emails/signupConfirmationEmailTemplate.html',package='TestPackage',pricePerMonth=17.00,shippingAddress='Test Address') email_service.send_mail('*****@*****.**', '*****@*****.**', 'Confirmation of subscription to Resupp.ly', 'html', emailHtml) return redirect('/')