rubenlagus / TelegramBots

Java library to create bots using Telegram Bots API
https://telegram.me/JavaBotsApi
MIT License
4.78k stars 1.22k forks source link

Payments API #254

Closed denred0 closed 6 years ago

denred0 commented 7 years ago

Hi!

I try to use payments API. I catch error:

июн 19, 2017 1:07:33 PM org.telegram.telegrambots.logging.BotLogger severe
SEVERE: BOTSESSION
java.lang.NullPointerException
    at org.telegram.telegrambots.api.methods.send.SendInvoice.validate(SendInvoice.java:354)
    at contactBot.botCreator2.handleIncomingMessage(botCreator2.java:229)
    at contactBot.botCreator2.onUpdateReceived(botCreator2.java:71)
    at org.telegram.telegrambots.updatesreceivers.DefaultBotSession$HandlerThread.run(DefaultBotSession.java:274)

Below my code:

List<LabeledPrice> price = new List<LabeledPrice>();
price.add(new LabeledPrice("label", 10000));

SendInvoice inv = new SendInvoice(Integer.parseInt(message.getChatId().toString()), "Hello", "Hello", "111", "#########:TEST:###", "StartParam", "RUB", price);
try {
    inv.validate();
} catch (TelegramApiValidationException e2) {
    e2.printStackTrace();
}
try {
    sendInvoice(inv);
} catch (TelegramApiException e1) {
    e1.printStackTrace();
}

Do you have example code of payments or where is my mistake? Thank you!

rubenlagus commented 7 years ago

Better if you just fix your line:

List<LabeledPrice> price = new List<LabeledPrice>();

You can not create an instance of an interface

denred0 commented 7 years ago

Thanks for fast answer.

Now works, but image not displayed. I use direct link (I try use gdrive links also) Please, give me advice about correct use setPhotoUrl. Below my code:

SendInvoice inv = new SendInvoice(Integer.parseInt(message.getChatId().toString()), "Hello", "Hello", "111", "#########:TEST:###", 
      "StartParam", "RUB", price).setPhotoUrl("https://1fichier.com/?m1grvfz34i");

Result: 0c7f2c85-56bd-46c5-b4df-b79c3acd31d9

Thank you!

rubenlagus commented 7 years ago

Check your image, it doesn't point to an image/jpeg file.

denred0 commented 7 years ago

Why? If go to link https://1fichier.com/?m1grvfz34i downloaded .jpg file. Or I dont understand...

rubenlagus commented 7 years ago

But it is not a correct image/jpeg:

image

denred0 commented 7 years ago

Another link with image/jpeg content-type. https://drive.google.com/uc?export=download&id=0BydBkApd9R5PQWdlQTcwWDh4SjA

Invoice disaplayed with white image also. When I click on image for display it on screen a catch error:

org.telegram.telegrambots.exceptions.TelegramApiRequestException: Error getting updates: [409] Conflict: terminated by other long poll or webhook
    at org.telegram.telegrambots.api.methods.updates.GetUpdates.deserializeResponse(GetUpdates.java:119)
    at org.telegram.telegrambots.updatesreceivers.DefaultBotSession$ReaderThread.run(DefaultBotSession.java:208)
rubenlagus commented 7 years ago

https://github.com/rubenlagus/TelegramBots/wiki/Errors-Handling#terminated-by-other-long-poll-or-webhook

denred0 commented 7 years ago

Sorry for stupid error((

Now error is dissapear, but image still white. When I tap on image it loaded endless. I test my internet connection - all works, I test invoice in bot @shopbot - image is displayed.

Its very strange. I dont understand whats wrong.

rubenlagus commented 7 years ago

@DenisWpk still no way to show the images? Have you tried using some random image from internet as a test?

denred0 commented 7 years ago

Hi! I try to use different image hosting but there is no result. The image is still white (

EXL commented 7 years ago

Same bug. Images are white on mobile, but normal on the desktop client.

Any suggestions? Thanks.

EXL commented 7 years ago

@DenisWpk

@shopbot - image is displayed

I tested now @shopbot on Android client and image in the invoice is not displayed. But on Desktop client all OK. Maybe there is a bug in Android client of Telegram?

Android: screenshot_2017-07-09-22-08-09

Desktop: screenshot_20170709_221502

minecraft8997 commented 6 years ago

plz give me full working code