-
Notifications
You must be signed in to change notification settings - Fork 5.9k
Add both handlers for queries from new Payment API #631
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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.
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
telegram/ext/filters.py
Outdated
|
|
||
| game = _Game() | ||
|
|
||
| class _SuccessfulPayment(BaseFilter): |
There was a problem hiding this comment.
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)
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.
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 :/
| 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.
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.
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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.
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.
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
| from .shippingquery import ShippingQuery | ||
| from .webhookinfo import WebhookInfo | ||
| from .gamehighscore import GameHighScore | ||
| from .videonote import VideoNote |
There was a problem hiding this comment.
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...)
There was a problem hiding this comment.
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...
There was a problem hiding this comment.
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
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.
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)):
There was a problem hiding this comment.
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
| 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.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
|
|
||
| def check_update(self, update): | ||
| if isinstance(update, Update) and update.pre_checkout_query: | ||
| return True |
There was a problem hiding this comment.
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
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.
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....)
| left_chat_participant (:class:`telegram.User`): Use `left_chat_member` | ||
| instead. | ||
There was a problem hiding this comment.
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.
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.
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..
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.
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
left a comment
There was a problem hiding this comment.
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.
|
@jeffffc |
|
LGTM. Waiting for travis before merging. |
|
@jeffffc |
|
great, thank you all ;) |
Added PreCheckoutQueryHandler and ShippingQueryHandler
(Re-open after merging #630 to beta branch)