def post(self): response = {} try: client_id = self.request.get_range('client_id') or int( self.request.headers.get('Client-Id') or 0) except ValueError: client_id = 0 client = None if client_id: if self.request.init_namespace: namespace_manager.set_namespace(self.request.init_namespace) client = Client.get(client_id) if not client: response['success'] = False self.render_json(response) outdated_client = None outdated_client_id = self.request.get_range('old_client_id') if outdated_client_id: outdated_client = Client.get(outdated_client_id) if outdated_client: if config.APP_KIND == AUTO_APP: if config.WALLET_ENABLED: wallet_balance = empatika_wallet.get_balance( outdated_client.key.id()) if wallet_balance > 0: source = "transfer from (%s) to (%s)" % ( outdated_client.key.id(), client.key.id()) empatika_wallet.deposit(client.key.id(), wallet_balance, source) empatika_wallet.pay(outdated_client.key.id(), source, wallet_balance) if config.PROMOS_API_KEY: accum_points = empatika_promos.get_user_points( outdated_client.key.id()) if accum_points > 0: empatika_promos.move_user_points( outdated_client.key.id(), client.key.id(), accum_points) history = Order.get(outdated_client) for order in history: order.client_id = client.key.id() order.put() response['success'] = True else: response['success'] = False self.render_json(response)
def activate_cash_back(self): from methods.empatika_wallet import deposit, get_balance from google.appengine.ext.deferred import deferred total_cash_back = 0 for cash_back in self.cash_backs: if cash_back.status == cash_back.READY: total_cash_back += cash_back.amount cash_back.status = cash_back.DONE if total_cash_back > 0: logging.info('cash back with sum=%s' % total_cash_back) deposit(self.client_id, total_cash_back, "order_id_%s" % self.key.id()) deferred.defer(get_balance, self.client_id, raise_error=True) # just to update memcache self.put() return total_cash_back
def post(self): client_id = self.request.get_range('client_id') client = Client.get(client_id) if not client: self.response.set_status(400) self.render_json({"description": u'Клиент не найден'}) return amount = self.request.get_range('amount', default=None) if amount is None or amount < 1: self.response.set_status(400) self.render_json({"description": u'Неверная сумма'}) return wallet_source = "barista:%s:%s" % (self.user.login, int(time.time())) try: wallet_result = empatika_wallet.deposit(client_id, amount * 100, wallet_source) except EmpatikaWalletError as e: self.response.set_status(400) self.render_json({ "description": e.message }) else: self.user.deposit_history.append(Deposit(source=wallet_source, amount=amount)) self.user.put() self.render_json({ "balance": wallet_result["balance"] / 100.0 })
def deactivate(self, namespace): from methods.empatika_promos import register_order from methods.empatika_wallet import deposit from models.config.config import config module = config.SHARE_INVITATION_MODULE if module.sender_accumulated_points or module.sender_wallet_points: sender_order_id = "sender_referral_%s" % self.recipient.id() if module.sender_accumulated_points: register_order(user_id=self.sender.id(), points=module.sender_accumulated_points, order_id=sender_order_id) if module.sender_wallet_points: deposit(self.sender.id(), module.sender_wallet_points * 100, source=sender_order_id) sender = self.sender.get() text = u'Приглашенный Вами друг сделал заказ. Вам начислены бонусы!' header = u'Бонусы!' SimplePush(text, False, text, header, sender, namespace).send() if module.recipient_accumulated_points or module.recipient_wallet_points: recipient_order_id = "recipient_referral_%s" % self.recipient.id() if module.recipient_accumulated_points: register_order(user_id=self.recipient.id(), points=module.recipient_accumulated_points, order_id=recipient_order_id) if module.recipient_wallet_points: deposit(self.recipient.id(), module.recipient_wallet_points * 100, source=recipient_order_id) recipient = self.recipient.get() text = u'Вы сделали заказ по приглашению. Вам начислены бонусы!' header = u'Бонусы!' SimplePush(text, False, text, header, recipient, namespace).send() self.status = self.DONE self.put()
def post(self): client_id = self.request.get("client_id") or int( self.request.headers.get('Client-Id', 0)) binding_id = self.request.get("binding_id") amount = self.request.get_range("amount") legal = LegalInfo.query().get( ) # TODO find solution for multiple legals order_number = "dp_%s_%s" % (client_id, int(time.time())) success, result = alfa_bank.create_simple(legal.alfa_login, legal.alfa_password, amount, order_number, "_", client_id) if not success: self.response.set_status(400) self.render_json({"description": u"Ошибка перевода с карты"}) return alfa_order_id = result success, error = alfa_bank.hold_and_check(legal.alfa_login, legal.alfa_password, alfa_order_id, binding_id) if not success: self.response.set_status(400) self.render_json({"description": u"Ошибка перевода с карты"}) return wallet_source = "alfa:%s" % alfa_order_id try: wallet_result = empatika_wallet.deposit(client_id, amount * 100, wallet_source) except empatika_wallet.EmpatikaWalletError as e: alfa_bank.reverse(legal.alfa_login, legal.alfa_password, alfa_order_id) self.response.set_status(400) self.render_json({"description": e.message}) else: alfa_bank.deposit(legal.alfa_login, legal.alfa_password, alfa_order_id, 0) self.render_json({"balance": wallet_result["balance"] / 100.0})