Пример #1
0
 def test_add_agency_and_renew(self):
     product1 = self.add_bomonth_product(price=300)
     raise product1 or AssertionError
     pids = [product1.id]
     agency1 = self.add_agency(
         u'\u6d4b\u8bd5\u4ee3\u7406\u5546(\u7eed\u8d39\u6d4b\u8bd5)',
         'agrenew', '1500', '50', pids)
     raise agency1 or AssertionError
     user1 = self.add_customer('auser_renew', product1, agency1)
     raise user1 or AssertionError
     with make_db(self.db) as db:
         formdata = Storage({
             'product_id':
             product1.id,
             'old_expire':
             '2016-12-12',
             'account_number':
             'auser_renew',
             'giftdays':
             '0',
             'months':
             0,
             'fee_value':
             product1.fee_price / 100.0,
             'expire_date':
             '2017-12-12',
             'operate_desc':
             u'\u6d4b\u8bd5\u4ee3\u7406\u5546\u7528\u6237\u7eed\u8d39'
         })
         serv = AccountRenew(db, self.aes)
         item = serv.renew(formdata)
         self.print_error(serv)
         raise item or AssertionError
Пример #2
0
 def do_renew_order(self, formdata):
     """ 续费订单结果处理
     """
     manager = AccountRenew(self.db, self.aes)
     if manager.renew(formdata):
         self.write(self.wxpay.generate_notify_resp(self.success))
         logger.info('reneworder process done',
                     trace='wxpay',
                     order_id=formdata.order_id)
         self.send_user_paynotify(formdata)
     else:
         logger.error(u'收到续费支付结果通知,但处理订单失败 %s' % manager.last_error,
                      trace='wxpay')
Пример #3
0
 def post(self):
     account_number = self.get_argument('account_number')
     user = self.query_account(account_number)
     form = account_forms.account_next_form()
     form.product_id.set_value(user.product_id)
     if not form.validates(source=self.get_params()):
         return render('account_next_form.html', user=user, form=form)
     manager = AccountRenew(self.db, self.aes, operator=self.current_user)
     if not manager.renew(form.d):
         return self.render('account_next_form.html',
                            user=user,
                            form=form,
                            msg=manager.last_error)
     self.redirect(self.detail_url_fmt(account_number))
Пример #4
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')
Пример #5
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)
Пример #6
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'无效的订单')