コード例 #1
0
def send_money(number, amount):
    number = validate_number(number)
    qiwi_token = get_config_var('QiwiToken')
    if not qiwi_token:
        return False
    s = requests.Session()
    s.headers['authorization'] = 'Bearer ' + qiwi_token
    id_details = detect_payment_system(number)
    if id_details['code']['value'] == '2' and 'Неверно введен номер банковской карты' in id_details['message']:
        payment_id = '99'
    else:
        payment_id = id_details["message"]

    url = f'https://edge.qiwi.com/sinap/api/v2/terms/{payment_id}/payments'
    data = {
        "id": str(int(time() * 1000)),
        "sum": {
            "amount": amount,
            "currency": "643"
        },
        "paymentMethod": {
            "type": "Account",
            "accountId": "643"
        },
        "fields": {
            "account": number
        }
    }
    res = s.post(url, json=data)
    if not res.ok:
        qiwi_logger.warning(res.text)
    return res.ok
コード例 #2
0
def get_yandex_balance():
    yandex_money_token = get_config_var('YandexMoneyToken')
    if not yandex_money_token:
        return False
    wallet = Wallet(yandex_money_token)
    account_info = wallet.account_info()
    return account_info['balance']
コード例 #3
0
def commission_amount(number, amount):
    number = validate_number(number)
    qiwi_token = get_config_var('QiwiToken')
    if not qiwi_token:
        return False
    s = requests.Session()
    s.headers['authorization'] = 'Bearer ' + qiwi_token
    id_details = detect_payment_system(number)
    if id_details['code']['value'] == '2':
        payment_id = '99'
    else:
        payment_id = id_details['message']
    url = f'https://edge.qiwi.com/sinap/providers/{payment_id}/onlineCommission'
    data = {
        "account": number,
        "paymentMethod": {
            "type": "Account",
            "accountId": "643"
        },
        "purchaseTotals": {
            "total": {
                "amount": amount,
                "currency": "643"
            }
        }
    }
    res = s.post(url, json=data)
    return res.json()['qwCommission']['amount']
コード例 #4
0
def add_commission(amount, payment, number=None):
    commission = get_config_var('Commission')
    commission = 10 if not commission else int(commission)
    res = amount * (1 + commission / 100)
    if payment != 'yad' and number:
        res += commission_amount(number, res)
    return res
コード例 #5
0
def get_qiwi_balance():
    qiwi_token = get_config_var('QiwiToken')
    if not qiwi_token:
        return False
    s = requests.Session()
    s.headers['authorization'] = 'Bearer ' + qiwi_token
    accounts = s.get(f"https://edge.qiwi.com/funding-sources/v2/persons/{validate_number(own_qiwi_number)}/accounts")
    for account in json.loads(accounts.text)['accounts']:
        if account['defaultAccount'] and account['currency'] == 643:
            return account['balance']['amount']
    return 0
コード例 #6
0
def check_payment_history(comment, amount):
    yandex_money_token = get_config_var('YandexMoneyToken')
    if not yandex_money_token:
        return False
    wallet = Wallet(yandex_money_token)
    options = {
        "type": "deposition",
        "details": "true"
    }
    for operation in wallet.operation_history(options)['operations']:
        try:
            if operation['message'] == comment and operation['amount'] >= amount:
                return True
        except KeyError:
            continue
    return False
コード例 #7
0
def check_payment_history(comment, amount):
    qiwi_token = get_config_var('QiwiToken')
    if not qiwi_token:
        return False
    s = requests.Session()
    s.headers['authorization'] = 'Bearer ' + qiwi_token
    params = {
        'rows': '50',
        'operation': 'IN'
    }
    h = s.get(f'https://edge.qiwi.com/payment-history/v2/persons/{validate_number(own_qiwi_number)}/payments',
              params=params)
    data = json.loads(h.text)['data']
    for payment in data:
        if payment['comment'] is not None and comment in payment['comment'] and payment['sum']['amount'] >= amount:
            return True
    return False
