def get(request, key): try: browser = Signer.loads(key)["browser"] except: browser = "" return render_to_response('confirm.html', { "key": key, "browser": browser, }, context_instance=RequestContext(request))
def get(request, key): key_json = Signer.loads(key) try: user = User.objects.get(username=key_json['email']) elastic.ElasticThread(doc_type='user_uninstall', user=user, req=request).start() except: pass return render_to_response( 'uninstall.html', {}, context_instance=RequestContext(request) )
def post(request): ipn_data = request.body data = dict((k, v if len(v) > 1 else v[0]) for k, v in parse_qs(ipn_data).iteritems()) key_json = Signer.loads(data['custom']) try: proxmate_user = User.objects.get(username=key_json['email']) except: return render_to_response('paypal-return.html', { 'payment_status': 'user_not_found' }, context_instance=RequestContext(request)) # for migrated users if they do not have email attached if not proxmate_user.email: proxmate_user.email = data['payer_email'] proxmate_user.save() # subscription signup if data['txn_type'] == 'subscr_signup': if proxmate_user.profile.paypal_subscr_id != data['subscr_id']: proxmate_user.profile.paypal_payer_id = data['payer_id'] proxmate_user.profile.paypal_subscr_id = data['subscr_id'] proxmate_user.profile.plan_status = data['item_number'] proxmate_user.profile.plan_expiration_date = proxmate_user.profile.plan_expiration_date + timedelta(minutes=120) proxmate_user.profile.payment_status = 'pending' proxmate_user.profile.subscription_status = 'subscribed' proxmate_user.profile.subscription_supplier = 'paypal' proxmate_user.profile.save() file_path = '/opt/proxmate/static/emails/confirmation_inline.html' with open(file_path) as email_file: email_template = string.Template(email_file.read()) html_message = email_template.safe_substitute( subscribedemail=str(proxmate_user.email), subsctiptionperiod=str(settings.PROXMATE_PLANS[proxmate_user.profile.plan_status]['period_name']), startdate=datetime.now().strftime("%d %B %Y"), paymentplan=str(settings.PROXMATE_PLANS[proxmate_user.profile.plan_status]['price_string']) ) send_mail(subject='Proxmate Subscription Confirmation', plain_content='', html_content=html_message, to_list=proxmate_user.email, from_list='*****@*****.**') # single payment signup if data['txn_type'] == 'web_accept': proxmate_user.profile.paypal_payer_id = data['payer_id'] proxmate_user.profile.plan_status = data['item_number'] proxmate_user.profile.plan_expiration_date = proxmate_user.profile.plan_expiration_date + timedelta(minutes=120) proxmate_user.profile.payment_status = 'pending' proxmate_user.profile.subscription_status = 'subscribed' proxmate_user.profile.subscription_supplier = 'paypal' proxmate_user.profile.save() file_path = '/opt/proxmate/static/emails/confirmation_one_off_inline.html' with open(file_path) as email_file: email_template = string.Template(email_file.read()) html_message = email_template.safe_substitute( subscribedemail=str(proxmate_user.email), subsctiptionperiod=str(settings.PROXMATE_PLANS[proxmate_user.profile.plan_status]['period_name']), startdate=datetime.now().strftime("%d %B %Y"), paymentplan=str(settings.PROXMATE_PLANS[proxmate_user.profile.plan_status]['price_string']) ) send_mail(subject='Proxmate Payment Confirmation', plain_content='', html_content=html_message, to_list=proxmate_user.email, from_list='*****@*****.**') return render_to_response('paypal-return.html', { 'payment_status': 'success' }, context_instance=RequestContext(request))