{"id":412614,"date":"2024-06-29T22:39:26","date_gmt":"2024-06-29T22:39:26","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=412614"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=412614","title":{"rendered":"<span>\u041f\u0440\u0438\u0435\u043c \u043f\u043b\u0430\u0442\u0435\u0436\u0435\u0439 \u0432 \u043a\u0440\u0438\u043f\u0442\u043e \u0432\u0430\u043b\u044e\u0442\u0430\u0445 \u0432 Telegram \u0431\u043e\u0442\u0435 \u0447\u0435\u0440\u0435\u0437 WalletPay \u0438 Python\/Flask<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w780q1\/getpro\/habr\/upload_files\/d91\/ae1\/66d\/d91ae166dfd801ccba991d3fa15eb2d6.jpg\" alt=\"\u041a\u0440\u0438\u043f\u0442\u043e\u0432\u0430\u043b\u044e\u0442\u044b \u0432 Telegram\" title=\"\" width=\"780\" height=\"438\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/d91\/ae1\/66d\/d91ae166dfd801ccba991d3fa15eb2d6.jpg\" data-blurred=\"true\"\/><\/figure>\n<p>\u041f\u0440\u0438\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e \u0441\u043e\u043e\u0431\u0449\u0435\u0441\u0442\u0432\u043e.<\/p>\n<p>\u0411\u043e\u0442 Telegram <a class=\"mention\" href=\"\/users\/wallet\">@wallet<\/a> \u043d\u0435\u0434\u0430\u0432\u043d\u043e \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u0438\u043b <a href=\"https:\/\/pay.wallet.tg\/\" rel=\"noopener noreferrer nofollow\">API \u0434\u043b\u044f \u043f\u0440\u0438\u0435\u043c\u0430 \u043f\u043b\u0430\u0442\u0435\u0436\u0435\u0439<\/a> \u0432 \u0441\u0442\u043e\u0440\u043e\u043d\u043d\u0438\u0445 Telegram \u0431\u043e\u0442\u0430\u0445. \u0418\u0437 \u043a\u0440\u0438\u043f\u0442\u043e \u0432\u0430\u043b\u044e\u0442 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u044e\u0442\u0441\u044f BTC, TON, USDT.<\/p>\n<p>\u041d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u0441\u0430\u0439\u0442\u0435, \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0441\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u043e \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u043c\u043e\u043c \u043a API \u0431\u043e\u0442\u0435, \u043f\u0440\u043e\u0439\u0442\u0438 \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u0443 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 (\u0431\u0438\u043e\u043c\u0435\u0442\u0440\u0438\u044f \u0434\u043b\u044f \u0444\u0438\u0437\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u043b\u0438\u0446), \u0434\u043e\u0436\u0434\u0430\u0442\u044c\u0441\u044f \u043e\u0434\u043e\u0431\u0440\u0435\u043d\u0438\u044f \u0437\u0430\u044f\u0432\u043a\u0438 \u0438 \u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0440\u0430\u0437\u043c\u0435\u0440\u0430 \u043a\u043e\u043c\u0438\u0441\u0441\u0438\u0438 \u0434\u043b\u044f \u0432\u0430\u0448\u0438\u0445 \u043f\u043b\u0430\u0442\u0435\u0436\u0435\u0439. \u0423 \u043c\u0435\u043d\u044f \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u0430 \u0437\u0430\u043d\u044f\u043b\u0430 \u0447\u0443\u0442\u044c \u0431\u043e\u043b\u0435\u0435 \u0441\u0443\u0442\u043e\u043a.<\/p>\n<p>\u041f\u043e\u0441\u043b\u0435 \u043e\u0434\u043e\u0431\u0440\u0435\u043d\u0438\u044f \u0437\u0430\u044f\u0432\u043a\u0438 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0435 \u0434\u043e\u0441\u0442\u0443\u043f \u0432 \u043b\u0438\u0447\u043d\u044b\u0439 \u043a\u0430\u0431\u0438\u043d\u0435\u0442, \u0433\u0434\u0435 \u043d\u0443\u0436\u043d\u043e \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u043b\u044e\u0447 \u0434\u043b\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a API WalletPay.<\/p>\n<p>\u041f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0438\u0441\u0442\u0443\u043f\u0430\u0442\u044c \u043a \u043f\u0440\u043e\u0434\u0430\u0436\u0430\u043c. \u041f\u043e\u043a\u0443\u043f\u0430\u0442\u0435\u043b\u044e \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0441\u0441\u044b\u043b\u043a\u0443 \u0434\u043b\u044f \u043e\u043f\u043b\u0430\u0442\u044b \u0447\u0435\u0440\u0435\u0437 WalletPay \u0442\u043e\u0432\u0430\u0440\u043e\u0432\/\u0443\u0441\u043b\u0443\u0433 \u0432\u0430\u0448\u0435\u0433\u043e \u0431\u043e\u0442\u0430. \u041a\u043e\u0434 \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u044d\u0442\u043e\u0439 \u0441\u0441\u044b\u043b\u043a\u0438 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0442\u0430\u043a\u0438\u043c.<\/p>\n<pre><code class=\"python\">import requests  def get_pay_link():     headers = {      'Wpay-Store-Api-Key': 'YOUR-API-KEY',      'Content-Type': 'application\/json',      'Accept': 'application\/json',     }      payload = {       'amount': {         'currencyCode': 'USD',  # \u0432\u044b\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c \u0441\u0447\u0435\u0442 \u0432 \u0434\u043e\u043b\u043b\u0430\u0440\u0430\u0445 \u0421\u0428\u0410         'amount': '1.00',       },       'description': 'Goods and service.',       'externalId': 'XXX-YYY-ZZZ',  # ID \u0441\u0447\u0435\u0442\u0430 \u043d\u0430 \u043e\u043f\u043b\u0430\u0442\u0443 \u0432 \u0432\u0430\u0448\u0435\u043c \u0431\u043e\u0442\u0435       'timeoutSeconds': 60 * 60 * 24,  # \u0432\u0440\u0435\u043c\u044f \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0441\u0447\u0435\u0442\u0430 \u0432 \u0441\u0435\u043a\u0443\u043d\u0434\u0430\u0445       'customerTelegramUserId': '999666999',  # ID \u0430\u043a\u043a\u0430\u0443\u043d\u0442\u0430 Telegram \u043f\u043e\u043a\u0443\u043f\u0430\u0442\u0435\u043b\u044f       'returnUrl': 'https:\/\/t.me\/mybot',  # \u043f\u043e\u0441\u043b\u0435 \u0443\u0441\u043f\u0435\u0448\u043d\u043e\u0439 \u043e\u043f\u043b\u0430\u0442\u044b \u043d\u0430\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u043f\u043e\u043a\u0443\u043f\u0430\u0442\u0435\u043b\u044f \u0432 \u043d\u0430\u0448 \u0431\u043e\u0442       'failReturnUrl': 'https:\/\/t.me\/wallet',  # \u043f\u0440\u0438 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u0438 \u043e\u043f\u043b\u0430\u0442\u044b \u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043f\u043e\u043a\u0443\u043f\u0430\u0442\u0435\u043b\u044f \u0432 @wallet     }      response = requests.post(       \"https:\/\/pay.wallet.tg\/wpay\/store-api\/v1\/order\",       json=payload, headers=headers, timeout=10     )     data = response.json()      if (response.status_code != 200) or (data['status'] not in [\"SUCCESS\", \"ALREADY\"]):         logging.warning(\"# code: %s json: %s\", response.status_code, data)         return ''      return data['data']['payLink'] <\/code><\/pre>\n<p>\u0421\u0447\u0435\u0442 \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c \u0432 \u0434\u043e\u043b\u043b\u0430\u0440\u0430\u0445 \u0421\u0428\u0410, \u0435\u0432\u0440\u043e \u0438\u043b\u0438 \u0440\u0443\u0431\u043b\u044f\u0445. \u041f\u0435\u0440\u0435\u0441\u0447\u0435\u0442 \u0432 BTC, TON, USDT \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d \u043f\u043e \u043a\u0443\u0440\u0441\u0443 WalletPay.<\/p>\n<p>\u0414\u043b\u044f \u043f\u043e\u0434\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0438\u044f \u0444\u0430\u043a\u0442\u0430 \u043e\u043f\u043b\u0430\u0442\u044b \u0441\u0447\u0435\u0442\u0430, WalletPay \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0434\u0432\u0435 \u043e\u043f\u0446\u0438\u0438:<\/p>\n<ul>\n<li>\n<p>\u043f\u0435\u0440\u0438\u043e\u0434\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043e\u043f\u0440\u043e\u0441 <a href=\"https:\/\/docs.wallet.tg\/pay\/#tag\/Order\/operation\/getPreview\" rel=\"noopener noreferrer nofollow\">\u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u0441\u0447\u0435\u0442\u0430<\/a> \u0441 \u0432\u0430\u0448\u0435\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u044b.<\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/docs.wallet.tg\/pay\/#section\/Webhook\" rel=\"noopener noreferrer nofollow\">POST-\u0437\u0430\u043f\u0440\u043e\u0441<\/a> \u043d\u0430 \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0439 \u0432\u0430\u043c\u0438 \u0432 \u043b\u0438\u0447\u043d\u043e\u043c \u043a\u0430\u0431\u0438\u043d\u0435\u0442\u0435 <code>https<\/code> \u0430\u0434\u0440\u0435\u0441 (webhook \u0432 \u0442\u0435\u0440\u043c\u0438\u043d\u0430\u0445 WalletPay).<\/p>\n<\/li>\n<\/ul>\n<p>\u042f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b \u0432\u0442\u043e\u0440\u043e\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442. \u041a\u043e\u0434 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430 \u0432\u0435\u0431\u0445\u0443\u043a\u0430 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0442\u0430\u043a\u0438\u043c.<\/p>\n<pre><code class=\"python\">from flask import Flask, request  app = Flask(__name__)  @app.route('\/tgwallet\/ipn', methods=['POST']) def ipn_tgwallet():     for event in request.get_json():         if event[\"type\"] == \"ORDER_PAID\":             data = event[\"payload\"]             print(\"\u041e\u043f\u043b\u0430\u0447\u0435\u043d \u0441\u0447\u0435\u0442 N {} \u043d\u0430 \u0441\u0443\u043c\u043c\u0443 {} {}. \u041e\u043f\u043b\u0430\u0442\u0430 {} {}.\".format(               data[\"externalId\"],  # ID \u0441\u0447\u0435\u0442\u0430 \u0432 \u0432\u0430\u0448\u0435\u043c \u0431\u043e\u0442\u0435, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u043b\u0438 \u043f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u0441\u0441\u044b\u043b\u043a\u0438 \u0434\u043b\u044f \u043e\u043f\u043b\u0430\u0442\u044b               data[\"orderAmount\"][\"amount\"],  # \u0421\u0443\u043c\u043c\u0430 \u0441\u0447\u0435\u0442\u0430, \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u0430\u044f \u043f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u0441\u0441\u044b\u043b\u043a\u0438 \u0434\u043b\u044f \u043e\u043f\u043b\u0430\u0442\u044b               data[\"orderAmount\"][\"currencyCode\"],  # \u0412\u0430\u043b\u044e\u0442\u0430 \u0441\u0447\u0435\u0442\u0430               data[\"selectedPaymentOption\"][\"amount\"][\"amount\"],  # \u0421\u043a\u043e\u043b\u044c\u043a\u043e \u043e\u043f\u043b\u0430\u0442\u0438\u043b \u043f\u043e\u043a\u0443\u043f\u0430\u0442\u0435\u043b\u044c               data[\"selectedPaymentOption\"][\"amount\"][\"currencyCode\"]  # \u0412 \u043a\u0430\u043a\u043e\u0439 \u043a\u0440\u0438\u043f\u0442\u043e\u0432\u0430\u043b\u044e\u0442\u0435             ))      # \u043d\u0443\u0436\u043d\u043e \u0432\u0441\u0435\u0433\u0434\u0430 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u043a\u043e\u0434 200, \u0447\u0442\u043e\u0431\u044b WalletPay \u043d\u0435 \u0434\u0435\u043b\u0430\u043b \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u044b\u0445 \u0432\u044b\u0437\u043e\u0432\u043e\u0432 \u0432\u0435\u0431\u0445\u0443\u043a\u0430     return 'OK' <\/code><\/pre>\n<p>\u041f\u0440\u0435\u0436\u0434\u0435 \u0447\u0435\u043c \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u043e\u043f\u043b\u0430\u0447\u0435\u043d\u043d\u044b\u0439 \u0442\u043e\u0432\u0430\u0440 \u0438\u043b\u0438 \u0443\u0441\u043b\u0443\u0433\u0443, \u043d\u0443\u0436\u043d\u043e \u0443\u0431\u0435\u0434\u0438\u0442\u044c\u0441\u044f, \u0447\u0442\u043e \u0432\u044b\u0437\u043e\u0432 \u0432\u0435\u0431\u0445\u0443\u043a\u0430 \u043f\u0440\u0438\u0448\u0435\u043b \u0438\u0437 WalletPay, \u0430 \u043d\u0435 \u043e\u0442 \u0437\u043b\u043e\u0443\u043c\u044b\u0448\u043b\u0435\u043d\u043d\u0438\u043a\u043e\u0432, \u0436\u0430\u0436\u0434\u0443\u0449\u0438\u0445 \u0437\u0430\u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043d\u0430\u0448 \u0442\u043e\u0432\u0430\u0440 \u0431\u0435\u0441\u043f\u043b\u0430\u0442\u043d\u043e.<\/p>\n<p>\u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e WalletPay \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u0435\u0442 \u0434\u0432\u0435 \u043e\u043f\u0446\u0438\u0438:<\/p>\n<ul>\n<li>\n<p>\u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u043f\u0440\u0438\u043d\u0430\u0434\u043b\u0435\u0436\u043d\u043e\u0441\u0442\u0438 IP \u0432\u044b\u0437\u043e\u0432\u0430 \u043a \u043f\u0443\u043b\u0443 IP \u0430\u0434\u0440\u0435\u0441\u043e\u0432 WalletPay;<\/p>\n<\/li>\n<li>\n<p>\u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u0445\u0435\u0448\u0430, \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u043e\u0433\u043e \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432\u044b\u0437\u043e\u0432\u0430 \u0432\u0435\u0431\u0445\u0443\u043a\u0430 \u0438 \u0432\u0430\u0448\u0435\u0433\u043e \u043a\u043b\u044e\u0447\u0430 API.<\/p>\n<\/li>\n<\/ul>\n<p>\u0421\u043f\u0438\u0441\u043e\u043a IP \u0430\u0434\u0440\u0435\u0441\u043e\u0432 WalletPay \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 \u0432 <a href=\"https:\/\/docs.wallet.tg\/pay\/#section\/Webhook\" rel=\"noopener noreferrer nofollow\">\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438<\/a>, \u0430 \u0434\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0445\u0435\u0448\u0430 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043a\u043e\u0434.<\/p>\n<pre><code class=\"python\">import base64, hashlib, hmac  ENCODING = 'utf-8'  def is_valid(flask_request):     text = '.'.join([       flask_request.method,  # 'POST'       flask_request.path,  # \u043d\u0443\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0447\u0430\u0441\u0442\u044c \u0430\u0434\u0440\u0435\u0441\u0430 \u0431\u0435\u0437 \u0438\u043c\u0435\u043d\u0438 \u0434\u043e\u043c\u0435\u043d\u0430, '\/tgwallet\/ipn' \u0432 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435       flask_request.headers.get('WalletPay-Timestamp'),       base64.b64encode(flask_request.get_data()).decode(ENCODING),     ])     signature = base64.b64encode(hmac.new(       bytes('YOUR-API-KEY', ENCODING),       msg=bytes(text, ENCODING),       digestmod=hashlib.sha256     ).digest())      return flask_request.headers.get('Walletpay-Signature') == signature.decode(ENCODING) <\/code><\/pre>\n<p>\u0417\u0430\u0442\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044e <code>is_valid<\/code> \u0434\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0432 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0435 \u0432\u0435\u0431\u0445\u0443\u043a\u0430.<\/p>\n<p>\u0421\u043f\u0430\u0441\u0438\u0431\u043e \u0437\u0430 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435.<\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/751848\/\"> https:\/\/habr.com\/ru\/articles\/751848\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<figure class=\"full-width\"><\/figure>\n<p>\u041f\u0440\u0438\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e \u0441\u043e\u043e\u0431\u0449\u0435\u0441\u0442\u0432\u043e.<\/p>\n<p>\u0411\u043e\u0442 Telegram <a class=\"mention\" href=\"\/users\/wallet\">@wallet<\/a> \u043d\u0435\u0434\u0430\u0432\u043d\u043e \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u0438\u043b <a href=\"https:\/\/pay.wallet.tg\/\" rel=\"noopener noreferrer nofollow\">API \u0434\u043b\u044f \u043f\u0440\u0438\u0435\u043c\u0430 \u043f\u043b\u0430\u0442\u0435\u0436\u0435\u0439<\/a> \u0432 \u0441\u0442\u043e\u0440\u043e\u043d\u043d\u0438\u0445 Telegram \u0431\u043e\u0442\u0430\u0445. \u0418\u0437 \u043a\u0440\u0438\u043f\u0442\u043e \u0432\u0430\u043b\u044e\u0442 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u044e\u0442\u0441\u044f BTC, TON, USDT.<\/p>\n<p>\u041d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u0441\u0430\u0439\u0442\u0435, \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0441\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u043e \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u043c\u043e\u043c \u043a API \u0431\u043e\u0442\u0435, \u043f\u0440\u043e\u0439\u0442\u0438 \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u0443 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 (\u0431\u0438\u043e\u043c\u0435\u0442\u0440\u0438\u044f \u0434\u043b\u044f \u0444\u0438\u0437\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u043b\u0438\u0446), \u0434\u043e\u0436\u0434\u0430\u0442\u044c\u0441\u044f \u043e\u0434\u043e\u0431\u0440\u0435\u043d\u0438\u044f \u0437\u0430\u044f\u0432\u043a\u0438 \u0438 \u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0440\u0430\u0437\u043c\u0435\u0440\u0430 \u043a\u043e\u043c\u0438\u0441\u0441\u0438\u0438 \u0434\u043b\u044f \u0432\u0430\u0448\u0438\u0445 \u043f\u043b\u0430\u0442\u0435\u0436\u0435\u0439. \u0423 \u043c\u0435\u043d\u044f \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u0430 \u0437\u0430\u043d\u044f\u043b\u0430 \u0447\u0443\u0442\u044c \u0431\u043e\u043b\u0435\u0435 \u0441\u0443\u0442\u043e\u043a.<\/p>\n<p>\u041f\u043e\u0441\u043b\u0435 \u043e\u0434\u043e\u0431\u0440\u0435\u043d\u0438\u044f \u0437\u0430\u044f\u0432\u043a\u0438 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0435 \u0434\u043e\u0441\u0442\u0443\u043f \u0432 \u043b\u0438\u0447\u043d\u044b\u0439 \u043a\u0430\u0431\u0438\u043d\u0435\u0442, \u0433\u0434\u0435 \u043d\u0443\u0436\u043d\u043e \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u043b\u044e\u0447 \u0434\u043b\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a API WalletPay.<\/p>\n<p>\u041f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0438\u0441\u0442\u0443\u043f\u0430\u0442\u044c \u043a \u043f\u0440\u043e\u0434\u0430\u0436\u0430\u043c. \u041f\u043e\u043a\u0443\u043f\u0430\u0442\u0435\u043b\u044e \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0441\u0441\u044b\u043b\u043a\u0443 \u0434\u043b\u044f \u043e\u043f\u043b\u0430\u0442\u044b \u0447\u0435\u0440\u0435\u0437 WalletPay \u0442\u043e\u0432\u0430\u0440\u043e\u0432\/\u0443\u0441\u043b\u0443\u0433 \u0432\u0430\u0448\u0435\u0433\u043e \u0431\u043e\u0442\u0430. \u041a\u043e\u0434 \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u044d\u0442\u043e\u0439 \u0441\u0441\u044b\u043b\u043a\u0438 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0442\u0430\u043a\u0438\u043c.<\/p>\n<pre><code class=\"python\">import requests  def get_pay_link():     headers = {      'Wpay-Store-Api-Key': 'YOUR-API-KEY',      'Content-Type': 'application\/json',      'Accept': 'application\/json',     }      payload = {       'amount': {         'currencyCode': 'USD',  # \u0432\u044b\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c \u0441\u0447\u0435\u0442 \u0432 \u0434\u043e\u043b\u043b\u0430\u0440\u0430\u0445 \u0421\u0428\u0410         'amount': '1.00',       },       'description': 'Goods and service.',       'externalId': 'XXX-YYY-ZZZ',  # ID \u0441\u0447\u0435\u0442\u0430 \u043d\u0430 \u043e\u043f\u043b\u0430\u0442\u0443 \u0432 \u0432\u0430\u0448\u0435\u043c \u0431\u043e\u0442\u0435       'timeoutSeconds': 60 * 60 * 24,  # \u0432\u0440\u0435\u043c\u044f \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0441\u0447\u0435\u0442\u0430 \u0432 \u0441\u0435\u043a\u0443\u043d\u0434\u0430\u0445       'customerTelegramUserId': '999666999',  # ID \u0430\u043a\u043a\u0430\u0443\u043d\u0442\u0430 Telegram \u043f\u043e\u043a\u0443\u043f\u0430\u0442\u0435\u043b\u044f       'returnUrl': 'https:\/\/t.me\/mybot',  # \u043f\u043e\u0441\u043b\u0435 \u0443\u0441\u043f\u0435\u0448\u043d\u043e\u0439 \u043e\u043f\u043b\u0430\u0442\u044b \u043d\u0430\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u043f\u043e\u043a\u0443\u043f\u0430\u0442\u0435\u043b\u044f \u0432 \u043d\u0430\u0448 \u0431\u043e\u0442       'failReturnUrl': 'https:\/\/t.me\/wallet',  # \u043f\u0440\u0438 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u0438 \u043e\u043f\u043b\u0430\u0442\u044b \u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043f\u043e\u043a\u0443\u043f\u0430\u0442\u0435\u043b\u044f \u0432 @wallet     }      response = requests.post(       \"https:\/\/pay.wallet.tg\/wpay\/store-api\/v1\/order\",       json=payload, headers=headers, timeout=10     )     data = response.json()      if (response.status_code != 200) or (data['status'] not in [\"SUCCESS\", \"ALREADY\"]):         logging.warning(\"# code: %s json: %s\", response.status_code, data)         return ''      return data['data']['payLink'] <\/code><\/pre>\n<p>\u0421\u0447\u0435\u0442 \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c \u0432 \u0434\u043e\u043b\u043b\u0430\u0440\u0430\u0445 \u0421\u0428\u0410, \u0435\u0432\u0440\u043e \u0438\u043b\u0438 \u0440\u0443\u0431\u043b\u044f\u0445. \u041f\u0435\u0440\u0435\u0441\u0447\u0435\u0442 \u0432 BTC, TON, USDT \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d \u043f\u043e \u043a\u0443\u0440\u0441\u0443 WalletPay.<\/p>\n<p>\u0414\u043b\u044f \u043f\u043e\u0434\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0438\u044f \u0444\u0430\u043a\u0442\u0430 \u043e\u043f\u043b\u0430\u0442\u044b \u0441\u0447\u0435\u0442\u0430, WalletPay \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0434\u0432\u0435 \u043e\u043f\u0446\u0438\u0438:<\/p>\n<ul>\n<li>\n<p>\u043f\u0435\u0440\u0438\u043e\u0434\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043e\u043f\u0440\u043e\u0441 <a href=\"https:\/\/docs.wallet.tg\/pay\/#tag\/Order\/operation\/getPreview\" rel=\"noopener noreferrer nofollow\">\u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u0441\u0447\u0435\u0442\u0430<\/a> \u0441 \u0432\u0430\u0448\u0435\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u044b.<\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/docs.wallet.tg\/pay\/#section\/Webhook\" rel=\"noopener noreferrer nofollow\">POST-\u0437\u0430\u043f\u0440\u043e\u0441<\/a> \u043d\u0430 \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0439 \u0432\u0430\u043c\u0438 \u0432 \u043b\u0438\u0447\u043d\u043e\u043c \u043a\u0430\u0431\u0438\u043d\u0435\u0442\u0435 <code>https<\/code> \u0430\u0434\u0440\u0435\u0441 (webhook \u0432 \u0442\u0435\u0440\u043c\u0438\u043d\u0430\u0445 WalletPay).<\/p>\n<\/li>\n<\/ul>\n<p>\u042f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b \u0432\u0442\u043e\u0440\u043e\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442. \u041a\u043e\u0434 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430 \u0432\u0435\u0431\u0445\u0443\u043a\u0430 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0442\u0430\u043a\u0438\u043c.<\/p>\n<pre><code class=\"python\">from flask import Flask, request  app = Flask(__name__)  @app.route('\/tgwallet\/ipn', methods=['POST']) def ipn_tgwallet():     for event in request.get_json():         if event[\"type\"] == \"ORDER_PAID\":             data = event[\"payload\"]             print(\"\u041e\u043f\u043b\u0430\u0447\u0435\u043d \u0441\u0447\u0435\u0442 N {} \u043d\u0430 \u0441\u0443\u043c\u043c\u0443 {} {}. \u041e\u043f\u043b\u0430\u0442\u0430 {} {}.\".format(               data[\"externalId\"],  # ID \u0441\u0447\u0435\u0442\u0430 \u0432 \u0432\u0430\u0448\u0435\u043c \u0431\u043e\u0442\u0435, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u043b\u0438 \u043f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u0441\u0441\u044b\u043b\u043a\u0438 \u0434\u043b\u044f \u043e\u043f\u043b\u0430\u0442\u044b               data[\"orderAmount\"][\"amount\"],  # \u0421\u0443\u043c\u043c\u0430 \u0441\u0447\u0435\u0442\u0430, \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u0430\u044f \u043f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u0441\u0441\u044b\u043b\u043a\u0438 \u0434\u043b\u044f \u043e\u043f\u043b\u0430\u0442\u044b               data[\"orderAmount\"][\"currencyCode\"],  # \u0412\u0430\u043b\u044e\u0442\u0430 \u0441\u0447\u0435\u0442\u0430               data[\"selectedPaymentOption\"][\"amount\"][\"amount\"],  # \u0421\u043a\u043e\u043b\u044c\u043a\u043e \u043e\u043f\u043b\u0430\u0442\u0438\u043b \u043f\u043e\u043a\u0443\u043f\u0430\u0442\u0435\u043b\u044c               data[\"selectedPaymentOption\"][\"amount\"][\"currencyCode\"]  # \u0412 \u043a\u0430\u043a\u043e\u0439 \u043a\u0440\u0438\u043f\u0442\u043e\u0432\u0430\u043b\u044e\u0442\u0435             ))      # \u043d\u0443\u0436\u043d\u043e \u0432\u0441\u0435\u0433\u0434\u0430 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u043a\u043e\u0434 200, \u0447\u0442\u043e\u0431\u044b WalletPay \u043d\u0435 \u0434\u0435\u043b\u0430\u043b \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u044b\u0445 \u0432\u044b\u0437\u043e\u0432\u043e\u0432 \u0432\u0435\u0431\u0445\u0443\u043a\u0430     return 'OK' <\/code><\/pre>\n<p>\u041f\u0440\u0435\u0436\u0434\u0435 \u0447\u0435\u043c \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u043e\u043f\u043b\u0430\u0447\u0435\u043d\u043d\u044b\u0439 \u0442\u043e\u0432\u0430\u0440 \u0438\u043b\u0438 \u0443\u0441\u043b\u0443\u0433\u0443, \u043d\u0443\u0436\u043d\u043e \u0443\u0431\u0435\u0434\u0438\u0442\u044c\u0441\u044f, \u0447\u0442\u043e \u0432\u044b\u0437\u043e\u0432 \u0432\u0435\u0431\u0445\u0443\u043a\u0430 \u043f\u0440\u0438\u0448\u0435\u043b \u0438\u0437 WalletPay, \u0430 \u043d\u0435 \u043e\u0442 \u0437\u043b\u043e\u0443\u043c\u044b\u0448\u043b\u0435\u043d\u043d\u0438\u043a\u043e\u0432, \u0436\u0430\u0436\u0434\u0443\u0449\u0438\u0445 \u0437\u0430\u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043d\u0430\u0448 \u0442\u043e\u0432\u0430\u0440 \u0431\u0435\u0441\u043f\u043b\u0430\u0442\u043d\u043e.<\/p>\n<p>\u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e WalletPay \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u0435\u0442 \u0434\u0432\u0435 \u043e\u043f\u0446\u0438\u0438:<\/p>\n<ul>\n<li>\n<p>\u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u043f\u0440\u0438\u043d\u0430\u0434\u043b\u0435\u0436\u043d\u043e\u0441\u0442\u0438 IP \u0432\u044b\u0437\u043e\u0432\u0430 \u043a \u043f\u0443\u043b\u0443 IP \u0430\u0434\u0440\u0435\u0441\u043e\u0432 WalletPay;<\/p>\n<\/li>\n<li>\n<p>\u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u0445\u0435\u0448\u0430, \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u043e\u0433\u043e \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432\u044b\u0437\u043e\u0432\u0430 \u0432\u0435\u0431\u0445\u0443\u043a\u0430 \u0438 \u0432\u0430\u0448\u0435\u0433\u043e \u043a\u043b\u044e\u0447\u0430 API.<\/p>\n<\/li>\n<\/ul>\n<p>\u0421\u043f\u0438\u0441\u043e\u043a IP \u0430\u0434\u0440\u0435\u0441\u043e\u0432 WalletPay \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 \u0432 <a href=\"https:\/\/docs.wallet.tg\/pay\/#section\/Webhook\" rel=\"noopener noreferrer nofollow\">\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438<\/a>, \u0430 \u0434\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0445\u0435\u0448\u0430 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043a\u043e\u0434.<\/p>\n<pre><code class=\"python\">import base64, hashlib, hmac  ENCODING = 'utf-8'  def is_valid(flask_request):     text = '.'.join([       flask_request.method,  # 'POST'       flask_request.path,  # \u043d\u0443\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0447\u0430\u0441\u0442\u044c \u0430\u0434\u0440\u0435\u0441\u0430 \u0431\u0435\u0437 \u0438\u043c\u0435\u043d\u0438 \u0434\u043e\u043c\u0435\u043d\u0430, '\/tgwallet\/ipn' \u0432 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435       flask_request.headers.get('WalletPay-Timestamp'),       base64.b64encode(flask_request.get_data()).decode(ENCODING),     ])     signature = base64.b64encode(hmac.new(       bytes('YOUR-API-KEY', ENCODING),       msg=bytes(text, ENCODING),       digestmod=hashlib.sha256     ).digest())      return flask_request.headers.get('Walletpay-Signature') == signature.decode(ENCODING) <\/code><\/pre>\n<p>\u0417\u0430\u0442\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044e <code>is_valid<\/code> \u0434\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0432 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0435 \u0432\u0435\u0431\u0445\u0443\u043a\u0430.<\/p>\n<p>\u0421\u043f\u0430\u0441\u0438\u0431\u043e \u0437\u0430 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435.<\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/751848\/\"> https:\/\/habr.com\/ru\/articles\/751848\/<\/a><br \/><\/br><\/br><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-412614","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/412614","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=412614"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/412614\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=412614"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=412614"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=412614"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}