Exemplo n.º 1
0
    def send_success_sms(message_key: str, user: User, other_user: User, amount: float, reason: str, tx_time: datetime,
                         balance: float):

        amount_dollars = rounded_dollars(amount)
        rounded_balance_dollars = rounded_dollars(balance)

        TokenProcessor.send_sms(user, message_key, amount=amount_dollars, token_name=default_token(user).symbol,
                                other_user=other_user.user_details(), date=tx_time.strftime('%d/%m/%Y'), reason=reason,
                                time=tx_time.strftime('%I:%M %p'), balance=rounded_balance_dollars)
Exemplo n.º 2
0
    def exchange_success_sms(message_key: str, user: User, other_user: User, own_amount: float, other_amount: float,
                             tx_time: datetime, balance: float):

        rounded_own_amount_dollars = rounded_dollars(own_amount)
        rounded_other_amount_dollars = rounded_dollars(other_amount)
        rounded_balance_dollars = rounded_dollars(balance)

        TokenProcessor.send_sms(
            user, message_key,
            own_amount=rounded_own_amount_dollars, other_amount=rounded_other_amount_dollars,
            own_token_name=default_token(user).symbol, other_token_name=default_token(other_user).symbol,
            other_user=other_user.user_details(), date=tx_time.strftime('%d/%m/%Y'),
            time=tx_time.strftime('%I:%M %p'), balance=rounded_balance_dollars)
Exemplo n.º 3
0
    def fetch_exchange_rate(user: User):
        from_token = default_token(user)

        default_limit, limit_amount = TokenProcessor.get_default_limit(
            user, from_token)
        exchange_rate_full_precision = TokenProcessor.get_exchange_rate(
            user, from_token)

        exchange_limit = rounded_dollars(limit_amount)
        exchange_rate = round_to_sig_figs(exchange_rate_full_precision, 3)
        exchange_sample_value = round(exchange_rate_full_precision *
                                      float(1000))

        if exchange_limit:
            TokenProcessor.send_sms(
                user,
                "exchange_rate_can_exchange_sms",
                token_name=from_token.symbol,
                exchange_rate=exchange_rate,
                exchange_limit=exchange_limit,
                exchange_sample_value=exchange_sample_value,
                limit_period=default_limit.time_period_days)
        else:
            TokenProcessor.send_sms(
                user,
                "exchange_rate_sms",
                token_name=from_token.symbol,
                exchange_rate=exchange_rate,
                exchange_sample_value=exchange_sample_value,
            )
    def send_success_sms(message_key: str, user: User, other_user: User,
                         amount: float, tx_time: datetime, balance: float):

        amount_dollars = rounded_dollars(amount)
        rounded_balance_dollars = rounded_dollars(balance)

        user_details = user.user_details().replace('+254', '0')
        other_user_details = other_user.user_details().replace('+254', '0')
        TokenProcessor.send_sms(user=user,
                                message_key=message_key,
                                amount=int(float(amount_dollars)),
                                token_name=default_token(user).symbol,
                                user_details=user_details,
                                other_user_details=other_user_details,
                                date=tx_time.strftime('%d/%m/%Y'),
                                time=tx_time.strftime('%I:%M %p'),
                                balance=int(float(rounded_balance_dollars)))
Exemplo n.º 5
0
 def ge_string(t):
     if t['limit'].transfer_balance_fraction:
         # TODO: This doesn't seem DRY with respect to 'get default exchange rate'
         allowed_amount = rounded_dollars(
             t['limit'].transfer_balance_fraction * t['balance'])
         rounded_rate = round_to_sig_figs(t['exchange_rate'], 3)
         return (
             f"{allowed_amount} {t['name']} (1 {t['name']} = {rounded_rate} {reserve_token.symbol})"
         )
     else:
         return ""
