#CameronBryce

1 messages ยท Page 1 of 1 (latest)

lavish fog
#

The metadata on Checkout Session is different than metadata on Subsciption

#

You can think metadata could be on any object, and Checkout and Subscription are different objects

viral folio
#

Ohh alright. I'm still a bit new, thanks for clearing that up ๐Ÿ™‚
Do you mind if I post my code here and you can see what could be possibly fixed with this?

#

I've been editing it for a few, trying to understand what might be the issue.

lavish fog
#

I already have a solution for you ๐Ÿ™‚

#

When you create the Checkout, you can specify the metadata directly for the Subscription inside it

#

not its own metadata

viral folio
#

Oh I apologize, I have that one currently ๐Ÿ˜‚
I must've explained it horribly.

I have a session created from that and I'm having issues retrieving the metadata at a later point.

#
@bot.slash_command(guild_ids=guild_ids, description='Test Description')
async def stripe_payment(interaction : Interaction):

    client_name_id = interaction.user.id
    stripe.api_key = key.stripe_key

    data = stripe.checkout.Session.create(
    success_url="xxx",
    cancel_url="xxx",
    line_items=[
        {
        "price": "price_1LTyehD8SEVc61tM5UJmROdQ",
        "quantity": 1,
        },
    ],
        subscription_data={
                    'metadata': {
                        'user_id': client_name_id
                    },
                },
    mode="subscription",
    )

    print(data['url'])
viral folio
#
@bot.slash_command(guild_ids=guild_ids, description='Test Description')
async def test_cmd(interaction : Interaction):
    client_name_id = interaction.user.id
    stripe.api_key = key.stripe_key

    data = stripe.Subscription.search(
        query = f"status: 'active' AND metadata['user_id']:'{client_name_id}'"
    )

    print(data)
#

CONSOLE OUTPUT

{
  "data": [],
  "has_more": false,
  "next_page": null,
  "object": "search_result",
  "url": "/v1/subscriptions/search"
}

I'm unsure why the response from this doesn't have any data?

lavish fog
#

Let confirm if your Subscription actually has the metadata first

#

Grab your subscription id and search on Dashboard

viral folio
#

I believe I got the right part pulled up. I tried to search it and it pulled up this page. I entered the metadata manually, does that effect anything?

#

Ah, I might've found what might be the issue

#

I found the subscription tab, I was using a regular 'product' I believe. Sorry, I'm really new to using Stripe.

lavish fog
#

Np!

viral folio
#

This was the original location of the product I was trying, would this be wrong?

lavish fog
#

Sorry what's wrong?

viral folio
#

Oh wait, I got it backwards again. I think that's fine ๐Ÿ˜‚ ๐Ÿ˜ญ

#

Okay, so, I think I have it setup properly.

#

To confirm, I went to subscriptions and payment links and it shows it.

#

I'm using an external site integrated with Stripe which manages it with me, so, it's a mess with "products" so, just trying to figure it out. I believe it's properly setup now.

lavish fog
#

Okie, for double check, can you give me the Subscription Id? sub_xxx

viral folio
#

Right, now I'm doubting myself again ๐Ÿ˜‚
Would it be this at the top right?
prod_MCNPKRZrS2m4yS

#

If it would be easier, I can set this up on a brand new account. This one is cluttered. If you could take me through setting it up or if you just have a video you can link.

lavish fog
#

No we are talking about a Subscription (sub_xxx)

#

I don't think it's necessary to create a new account

viral folio
#

Understood ๐Ÿ™‚ Where might I find the ID?

lavish fog
#

Do you have any Ids returns back from your Checkout Session creation request?

#

any id, is fine

viral folio
#

I have something through the metadata being called user_id which collects when they enter a command.

    client_name_id = interaction.user.id
    stripe.api_key = key.stripe_key

    data = stripe.checkout.Session.create(
    success_url="xxx",
    cancel_url="xxx",
    line_items=[
        {
        "price": "price_1LTyehD8SEVc61tM5UJmROdQ",
        "quantity": 1,
        },
    ],
        subscription_data={
                    'metadata': {
                        'user_id': client_name_id
                    },
                },
    mode="subscription",
    )
    print(data['url'])
lavish fog
#

if you print out data, what would you see?

