#CameronBryce
1 messages ยท Page 1 of 1 (latest)
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
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.
I already have a solution for you ๐
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
When you create the Checkout, you can specify the metadata directly for the Subscription inside it
not its own metadata
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'])
So, I have this and it seems to be working so far. But when I run a test through my other command, I'll show the result.
@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?
Let confirm if your Subscription actually has the metadata first
Grab your subscription id and search on Dashboard
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.
Np!
This was the original location of the product I was trying, would this be wrong?
Sorry what's wrong?
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.
Okie, for double check, can you give me the Subscription Id? sub_xxx
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.
No we are talking about a Subscription (sub_xxx)
I don't think it's necessary to create a new account
Understood ๐ Where might I find the ID?
Do you have any Ids returns back from your Checkout Session creation request?
any id, is fine
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'])
if you print out data, what would you see?
{
"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"
}
ok I wanted this cs_live_a1UtQbA9dnbccjnKUPTsh86hdUDBEEhES4JDOzpe0JO6zW587FCAnH8Ttl
This is a live mode request. Why don't you use Test mode to test?
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.
Why? Test mode should work and you absolutely should test in Test mode instead
I thought the same thing, they told me they paid each subscription and refunded each time ๐
I'll replace that, for sure.
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
Understood, thank you. I'll do that really quickly.
fyi we have many test cards here https://stripe.com/docs/testing#cards Easiest is 4242 4242 4242 4242
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
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 ๐
Sign in to the Stripe Dashboard to manage business payments and operations in your account. Manage payments and refunds, respond to disputes and more.
I see the metadata
Perfect ๐ Let me go see if the other command works!
You might don't see the result appear in Search API immediately, but give it a try!
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)
Hmm I am not familiar with Search API TBH, but I think it looks good ๐ค
One concern about quote vs double quote
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?
Hmm not sure about the time. Let us know if you wait for too long
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
Sure, don't worry. Another colleague of mine could be here shortly
Awesome, thanks ๐
@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. ๐
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?
@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)
So, the issues before were just me being unfamiliar with stripe and basically following the wrong advice. Here is my entire code.
When a user buys it, they type a command, this command will log the users Discord ID (812809631767986226) in the metadata. Though, I am failing to get the metadata to properly add in the top command.
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?
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)
The payment works and the payment gets confirmed. So, I am doing something wrong with the metadata I believe.
gimme a while to take a look
Okay, thank you for your time ๐
do you have the Checkout Session id? it'll look like cs_test_123
Would this be it?
"id": "cs_test_a1jyhkcGDtWtdiHf0UAXtGhoM64krBJ0VNyTtjHR4PdNGo9O7BNQzk69sx"
yep!
Okay, awesome !
have you made the payment for that checkout session?
Not yet, will do right now!
Okay, done, it was confirmed.
my guess is that you're looking at https://dashboard.stripe.com/test/payments/pi_3LXtopEVpw8aLezp1UWgegM3 to see if the metadata shows?
I'm looking right here currently. The link says 'No such payment_intent: 'pi_3LXtopEVpw8aLezp1UWgegM3''
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
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
onesec, let me finish explaining
For sure ๐
if you want the metadata to appear in the Subscription as well, you need to populate this parameter when creating the Checkout Session : https://stripe.com/docs/api/checkout/sessions/create#create_checkout_session-subscription_data-metadata
try that out and the second command should work
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)
looks correct to me, you can try creating a Checkout Session with that, make payment, and see if that works
Oh, that's how it was already ๐
I think I was reading the metadata wrong, it might actually already be in there
oh, sorry, ๐ตโ๐ซ i missed it too
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)
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
Got it ๐ I'm not sure what else it could be. I'm not very experienced but I can't see it lol
you're searching for sub_1LY1XND8SEVc61tMFWikhpTj?
I'm trying to search for the user id stored. So, in the link you sent above I'm trying to get the 812809631767986226 value returned back
I tried a loop earlier to get all of them to match, I still couldn't get any values. I'm really not sure
hmm
give a me a second to try this out too
i haven't played around much with the Search API yet
Do you think a better API would work for this?
I'm not too experienced, so, it could also just be my error
maybe you can explain more on why you need to search for the subscription? I can suggest some other options (if any)
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. ๐
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
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 ๐
@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}'"