@Armlet_abuse

Как создать платеж AnyPay?

Не могу создать платёж вылезает ошибка
KeyError: 'result'(почему она вылезает?)
Вот код:
merchant_id='мой айди'
currency = 'RUB'
pay_id = 101
amount = 10,00
desc = 'Test'
method = 'card'
email = 'r@mail.ru'
sign = hashlib.sha256(
f'create-payment{api_id}{project_id}{pay_id}{amount}{currency}{desc}{method}{api_key}'.encode())
responce = requests.get(
f"https://anypay.io/api/create-payment/{api_id}?proj...}",
params={"sign": sign.hexdigest()})

json_dump = json.loads(responce.text)
url = json_dump["result"]["payment_url"]
bot.send_message(url)
return url
  • Вопрос задан
  • 571 просмотр
Решения вопроса 1
Варианты:
Проверь: ключ API, ID продавца и ID проекта.
правильный ли URL для конечной точки API?
Какой ответ от API получаешь? выведи в responce.text
api_id = 'your_api_id'
project_id = 'your_project_id'
pay_id = 101
amount = 10.00
currency = 'RUB'
desc = 'Test'
method = 'card'
email = 'r@mail.ru'
api_key = 'your_api_key'

sign = hashlib.sha256(f'create-payment{api_id}{project_id}{pay_id}{amount}{currency}{desc}{method}{api_key}'.encode()).hexdigest()

response = requests.get(f'https://anypay.io/api/create-payment/{api_id}',
                        params={'project_id': project_id, 
                                'pay_id': pay_id,
                                'amount': amount,
                                'currency': currency,
                                'desc': desc,
                                'method': method,
                                'email': email,
                                'sign': sign})

response_json = json.loads(response.text)

if 'result' in response_json:
    url = response_json['result']['payment_url']
    print(url)
else:
    print(response_json['error'])

Можешь попробовать это
Ответ написан
Комментировать
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы