#some1ataplace_api
1 messages ¡ Page 1 of 1 (latest)
Below are links to other discussions we've had with you in the past week in case you want to review that information. If your question is related to one of these previous discussions, please provide a comprehensive summary of the current state and what you need help with now. We help many users simultaneously, so a summary allows us to resolve your issue as soon as possible.
- some1ataplace_api, 35 minutes ago, 11 messages
- some1ataplace_api, 2 hours ago, 23 messages
đ Welcome to your new thread!
â˛ď¸ We'll be here soon! We typically respond in a few minutes, but in some cases we might need a bit more time (e.g., server's busy, you've got a complex question, etc.).
âąď¸ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can start a new thread if you have another question.
đ This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1257802560551649485
đ Have more to share? Add details, code, screenshots, videos, etc. below.
Hi there!
Hi
I think because the coupon code applies to a specific product on stripe it did not work because I did not specify the product in checkout?
Right, I'm pulling up the coupon's details right now just to be sure
Yep, that's it
so what do i do to fix it?
The Coupon applies to items within a specific product only. The Checkout Session uses product_data , which means a new Product is being created in line
I see you're also passing price_data when creating the Checkout Session. This means you're also creating a new one-time Price in this case. Is this what you want?
Yes, I have a cart with many items and prices so they all vary
To be clear, will any other customers add those same items later? If so, I recommend creating Products and Prices first, then using those IDs to create the Checkout Session. Does that make sense?
Would I have to add a product ID somewhere?
line_items=[{
'price_data': {
'currency': 'usd',
'unit_amount': converted_amount,
'product_data': {
'name': 'Order'
},
},
'quantity': 1,
}],
Yes, more than 1 user could buy a cart product. Like a course for example. But in my case, they can only buy it once.
They can buy more than 1 course at the same time though
Yes, you can add a Product ID as the value of line_items.price_data.product: https://docs.stripe.com/api/checkout/sessions/create#create_checkout_session-line_items-price_data-product
If you want the coupon to apply, you'll need to use the Product ID that applies to this coupon
However, if you do this, each Checkout Session you create this way will have a unique Price ID. Those Price IDs will not be reusable since passing price_data creates a one-time Price object that is immediately archived
That is okay. I just need a way to separate Course Orders (from the cart) and Course membership subscriptions since they are technically 2 different products
Request req_0zs4kx6TyQwM8V: You may only specify one of these parameters: product, product_data.
line_items=[{
'price_data': {
'currency': 'usd',
'unit_amount': converted_amount,
'product': 'prod_QOyoxotb51dTbo',
'product_data': {
'name': 'Order'
},
},
'quantity': 1,
}],
Request req_neBlhftkzyISUN: Received unknown parameter: line_items[0][price_data][product_data][product]
line_items=[{
'price_data': {
'currency': 'usd',
'unit_amount': converted_amount,
'product_data': {
'name': 'Order',
'product': 'prod_QOyoxotb51dTbo',
},
},
'quantity': 1,
}],
Pay close attention to syntax and the docs here.
It makes me believe what I did the first time was what the docs said
product requires a string and product_data is not needed
line_items=[{
'price_data': {
'currency': 'usd',
'unit_amount': converted_amount,
'product': 'prod_QOyoxotb51dTbo',
},
'quantity': 1,
}]
You wouldn't. You should only use product_data if you want to create a brand-new one-time Product with this Session.
hmm so what would an example be of product_data?
So if the many users could buy one or more courses as a one time payment (but can only buy a course once, and once they own it, they cannot buy again), I would use product not product_data?
What you wrote worked btw
You would use product_data if you don't need to use that product ever again or if it doesn't matter to you to keep a product catalog in Stripe (e.g., if you only really care about the Session's amount)
interesting
Since you're working with coupons/discounts that apply to specific Products, you should always create a Product first then use that Product ID for any Sessions
I wonder what I am doing for my 1 time donations...
Ah I am using product_data for that tooo.. but I probably should not be, right?
A user could make a 1 time donation or make a recurring donation
hmm but I havee a donation product with many different prices
It really depends on what you want to do, if you expect to be able to use those Products later
They all vary though, a user could donate X amount
Using product_data works just fine but you'll run into thins with Coupons like you did with the earlier request
Coupons will not work with donations in my case
It sounds like you probably want to use price_data since the amount could be variable so you always create a new one-time price, but maybe create a single "Product" for donations or a specific type of donations or whatever fits your use case for categories of prices
This is what I have, does it seem right?
1 time donations:
submit_type='donate',
line_items=[{
'price_data': {
'currency': 'usd',
'unit_amount': converted_amount,
'product_data': {
'name': 'Donation'
},
},
'quantity': 1,
}],
And this too:
Subscription donations:
stripe_donation_product_id = settings.STRIPE_DONATION_PRODUCT_ID
price = stripe.Price.create(
product=stripe_donation_product_id,
unit_amount=converted_amount,
currency='usd',
recurring={'interval': interval,},)
checkout_session = stripe.checkout.Session.create(
success_url=request.build_absolute_uri(reverse('donate:stripe_success')) + '?session_id={CHECKOUT_SESSION_ID}',
cancel_url=request.build_absolute_uri(reverse('donate:stripe_cancelled')),
#payment_method_types=['card'],
customer=customer_id,
mode="subscription",
line_items=[{
'price': price,
'quantity':1,
}],
What do you mean by "right" exactly? Both of these will work
One-time donations will result in the creation of a brand new Price object and a brand new Product object. You're creating a brand new Price with price_data and a brand new price with product_data
okay, just making sure. Idk I am confused about product versus product_data.
With donations, you seem to be creating a Price first (price) that belongs to an existing Product (stripe_donation_product_id) and using this to create the Session