Skip to content

Add both handlers for queries from new Payment API - #631

Merged
tsnoam merged 26 commits into
python-telegram-bot:masterfrom
jeffffc:paymenthandlers
Jun 9, 2017
Merged

Add both handlers for queries from new Payment API#631
tsnoam merged 26 commits into
python-telegram-bot:masterfrom
jeffffc:paymenthandlers

Conversation

@jeffffc

@jeffffc jeffffc commented May 22, 2017

Copy link
Copy Markdown
Contributor

Added PreCheckoutQueryHandler and ShippingQueryHandler

(Re-open after merging #630 to beta branch)

@jsmnbom

jsmnbom commented May 24, 2017

Copy link
Copy Markdown
Member

Oh I'd already handed adding all the needed filters in #622, but no worries, we'll just fix it in the merge I guess. Also it would probably have been better if you'd opened a new PR with all this extra stuff that did not get merged to the beta branch, instead of just piling it on, but we'll figure something out :)
EDIT: sorry, it seems you did commit the other changes to the beta branch, pardon me

@jsmnbom jsmnbom mentioned this pull request Jun 2, 2017
@tsnoam

tsnoam commented Jun 2, 2017

Copy link
Copy Markdown
Member

@jeffffc

  1. Would you mind merging from master?
  2. When (& after) you merge please note the convention we use at functions like answer_shipping_query():
    When checking if an optional parameter was supplied we compare it to None like this:
if ok is not None:
    do_something()

It's an important semantic difference as you might want to know that ok is actually False in contrary to never supplied.

jeffffc added 2 commits June 3, 2017 01:09
# Conflicts:
#	telegram/bot.py
#	telegram/message.py
#	telegram/precheckoutquery.py
#	telegram/shippingquery.py
Merge from master and resolve conflicts
@jeffffc

jeffffc commented Jun 2, 2017

Copy link
Copy Markdown
Contributor Author

@tsnoam I have just resolved the conflicts and merged from master, please do tell me if there is any more problem
and yea it was my first time doing such coding, thanks for the advice, it helps me a lot also

@jsmnbom jsmnbom left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All in all looks good ^^
I've added a few comments in the code

Comment thread telegram/ext/filters.py Outdated

game = _Game()

class _SuccessfulPayment(BaseFilter):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This filter seems to be duplicated as it's been added in another commit too ( see further down)

Comment thread telegram/message.py Outdated
left_chat_participant (:class:`telegram.User`): Use `left_chat_member`
instead.

<<<<<<<<< Temporary merge branch 1

@jsmnbom jsmnbom Jun 2, 2017

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something weird happened here....
I think it can all just be deleted tbh :/

Comment thread tests/test_filters.py
self.assertTrue(Filters.successful_payment(self.message))
self.message.successful_payment = None
self.assertFalse(Filters.successful_payment(self.message))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a test for invoice too? I know you didn't actually add the filter, but i just saw that it was missing.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure, meanwhile please check with the updated codes again, thanks a lot!

@tsnoam tsnoam left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jeffffc
Thank you for your contribution, it is highly appreciated.
I have left several comments on the code. Please take a look. Some of them are nitpicks, but should be quick fixes while you're fixing the more substantial parts.

Comment thread telegram/bot.py Outdated
data['need_name'] = need_name
if need_phone_number is not None:
data['need_phone_number'] = need_phone_number
if need_email:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix to: if need_email is not None

Comment thread telegram/__init__.py
from .shippingquery import ShippingQuery
from .webhookinfo import WebhookInfo
from .gamehighscore import GameHighScore
from .videonote import VideoNote

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick:
why remove here and add above? (I prefer the minimal change in diff...)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's on me... I moved it long ago to fix a circular import issue I had... not sure why it's showing up in this diff though...

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well, what every git voodoo happened here, I prefer it not to be part of this PR

Comment thread telegram/bot.py Outdated
url = '{0]/answerPreCheckoutQuery'.format(self.base_url)

if ((ok is not True and error_message is None) or
(ok is True and error_message is not None)):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In here, for readability I would prefer a shorter form like this:

if not (ok ^ (error_message is None)):

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure i could not think of such short version, thank you

Comment thread telegram/bot.py
raise TelegramError(
'answerPreCheckoutQuery: If ok is True, there should '
'not be error_message; if ok is False, error_message '
'should not be empty')

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Open for discussion:
I don't think that we should raise an exception here. If user wants to do unorthodox things, he might know better than us. At most I would issue a warning here.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning seems better... especially since we don't raise errors anywhere else if arguments are wrong, so it would be a bit strange to do it here imo

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm ok with a warning.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay for this one i believe i checked with the other existing methods beforehand about these mutual exclusive parameters
i raise exception there was because i was following edit_message_caption and similar ones with either inline messages or normal messages
what do you guys think?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tsnoam @bomjacob what do you guys think about this?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm.. you seen to be correct... I don't really have a preference either way then... It's your call @tsnoam

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jeffffc
lol... edit_message_caption exception is my doing. lets keep it that way.

Comment thread telegram/ext/precheckoutqueryhandler.py Outdated

def check_update(self, update):
if isinstance(update, Update) and update.pre_checkout_query:
return True

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

too long.... this would be sufficient:

return isinstance(update, Update) and update.pre_checkout_query

Comment thread telegram/ext/shippingqueryhandler.py Outdated

def check_update(self, update):
if isinstance(update, Update) and update.shipping_query:
return True

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comments like above (too long....)

Comment thread telegram/message.py

left_chat_participant (:class:`telegram.User`): Use `left_chat_member`
instead.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please don't remove that line.

Comment thread telegram/precheckoutquery.py Outdated
total_amount (int): Total price in the smallest units of the currency (integer)
invoice_payload (str): Bot specified invoice payload

Keyword Args:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are not Keyword Args in the sense of how documentation is generated. Please remove.
Also, bot is missing from the docstring, please add it..

Comment thread telegram/update.py Outdated
chosen_inline_result=None,
callback_query=None,
shipping_query=None,
pre_checkout_query=None,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For backward compatibility (if some1 for any reason, decided to use Update directly) please add the new parameters to the end (just before **kwargs).

@tsnoam tsnoam left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed some of my comments. They were wrong.

@tsnoam

tsnoam commented Jun 7, 2017

Copy link
Copy Markdown
Member

@jeffffc
I'm sorry for the delay in my response, I had several busy days.
I responded to your question above.

@jeffffc

jeffffc commented Jun 8, 2017

Copy link
Copy Markdown
Contributor Author

@tsnoam It's alright!
and @bomjacob I pushed the fixes already, please have a brief check, thanks!

@tsnoam

tsnoam commented Jun 9, 2017

Copy link
Copy Markdown
Member

LGTM. Waiting for travis before merging.

@tsnoam
tsnoam merged commit da8a3ce into python-telegram-bot:master Jun 9, 2017
@tsnoam

tsnoam commented Jun 9, 2017

Copy link
Copy Markdown
Member

@jeffffc
Thank you for your contribution.

@jeffffc

jeffffc commented Jun 10, 2017

Copy link
Copy Markdown
Contributor Author

great, thank you all ;)

@github-actions github-actions Bot locked and limited conversation to collaborators Aug 23, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants