def Unblock(self, amount_pln, game):
     self._proto.payments.free_balance_pln += amount_pln
     self._proto.payments.total_blocked_pln -= amount_pln
     self._proto.payments.transaction.add(
         timestamp=time_util.DateTimeToTimestampProto(time_util.now()),
         type=vbreg_pb2.Transaction.UNBLOCK,
         amount_pln=amount_pln,
         game={'id': game.id})
 def GetCancelationFee(self):
     num_days_before_game = int(
         max((self.GetStartTime() - time_util.now()).total_seconds(), 0) /
         _NUM_SECONDS_IN_DAY)
     rule = list_util.GetOnlyOneByPredicate(
         CONFIG.cancelation_fee_rule, lambda rule:
         (rule.min_days <= num_days_before_game and (not rule.HasField(
             'max_days') or num_days_before_game < rule.max_days)))
     return round(rule.fraction * self.price_pln)
 def Return(self, amount_pln, game):
     self._proto.payments.balance_pln += amount_pln
     self._proto.payments.free_balance_pln += amount_pln
     self._proto.payments.total_paid_pln -= amount_pln
     self._proto.payments.transaction.add(
         timestamp=time_util.DateTimeToTimestampProto(time_util.now()),
         type=vbreg_pb2.Transaction.RETURN,
         amount_pln=amount_pln,
         game={'id': game.id})
 def Deposit(self, amount_pln, deposit_source):
     self._proto.payments.balance_pln += amount_pln
     self._proto.payments.free_balance_pln += amount_pln
     self._proto.payments.total_deposited_pln += amount_pln
     self._proto.payments.transaction.add(
         timestamp=time_util.DateTimeToTimestampProto(time_util.now()),
         type=vbreg_pb2.Transaction.DEPOSIT,
         amount_pln=amount_pln,
         deposit_source=deposit_source)
 def _AssertStartTimeEndTimeValid(cls, request, proto=None):
     start_time = time_util.DateTimeFromTimestampProto(
         request.start_time if request.HasField('start_time'
                                                ) else proto.start_time)
     end_time = time_util.DateTimeFromTimestampProto(
         request.end_time if request.HasField('end_time'
                                              ) else proto.end_time)
     if start_time < time_util.now():
         raise UserVisibleException('Start time must be in the future')
     if end_time <= start_time:
         raise UserVisibleException(
             'End time must be later than start time')
    def FromRequest(cls, request, games):
        """Creates an instance from a proto request. Factory method.

    Args:
      request: PlayerAddOrTouchRequest. Player to add.
      games: Games. Shared service state.
    Returns:
      _Player.
    """
        # Create a new Player proto from request.
        proto = vbreg_pb2.Player(
            facebook_id=request.facebook_id,
            name=request.name,
            bank_transfer_id=cls._GenerateBankTransferId(request.name, games),
            last_touch=time_util.DateTimeToTimestampProto(time_util.now()))
        proto.payments.balance_pln = 0
        proto.payments.free_balance_pln = 0
        proto.payments.total_deposited_pln = 0
        proto.payments.total_paid_pln = 0
        proto.payments.total_blocked_pln = 0
        # Wrap a _Player instance around the Player proto.
        return cls(observable.Create(proto, with_delta=False))
 def UpdateLastTouch(self):
     time_util.DateTimeToTimestampProto(time_util.now(),
                                        self._proto.last_touch)