def get(self): try: if not self.get_argument('id', None): self.status_code = 404 return self.render_template('404.html') f = form_service.get_form(id = self.get_argument('id')).to_dict() u = user_service.get_user(id = f.get('user_id', None)).to_dict() months = [ {'value' : '', 'month' : ''}, {'value' : '01', 'month' : 'Jan'}, {'value' : '02', 'month' : 'Feb'}, {'value' : '03', 'month' : 'Mar'}, {'value' : '04', 'month' : 'Apr'}, {'value' : '05', 'month' : 'May'}, {'value' : '06', 'month' : 'Jun'}, {'value' : '07', 'month' : 'Jul'}, {'value' : '08', 'month' : 'Aug'}, {'value' : '09', 'month' : 'Sep'}, {'value' : '10', 'month' : 'Oct'}, {'value' : '11', 'month' : 'Nov'}, {'value' : '12', 'month' : 'Dec'} ] years = [''] for i in range(0, 20): years.append(int(datetime.utcnow().strftime('%Y')) + i) context = { 'f' : f, 'u' : u, 'months' : months, 'years' : years } return self.render_template('payment_form.html', **context) except Exception as e: log.exception('exception: %s' %(e)) return self.render_template('404.html')
def get(self): form_id = self.get_argument('id') u = user_service.get_user(id = self.current_user).to_dict() f = form_service.get_form(id = form_id).to_dict() if u and f: context = { 'f' : f, 'name' : u.get('name', None) if u.get('name', None) else '', 'username' : self.username, } return self.render_template('form_conf.html', **context)
def save_test_tokens(code, form_id): d = stripe_service.get_test_info(code = code) log.info('d: %s' %(d)) f = form_service.get_form(id = form_id).to_dict() update_params = { 'set__test_access_token' : d.get('access_token', None), 'set__test_token_type' : d.get('token_type', None), 'set__test_scope' : d.get('scope', None), 'set__test_refresh_token' : d.get('refresh_token', None), 'set__test_stripe_publishable_key' : d.get('stripe_publishable_key', None) } # For localhost, as we are same secret - update access_token # update_params['set__live_access_token'] = d.get('access_token', None) log.info('update_params: %s' %(update_params)) User.objects(id = f.get('user_id')).update(**update_params)
def post(self): resp = {} try: if not self.get_argument('token', None) \ or not self.get_argument('form_id', None) \ or not self.get_argument('name_on_card', None) \ or not self.get_argument('email', None) \ or not self.get_argument('billing_address', None) \ or not self.get_argument('city', None) \ or not self.get_argument('state', None) \ or not self.get_argument('postal_code', None) \ or not self.get_argument('country', None): resp['error'] = ERROR_MISSING_PARAMS else: f = form_service.get_form(id = self.get_argument('form_id')).to_dict() u = user_service.get_user(id = f.get('user_id')).to_dict() kwargs = { 'name_on_card' : self.get_argument('name_on_card', None), 'email' : self.get_argument('email', None), 'billing_address' : self.get_argument('billing_address', None), 'city' : self.get_argument('city', None), 'state' : self.get_argument('state', None), 'postal_code' : self.get_argument('postal_code', None), 'country' : self.get_argument('country', None), 'form_name' : f.get('name', None) } access_token = u.get('live_access_token') if f.get('livemode') else u.get('test_access_token') tid = stripe_service.make_payment(cost = float(f.get('cost')), form_id = f.get('id'), token = self.get_argument('token', None), access_token = access_token, livemode = f.get('livemode', True), **kwargs) if tid: resp = { 'success' : True, 'name_on_card' : kwargs.get('name_on_card', None), 'email' : kwargs.get('email', None), 'cost' : f.get('cost'), 'transaction_id' : tid } if f.get('send_invoice_email'): TransactionSuccessfulEmailTask.delay(tid = tid) else: resp['error'] = 'Could not charge card' except Exception as e: log.exception('exception: %s' %(e)) resp['error'] = '%s' %(e) self.set_body(resp) return self.render()
def run(self, tid): try: make_connection.configure() # Making the DB connection from potter.services import stripe_service as stripe_service from potter.services import form as form_service from potter.services import user as user_service t = stripe_service.get_transaction(id = tid).to_dict() f = form_service.get_form(id = t.get('form_id')).to_dict() u = user_service.get_user(id = f.get('user_id')).to_dict() sender_name = u.get('business_name') if u.get('business_name') else \ (u.get('name') if u.get('name') else u.get('email')) data = { 't' : t, 'f' : f, 'u' : u, 'sender_name' : sender_name } sender_name = u.get('business_name') if u.get('business_name') else \ (u.get('name') if u.get('name') else u.get('email')) bcc = u.get('email') if f.get('bcc_email') else None notification_service.notify(type = 'on_payment_successful', to = t.get('email'), sender_name = sender_name, data = data, cc = None, bcc = bcc) except Exception as e: log.exception('exception while sending email. e: %s' %(e))