def shipping_callback(update: Update, context: CallbackContext): query = update.shipping_query if query.invoice_payload != 'Custom-Payload': query.answer(ok=False, error_message="Что-то сломалось.") options = list() options.append( ShippingOption('1', 'Shipping Option A', [LabeledPrice('A', 100)])) price_list = [LabeledPrice('B1', 150), LabeledPrice('B2', 200)] options.append(ShippingOption('2', 'Shipping Option B', price_list)) query.answer(ok=True, shipping_options=options)
def shipping_callback(update, context): query = update.shipping_query # check the payload, is this from your bot? if query.invoice_payload != 'Custom-Payload': # answer False pre_checkout_query query.answer(ok=False, error_message="Something went wrong...") return else: options = list() # a single LabeledPrice options.append(ShippingOption('1', 'Shipping Option A', [LabeledPrice('A', 100)])) # an array of LabeledPrice objects price_list = [LabeledPrice('B1', 150), LabeledPrice('B2', 200)] options.append(ShippingOption('2', 'Shipping Option B', price_list)) query.answer(ok=True, shipping_options=options)
def test_answer_shipping_query_errors(self, monkeypatch, bot): shipping_options = ShippingOption(1, 'option1', [LabeledPrice('price', 100)]) with pytest.raises( TelegramError, match='should not be empty and there should not be'): bot.answer_shipping_query(1, True, error_message='Not enough fish') with pytest.raises( TelegramError, match='should not be empty and there should not be'): bot.answer_shipping_query(1, False) with pytest.raises( TelegramError, match='should not be empty and there should not be'): bot.answer_shipping_query(1, False, shipping_options=shipping_options) with pytest.raises( TelegramError, match='should not be empty and there should not be'): bot.answer_shipping_query(1, True)
def test_answer_shipping_query_ok(self, monkeypatch, bot): # For now just test that our internals pass the correct data def test(_, url, data, *args, **kwargs): return data == { 'shipping_query_id': 1, 'ok': True, 'shipping_options': [{ 'title': 'option1', 'prices': [{ 'label': 'price', 'amount': 100 }], 'id': 1 }] } monkeypatch.setattr('telegram.utils.request.Request.post', test) shipping_options = ShippingOption(1, 'option1', [LabeledPrice('price', 100)]) assert bot.answer_shipping_query(1, True, shipping_options=[shipping_options])
def shipping_callback(update: Update, context: CallbackContext) -> None: """Answers the ShippingQuery with ShippingOptions""" query = update.shipping_query # check the payload, is this from your bot? if query.invoice_payload != 'Custom-Payload': # answer False pre_checkout_query query.answer(ok=False, error_message="Something went wrong...") return # First option has a single LabeledPrice options = [ ShippingOption('1', 'Shipping Option A', [LabeledPrice('A', 100)]) ] # second option has an array of LabeledPrice objects price_list = [LabeledPrice('B1', 150), LabeledPrice('B2', 200)] options.append(ShippingOption('2', 'Shipping Option B', price_list)) query.answer(ok=True, shipping_options=options)
async def shipping_callback(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None: """Answers the ShippingQuery with ShippingOptions""" query = update.shipping_query # check the payload, is this from your bot? if query.invoice_payload != "Custom-Payload": # answer False pre_checkout_query await query.answer(ok=False, error_message="Something went wrong...") return # First option has a single LabeledPrice options = [ ShippingOption("1", "Shipping Option A", [LabeledPrice("A", 100)]) ] # second option has an array of LabeledPrice objects price_list = [LabeledPrice("B1", 150), LabeledPrice("B2", 200)] options.append(ShippingOption("2", "Shipping Option B", price_list)) await query.answer(ok=True, shipping_options=options)
def test_equality(self): a = ShippingOption(self.id, self.title, self.prices) b = ShippingOption(self.id, self.title, self.prices) c = ShippingOption(self.id, '', []) d = ShippingOption(0, self.title, self.prices) e = Voice(self.id, 0) assert a == b assert hash(a) == hash(b) assert a is not b assert a == c assert hash(a) == hash(c) assert a != d assert hash(a) != hash(d) assert a != e assert hash(a) != hash(e)
def shipping_callback(bot, update): """ Запрос адреса доставки """ query = update.shipping_query # check the payload, is this from your bot? if query.invoice_payload != 'Custom-Payload': # answer False pre_checkout_query bot.answer_shipping_query(shipping_query_id=query.id, ok=False, error_message="Something went wrong...") return else: options = list() # a single LabeledPrice options.append( ShippingOption('1', 'Бесплатная доставка', [LabeledPrice('Стоимость доставки', 0)])) bot.answer_shipping_query(shipping_query_id=query.id, ok=True, shipping_options=options)
def shipping_option(): return ShippingOption(TestShippingOption.id, TestShippingOption.title, TestShippingOption.prices)