viral folio
#
{
  "after_expiration": null,
  "allow_promotion_codes": null,
  "amount_subtotal": 1000,
  "amount_total": 1000,
  "automatic_tax": {
    "enabled": false,
    "status": null
  },
  "billing_address_collection": null,
  "cancel_url": "https://discord.gg/KAUYX3Pk7m",
  "client_reference_id": null,
  "consent": null,
  "consent_collection": null,
  "currency": "usd",
  "customer": null,
  "customer_creation": "always",
  "customer_details": null,
  "customer_email": null,
  "expires_at": 1660884309,
  "id": "cs_live_a1UtQbA9dnbccjnKUPTsh86hdUDBEEhES4JDOzpe0JO6zW587FCAnH8Ttl",
  "livemode": true,
  "locale": null,
  "metadata": {},
  "mode": "subscription",
  "object": "checkout.session",
  "payment_intent": null,
  "payment_link": null,
  "payment_method_collection": "always",
  "payment_method_options": null,
  "payment_method_types": [
    "card"
  ],
  "payment_status": "unpaid",
  "phone_number_collection": {
    "enabled": false
  },
  "recovered_from": null,
  "setup_intent": null,
  "shipping": null,
  "shipping_address_collection": null,
  "shipping_options": [],
  "shipping_rate": null,
  "status": "open",
  "submit_type": null,
  "subscription": null,
  "success_url": "https://discord.gg/KAUYX3Pk7m",
  "total_details": {
    "amount_discount": 0,
    "amount_shipping": 0,
    "amount_tax": 0
  },
  "url": "https://checkout.stripe.com/pay/cs_live_a1UtQbA9dnbccjnKUPTsh86hdUDBEEhES4JDOzpe0JO6zW587FCAnH8Ttl#fidkdWxOYHwnPyd1blppbHNgWjA0TnxqaWpBPVZAU2YzNHFIT3ZAYlNkU01%2FYGdxfDV1X0g9dzBgdVdGcVBKT1FdMzVpZ0pJfWB8SWZmcWpcdWxvQlJwS3BHTjBpRkl%2FY25vM1dpRFNpT1xONTVRMDVIXF1VYScpJ2N3amhWYHdzYHcnP3F3cGApJ2lkfGpwcVF8dWAnPyd2bGtiaWBabHFgaCcpJ2BrZGdpYFVpZGZgbWppYWB3dic%2FcXdwYHgl"
}
lavish fog
#

ok I wanted this cs_live_a1UtQbA9dnbccjnKUPTsh86hdUDBEEhES4JDOzpe0JO6zW587FCAnH8Ttl

#

This is a live mode request. Why don't you use Test mode to test?

viral folio
#

I was told by another developer that the test mode doesn't work for what I wanted.
I'm guessing it does, I can definitely replace the key if so.

lavish fog
#

Why? Test mode should work and you absolutely should test in Test mode instead

viral folio
#

I'll replace that, for sure.

lavish fog
#

Okie

#

So this session is created but haven't been paid yet, right? And that's why a subscription hasn't been created

#

You want to create a Test mode Checkout Session, open its URL in the browser, use a Stripe Test card to pay

#

then after that, the Subscription will be created

viral folio
#

Understood, thank you. I'll do that really quickly.

lavish fog
#

they paid each subscription and refunded each time
I don't know the motivation but this sounds bad since you lost Stripe fee per each transaction. Refunding doesn't give fee back

viral folio
#

Awesome, I'll make sure to use that. And yeah, it didn't make any sense to me at all. I didn't pay at all with my card normally though.

And I did the test mode demo, the payment was successful.
"id": "cs_test_a17uYWS3YLj3Sffhbqscg3QHtq3jD43GwJyJAAoSXa5jiOzWCNQTTMVyao",

#

Let me go check the metadata now, thanks again ๐Ÿ™‚

lavish fog
#

I see the metadata

viral folio
#

Perfect ๐Ÿ˜„ Let me go see if the other command works!

lavish fog
#

You might don't see the result appear in Search API immediately, but give it a try!

viral folio
#

Yeah, it didn't show up just yet. The response is still empty in the data. If you don't mind, you're a far more experienced dev than me, would this command work normally when it registers? Just to confirm ๐Ÿ˜„

    client_name_id = interaction.user.id
    stripe.api_key = key.stripe_key

    data = stripe.Subscription.search(
        query = f"status: 'active' AND metadata['user_id']:'{client_name_id}'"
    )
    print(data)
lavish fog
#

Hmm I am not familiar with Search API TBH, but I think it looks good ๐Ÿค”

#

One concern about quote vs double quote

viral folio
#

Yeah, my buddy sent me this. I had the same question but I figured it was just something that needed to be added. The Stripe API is basically the last feature I'm aiming to add, needed some help with it lol

#

I will def fix that

#

(same person who paid and refunded their card 10x btw) ๐Ÿ˜„

#

I do appreciate the help, I'll fix it and see how it all works

#

So, does the metadata register in under 5m normally?

lavish fog
#

Hmm not sure about the time. Let us know if you wait for too long

viral folio
#

Okay, I went ahead and deleted it and am gonna try it again.
Do you mind if I leave this open and mess with it some?

I'd rather check into it vs asking you questions every other second lol
I don't' wanna waste your time

lavish fog
#

Sure, don't worry. Another colleague of mine could be here shortly

viral folio
#

Awesome, thanks ๐Ÿ™‚

viral folio
#
@bot.slash_command(description="Test Description")
async def test_payment(interaction : Interaction):

    client_name_id = interaction.user.id
    stripe.api_key = key.stripe_key

    data = stripe.checkout.Session.create(
    success_url="xxx",
    cancel_url="xxx",
    line_items=[
        {
        "price": "price_1LTyXFD8SEVc61tMCBGWGNg5",
        "quantity": 1,
        },
    ],
        subscription_data={
                    "metadata": {
                        "user_id": client_name_id
                    },
                },
    mode="subscription",
    )
    print(data)

So, I went through and it seemed to upload the metadata but I believe that was from earlier, when I was messing with it. I'm unsure what might be wrong with the code. I ran it a few times and waited a bit. Do you have any idea if there's something wrong?

There isn't any error codes. It just isn't posting the metadata, the rest seems to work perfectly. I'm unsure what I'm doing wrong. ๐Ÿ˜…

hollow venture
#

hi there, stepping in on behalf of orakaro. If you don't mind, could you summarize what's the issue you're having? Is it that you ran the code, but when you use the Search API, you aren't able to get any results?

viral folio
#
@bot.slash_command(description="Test Description")
async def test_payment(interaction : Interaction):

    client_name_id = interaction.user.id
    stripe.api_key = key.stripe_key

    data = stripe.checkout.Session.create(
    success_url="xxx",
    cancel_url="xxx",
    line_items=[
        {
        "price": "price_1LTyXFD8SEVc61tMCBGWGNg5",
        "quantity": 1,
        },
    ],
        subscription_data={
                    "metadata": {
                        "user_id": client_name_id
                    },
                },
    mode="subscription",
    )
    print(data)

@bot.slash_command(description="Test Description")
async def test_metadata(interaction : Interaction):
    client_name_id = interaction.user.id
    stripe.api_key = key.stripe_key

    data = stripe.Subscription.search(
        query=f"status:"active" AND metadata["user_id"]: {client_name_id}",
    )

    print(data)
viral folio
hollow venture
#

when you say you're failing to get the metadata to properly add in the top command - what do you mean by failing - are you seeing an error? and what is the top command you're referring to?

viral folio
# hollow venture when you say you're failing to get the metadata to properly add in the top comma...

Sorry, I'll try to make it more specific ๐Ÿ˜„
So, by failing, I mean it's just not adding. There isn't any error codes and when I view it on the dashboard, it shows no metadata after 5m. And as for the top command, it's just his one right here.

@bot.slash_command(description="Test Description")
async def test_payment(interaction : Interaction):

    client_name_id = interaction.user.id
    stripe.api_key = key.stripe_key

    data = stripe.checkout.Session.create(
    success_url="xxx",
    cancel_url="xxx",
    line_items=[
        {
        "price": "price_1LTyXFD8SEVc61tMCBGWGNg5",
        "quantity": 1,
        },
    ],
        subscription_data={
                    "metadata": {
                        "user_id": client_name_id
                    },
                },
    mode="subscription",
    )
    print(data)
viral folio
hollow venture
#

gimme a while to take a look

viral folio
#

Okay, thank you for your time ๐Ÿ˜„

hollow venture
#

do you have the Checkout Session id? it'll look like cs_test_123

viral folio
hollow venture
#

yep!

viral folio
#

Okay, awesome !

