#mattc
1 messages · Page 1 of 1 (latest)
No, you can add as many prices as you want to a product
perfect - there are many its an apartment with many prices for different nights
If you are changing it per night, you might find it easier to only create the Product and then use the price_data hash to define a one time price each time you charge
One product for the apartment and a price for each night
so 365 prices on one product?
But the price doesn't need to be its own Price object, you can just define it per Checkout Session or Invoice
ah k so i dont need to create a price each time or lookup a price
Can you tell me more about how you want to charge for this apartment? Will every single night cost a different amount?
i can simple add a price each checkout without an item existing
not every night but it may get updated closer to dates if still available
so it will fluctuate
So yes, in that case it might be easier to use this parameter instead of creating a new Price object yourself every night. https://stripe.com/docs/api/checkout/sessions/create#create_checkout_session-line_items-price_data
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
same as a one time item - https://stripe.com/docs/payments/checkout/migrating-prices?locale=en-GB
Correct
these properties dont look to exist
Name = "T-shirt",
Description = "Comfortable cotton t-shirt",
Amount = 2000,
Currency = "usd",
in namespace Stripe.Checkout
What section of that doc are you looking at?
Description is on the Product
Amount is now UnitAmount
under Server-side code for inline items
Currency should still exist on the PriceData
.net example
The red sections meant that that is deprecated
Use the code from the green section
does this mean no product will be create when its price data in effect
in the portal
and its dynamic
Correct, if you provide a pre-defined product we won't create a new product
You can also create one-time products with the product_data hash, but here it will probably make more sense to use a pre-made Product object if this is always the same thing
so for example i have an apartment and one price for one night and another price for another night
should i always use price data
Yes. Unless you are in a situation where the room will always be one of three pre-defined prices it will probably make sense to just use one-time prices
one time prices means price_data?
It sounds like here you are calculating the price each night right? In that case one time prices will be the easiest to work with
Correct. One time prices means price_data
yes i am calculating
then there is a cleaning cost
should cleaning cost be a product with a price
and night prices be price data in effect then
in my list or SessionLineItemOptions
You can do it either way. Having it be a separate Product might make the cost breakdown clearer
as in a separate product for every booking?
something like this
think i need to go with something like this
can you apply a discount for checkout too?
i.e over 30 days 20% discount applied
You can do a separate product each time if you want. Either would work
Yes Checkout supports discounts. Are you trying to add the discount to the session via the API or to allow your users to add the code themselves?
i think maybe too many products
i would apply it
say for a month booking 20%
of nightly rate
You can specify the coupon or promotion code in the discounts hash when creating your Checkout Session https://stripe.com/docs/api/checkout/sessions/create#create_checkout_session-discounts
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
Right
so 20% of the nightly price for 30 days and cleaning fee is standard and no discount
this is possible?
Yes, though in this case it would be easier to have the apartment be its own product. You can create a coupon that only works for certain products https://stripe.com/docs/api/coupons/create#create_coupon-applies_to-products
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
So that would be easy to do for a pre-defined product, but you cannot create a discount ahead of time that will only work for a product_data product
And you can set the coupon to work for a whole month https://stripe.com/docs/api/coupons/create#create_coupon-duration_in_months
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
product_data cant apply a discount?
so i could effectively end up with 365 products?
So if you want the coupon to apply to the room rate but not cleaning then you will need to use pre-defined Product object
one for each day?
More than that, we will create a new object each session
wont this be unmanagable
So if you rent it more than 365 times then Checkout will keep creating products
Yes, so you should not use the product_data hash and should instead create one Product object per apartment
one product for each booking
or one product with multiple prices?
as in product 1 - apartment 1 for 5th July - 10th July/ product 2 - apartment 1 for 11th July - 20th July
or product 1 - apartment 1
price 1 - 5th July to 10 July - £300
price 2 - 11 July - 20th july - £500
The way that I would do it is product 1 -> apartment 1 and then a new price per booking
ok and i can apply the discount this way also right?
to the nightly price
i.e 30 days booking 20% discount to nighly rate and then standard cleaning fee £50
Yes, you could create a 20% off coupon with a one month duration that only applies to the apartment product
ok
so one product multiple prices
apply discount to price
rather than product right?
i.e. product 1 is apartment 1
user books thirty days - add a price - 01/07/2023-30/07/2023 and apply a discount to this price?
apply discount to price
rather than product right?
Discounts can only be restricted by product. The API reference shows this https://stripe.com/docs/api/coupons/create#create_coupon-applies_to-products
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
No
i thought i passed in the price id to the sessionlineitemsoption
You can but that is irrelevant to how the discount works
I thought you wanted to charge an apartment fee and a cleaning fee but only have the 20% discount apply to the apartment fee
For that you will want the apartment fee and cleaning fee to be separate products
thats correct
You can create a 20% coupon that applies specifically to the apartment fee product
That will work regardless of whether you use the price_data hash or whether you create prices and pass in their IDs
do i can use a coupon with price_data
You don't
cant?
You can, just not how you are describing
So here is the link I sent earlier https://stripe.com/docs/api/checkout/sessions/create#create_checkout_session-discounts
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
Notice that the discounts property is at the top level of that call. It applies to the entire Checkout Session
And remember that coupons only apply to specific products
I was just explaining how that wouldn't work
I think you need to read the docs that I sent you
Yes
I would reccommend testing your code to check how it works though
We can't verify too much just by looking at it
ok hows the coupon link to the product id?
Please read the docs that I send you https://stripe.com/docs/api/coupons/create#create_coupon-applies_to-products
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
ok will do thanks for your help
would you recommend doing lookups on prices and updates in case another user did not complete checkout
and an update if the price has changed
or just double up and add the price again
Unfortunately the prices on Checkout Sessions can't be updated. You would need to delete the old one and create a new one. How often will your prices change like this?
I am unclear on this new scenario, can you give me an example of how the price might change and what you would want to do there?
ok so user a goes to checkout 01/06/2023-10/06/2023 for £400
doesnt complete
user b comes back and 01/06/2023-10/06/2023 prices have changed as its 3 weeks later
Checkout Sessions only last for 24 hours, so you will have to create a new Session if they come back more than a day later
and a new price object right?
as the existing price object that i created will not longer be valid
or update the existing price item?
Yes it will need to be a new Price object. If you created it with price_data then the old one will already be invalid
i cant use price_data right
as i may need to apply a discount
discounts dont work with price_data right
or you saying bets to use price_data if there is no discount
i.e. user 1 comes along wants to book apartment 1 for 30 days - i want to apply a 20% discount
they dont complete
user 2 comes along 30 days for the same dates and the prices have changed
i basically need to store the details locally right for the dates and see if i already have a product then validate the price and if updated update right?
Discounts work with price_data prices as long as the price_data uses a product that the discount applies to
ok you have any exampl eof this
No, just use your code but with price_data instead of price
how does the discount get applied to price data
i can see that the coupon is applied to the product
So in our system Products have a one to many relationship with prices
You create one or more Price for each Product
A Price must have a product
If the price is for a product that the discount applies to, then the discount applies to that price
It does not matter whether you made the price directly or via price_data
The discount will apply either way
If you test this code out I think it will all become much clearer
like this?
i get this error - Stripe.StripeException: 'You may only specify one of these parameters: product, product_data.'
👋 taking over
What does the error tell you? 🙂
Does the error say price data or product data?
product_data
i thought - A Price must have a product
how do i specify a product when using productdata
Yup, but you're setting a "product" and "product_data" in your price_data parameter
You must choose one
if i choose product data how do i apply a discount
this is part i am little unsure on
If the price is for a product that the discount applies to, then the discount applies to that price
It does not matter whether you made the price directly or via price_data
The discount will apply either way
if i use price_data how do i apply the discount to the price_data
It does not matter whether you made the price directly or via price_data
The discount will apply either way
it doesn't matter, correct.
If you use price_data then you associate it to a product by passing in a product id to the product parameter (instead of using product_data)
ok
if i use
can i change the description dynamically or not
i.e. from 15/06/2023 to 20/06/2023
No, you can't change the description dynamically in that case
If you use price_data then you associate it to a product by passing in a product id to the product parameter (instead of using product_data)
i thought i couild not have product and product_data
ok i am unclear what this means -
If you use price_data then you associate it to a product by passing in a product id to the product parameter (instead of using product_data)
did you test the code you shared in the last screenshot?
yes i wanted description to read like on product_data
but then cant seem to associate a discount
i get this -
Okay so applying the discount works at this point right?
I feel like you're going in circles trying to solve unrelated issues
yes but like description to read like this
with the discount
its clear then the property name, dates and discount applied
Yeah you won't be able to have the discount apply and create a product using product_data at the same time.
Ignore the custom field suggestion, that won't work
Yup
ok
You can customize the success page with the name, dates etc
https://stripe.com/docs/payments/checkout/custom-success-page
ok
thanks for your help
be a nice addition in future
to be able to customise description using a product id
you can see my point with no dates -
at checkout
Totally understand. You can file a feature request by writing in to our support via
https://support.stripe.com/?contact=true
That way you should also be able to check back if there were any updates on that
ok perfect will do
Appreciate your patience! 🙂 Good luck
i just drop an email for a feature request?
yup
would recommend providing context on your usecase so its easier for the team to understand
ok support chat or sales?
support
api integration?
yup
Hmm I don't think discord supports that unfortunately.
You'd likely want to summarize in your own words