Как интегрировать платежную систему в telegram bot на java?
Я пишу telegram bot на языке java и пытаясь внедрить систему оплаты. Я столкнулся с некоторыми проблемами, а именно: В основном все платежные провайдеры (Юкасса, Тинкофф, Сбербанк и тд) не имеют API для java, и иза этой проблемы возникает слудующая, более локальная, это payments 2.0 от телеграм. Моя попытка вставить эта в мой код увенчалась провалом, которая скорее всего связана с моей рассеянностью и невнимательностью. Вставив пример кода payment в свой, меня ожидали одни ошибки связанные с SendResponse, bot.execute, chatID, pay() и тп. Они помечены красным, а их природу и причину я не знаю.
Помогите пожалуйста решением этой проблемы, уже неделю с этим мучаюсь.
Вот весь код бота:
`
public void onUpdateReceived(Update update)
{
if (update.hasMessage() && update.getMessage().hasText()) {
String textLine = update.getMessage().getText();
long chat_id = update.getMessage().getChatId();
if ((textLine == null) || (textLine.length() < 1))
textLine = MagicStrings.null_input;
String request = textLine;
///////Just for Log memes :p Disabled by default
if (MagicBooleans.trace_mode)
System.out.println("STATE=" + request + ":THAT=" + ((History) chatSession.thatHistory.get(0)).get(0) + ":TOPIC=" + chatSession.predicates.get("topic"));
else if (request.equals("/start")) {
response=" ";
SendMessage message = new SendMessage() // Create a message object object
.setChatId(chat_id)
.setText("Hello!");
// Create ReplyKeyboardMarkup object
ReplyKeyboardMarkup keyboardMarkup = new ReplyKeyboardMarkup();
keyboardMarkup.setResizeKeyboard(true);
// Create the keyboard (list of keyboard rows)
List<KeyboardRow> keyboard = new ArrayList<>();
// Create a keyboard row
KeyboardRow row = new KeyboardRow();
// Set each button, you can also use KeyboardButton objects if you need something else than text
row.add("/Email");
row.add("/Buy");
// Add the first row to the keyboard
keyboard.add(row);
keyboardMarkup.setKeyboard(keyboard);
// Add it to the message
message.setReplyMarkup(keyboardMarkup);
try {
sendMessage(message); // Sending our message object to user
} catch (TelegramApiException e) {
e.printStackTrace();
}
}
else if(request.contains("/Email") ||request.contains("/Buy")) {
{
response=" ";
if (update.getMessage().getText().equals("/Email")) {
SendMessage message = new SendMessage() // Create a message object object
.setChatId(chat_id)
.setText("Thank you so much for leaving feedback on me. It means a lot to my creators and to me.");
InlineKeyboardMarkup markupInline = new InlineKeyboardMarkup();
List<List<InlineKeyboardButton>> rowsInline = new ArrayList<>();
List<InlineKeyboardButton> rowInline = new ArrayList<>();
rowInline.add(new InlineKeyboardButton().setUrl("https://mail.google.com").setCallbackData("Feed Back").setText("Email"));
// Set the keyboard to the markup
rowsInline.add(rowInline);
// Add it to the message
markupInline.setKeyboard(rowsInline);
message.setReplyMarkup(markupInline);
try {
sendMessage(message); // Sending our message object to user
} catch (TelegramApiException e) {
e.printStackTrace();
}
}
}if (update.getMessage().getText().equals("/Buy")) {
SendMessage message = new SendMessage(); // Create a message object object
SendResponse response = bot.execute(new SendInvoice(chatID, "title", "desc", "my_payload",
"284685063:TEST:NThlNWQ3NDk0ZDQ5", "my_start_param", "USD", new LabeledPrice("label", 200))
.providerData("{\"foo\" : \"bar\"}")
.photoUrl("https://telegram.org/img/t_logo.png").photoSize(100).photoHeight(100).photoWidth(100)
.needPhoneNumber(true).needShippingAddress(true).needEmail(true).needName(true)
.isFlexible(true)
.replyMarkup(new InlineKeyboardMarkup(new InlineKeyboardButton[]{
new InlineKeyboardButton("just pay").pay(),
new InlineKeyboardButton("google it").url("www.google.com")
}))
);
InvoiceCheck.check(response.message().invoice());
}
try {
sendMessage(message); // Sending our message object to user
} catch (TelegramApiException e) {
e.printStackTrace();
}}
} else if (update.hasCallbackQuery()) {
// Set variables
String call_data = update.getCallbackQuery().getData();
long message_id = update.getCallbackQuery().getMessage().getMessageId();
long chat_id1 = update.getCallbackQuery().getMessage().getChatId();
response=" ";
if (call_data.equals("Email")) {
String answer = "Updated message text";
EditMessageText new_message = new EditMessageText()
.setChatId(chat_id1)
.setMessageId(toIntExact(message_id))
.setText(answer);
try {
editMessageText(new_message);
} catch (TelegramApiException e) {
e.printStackTrace();
}
}
}else if(request.equals("/help"))
{
response="What's wrong man? ";
}
else
{
response = chatSession.multisentenceRespond(request);
if(response.contains("<"))
{
response="Sorry, there was some error! ";
}
}
SendMessage message = new SendMessage().setChatId(chat_id).setText(response);
try {
execute(message);
}
catch (TelegramApiException e)
{
e.printStackTrace();
}
}
}
public String getBotUsername()
{
return "Talk_to_me_Bot";
}
@Override
public String getBotToken()
{
return "170925sdzxfhcgvfgcdxy34567-sdvhgsdcwcw";
}
private static String getResourcesPath()
{
File currDir = new File(".");
String path = currDir.getAbsolutePath();
path = path.substring(0, path.length() - 2);
System.out.println(path);
String resourcesPath = path + File.separator + "src" + File.separator + "main" + File.separator + "resources";
return resourcesPath;
}
} `