Exemplo n.º 1
0
def get_credit (username, password, account):
    """
        Return credit for an user and an account given
    """

    account = Customer.check_customer_and_credit (username, password, account)
    if account < 0:
        if account == Purchase.INSUFFICIENT_CREDIT:
            return 0
        return account #Error
    return account.get_real_credit ()
Exemplo n.º 2
0
def send_sms_channel(username, password, account, channel, text, activationDate = None):
    """
        Send a msg to a channel, with a account given        
    """
    try:
        account = Customer.check_customer_and_credit (username, password, account)
    except OutOfCredit:
        return ACCOUNT_NO_CREDIT
    if account < 0:
        return account
    if activationDate is None:
        activationDate = datetime.datetime.now ()
    chmsg_id = Channel.create_one (text, channel, account, activationDate)
    return Message.objects.get(channelmessage__id = chmsg_id).id
Exemplo n.º 3
0
def send_sms(username, password, account, phoneNumber, text, activationDate = None):
    """
        Send a text msg to a phone over an account given
    """
    try:
        account = Customer.check_customer_and_credit(username, password, account)
    except OutOfCredit:
        return ACCOUNT_NO_CREDIT 
    if account < 0:
        return account
    if not activationDate:
        activationDate = datetime.datetime.now()
    phoneNumber = check_mobile(phoneNumber)
    if phoneNumber < 0:
        return phoneNumber
    return Message.create_one(text, phoneNumber, activationDate, account)
Exemplo n.º 4
0
def send_sms_many(username, password, account, phoneList, text, activationDate = None):
    """
        Send a text msg to a many phones over an account given
    """
    try:
        account = Customer.check_customer_and_credit (username, password, account, len(phoneList))
    except OutOfCredit:
        return [ACCOUNT_NO_CREDIT]
    if account < 0:
        return [account]
    activationDate = datetime.datetime.now ()
    idlist = []
    for phone in phoneList:
        if check_mobile(phone) < 0:
            return [-50] # FIXME: cambiar esto por MobileErrorException cuando se implemente
    for phone in phoneList:
        phone = phone.strip()
        idlist.append(Message.create_one (text, phone, activationDate, account))
    return idlist