国外三大支付paypal,braintree,stripe,有兴趣可以去了解一下他们的区别。电报机器人支持Strip,也是官方推荐使用平台。

Stripe官方网站: https://stripe.com/

测试VISA
卡号:4242 4242 4242 4242
到期日期:01/50(本源-丹·布朗)
CVC:050

电报机器人: https://t.me/MeekLionBot
# -*- coding: utf-8 -*-
# telegram_bot_payment.py
# 测试银行
# 卡号:4242 4242 4242 4242
# 到期日期:01/50(本源-丹·布朗)
# CVC:050


import logging
from telegram import LabeledPrice, ShippingOption
from telegram.ext import CommandHandler, MessageHandler, Filters, PreCheckoutQueryHandler, ShippingQueryHandler


def start_callback(bot, update):
msg = "Use /shipping to get invoice for shipping-payment,"
msg += "or /noshipiing for an invoice without shipping."
update.message.reply_text(msg)


def start_with_shipping_callback(bot, update):
chat_id = update.message.chat_id
title = "需要快递服务支付"
description = "Payment Example using python-telegram-bot"
payload = "Custom-Payload"
provider_token = '284685063:TEST:N2Y5MGQ2NjJhMjVh'
start_parameter = 'test-payment'
currency = 'USD'
price = 1
prices = [LabeledPrice("Test", price*100)]
bot.send_invoice(chat_id, title, description, payload, provider_token, start_parameter, currency, prices,
need_name=True, need_phone_number=True, need_email=True, need_shipping_address=True, is_flexible=True)


def start_without_shipping_callback(bot, update):
chat_id = update.message.chat_id
title = "不要发货支付"
description = "Payment Example using python-telegram-bot"
payload = "Custom-Payload"
provider_token = '284685063:TEST:N2Y5MGQ2NjJhMjVh'
start_parameter = 'test-payment'
currency = 'USD'
price = 1
prices = [LabeledPrice("Test", price*100)]
bot.send_invoice(chat_id, title, description, payload, provider_token, start_parameter, currency, prices)


def shipping_callback(bot, update):
query = update.shipping_query
logging.info('shipping_callback query: %s' % query)
if query.invoice_payload != 'Custom-Payload':
bot.answer_shipping_query(update.shipping_query.id, ok=False, error_message="Something went wrong...")
else:
options = list()
options.append(ShippingOption('1', "Shipping Option A", [LabeledPrice('A', 100)]))
options.append(ShippingOption('2', 'Shipping Option B', [LabeledPrice('B1', 150), LabeledPrice('B2', 200)]))
bot.answer_shipping_query(update.shipping_query.id, ok=True, shipping_options=options)


def precheckout_callback(bot, update):
query = update.pre_checkout_query
if query.invoice_payload != 'Custom-Payload':
query.answer(ok=False, error_message="Something went wrong...")
else:
query.answer(ok=True)


def successful_payment_callback(bot, update):
logging.info('successful_payment_callback message: %s' % update.message)

update.message.reply_text("Thank you for you payment!")


def start_bot_payment(dispatcher):
logging.info('start_dfa_payment')

dispatcher.add_handler(CommandHandler("start", start_callback))
dispatcher.add_handler(CommandHandler("shipping", start_with_shipping_callback))
dispatcher.add_handler(CommandHandler("noshipping", start_without_shipping_callback))
dispatcher.add_handler(ShippingQueryHandler(shipping_callback))
dispatcher.add_handler(PreCheckoutQueryHandler(precheckout_callback))
dispatcher.add_handler(MessageHandler(Filters.successful_payment, successful_payment_callback))

# -*- coding: utf-8 -*-
# telegram_bot_jobs.py

import logging
from telegram.ext import Updater
from datetime import datetime

import telegram_bot_payment


def error(bot, update, err):
logging.error('bot : %s update : %s error : %s' % (bot, update, err))


def echo(bot, update):
logging.info("bot : %s chat_id:%d text:%s" % (bot, update.message.chat_id, update.message.text))


def start_bot():
try:
start_time = datetime.now() # 获取当前datetime
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO)

# 温顺的莱昂
updater = Updater(token='739344882:AAF_BMyjc7S45nado1dK5E6sMt-0jYH5VMA')
dp = updater.dispatcher
dp.add_error_handler(error)

# #6 电报机器人-Stripe支付
telegram_bot_payment.start_bot_payment(dp)

updater.start_polling()
logging.info('telegram bot updater start_polling...')
updater.idle()

end_time = datetime.now() # 获取当前datetime
logging.info('花费时间:%f秒' % (end_time - start_time).total_seconds())
except BaseException as start_bot_ex:
logging.error("telegram_bot_jobs ex : %s" % start_bot_ex)


发表评论

电子邮件地址不会被公开。 必填项已用*标注