示例#1
0
 def post(self):
     try:
         product_id = self.get_argument('product_id', '')
         product = self.db.query(models.TrProduct).get(product_id)
         if not product:
             return self.render('neworder_form.html', form=form, msg=u'套餐不存在')
         form = order_forms.order_form(product.product_policy)
         if not form.validates(source=self.get_params()):
             return self.render('neworder_form.html', form=form, msg=form.errors)
         account_count = self.db.query(models.TrCustomer).filter_by(email=form.d.email).count()
         if account_count > 0:
             return self.render('neworder_form.html', form=form, msg=u'电子邮件已经存在')
         if form.d.vcard_code and form.d.vcard_pwd:
             return self.do_vcard(form, product)
         _feevalue, _expire = self.order_calc(form.d.product_id)
         order_id = utils.gen_order_id()
         formdata = Storage(form.d)
         formdata.order_id = order_id
         formdata['node_id'] = self.get_param_value('default_user_node_id', 1)
         formdata['area_id'] = ''
         formdata['fee_value'] = _feevalue
         formdata['expire_date'] = _expire
         formdata['accept_source'] = 'ssportal'
         formdata['giftdays'] = 0
         formdata['giftflows'] = 0
         formdata['ip_address'] = ''
         formdata['status'] = 1
         formdata['customer_desc'] = u'客户自助开户'
         formdata['product_name'] = product.product_name
         self.paycache.set(order_paycaache_key(order_id), formdata)
         return self.render('order_alipay.html', formdata=formdata)
     except Exception as err:
         logger.exception(err)
         return self.render('neworder_form.html', form=form, msg=u'无效的订单')
示例#2
0
 def post(self, order_type):
     isok = self.alipay.notify_verify(self.get_params())
     if not isok:
         self.write('failure')
         logger.info(u'收到支付宝订单通知,订单无效', trace='alipay', **self.get_params())
         return
     order_id = self.get_argument('out_trade_no')
     if self.db.query(models.TrCustomerOrder).filter_by(
             order_id=order_id, pay_status=1).count() == 1:
         self.write('success')
         return
     formdata = self.paycache.get(order_paycaache_key(order_id))
     if not formdata:
         logger.error(u'收到支付宝订单通知,但是本地缓存查不到订单%s' % order_id, trace='alipay')
         self.write('failure')
         return
     ret = False
     if order_type == 'new':
         manager = CustomerAdd(self.db, self.aes)
         ret = manager.add(formdata)
     if order_type == 'renew':
         manager = AccountRenew(self.db, self.aes)
         ret = manager.renew(formdata)
     if order_type == 'charge':
         manager = AccountChange(self.db, self.aes)
         ret = manager.charge(formdata)
     if ret:
         self.write('success')
         logger.info(u'收到支付宝订单通知,处理成功',
                     trace='alipay',
                     account_number=formdata.account_number,
                     order_id=formdata.order_id)
     else:
         logger.error(u'订单处理失败', trace='alipay')
示例#3
0
 def get(self, order_type):
     isok = self.alipay.notify_verify(self.get_params())
     if not isok:
         logger.info(u'收到支付宝订单通知,订单校验无效',
                     trace='alipay',
                     **self.get_params())
         return self.render_error(code=1, msg=u'订单校验无效')
     order_id = self.get_argument('out_trade_no')
     order = self.db.query(models.TrCustomerOrder).get(order_id)
     if order and order.pay_status == 1:
         return self.render('alipay_return.html', order=order)
     formdata = self.paycache.get(order_paycaache_key(order_id))
     if not formdata:
         logger.error(u'收到支付宝订单通知,但是本地查不到订单%s' % order_id, trace='alipay')
         return self.render_error(code=1, msg=u'订单不存在')
     ret = False
     if order_type == 'new':
         manager = CustomerAdd(self.db, self.aes)
         ret = manager.add(formdata)
     if order_type == 'renew':
         manager = AccountRenew(self.db, self.aes)
         ret = manager.renew(formdata)
     if order_type == 'charge':
         manager = AccountCharge(self.db, self.aes)
         ret = manager.charge(formdata)
     if ret:
         order = self.db.query(models.TrCustomerOrder).get(order_id)
         logger.info(u'收到支付宝订单通知,处理成功',
                     trace='alipay',
                     account_number=formdata.account_number,
                     order_id=order_id)
         self.render('alipay_return.html', order=order)
     else:
         return self.render_error(code=1,
                                  msg=u'订单处理失败 %s' % manager.last_error)
