Add both handlers for queries from new Payment API#631
Add both handlers for queries from new Payment API#631tsnoam merged 26 commits intopython-telegram-bot:masterfrom jeffffc:paymenthandlers
Conversation
# Conflicts: # telegram/__init__.py # telegram/message.py
* add handlers for new payment API * fix typo * fix docstring mistakes * added missing 'from_user'
bugfixes added payment-related handlers
|
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 |
It's an important semantic difference as you might want to know that |
# Conflicts: # telegram/bot.py # telegram/message.py # telegram/precheckoutquery.py # telegram/shippingquery.py
Merge from master and resolve conflicts
|
@tsnoam I have just resolved the conflicts and merged from master, please do tell me if there is any more problem |
jsmnbom
left a comment
There was a problem hiding this comment.
All in all looks good ^^
I've added a few comments in the code
telegram/ext/filters.py
Outdated
|
|
||
| game = _Game() | ||
|
|
||
| class _SuccessfulPayment(BaseFilter): |
There was a problem hiding this comment.
This filter seems to be duplicated as it's been added in another commit too ( see further down)
telegram/message.py
Outdated
| left_chat_participant (:class:`telegram.User`): Use `left_chat_member` | ||
| instead. | ||
|
|
||
| <<<<<<<<< Temporary merge branch 1 |
There was a problem hiding this comment.
Something weird happened here....
I think it can all just be deleted tbh :/
| self.assertTrue(Filters.successful_payment(self.message)) | ||
| self.message.successful_payment = None | ||
| self.assertFalse(Filters.successful_payment(self.message)) | ||
|
|
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
sure, meanwhile please check with the updated codes again, thanks a lot!
tsnoam
left a comment
There was a problem hiding this comment.
@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.
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: |
There was a problem hiding this comment.
Please fix to: if need_email is not None
| from .shippingquery import ShippingQuery | ||
| from .webhookinfo import WebhookInfo | ||
| from .gamehighscore import GameHighScore | ||
| from .videonote import VideoNote |
There was a problem hiding this comment.
nitpick:
why remove here and add above? (I prefer the minimal change in diff...)
There was a problem hiding this comment.
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...
There was a problem hiding this comment.
well, what every git voodoo happened here, I prefer it not to be part of this PR
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)): |
There was a problem hiding this comment.
In here, for readability I would prefer a shorter form like this:
if not (ok ^ (error_message is None)):
There was a problem hiding this comment.
sure i could not think of such short version, thank you
| raise TelegramError( | ||
| 'answerPreCheckoutQuery: If ok is True, there should ' | ||
| 'not be error_message; if ok is False, error_message ' | ||
| 'should not be empty') |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Hmm.. you seen to be correct... I don't really have a preference either way then... It's your call @tsnoam
There was a problem hiding this comment.
@jeffffc
lol... edit_message_caption exception is my doing. lets keep it that way.
|
|
||
| def check_update(self, update): | ||
| if isinstance(update, Update) and update.pre_checkout_query: | ||
| return True |
There was a problem hiding this comment.
too long.... this would be sufficient:
return isinstance(update, Update) and update.pre_checkout_query
telegram/ext/shippingqueryhandler.py
Outdated
|
|
||
| def check_update(self, update): | ||
| if isinstance(update, Update) and update.shipping_query: | ||
| return True |
There was a problem hiding this comment.
same comments like above (too long....)
|
|
||
| left_chat_participant (:class:`telegram.User`): Use `left_chat_member` | ||
| instead. | ||
|
|
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: |
There was a problem hiding this comment.
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..
telegram/update.py
Outdated
| chosen_inline_result=None, | ||
| callback_query=None, | ||
| shipping_query=None, | ||
| pre_checkout_query=None, |
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
I removed some of my comments. They were wrong.
|
@jeffffc |
|
LGTM. Waiting for travis before merging. |
|
@jeffffc |
|
great, thank you all ;) |
Added PreCheckoutQueryHandler and ShippingQueryHandler
(Re-open after merging #630 to beta branch)