コード例 #1
0
ファイル: internal.py プロジェクト: bigbag/archive_term-flask
def api_internal_yandex_get_auth_url(discodes_id):
    log = logging.getLogger('payment')

    result = {'error': 1}
    if not PaymentWallet.get_valid_by_discodes_id(discodes_id):
        return make_response(jsonify(result))

    url = None
    if 'url' in request.args:
        url = request.args['url']
    if not url:
        return make_response(jsonify(result))

    try:
        auth_url = Wallet.build_obtain_token_url(
            YandexMoneyConfig.CLIENT_ID,
            url,
            YandexMoneyConfig.WALLET_SCOPE)
    except Exception as e:
        log.error(e)
        return make_response(jsonify(result))
    else:
        result['error'] = 0
        result['url'] = auth_url

    return make_response(jsonify(result))
コード例 #2
0
 def testObtainTokenUrl(self):
     client_id = "client-id"
     url = Wallet.build_obtain_token_url(
         "client-id",
         "http://localhost/redirect",
         ["account-info", "operation_history"]
     )
コード例 #3
0
ファイル: deploy.py プロジェクト: gusarow4321/Exchanger
def get_yandex_auth_url():
    scope = [
        'account-info', 'operation-history', 'operation-details',
        'payment-p2p.limit(1,100000)', 'money-source("wallet","card")'
    ]
    return Wallet.build_obtain_token_url(client_id, 'http://' + ip + '/ym',
                                         scope) + '&response_type=code'
コード例 #4
0
ファイル: bot.py プロジェクト: o0neup/hackaym
def get_auth_url(user_id, code_redirect_uri=REDIRECT_TO):
    """
    :param user_id:
    :param code_redirect_uri:
    :return:
    """
    redirect_url = "{}/{}?user_id={}".format(
        BASE_URL, code_redirect_uri, user_id)
    return Wallet.build_obtain_token_url(client_id=YM_CLIENT_ID, redirect_uri=redirect_url,
                                         scope=YM_SCOPE)
コード例 #5
0
ファイル: views.py プロジェクト: longshortT/tradeinsights
def wallet(request):
    if request.method == 'POST':
        wallet = Wallets.objects.get(pk=request.POST.get('wallet'))
        if wallet.name == 'Yandex Money':
            if not settings.YANDEX_MONEY_CLIENT_ID or not settings.YANDEX_MONEY_REDIRECT_URI or not \
                    settings.YANDEX_MONEY_CLIENT_SECRET:
                return HttpResponse('You must define yandex money settings',
                                    status=404)
            scope = ['account-info', 'operation-history', 'operation-details']
            auth_url = Wallet.build_obtain_token_url(
                client_id=settings.YANDEX_MONEY_CLIENT_ID,
                redirect_uri=settings.YANDEX_MONEY_REDIRECT_URI,
                scope=scope) + '&response_type=code'
            return redirect(auth_url)
        else:
            uw = UserWallet()
            uw.user = request.user
            uw.address = request.POST.get('address')
            uw.wallet = wallet
            uw.save()
    elif request.method == 'GET':
        if not settings.YANDEX_MONEY_CLIENT_ID or not settings.YANDEX_MONEY_REDIRECT_URI or not \
                settings.YANDEX_MONEY_CLIENT_SECRET:
            return HttpResponse('You must define yandex money settings',
                                status=404)
        access_token = Wallet.get_access_token(
            client_id=settings.YANDEX_MONEY_CLIENT_ID,
            redirect_uri=settings.YANDEX_MONEY_REDIRECT_URI,
            code=request.GET.get('code'),
            client_secret=settings.YANDEX_MONEY_CLIENT_SECRET)
        access_token = access_token['access_token']
        wallet = Wallet(access_token)
        account_info = wallet.account_info()
        uw = UserWallet()
        uw.wallet = Wallets.objects.get(name='Yandex Money')
        uw.access_token = access_token
        uw.user = request.user
        uw.address = account_info['account']
        uw.balance = account_info['balance']
        uw.save()
    return redirect(index)
コード例 #6
0
ファイル: server.py プロジェクト: EremeykinS/bot
 def do_GET(self):
     #DB connection
     con = sqlite3.connect('/home/user/bot/users.sqlite')
     cur = con.cursor()
     p = urlparse(self.path)
     q = parse_qs(p.query)
     self.send_response(302, 'Found')
     if 'cid' in q:
         scope = ['account-info', 'operation-history', 'payment-p2p']
         auth_url = Wallet.build_obtain_token_url(config.client_id, config.redirect_uri, scope)
         self.send_header('Location', auth_url)
         if 'b' in q:
             self.send_header("Set-Cookie", "cid=" + q['cid'][0] + '&b=1')
         else:
             self.send_header("Set-Cookie", "cid=" + q['cid'][0] + '&to=' + q['to'][0] + '&amount=' + q['amount'][0])
     elif 'code' in q:
         access_token = Wallet.get_access_token(config.client_id, q['code'][0], config.redirect_uri, client_secret=None)
         cookie = parse_qs(self.headers.get('Cookie'))
         cid = cookie['cid'][0]
         cur.execute('INSERT INTO users (cid, token) VALUES ("' + str(cid) +'", "' + access_token['access_token'] + '")')
         con.commit()
         wallet = Wallet(access_token['access_token'])
         if 'b' in cookie:
             queue.put({'cid': cid, 'b': wallet.account_info()['balance_details']['available']})
         else:
             to = cookie['to'][0]
             amount = cookie['amount'][0]
             request_options = {"pattern_id": "p2p", "to": to, "amount_due": amount, "comment": "переведено через бота", "message": "переведено через бота", "label": "testPayment"}
             request_result = wallet.request_payment(request_options)
             # check status
             process_payment = wallet.process_payment({"request_id": request_result['request_id'],})
             # check result
             if process_payment['status'] == "success":
                 queue.put({'cid': cid, 'result':'+'})
             else:
                 queue.put({'cid': cid, 'result':'-'})
         self.send_header('Location', 'http://telegram.me/GodMoneyBot')
     self.end_headers()
     con.close()