hollow venture
#

have you made the payment for that checkout session?

viral folio
viral folio
hollow venture
viral folio
hollow venture
#

okay, let me explain to clear things up

#

so when you add metadata to the Checkout Session

#

the metadata is created on the Checkout Session object

#

that page which you're looking at is the Product page

#

you shouldn't be looking at the Product page to find the metadata of a Checkout Session

viral folio
#

Understood ๐Ÿ˜„ I tried the search as well, it didn't return anything, I figured that this would show. There might be an issue with my 2nd command then?

#

I'll go grab it and see

hollow venture
#

onesec, let me finish explaining

viral folio
#

For sure ๐Ÿ™‚

hollow venture
#

try that out and the second command should work

viral folio
#

Okay, got it. I believe I have that already, or am I misunderstanding?

    data = stripe.checkout.Session.create(
    success_url="xx",
    cancel_url="xx",
    line_items=[
        {
        "price": "price_1LTyXFD8SEVc61tMCBGWGNg5",
        "quantity": 1,
        },
    ],
        subscription_data={
                    "metadata": {
                        "user_id": client_name_id
                    },
                },
    mode="subscription",
    )
    print(data)
hollow venture
#

looks correct to me, you can try creating a Checkout Session with that, make payment, and see if that works

viral folio
#

Oh, that's how it was already ๐Ÿ˜„

#

I think I was reading the metadata wrong, it might actually already be in there

hollow venture
#

oh, sorry, ๐Ÿ˜ตโ€๐Ÿ’ซ i missed it too

viral folio
#

So, instead of my 1st command being wrong, since you explained you can't view it form the dashboard, I figured my 2nd command might be having issues then, not that one.

@bot.slash_command(guild_ids=guild_ids, description="Test Description")
async def test_metadata(interaction : Interaction):
    client_name_id = interaction.user.id
    stripe.api_key = key.stripe_key

    data = stripe.Subscription.search(
        query=f"status:'active' AND metadata['user_id']:{client_name_id}",
    )

    print(data)
hollow venture
viral folio
#

Ohhhh let me look

#

SWEET okay, it is working. So, it is the 2nd command I believe.

hollow venture
#

how about you try searching for something older to see if it works?

#

i'm wondering if the search API is a bit laggy

#

it sometimes happens

viral folio
#

Got it ๐Ÿ˜„ I'm not sure what else it could be. I'm not very experienced but I can't see it lol

hollow venture
#

you're searching for sub_1LY1XND8SEVc61tMFWikhpTj?

viral folio
#

I tried a loop earlier to get all of them to match, I still couldn't get any values. I'm really not sure

hollow venture
#

hmm

#

give a me a second to try this out too

#

i haven't played around much with the Search API yet

viral folio
#

Do you think a better API would work for this?
I'm not too experienced, so, it could also just be my error

hollow venture
#

maybe you can explain more on why you need to search for the subscription? I can suggest some other options (if any)

viral folio
#

So, if you're familiar with Discord bots, I am wanting to let users buy a premium version of mine. So, you'd just type /premium and if you buy it, it would mark the guild that the user is in as 'paid' for example. Then, all the commands would work.

#

Hopefully that makes sense.

So right now, I have the id of the user/guild being logged into the metadata, I'd have the Search API confirm if they're subscribed for the commands to work.

#

If it's a huge hassle, it's not an issue. One of my buddies figured it out and I can just annoy him to show me in a few days. ๐Ÿ˜„

hollow venture
#

the way you're doing it now is the way i'd go about it too

#

i'm juggling a couple of other questions right now, but if you're still around later, i can try it on my end also to see if there's anything wrong

viral folio
#

For sure, it's pretty late anyway. I am really new to stripe which I'm sure doesn't help as well. Plus, I am still a new developer, I can't piece all of it together so I don't wanna hold you up if you're busy. Lol Either way, I appreciate the time ๐Ÿ˜„

hollow venture
#

@viral folio the problem is with

"status:'active' AND metadata['user_id']:{client_name_id}"

This is coming through to Stripe as https://dashboard.stripe.com/test/logs/iar_KbUcmmIRwvLFvJ

"status:'active' AND metadata['user_id']: 812809631767986226"

it should probably be like below. You're missing the single quotes around the {client_name_id}

"status:'active' AND metadata['user_id']:'{client_name_id}'"