Exemplo n.º 6
0
    def exchange_token(sender: User, agent: User, amount: float):
        try:
            # TODO: do agents have default token being reserve?
            to_amount = TokenProcessor.transfer_token(
                sender, agent, amount, transfer_subtype=TransferSubTypeEnum.AGENT_OUT
            )
            sender_tx_time = pendulum.now(sender.default_organisation.timezone)
            agent_tx_time = pendulum.now(agent.default_organisation.timezone)
            sender_balance = TokenProcessor.get_balance(sender)
            agent_balance = TokenProcessor.get_balance(agent)
            TokenProcessor.exchange_success_sms(
                "exchange_token_sender_sms", sender, agent, amount, to_amount, sender_tx_time, sender_balance
            )
            TokenProcessor.exchange_success_sms(
                "exchange_token_agent_sms", agent, sender, to_amount, amount, agent_tx_time, agent_balance
            )

        except NoTransferAllowedLimitError as e:
            TokenProcessor.send_sms(
                sender,
                "exchange_not_allowed_error_sms",
            )

        except (TransferAmountLimitError, MinimumSentLimitError) as e:
            TokenProcessor.send_sms(
                sender,
                "exchange_amount_error_sms",
                amount=rounded_dollars(e.transfer_amount_limit),
                token=e.token,
                limit_period=e.limit_time_period_days
            )
        except TransferBalanceFractionLimitError as e:
            TokenProcessor.send_sms(
                sender,
                "exchange_fraction_error_sms",
                token=e.token,
                percent=f"{int(e.transfer_balance_fraction_limit * 100)}%"
            )
        except TransferCountLimitError as e:
            TokenProcessor.send_sms(
                sender,
                "exchange_count_error_sms",
                count=e.transfer_count_limit,
                token=e.token,
                limit_period=e.limit_time_period_days
            )
        except MaximumPerTransferLimitError as e:
            TokenProcessor.send_sms(
                sender,
                "maximum_per_transaction_error_sms",
                token=e.token,
                amount=e.maximum_amount_limit
            )
Exemplo n.º 7
0
def send_onboarding_sms_messages(user):

    # First send the intro message
    organisation = getattr(g, 'active_organisation', None) or user.default_organisation

    intro_message = i18n_for(
        user,
        "general_sms.welcome.{}".format(organisation.custom_welcome_message_key or 'generic'),
        first_name=user.first_name,
        balance=rounded_dollars(user.transfer_account.balance),
        token=user.transfer_account.token.name
    )

    send_message(user.phone, intro_message)

    send_terms_message_if_required(user)
Exemplo n.º 8
0
    def send_token(sender: User, recipient: User, amount: float,
                   reason_str: str, reason_id: int):
        try:
            exchanged_amount = TokenProcessor.transfer_token(
                sender, recipient, amount, reason_id)

            sender_tx_time = pendulum.now(sender.default_organisation.timezone)
            recipient_tx_time = pendulum.now(
                recipient.default_organisation.timezone)

            sender_balance = TokenProcessor.get_balance(sender)
            recipient_balance = TokenProcessor.get_balance(recipient)
            if exchanged_amount is None:
                TokenProcessor.send_success_sms("send_token_sender_sms",
                                                sender, recipient, amount,
                                                reason_str, sender_tx_time,
                                                sender_balance)

                TokenProcessor.send_success_sms("send_token_recipient_sms",
                                                recipient, sender, amount,
                                                reason_str, recipient_tx_time,
                                                recipient_balance)
            else:
                TokenProcessor.exchange_success_sms(
                    "exchange_token_sender_sms", sender, recipient, amount,
                    exchanged_amount, sender_tx_time, sender_balance)

                TokenProcessor.exchange_success_sms("exchange_token_agent_sms",
                                                    recipient, sender,
                                                    exchanged_amount, amount,
                                                    recipient_tx_time,
                                                    recipient_balance)

        except InsufficientBalanceError as e:
            token_balances_dollars, token_exchanges = TokenProcessor._get_token_balances(
                sender)

            TokenProcessor.send_sms(sender,
                                    "insufficient_balance_sms",
                                    amount=cents_to_dollars(amount),
                                    token_name=default_token(sender).name,
                                    recipient=recipient.user_details(),
                                    token_balances=token_balances_dollars)

        except TransferAmountLimitError as e:
            # Use a different message here from that used for exchange,
            # because the issue is caused by KYC (ie something the user can change by providing), rather than
            # our price-stability controls
            TokenProcessor.send_sms(sender,
                                    "transfer_amount_error_sms",
                                    amount=rounded_dollars(
                                        e.transfer_amount_limit),
                                    token=e.token,
                                    limit_period=e.limit_time_period_days)

        except Exception as e:
            # TODO: SLAP? all the others take input in cents
            TokenProcessor.send_sms(sender,
                                    "send_token_error_sms",
                                    amount=cents_to_dollars(amount),
                                    token_name=default_token(sender).name,
                                    recipient=recipient.user_details())