#🔒 Variable problem

64 messages · Page 1 of 1 (latest)

wispy mountain
#

I have a status variable that has different states, but I need that when this variable equals "succeeded" a response is sent with the text "Your order number"

tidal runeBOT
#

@wispy mountain

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

chilly patio
#

instead of changing this status variable, why not call a function to do this?

#

you can have the function update the status as well if you still need that

brisk loom
#

What's the context here? Are threads being used?

wispy mountain
wispy mountain
#

I cant understand

brisk loom
#

Can you share the code you've written?

wispy mountain
#
@bot.hybrid_command()
async def test(ctx: commands.Context, value, description):
    payment = Payment.create({
        "amount": {
            "value": value,
            "currency": "RUB"
        },
        "confirmation": {
            "type": "redirect",
            "return_url": "https://discord.com/channels/1218919938442395669/1218942092643143712"
        },
        "capture": True,
        "description": description
    }, uuid.uuid4())
    confirmation_url = payment.confirmation.confirmation_url
    link_button = Button(
        style=discord.ButtonStyle.link,
        label="Перейти к оплате",
        url=confirmation_url,
    )
    # Create a view to hold the button
    orderview = View()
    orderview.add_item(link_button)
    await ctx.send("Оплатите здесь, чтобы создать заказ", ephemeral=True, view=orderview)
    Payment.capture(payment_id=payment.id)
brisk loom
#

Ah, discord.

wispy mountain
#

!paste

brisk loom
#

Where's your state variable?

#

Are you waiting for a payment succeed event?

wispy mountain
wispy mountain
brisk loom
#

And what sets that variable?

wispy mountain
brisk loom
#

Can you share the Payment class?

#

Do you handle payments, or use a third party?

wispy mountain
brisk loom
#

is the payment service using a callback url?

wispy mountain
#

I just don't really understand what you're talking about

#

I can send you a library API

brisk loom
#

yes

#

!pip

tidal runeBOT
#
Missing required argument

package

brisk loom
#

Use that if it's a package from pypi

tidal runeBOT
brisk loom
#

I can't access that site

wispy mountain
brisk loom
#

I'm on a corporate laptop

#

The VPN is to work

wispy mountain
brisk loom
#

no.

wispy mountain
#

How i can show you a class?

brisk loom
#

Anyway, the return url probably wants a site you control, not discord.

#

you can handle the callback by setting something in a service like redis or rabbitmq. You can use aioredis to wait for an event to be set.

#

!pip aioredis

tidal runeBOT
wispy mountain
#

Status sets automaticaly without any code.

brisk loom
#

is Payment.capture blocking?

brisk loom
tidal runeBOT
#

Python client for Redis database and key-value store

Released on <t:1713892326:D>.

wispy mountain
brisk loom
#

My first thought is to use asyncio.Event

wispy mountain
#

I'll be gone for 15 minutes

#

Sorry

brisk loom
#

You'll need to inspect how Payment.capture works to set the status variable.

wispy mountain
brisk loom
#

using requests?

wispy mountain
# brisk loom using `requests`?

Example of the object

{
  "id": "2419a771-000f-5000-9000-1edaf29243f2",
  "status": "pending",
  "paid": false,
  "amount": {
    "value": "100.00",
    "currency": "RUB"
  },
  "confirmation": {
    "type": "redirect",
    "confirmation_url": "https://yoomoney.ru/api-pages/v2/payment-confirm/epl?orderId=2419a771-000f-5000-9000-1edaf29243f2"
  },
  "created_at": "2019-03-12T11:10:41.802Z",
  "description": "Заказ №37",
  "metadata": {
    "order_id": "37"
  },
  "recipient": {
    "account_id": "100500",
    "gateway_id": "100700"
  },
  "refundable": false,
  "test": false
}
#

How you can see the object have a status

brisk loom
#

if there's no callback url, keep querying it until it says success

#

I'm not familiar with the api and can't access the docs. Do they have any examples?

wispy mountain
wispy mountain
wispy mountain
brisk loom
#

no idea.

tidal runeBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.