コード例 #7
0
ファイル: internal.py プロジェクト: bigbag/archive_term-flask
def api_internal_yandex_get_auth_url(discodes_id):
    log = logging.getLogger('payment')

    result = {'error': 1}
    if not PaymentWallet.get_valid_by_discodes_id(discodes_id):
        return make_response(jsonify(result))

    url = None
    if 'url' in request.args:
        url = request.args['url']
    if not url:
        return make_response(jsonify(result))

    try:
        auth_url = Wallet.build_obtain_token_url(
            YandexMoneyConfig.CLIENT_ID, url, YandexMoneyConfig.WALLET_SCOPE)
    except Exception as e:
        log.error(e)
        return make_response(jsonify(result))
    else:
        result['error'] = 0
        result['url'] = auth_url

    return make_response(jsonify(result))
コード例 #8
0
 def testObtainTokenUrl(self):
     Wallet.build_obtain_token_url("client-id", "http://localhost/redirect",
                                   ["account-info", "operation_history"])
コード例 #9
0
from yandex_money.api import Wallet, ExternalPayment

scope = ['account-info', 'operation-history'] # etc..
auth_url = Wallet.build_obtain_token_url(client_id,
    redirect_uri, scope)

access_token = Wallet.get_access_token(client_id, code, redirect_uri,
    client_secret=None)

account_info = api.account_info()
balance = account_info['balance'] # and so on

request_options = {
    "pattern_id": "p2p",
    "to": "410011161616877",
    "amount_due": "0.02",
    "comment": "test payment comment from yandex-money-python",
    "message": "test payment message from yandex-money-python",
    "label": "testPayment",
    "test_payment": true,
    "test_result": "success"
};
request_result = api.request(request_options)
# check status

process_payment = api.process({
    "request_id": request_result['request_id'],
})
# check result
if process_payment['status'] == "success":
    # show success page
コード例 #10
0
 def do_GET(self):
     #DB connection
     con = sqlite3.connect('/home/user/bot/users.sqlite')
     cur = con.cursor()
     p = urlparse(self.path)
     q = parse_qs(p.query)
     self.send_response(302, 'Found')
     if 'cid' in q:
         scope = [
             'account-info', 'operation-history', 'payment-p2p'
         ]
         auth_url = Wallet.build_obtain_token_url(
             config.client_id, config.redirect_uri, scope)
         self.send_header('Location', auth_url)
         if 'b' in q:
             self.send_header("Set-Cookie",
                              "cid=" + q['cid'][0] + '&b=1')
         else:
             self.send_header(
                 "Set-Cookie", "cid=" + q['cid'][0] + '&to=' +
                 q['to'][0] + '&amount=' + q['amount'][0])
     elif 'code' in q:
         access_token = Wallet.get_access_token(config.client_id,
                                                q['code'][0],
                                                config.redirect_uri,
                                                client_secret=None)
         cookie = parse_qs(self.headers.get('Cookie'))
         cid = cookie['cid'][0]
         cur.execute('INSERT INTO users (cid, token) VALUES ("' +
                     str(cid) + '", "' +
                     access_token['access_token'] + '")')
         con.commit()
         wallet = Wallet(access_token['access_token'])
         if 'b' in cookie:
             queue.put({
                 'cid':
                 cid,
                 'b':
                 wallet.account_info()['balance_details']
                 ['available']
             })
         else:
             to = cookie['to'][0]
             amount = cookie['amount'][0]
             request_options = {
                 "pattern_id": "p2p",
                 "to": to,
                 "amount_due": amount,
                 "comment": "переведено через бота",
                 "message": "переведено через бота",
                 "label": "testPayment"
             }
             request_result = wallet.request_payment(
                 request_options)
             # check status
             process_payment = wallet.process_payment({
                 "request_id":
                 request_result['request_id'],
             })
             # check result
             if process_payment['status'] == "success":
                 queue.put({'cid': cid, 'result': '+'})
             else:
                 queue.put({'cid': cid, 'result': '-'})
         self.send_header('Location',
                          'http://telegram.me/GodMoneyBot')
     self.end_headers()
     con.close()
コード例 #11
0
print(delete('http://localhost:5000/api/news/1').json())'''
'''s = get('http://localhost:5000//api/v2/image/1').json()['image']
print(s)'''
'''with open('photo.jpg', 'rb') as f:
    a = f.read()
a = a.decode('latin1')
a = a.encode('latin1')

with open('good.jpg', 'wb') as file:
    file.write(a)'''

scope = ['account-info', 'operation-history']  # etc..
client_id = 'A76ACB24B8300F9585A065ECEBF272C746AC909DE178E8D696D17B6E1D0BA0C6'
redirect_uri = 'http://localhost/redirect'
url = Wallet.build_obtain_token_url(client_id, "http://localhost/redirect",
                                    ["account-info", "operation_history"])
print(url)
access_token = Wallet.get_access_token(client_id,
                                       code,
                                       redirect_uri,
                                       client_secret=None)
api = Wallet(access_token)
account_info = api.account_info()
balance = account_info['balance']  # and so on

request_options = {
    "pattern_id": "p2p",
    "to": "410011161616877",
    "amount_due": "0.02",
    "comment": "test payment comment from yandex-money-python",
    "message": "test payment message from yandex-money-python",