コード例 #8
0
def send_money(number, amount):
    yandex_money_token = get_config_var('YandexMoneyToken')
    if not yandex_money_token:
        return False
    wallet = Wallet(yandex_money_token)
    options = {
        "pattern_id": "p2p",
        "to": number,
        "amount_due": amount
    }
    request_result = wallet.request_payment(options)
    process_payment = wallet.process_payment({"request_id": request_result['request_id']})
    if process_payment['status'] == "success":
        return True
    else:
        ym_logger.warning(process_payment['error'])
        return False
コード例 #9
0
ファイル: coinbase_api.py プロジェクト: gusarow4321/Exchanger
def get_client():
    coinbase_api_key = get_config_var('CoinbaseApiKey')
    coinbase_api_secret = get_config_var('CoinbaseSecretKey')
    if not coinbase_api_key or not coinbase_api_secret:
        return False
    return Client(coinbase_api_key, coinbase_api_secret)
コード例 #10
0
def paying(message):
    user_id = message.from_user.id
    text = message.text
    if text == '✅ Проверить оплату':
        date, state, payment, action, rub, btc, address = db.get_state(
            user_id, [
                'Date', 'State', 'Payment', 'Action', 'AmountRUB', 'AmountBTC',
                'Address'
            ])
        if (datetime.now() - date).seconds // 3600 > 24:
            db.set_state(user_id, {'State': ''})
            bot.send_message(
                user_id,
                'Ваша операция просрочена. Вы можете начать новую\n\n' +
                menu_message.format(*get_rates()),
                reply_markup=menu_markup)
        else:
            comment = state.split('|')[1]
            admin_username = db.get_config_var('AdminUsername')
            if action == 'buy':
                confirmed = payments_checking[payment](comment, rub)
            else:
                confirmed = payments_checking['btc'](comment, btc)

            if confirmed:
                converted = round(convert_to_rub(btc))
                if action == 'buy':
                    tx_hash = send_btc(address, btc)
                    if tx_hash:
                        bot.send_message(
                            user_id,
                            f'Ваш платеж принят. Ожидайте поступления BTC на свой адрес.'
                        )
                        db.new_transaction(user_id, rub, converted,
                                           datetime.now())
                        bot.send_message(
                            admin_id,
                            f'❇️ Новая операция ❇️\nПользователь @{message.from_user.username} '
                            f'id:`{user_id}`\nОплачено: {rub}\nПолучено: {converted}'
                        )
                    else:
                        bot.send_message(
                            user_id,
                            f'Возникла ошибка во время перевода... Возможно вы неверно указали '
                            f'свой номер\nОбратитесь за помощью к админу {admin_username}'
                        )
                else:
                    if payment == 'yad':
                        sent = yandexmoney.send_money(address, rub)
                    else:
                        sent = qiwi.send_money(address, rub)

                    if sent:
                        bot.send_message(
                            user_id,
                            'Ваш платеж принят. Ожидайте поступления средств.')
                        db.new_transaction(user_id, convert_to_rub(btc), rub,
                                           datetime.now())
                        bot.send_message(
                            admin_id,
                            f'❇️ Новая операция ❇️\nПользователь @{message.from_user.username} '
                            f'id:`{user_id}`\nОплачено: {converted}\nПолучено: {rub}'
                        )
                    else:
                        bot.send_message(
                            user_id,
                            f'Возникла ошибка во время перевода... Возможно вы неверно указали '
                            f'свой номер\nОбратитесь за помощью к админу {admin_username}'
                        )
                start_handler(message)
            else:
                bot.send_message(
                    user_id,
                    f'Что то пошло не так...\nПопробуйте еще раз через 5-10 минут.\nВ случае '
                    f'нескольких неудач, обратитесь за помощью к админу {admin_username}'
                )
    elif text == '❌ Отменить операцию':
        db.set_state(user_id, {'State': ''})
        bot.send_message(user_id,
                         menu_message.format(*get_rates()),
                         reply_markup=menu_markup)