#some1ataplace_api

1 messages ¡ Page 1 of 1 (latest)

tough citrusBOT
thorny sedgeBOT
#

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.

tough citrusBOT
#

👋 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.

marble olive
#

Hi there!

deft haven
#

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?

marble olive
#

Right, I'm pulling up the coupon's details right now just to be sure

#

Yep, that's it

deft haven
#

so what do i do to fix it?

marble olive
#

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?

deft haven
#

Yes, I have a cart with many items and prices so they all vary

marble olive
#

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?

deft haven
#

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

marble olive
#

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

deft haven
#

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,
}],

marble olive
#

Pay close attention to syntax and the docs here.

deft haven
#

It makes me believe what I did the first time was what the docs said

marble olive
#

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,
}]

deft haven
#

ooh

#

Why would I use product_data then?

marble olive
#

You wouldn't. You should only use product_data if you want to create a brand-new one-time Product with this Session.

deft haven
#

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

marble olive
#

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)

deft haven
#

interesting

marble olive
#

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

deft haven
#

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

marble olive
#

It really depends on what you want to do, if you expect to be able to use those Products later

deft haven
#

They all vary though, a user could donate X amount

marble olive
#

Using product_data works just fine but you'll run into thins with Coupons like you did with the earlier request

deft haven
#

Coupons will not work with donations in my case

marble olive
#

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

deft haven
#

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,
}],

marble olive
#

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

deft haven
#

okay, just making sure. Idk I am confused about product versus product_data.

marble olive
#

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

deft haven
#

right

#

okay I will keep playing around and see what happens. Thanks for all the help. What time is discord open to each day?

marble olive
#

We are typically open Monday mornings in Singapore time to Friday evenings in Pacific time. If we're not open, you'll see a message stating as such in #dev-help