示例#4
0
 def post(self):
     order_id = self.get_argument('order_id')
     formdata = self.paycache.get(order_paycaache_key(order_id))
     product_name = self.get_product_name(formdata.product_id)
     self.redirect(
         self.alipay.create_direct_pay_by_user(
             order_id,
             u'账号充值:%s' % product_name,
             product_name,
             formdata.fee_value,
             notify_path='/ssportal/alipay/verify/charge',
             return_path='/ssportal/alipay/verify/charge'))
示例#5
0
 def get(self):
     order_id = self.get_argument('order_id', '')
     if not order_id:
         return self.render_error(code=1, msg=u'订单不存在')
     formdata = self.paycache.get(order_paycaache_key(order_id))
     if not formdata:
         return self.render_error(code=1, msg=u'订单已过期')
     try:
         formdata.order_id = order_id
         self.render('charge_alipay.html', formdata=formdata)
     except Exception as err:
         logger.exception(err)
         self.render_error(msg=u'订单处理错误,请联系管理员')
示例#6
0
 def post(self):
     form = order_forms.charge_form()
     if not form.validates(source=self.get_params()):
         return self.render_json(code=1, msg=form.errors)
     account = self.db.query(models.TrAccount).get(form.d.account_number)
     if not account:
         return self.render_json(code=1, msg=u'账号不存在')
     try:
         order_id = utils.gen_order_id()
         formdata = Storage(form.d)
         formdata['order_id'] = order_id
         formdata['product_id'] = account.product_id
         formdata['fee_value'] = form.d.fee_value
         formdata['accept_source'] = 'ssportal'
         formdata['operate_desc'] = u'用户自助充值'
         self.paycache.set(order_paycaache_key(order_id), formdata)
         self.render_json(code=0, msg=u'订单创建成功', order_id=order_id)
     except Exception as err:
         logger.exception(err)
         return self.render_json(code=0, msg=u'无效的订单')
示例#7
0
 def post(self):
     product_id = self.get_argument('product_id')
     product = self.db.query(models.TrProduct).get(product_id)
     form = order_forms.renew_form(product.product_policy)
     if not form.validates(source=self.get_params()):
         return self.render_json(code=1, msg=form.errors)
     account = self.db.query(models.TrAccount).get(form.d.account_number)
     if not account:
         return self.render_json(code=1, msg=u'账号不存在')
     try:
         _feevalue, _expire = self.order_calc(
             account.product_id,
             old_expire=self.get_expire_date(account.expire_date))
         order_id = utils.gen_order_id()
         formdata = Storage(form.d)
         formdata['order_id'] = order_id
         formdata['product_id'] = account.product_id
         formdata['fee_value'] = _feevalue
         formdata['expire_date'] = _expire
         formdata['accept_source'] = 'ssportal'
         formdata['giftdays'] = 0
         formdata['operate_desc'] = u'用户自助续费'
         formdata['old_expire'] = account.expire_date
         if form.d.vcard_code and form.d.vcard_pwd:
             formdata['vcard_code'] = form.d.vcard_code
             formdata['vcard_pwd'] = form.d.vcard_pwd
             manager = AccountRenew(self.db, self.aes)
             ret = manager.renew(formdata)
             if ret:
                 logger.info(u'充值卡续费成功')
                 self.render_json(code=100, msg=u'充值卡续费成功')
             else:
                 return self.render_json(code=1,
                                         msg=u'充值卡订单处理失败 %s' %
                                         manager.last_error)
         else:
             self.paycache.set(order_paycaache_key(order_id), formdata)
             self.render_json(code=0, msg=u'订单创建成功', order_id=order_id)
     except Exception as err:
         logger.exception(err)
         return self.render_json(code=0, msg=u'无效的订单')
示例#8
0
 def post(self):
     order_id = self.get_argument('order_id')
     formdata = self.paycache.get(order_paycaache_key(order_id))
     product_name = self.db.query(models.TrProduct.product_name).filter_by(id=formdata.product_id).scalar()
     self.redirect(self.alipay.create_direct_pay_by_user(order_id, product_name, product_name, formdata.fee_value, notify_path='/ssportal/alipay/verify/new', return_path='/ssportal/alipay/verify/new'))